DeliveryService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\store;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 配送员
  18. * Class DeliveryService
  19. * @package app\model\store
  20. */
  21. class DeliveryService 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 = 'delivery_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. * 商户搜索器
  64. * @param Model $query
  65. * @param $value
  66. */
  67. public function searchTypeAttr($query, $value)
  68. {
  69. if (is_array($value)) {
  70. if ($value) $query->whereIn('type', $value);
  71. } else {
  72. if ($value !== '') $query->where('type', $value);
  73. }
  74. }
  75. /**
  76. * 关联门店ID、供应商ID搜索器
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchRelationIdAttr($query, $value)
  81. {
  82. if (is_array($value)) {
  83. if ($value) $query->whereIn('relation_id', $value);
  84. } else {
  85. if ($value !== '') $query->where('relation_id', $value);
  86. }
  87. }
  88. /**
  89. * 供应商
  90. * @param Model $query
  91. * @param $value
  92. */
  93. public function searchSupplierIdAttr($query, $value)
  94. {
  95. if (is_array($value)) {
  96. if ($value) $query->whereIn('relation_id', $value)->where('type', 2);
  97. } else {
  98. if ($value !== '') $query->where('relation_id', $value)->where('type', 2);
  99. }
  100. }
  101. /**
  102. * 门店
  103. * @param Model $query
  104. * @param $value
  105. */
  106. public function searchStoreIdAttr($query, $value)
  107. {
  108. if (is_array($value)) {
  109. if ($value) $query->whereIn('relation_id', $value)->where('type', 1);
  110. } else {
  111. if ($value !== '') $query->where('relation_id', $value)->where('type', 1);
  112. }
  113. }
  114. /**
  115. * status搜索器
  116. * @param Model $query
  117. * @param $value
  118. */
  119. public function searchStatusAttr($query, $value)
  120. {
  121. $query->where('status', $value);
  122. }
  123. /**
  124. * customer
  125. * @param Model $query
  126. * @param $value
  127. */
  128. public function searchCustomerAttr($query, $value)
  129. {
  130. $query->where('customer', $value);
  131. }
  132. /**
  133. * 用户昵称搜索器
  134. * @param Model $query
  135. * @param $value
  136. */
  137. public function searchNicknameAttr($query, $value)
  138. {
  139. $query->whereLike('nickname', '%' . $value . '%');
  140. }
  141. public function searchPhoneAttr($query, $value)
  142. {
  143. $query->where('phone', $value);
  144. }
  145. /**
  146. * 是否删除
  147. * @param $query
  148. * @param $value
  149. */
  150. public function searchIsDelAttr($query, $value)
  151. {
  152. if ($value !== '') {
  153. $query->where('is_del', $value);
  154. }
  155. }
  156. }