链街Dcat后台
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.

153 lines
4.8 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Models;
  3. use App\Admin\Common\Rpc;
  4. use Dcat\Admin\Traits\HasDateTimeFormatter;
  5. use App\Models\v3\Market as MarketModel;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Support\Facades\DB;
  8. use App\Models\v3\LanzuEmployees as EmployeesModel;
  9. class ImsCjdcOrderMain extends Model
  10. {
  11. // 线上订单,外卖
  12. const ORDER_TYPE_ONLINE = 1;
  13. // 线下订单,当面付
  14. const ORDER_TYPE_OFFLINE = 4;
  15. // 订单状态
  16. // 待付款
  17. const ORDER_STATE_UNPAY = 1;
  18. // 待接单
  19. const ORDER_STATE_UNTAKE = 2;
  20. // 待送达
  21. const ORDER_STATE_DELIVERY = 3;
  22. // 已完成
  23. const ORDER_STATE_COMPLETE = 4;
  24. // 已评价
  25. const ORDER_STATE_EVALUATED = 5;
  26. // 已取消
  27. const ORDER_STATE_CANCEL = 6;
  28. // 已拒单
  29. const ORDER_STATE_REFUSE = 7;
  30. // 退款中
  31. const ORDER_STATE_REFUNDING = 8;
  32. // 已退款
  33. const ORDER_STATE_REFUNDED = 9;
  34. // 拒绝退款
  35. const ORDER_STATE_UNREFUND = 10;
  36. // 完成状态组合
  37. const ORDER_STATE_FINISH = [self::ORDER_STATE_COMPLETE, self::ORDER_STATE_EVALUATED, self::ORDER_STATE_UNREFUND];
  38. // 订单支付方式
  39. // 微信支付
  40. const ORDER_PAY_WX = 1;
  41. // 余额支付
  42. const ORDER_PAY_BALANCE = 2;
  43. use HasDateTimeFormatter;
  44. //protected $table = 'ims_cjdc_order_main';
  45. protected $table = 'lanzu_order_main';
  46. public $timestamps = false;
  47. public static $tableName = 'lanzu_order_main';
  48. public function imsCjdcUser()
  49. {
  50. return $this->hasOne('\App\Models\ImsCjdcUser', 'id', 'user_id');
  51. }
  52. public function market()
  53. {
  54. return $this->hasOne('\App\Models\ImsCjdcMarket', 'id', 'market_id');
  55. }
  56. /**
  57. * 变更订单状态,
  58. * @param $oid //主订单id
  59. * @param $state //订单状态
  60. */
  61. public function modifyState($oid, $state)
  62. {
  63. $where = [];
  64. $where['state'] = $state;
  65. $where['updated_at'] = time();
  66. if ($state == 3) {
  67. $where['receive_time'] = time();
  68. } elseif ($state == 4) {
  69. $where['complete_time'] = time();
  70. } elseif ($state == 6) {
  71. $where['cancel_time'] = time();
  72. }
  73. return self::where('id', $oid)->update($where);
  74. }
  75. public function updateShippingType($oid, $type)
  76. {
  77. return self::where('id', $oid)->update(['shipping_type' => $type]);
  78. }
  79. public static function getOrderData($oid)
  80. {
  81. $order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray();
  82. $order['created_at'] = date('Y-m-d H:i:s', $order['created_at']);
  83. $order['updated_at'] = $order['updated_at'] ? date('Y-m-d H:i:s', $order['updated_at']) : null;
  84. $order['pay_type'] = config('order.pay_type')[$order['pay_type']];
  85. $order['shipping_type_num'] = $order['shipping_type'];
  86. $order['shipping_type'] = config('order.shipping_type')[$order['shipping_type']];
  87. $order['horseman_name'] = $order['shipping_name'] ?? LanzuServiceHorseman::getName($order['horseman_id']);
  88. // 获取市场
  89. $marketId = $order['market_id']?$order['market_id']:0;
  90. $market = MarketModel::getMarketInfo($marketId,['name','lat','lng']);
  91. $order['market_name'] = $market?$market['name']:'';
  92. $order['market_lat'] = $market?$market['lat']:'';
  93. $order['market_lng'] = $market?$market['lng']:'';
  94. //获取市场经纬度
  95. //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray();
  96. //$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result'];
  97. if ($order['delivery_distance'] > 1000) {
  98. $order['delivery_distance'] = number_format(($order['delivery_distance'] / 1000), 1) . 'km';
  99. } else {
  100. $order['delivery_distance'] .= '米';
  101. }
  102. return $order;
  103. }
  104. /**
  105. * 根据订单状态统计数量
  106. * @param $state
  107. * @param null $marketId
  108. * @return mixed
  109. */
  110. public static function getOrderStateCount($state, $marketId = null)
  111. {
  112. $builder = self::where('type', 1)
  113. ->where('created_at','>=',time()-(7*86400));
  114. if ($marketId) {
  115. $builder = $builder->where('market_id',$marketId);
  116. }
  117. if ($state==3){
  118. $builder = $builder->where('state',$state)->where('shipping_type',1)->where('horseman_id',0);
  119. }elseif ($state==311){
  120. $builder = $builder->where('state',3)->where('shipping_type',1)->where('horseman_id','>',0);
  121. }else{
  122. $builder = $builder->where('state',$state);
  123. }
  124. $count = $builder->count();
  125. return $count;
  126. }
  127. /**
  128. * 关联懒族员工表
  129. */
  130. public function employees()
  131. {
  132. return $this->belongsTo(new EmployeesModel(),'horseman_id','id','left');
  133. }
  134. }