StoreServiceLogDao.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\service;
  12. use app\common\dao\BaseDao;
  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 $uid
  58. * @param $serviceId
  59. * @return int
  60. * @throws \think\db\exception\DbException
  61. * @author xaboy
  62. * @day 2020/10/15
  63. */
  64. public function serviceRead($merId, $uid, $serviceId)
  65. {
  66. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->where('service_id', $serviceId)->where('service_type', '<>', 1)->update(['service_type' => 1]);
  67. }
  68. /**
  69. * @param array $where
  70. * @return \think\db\BaseQuery
  71. * @author xaboy
  72. * @day 2020/6/16
  73. */
  74. public function search(array $where)
  75. {
  76. return StoreServiceLog::getDB()->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
  77. $query->where('uid', $where['uid']);
  78. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  79. $query->where('mer_id', $where['mer_id']);
  80. })->when(isset($where['last_id']) && $where['last_id'] !== '', function ($query) use ($where) {
  81. $query->where('service_log_id', '<', $where['last_id']);
  82. })->when(isset($where['service_id']) && $where['service_id'] !== '', function ($query) use ($where) {
  83. $query->where('service_id', $where['service_id']);
  84. });
  85. }
  86. /**
  87. * @param $merId
  88. * @param $uid
  89. * @return mixed
  90. * @author xaboy
  91. * @day 2020/5/29
  92. */
  93. public function getLastServiceId($merId, $uid)
  94. {
  95. return StoreServiceLog::getDB()->where('mer_id', $merId)->order('service_log_id DESC')->where('uid', $uid)->value('service_id');
  96. }
  97. /**
  98. * @param $uid
  99. * @return BaseQuery
  100. * @author xaboy
  101. * @day 2020/6/16
  102. */
  103. public function getMerchantListQuery($uid)
  104. {
  105. return StoreServiceLog::getDB()->where('uid', $uid)->group('mer_id');
  106. }
  107. /**
  108. * TODO 客服的所有用户
  109. * @param $serviceId
  110. * @return BaseQuery
  111. * @author xaboy
  112. * @day 2020/6/16
  113. */
  114. public function getUserListQuery($serviceId)
  115. {
  116. return StoreServiceLog::getDB()->where('service_id', $serviceId);
  117. }
  118. /**
  119. * TODO 商户的所有用户
  120. * @param $merId
  121. * @return mixed
  122. * @author Qinii
  123. * @day 2020-06-19
  124. */
  125. public function getMerchantUserList($merId)
  126. {
  127. return StoreServiceLog::getDB()->where('mer_id', $merId);
  128. }
  129. /**
  130. * @param $merId
  131. * @param $uid
  132. * @return array|\think\Model|null
  133. * @throws \think\db\exception\DataNotFoundException
  134. * @throws \think\db\exception\DbException
  135. * @throws \think\db\exception\ModelNotFoundException
  136. * @author xaboy
  137. * @day 2020/6/19
  138. */
  139. public function getLastLog($merId, $uid)
  140. {
  141. return StoreServiceLog::getDB()->where('mer_id', $merId)->where('uid', $uid)->order('service_log_id DESC')->find();
  142. }
  143. /**
  144. * @param $merId
  145. * @param $uid
  146. * @param $sendType
  147. * @return int
  148. * @author xaboy
  149. * @day 2020/6/19
  150. */
  151. public function getUnReadNum($merId, $uid, $sendType)
  152. {
  153. return StoreServiceLog::getDB()->where('uid', $uid)->where('mer_id', $merId)->where('send_type', $sendType)->where($sendType ? 'type' : 'service_type', 0)->count();
  154. }
  155. /**
  156. * @param $uid
  157. * @return int
  158. * @author xaboy
  159. * @day 2020/6/19
  160. */
  161. public function totalUnReadNum($uid)
  162. {
  163. return StoreServiceLog::getDB()->where('uid', $uid)->where('send_type', 1)->where('type', 0)->count();
  164. }
  165. }