ChatTeamUser.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Repositories;
  3. use App\Exceptions\TencentImException;
  4. use App\Models\ChatTeam;
  5. use App\Services\TencentImGroupService;
  6. use App\Services\TencentImMessage;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Repositories\Repository;
  9. use GuzzleHttp\Exception\GuzzleException;
  10. use Illuminate\Pagination\LengthAwarePaginator;
  11. class ChatTeamUser extends Repository
  12. {
  13. public $group_id;
  14. public $to_user_id;
  15. public function __construct($group_id)
  16. {
  17. $this->group_id = $group_id;
  18. }
  19. /**
  20. * 查询表格数据
  21. *
  22. * @param Grid\Model $model
  23. * @return LengthAwarePaginator
  24. */
  25. public function get(Grid\Model $model)
  26. {
  27. $currentPage = $model->getCurrentPage();
  28. $perPage = $model->getPerPage();
  29. $data =new TencentImGroupService();
  30. try {
  31. $res = $data->getGroupMemberInfo($this->group_id);
  32. if (!empty($res)) {
  33. ChatTeam::query()->where(['GroupId'=>$this->group_id])->update(['MemberCount'=>$res['MemberNum']]);
  34. return $model->makePaginator($res['MemberNum'],$res['MemberList']);
  35. }
  36. } catch (TencentImException | GuzzleException $e) {
  37. return $e->getMessage();
  38. }
  39. }
  40. }