StoreServiceLogDao.php 4.5 KB

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