You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DeliveryService.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\model\store;
  3. use app\model\user\User;
  4. use crmeb\basic\BaseModel;
  5. use crmeb\traits\ModelTrait;
  6. use think\Model;
  7. /**
  8. * 配送员
  9. * Class DeliveryService
  10. * @package app\model\store
  11. */
  12. class DeliveryService extends BaseModel
  13. {
  14. use ModelTrait;
  15. /**
  16. * 数据表主键
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * 模型名称
  22. * @var string
  23. */
  24. protected $name = 'delivery_service';
  25. /**
  26. * @var bool
  27. */
  28. protected $updateTime = false;
  29. protected function getAddTimeAttr($value)
  30. {
  31. if ($value) return date('Y-m-d H:i:s', $value);
  32. return $value;
  33. }
  34. /**
  35. * 用户名一对多关联
  36. * @return mixed
  37. */
  38. public function user()
  39. {
  40. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname'])->bind([
  41. 'nickname' => 'nickname'
  42. ]);
  43. }
  44. /**
  45. * uid搜索器
  46. * @param Model $query
  47. * @param $value
  48. */
  49. public function searchUidAttr($query, $value)
  50. {
  51. $query->where('uid', $value);
  52. }
  53. /**
  54. * type搜索器
  55. * @param Model $query
  56. * @param $value
  57. */
  58. public function searchTypeAttr($query, $value)
  59. {
  60. if ($value) $query->where('type', $value);
  61. }
  62. /**
  63. * store_id搜索器
  64. * @param Model $query
  65. * @param $value
  66. */
  67. public function searchStoreIdAttr($query, $value)
  68. {
  69. if ($value !== '') $query->where('store_id', $value);
  70. }
  71. /**
  72. * status搜索器
  73. * @param Model $query
  74. * @param $value
  75. */
  76. public function searchStatusAttr($query, $value)
  77. {
  78. $query->where('status', $value);
  79. }
  80. /**
  81. * customer
  82. * @param Model $query
  83. * @param $value
  84. */
  85. public function searchCustomerAttr($query, $value)
  86. {
  87. $query->where('customer', $value);
  88. }
  89. /**
  90. * 用户昵称搜索器
  91. * @param Model $query
  92. * @param $value
  93. */
  94. public function searchNicknameAttr($query, $value)
  95. {
  96. $query->whereLike('nickname', '%' . $value . '%');
  97. }
  98. public function searchPhoneAttr($query, $value)
  99. {
  100. $query->where('phone', $value);
  101. }
  102. /**
  103. * 是否删除
  104. * @param $query
  105. * @param $value
  106. */
  107. public function searchIsDelAttr($query, $value)
  108. {
  109. if ($value !== '') {
  110. $query->where('is_del', $value);
  111. }
  112. }
  113. }