DeliveryOrder.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\delivery;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\order\StoreOrder;
  14. use app\common\model\store\order\StoreOrderStatus;
  15. use app\common\model\system\merchant\Merchant;
  16. use crmeb\services\DeliverySevices;
  17. class DeliveryOrder extends BaseModel
  18. {
  19. public static function tablePk(): string
  20. {
  21. return 'delivery_order_id';
  22. }
  23. public static function tableName(): string
  24. {
  25. return 'delivery_order';
  26. }
  27. public function getReceiverPhoneAttr($value)
  28. {
  29. if (env('SHOW_PHONE',false) && app('request')->hasMacro('adminInfo') && $value && is_numeric($value)){
  30. if (app('request')->userType() !== 2 || app('request')->adminInfo()['level'] != 0) {
  31. return substr_replace($value, '****', 3, 4);
  32. }
  33. }
  34. return $value;
  35. }
  36. public function merchant()
  37. {
  38. return $this->hasOne(Merchant::class, 'mer_id','mer_id');
  39. }
  40. public function station()
  41. {
  42. return $this->hasOne(DeliveryStation::class, 'station_id','station_id');
  43. }
  44. public function storeOrder()
  45. {
  46. return $this->hasOne(StoreOrder::class, 'order_id','order_id');
  47. }
  48. public function storeOrderStatus()
  49. {
  50. return $this->hasMany(StoreOrderStatus::class, 'order_id','order_id')->order('change_time DESC');
  51. }
  52. public function getDistanceAttr($value)
  53. {
  54. if ($value >= 1000) {
  55. return round(($value / 1000),2) . ' km';
  56. } else {
  57. return $value . 'm';
  58. }
  59. }
  60. public function searchStatusAttr($query,$value)
  61. {
  62. $query->where('status',$value);
  63. }
  64. public function searchKeywordAttr($query,$value)
  65. {
  66. $query->whereLike('order_sn|from_address',"%{$value}%");
  67. }
  68. public function searchMerIdAttr($query,$value)
  69. {
  70. $query->where('mer_id',$value);
  71. }
  72. public function searchStationIdAttr($query,$value)
  73. {
  74. $query->where('station_id',$value);
  75. }
  76. public function searchStationTypeAttr($query,$value)
  77. {
  78. $query->where('station_type',$value);
  79. }
  80. public function searchOrderIdAttr($query,$value)
  81. {
  82. $query->where('order_id',$value);
  83. }
  84. public function searchSnAttr($query,$value)
  85. {
  86. $query->where('order_sn',$value);
  87. }
  88. public function searchDateAttr($query,$value)
  89. {
  90. getModelTime($query, $value);
  91. }
  92. public function searchOrderSnAttr($query,$value)
  93. {
  94. $ids = StoreOrder::whereLike('order_sn',"%{$value}%")->column('order_id');
  95. $query->whereIn('order_id', $ids);
  96. }
  97. }