StoreService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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\model\message\service;
  12. use app\model\user\User;
  13. use app\model\work\WorkMember;
  14. use crmeb\basic\BaseModel;
  15. use crmeb\traits\ModelTrait;
  16. use think\Model;
  17. /**
  18. * 客服
  19. * Class StoreService
  20. * @package app\model\message\service
  21. */
  22. class StoreService extends BaseModel
  23. {
  24. use ModelTrait;
  25. /**
  26. * 数据表主键
  27. * @var string
  28. */
  29. protected $pk = 'id';
  30. /**
  31. * 模型名称
  32. * @var string
  33. */
  34. protected $name = 'store_service';
  35. /**
  36. * @var bool
  37. */
  38. protected $updateTime = false;
  39. /**
  40. * @return \think\model\relation\HasOne
  41. */
  42. public function workMember()
  43. {
  44. return $this->hasOne(WorkMember::class, 'uid', 'uid');
  45. }
  46. protected function getAddTimeAttr($value)
  47. {
  48. if ($value) return date('Y-m-d H:i:s', $value);
  49. return $value;
  50. }
  51. /**
  52. * 用户名一对多关联
  53. * @return mixed
  54. */
  55. public function user()
  56. {
  57. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname'])->bind([
  58. 'nickname' => 'nickname'
  59. ]);
  60. }
  61. /**
  62. * uid搜索器
  63. * @param Model $query
  64. * @param $value
  65. */
  66. public function searchUidAttr($query, $value)
  67. {
  68. $query->where('uid', $value);
  69. }
  70. /**
  71. * status搜索器
  72. * @param Model $query
  73. * @param $value
  74. */
  75. public function searchStatusAttr($query, $value)
  76. {
  77. $query->where('status', $value);
  78. }
  79. /**
  80. * status搜索器
  81. * @param Model $query
  82. * @param $value
  83. */
  84. public function searchAccountStatusAttr($query, $value)
  85. {
  86. $query->where('account_status', $value);
  87. }
  88. /**
  89. * account搜索器
  90. * @param Model $query
  91. * @param $value
  92. */
  93. public function searchAccountAttr($query, $value)
  94. {
  95. $query->where('account', $value);
  96. }
  97. /**
  98. * phone搜索器
  99. * @param Model $query
  100. * @param $value
  101. */
  102. public function searchPhoneAttr($query, $value)
  103. {
  104. $query->where('phone', $value);
  105. }
  106. /**
  107. * customer
  108. * @param Model $query
  109. * @param $value
  110. */
  111. public function searchCustomerAttr($query, $value)
  112. {
  113. $query->where('customer', $value);
  114. }
  115. /**
  116. * 用户昵称搜索器
  117. * @param Model $query
  118. * @param $value
  119. */
  120. public function searchNicknameAttr($query, $value)
  121. {
  122. if ($value) $query->whereLike('nickname', '%' . $value . '%');
  123. }
  124. /**
  125. * @param Model $query
  126. * @param $value
  127. */
  128. public function searchOnlineAttr($query, $value)
  129. {
  130. $query->where('online', $value);
  131. }
  132. /**
  133. * 用户uid搜索器
  134. * @param Model $query
  135. * @param $value
  136. */
  137. public function searchNoUidAttr($query, $value)
  138. {
  139. if ($value) $query->whereNotIn('uid', $value);
  140. }
  141. }