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

144 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 static $tableName = 'lanzu_order_main';
  47. public function imsCjdcUser()
  48. {
  49. return $this->hasOne('\App\Models\ImsCjdcUser', 'id', 'user_id');
  50. }
  51. public function market()
  52. {
  53. return $this->hasOne('\App\Models\ImsCjdcMarket', 'id', 'market_id');
  54. }
  55. /**
  56. * 变更订单状态,
  57. * @param $oid //主订单id
  58. * @param $state //订单状态
  59. */
  60. public function modifyState($oid, $state)
  61. {
  62. $where = [];
  63. $where['state'] = $state;
  64. $where['updated_at'] = time();
  65. if ($state == 3) {
  66. $where['receive_time'] = time();
  67. } elseif ($state == 4) {
  68. $where['complete_time'] = time();
  69. } elseif ($state == 6) {
  70. $where['cancel_time'] = time();
  71. }
  72. return self::where('id', $oid)->update($where);
  73. }
  74. public function updateShippingType($oid, $type)
  75. {
  76. return self::where('id', $oid)->update(['shipping_type' => $type]);
  77. }
  78. public static function getOrderData($oid)
  79. {
  80. $order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray();
  81. $order['created_at'] = date('Y-m-d H:i:s', $order['created_at']);
  82. $order['updated_at'] = $order['updated_at'] ? date('Y-m-d H:i:s', $order['updated_at']) : null;
  83. $order['pay_type'] = config('order.pay_type')[$order['pay_type']];
  84. $order['shipping_type_num'] = $order['shipping_type'];
  85. $order['shipping_type'] = config('order.shipping_type')[$order['shipping_type']];
  86. $order['horseman_name'] = $order['shipping_name'] ?? LanzuServiceHorseman::getName($order['horseman_id']);
  87. // 获取市场
  88. $marketId = $order['market_id']?$order['market_id']:0;
  89. $market = MarketModel::getMarketInfo($marketId,['name','lat','lng']);
  90. $order['market_name'] = $market?$market['name']:'';
  91. $order['market_lat'] = $market?$market['lat']:'';
  92. $order['market_lng'] = $market?$market['lng']:'';
  93. //获取市场经纬度
  94. //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray();
  95. //$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result'];
  96. if ($order['delivery_distance'] > 1000) {
  97. $order['delivery_distance'] = number_format(($order['delivery_distance'] / 1000), 1) . 'km';
  98. } else {
  99. $order['delivery_distance'] .= '米';
  100. }
  101. return $order;
  102. }
  103. /**
  104. * 根据订单状态统计数量
  105. * @param $state
  106. * @param null $marketId
  107. * @return mixed
  108. */
  109. public static function getOrderStateCount($state, $marketId = null)
  110. {
  111. $builder = self::where('type', 1)
  112. ->where('created_at','>=',time()-(7*86400));
  113. if ($marketId) {
  114. $builder = $builder->where('market_id',$marketId);
  115. }
  116. if ($state==3){
  117. $builder = $builder->where('state',$state)->where('shipping_type',1)->where('horseman_id',0);
  118. }elseif ($state==311){
  119. $builder = $builder->where('state',3)->where('shipping_type',1)->where('horseman_id','>',0);
  120. }else{
  121. $builder = $builder->where('state',$state);
  122. }
  123. $count = $builder->count();
  124. return $count;
  125. }
  126. }