StoreService.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\model\wechat;
  3. use app\admin\model\wechat\StoreServiceLog as ServiceLogModel;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. /**
  7. * 客服管理 model
  8. * Class StoreProduct
  9. * @package app\admin\model\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. /**
  25. * @param $mer_id
  26. * @return array
  27. */
  28. public static function getList($mer_id)
  29. {
  30. return self::page(self::where('mer_id', $mer_id)->order('id desc'), function ($item) {
  31. $item['wx_name'] = WechatUser::where(['uid' => $item['uid']])->value('nickname');
  32. });
  33. }
  34. /**
  35. * 获取聊天记录用户
  36. * @param $now_service
  37. * @param $mer_id
  38. * @return array|null
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. public static function getChatUser($now_service, $mer_id)
  44. {
  45. $chat_list = ServiceLogModel::field("uid,to_uid")->where('mer_id', $mer_id)->where('to_uid|uid', $now_service["uid"])->group("uid,to_uid")->select();
  46. if (count($chat_list) > 0) {
  47. $chat_list = $chat_list->toArray();
  48. $arr_user = $arr_to_user = [];
  49. foreach ($chat_list as $key => $value) {
  50. array_push($arr_user, $value["uid"]);
  51. array_push($arr_to_user, $value["to_uid"]);
  52. }
  53. $uids = array_merge($arr_user, $arr_to_user);
  54. $uids = array_flip(array_flip($uids));
  55. $uids = array_flip($uids);
  56. unset($uids[$now_service["uid"]]);
  57. $uids = array_flip($uids);
  58. if (!count($uids)) return null;
  59. return WechatUser::field("uid,nickname,headimgurl")->whereIn('uid', $uids)->select()->toArray();
  60. }
  61. return null;
  62. }
  63. }