StoreService.php 3.1 KB

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