DeliveryOrder.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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 merchant()
  28. {
  29. return $this->hasOne(Merchant::class, 'mer_id','mer_id');
  30. }
  31. public function station()
  32. {
  33. return $this->hasOne(DeliveryStation::class, 'station_id','station_id');
  34. }
  35. public function storeOrder()
  36. {
  37. return $this->hasOne(StoreOrder::class, 'order_id','order_id');
  38. }
  39. public function storeOrderStatus()
  40. {
  41. return $this->hasMany(StoreOrderStatus::class, 'order_id','order_id')->order('change_time DESC');
  42. }
  43. public function getDistanceAttr($value)
  44. {
  45. if ($value >= 1000) {
  46. return round(($value / 1000),2) . ' km';
  47. } else {
  48. return $value . 'm';
  49. }
  50. }
  51. public function searchStatusAttr($query,$value)
  52. {
  53. $query->where('status',$value);
  54. }
  55. public function searchKeywordAttr($query,$value)
  56. {
  57. $query->whereLike('order_sn|from_address',"%{$value}%");
  58. }
  59. public function searchMerIdAttr($query,$value)
  60. {
  61. $query->where('mer_id',$value);
  62. }
  63. public function searchStationIdAttr($query,$value)
  64. {
  65. $query->where('station_id',$value);
  66. }
  67. public function searchStationTypeAttr($query,$value)
  68. {
  69. $query->where('station_type',$value);
  70. }
  71. public function searchOrderIdAttr($query,$value)
  72. {
  73. $query->where('order_id',$value);
  74. }
  75. public function searchSnAttr($query,$value)
  76. {
  77. $query->where('order_sn',$value);
  78. }
  79. public function searchDateAttr($query,$value)
  80. {
  81. getModelTime($query, $value);
  82. }
  83. public function searchOrderSnAttr($query,$value)
  84. {
  85. $ids = StoreOrder::whereLike('order_sn',"%{$value}%")->column('order_id');
  86. $query->whereIn('order_id', $ids);
  87. }
  88. }