StoreServiceLogDao.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace app\common\dao\store\service;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\store\service\StoreServiceLog;
  6. use think\db\BaseQuery;
  7. /**
  8. * Class StoreServiceLogDao
  9. * @package app\common\dao\store\service
  10. * @author xaboy
  11. * @day 2020/5/29
  12. */
  13. class StoreServiceLogDao extends BaseDao
  14. {
  15. /**
  16. * @return string
  17. * @author xaboy
  18. * @day 2020/5/29
  19. */
  20. protected function getModel(): string
  21. {
  22. return StoreServiceLog::class;
  23. }
  24. /**
  25. * @param $merId
  26. * @param $uid
  27. * @return int
  28. * @throws \think\db\exception\DbException
  29. * @author xaboy
  30. * @day 2020/6/16
  31. */
  32. public function userRead($merId, $uid)
  33. {
  34. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->where('type', '<>', 1)->update(['type' => 1]);
  35. }
  36. /**
  37. * @param $uid
  38. * @param $merId
  39. * @return bool
  40. * @author xaboy
  41. * @day 2020/6/16
  42. */
  43. public function issetLog($uid, $merId)
  44. {
  45. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->where('send_type', 0)->limit(1)->count() > 0;
  46. }
  47. /**
  48. * @param $merId
  49. * @param $uid
  50. * @param $serviceId
  51. * @return int
  52. * @throws \think\db\exception\DbException
  53. * @author xaboy
  54. * @day 2020/10/15
  55. */
  56. public function serviceRead($merId, $uid, $serviceId)
  57. {
  58. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->where('service_id', $serviceId)->where('service_type', '<>', 1)->update(['service_type' => 1]);
  59. }
  60. /**
  61. * @param array $where
  62. * @return \think\db\BaseQuery
  63. * @author xaboy
  64. * @day 2020/6/16
  65. */
  66. public function search(array $where)
  67. {
  68. return StoreServiceLog::getDB()->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  69. $query->where('uid', $where['uid']);
  70. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  71. $query->where('mer_id', $where['mer_id']);
  72. })->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
  73. $query->where('service_id', $where['service_id']);
  74. });
  75. }
  76. /**
  77. * @param $merId
  78. * @param $uid
  79. * @return mixed
  80. * @author xaboy
  81. * @day 2020/5/29
  82. */
  83. public function getLastServiceId($merId, $uid)
  84. {
  85. return StoreServiceLog::getDB()->where('mer_id', $merId)->order('service_log_id DESC')->where('uid', $uid)->value('service_id');
  86. }
  87. /**
  88. * @param $uid
  89. * @return BaseQuery
  90. * @author xaboy
  91. * @day 2020/6/16
  92. */
  93. public function getMerchantListQuery($uid)
  94. {
  95. return StoreServiceLog::getDB()->where('uid', $uid)->group('mer_id');
  96. }
  97. /**
  98. * TODO 客服的所有用户
  99. * @param $serviceId
  100. * @return BaseQuery
  101. * @author xaboy
  102. * @day 2020/6/16
  103. */
  104. public function getUserListQuery($serviceId)
  105. {
  106. return StoreServiceLog::getDB()->where('service_id', $serviceId)->group('uid');
  107. }
  108. /**
  109. * TODO 商户的所有用户
  110. * @param $merId
  111. * @return mixed
  112. * @author Qinii
  113. * @day 2020-06-19
  114. */
  115. public function getMerchantUserList($merId)
  116. {
  117. return StoreServiceLog::getDB()->where('mer_id', $merId)->group('uid');
  118. }
  119. /**
  120. * @param $merId
  121. * @param $uid
  122. * @return array|\think\Model|null
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\DbException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. * @author xaboy
  127. * @day 2020/6/19
  128. */
  129. public function getLastLog($merId, $uid)
  130. {
  131. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->order('service_log_id DESC')->find();
  132. }
  133. /**
  134. * @param $merId
  135. * @param $uid
  136. * @param $sendType
  137. * @return int
  138. * @author xaboy
  139. * @day 2020/6/19
  140. */
  141. public function getUnReadNum($merId, $uid, $sendType)
  142. {
  143. return StoreServiceLog::getDB()->where('uid', $uid)->where('mer_id', $merId)->where('send_type', $sendType)->where($sendType ? 'type' : 'service_type', 0)->count();
  144. }
  145. /**
  146. * @param $uid
  147. * @return int
  148. * @author xaboy
  149. * @day 2020/6/19
  150. */
  151. public function totalUnReadNum($uid)
  152. {
  153. return StoreServiceLog::getDB()->where('uid', $uid)->where('send_type', 1)->where('type', 0)->count();
  154. }
  155. }