StoreServiceLogDao.php 5.1 KB

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