DeliveryService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\order;
  12. use app\model\user\User;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**配送员
  17. * Class DeliveryService
  18. * @package app\model\service
  19. */
  20. class DeliveryService extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'delivery_service';
  33. /**
  34. * @var bool
  35. */
  36. protected $updateTime = false;
  37. protected function getAddTimeAttr($value)
  38. {
  39. if ($value) return date('Y-m-d H:i:s', $value);
  40. return $value;
  41. }
  42. /**
  43. * 用户名一对多关联
  44. * @return mixed
  45. */
  46. public function user()
  47. {
  48. return $this->hasOne(User::class, 'uid', 'uid')->field(['uid', 'nickname'])->bind([
  49. 'nickname' => 'nickname'
  50. ]);
  51. }
  52. /**
  53. * uid搜索器
  54. * @param Model $query
  55. * @param $value
  56. */
  57. public function searchUidAttr($query, $value)
  58. {
  59. $query->where('uid', $value);
  60. }
  61. /**
  62. * status搜索器
  63. * @param Model $query
  64. * @param $value
  65. */
  66. public function searchStatusAttr($query, $value)
  67. {
  68. $query->where('status', $value);
  69. }
  70. /**
  71. * customer
  72. * @param Model $query
  73. * @param $value
  74. */
  75. public function searchCustomerAttr($query, $value)
  76. {
  77. $query->where('customer', $value);
  78. }
  79. /**
  80. * 用户昵称搜索器
  81. * @param Model $query
  82. * @param $value
  83. */
  84. public function searchNicknameAttr($query, $value)
  85. {
  86. $query->whereLike('nickname', '%' . $value . '%');
  87. }
  88. public function searchPhoneAttr($query, $value)
  89. {
  90. $query->where('phone', $value);
  91. }
  92. }