StoreServiceRecordDao.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\message\service;
  12. use app\dao\BaseDao;
  13. use app\model\message\service\StoreServiceRecord;
  14. /**
  15. * Class StoreServiceRecordDao
  16. * @package app\dao\message\service
  17. */
  18. class StoreServiceRecordDao extends BaseDao
  19. {
  20. /**
  21. * StoreServiceRecordDao constructor.
  22. */
  23. public function __construct()
  24. {
  25. $this->deleteWeekRecord();
  26. }
  27. /**
  28. * 设置模型
  29. * @return string
  30. */
  31. protected function setModel(): string
  32. {
  33. return StoreServiceRecord::class;
  34. }
  35. /**
  36. * 删除上周游客记录
  37. */
  38. protected function deleteWeekRecord()
  39. {
  40. $this->search(['time' => 'last week', 'timeKey' => 'update_time', 'is_tourist' => 1])->delete();
  41. }
  42. /**
  43. * 获取客服聊天用户列表
  44. * @param array $where
  45. * @param int $page
  46. * @param int $limit
  47. * @param array $with
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getServiceList(array $where, int $page, int $limit, array $with = [])
  54. {
  55. return $this->search($where)->page($page, $limit)->when(count($with), function ($query) use ($with) {
  56. $query->with($with);
  57. })->order('update_time desc')->select()->toArray();
  58. }
  59. /**
  60. * 查询最近和用户聊天的uid用户
  61. * @param array $where
  62. * @param string $key
  63. * @return array|\think\Model|null
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. public function getLatelyMsgUid(array $where, string $key)
  69. {
  70. return $this->search($where)->order('update_time DESC')->value($key);
  71. }
  72. }