StoreServiceRecordDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\service;
  12. use app\dao\BaseDao;
  13. use app\model\service\StoreServiceRecord;
  14. /**
  15. * Class StoreServiceRecordDao
  16. * @package app\dao\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 array $data
  46. * @return \crmeb\basic\BaseModel
  47. */
  48. public function updateOnline(array $where, array $data)
  49. {
  50. return $this->getModel()->whereNotIn('to_uid', $where['notUid'])->update($data);
  51. }
  52. /**
  53. * 获取客服聊天用户列表
  54. * @param array $where
  55. * @param int $page
  56. * @param int $limit
  57. * @param array $with
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. */
  63. public function getServiceList(array $where, int $page, int $limit, array $with = [])
  64. {
  65. return $this->search($where)->page($page, $limit)->when(count($with), function ($query) use ($with) {
  66. $query->with($with);
  67. })->order('update_time desc')->select()->toArray();
  68. }
  69. /**
  70. * 查询最近和用户聊天的uid用户
  71. * @param array $where
  72. * @param string $key
  73. * @return array|\think\Model|null
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function getLatelyMsgUid(array $where, string $key)
  79. {
  80. return $this->search($where)->order('update_time DESC')->value($key);
  81. }
  82. }