StoreService.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\models\wechat;
  3. use app\models\wechat\StoreServiceLog as ServiceLogModel;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. /**
  7. * 客服管理 model
  8. * Class StoreProduct
  9. * @package app\models\store
  10. */
  11. class StoreService extends BaseModel
  12. {
  13. /**
  14. * 数据表主键
  15. * @var string
  16. */
  17. protected $pk = 'id';
  18. /**
  19. * 模型名称
  20. * @var string
  21. */
  22. protected $name = 'store_service';
  23. use ModelTrait;
  24. protected function getAddTimeAttr($value)
  25. {
  26. if ($value) return date('Y-m-d H:i:s', $value);
  27. return $value;
  28. }
  29. /**
  30. * @param $mer_id
  31. * @return array
  32. */
  33. public static function getList($where)
  34. {
  35. $model = new self;
  36. $model = $model->where('mer_id', $where['mer_id'])->order('id desc');
  37. $count = $model->count();
  38. $list = $model->page((int)$where['page'], (int)$where['limit'])
  39. ->select()
  40. ->each(function ($item) {
  41. $item['wx_name'] = WechatUser::where(['uid' => $item['uid']])->value('nickname');
  42. });
  43. return compact('count', 'list');
  44. }
  45. /**
  46. * 获取聊天记录用户
  47. * @param $now_service
  48. * @param $mer_id
  49. * @return array|null
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. public static function getChatUser($now_service, $mer_id, $page, $limit)
  55. {
  56. $chat_list = ServiceLogModel::field("uid,to_uid")->where('mer_id', $mer_id)->where('to_uid|uid', $now_service["uid"])->group("uid,to_uid")->select();
  57. if (count($chat_list) > 0) {
  58. $chat_list = $chat_list->toArray();
  59. $arr_user = $arr_to_user = [];
  60. foreach ($chat_list as $key => $value) {
  61. array_push($arr_user, $value["uid"]);
  62. array_push($arr_to_user, $value["to_uid"]);
  63. }
  64. $uids = array_merge($arr_user, $arr_to_user);
  65. $uids = array_flip(array_flip($uids));
  66. $uids = array_flip($uids);
  67. unset($uids[$now_service["uid"]]);
  68. $uids = array_flip($uids);
  69. if (!count($uids)) return null;
  70. return WechatUser::field("uid,nickname,headimgurl")
  71. ->page((int)$page, (int)$limit)
  72. ->whereIn('uid', $uids)
  73. ->select()
  74. ->toArray();
  75. }
  76. return null;
  77. }
  78. }