链街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.

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