OrderConfirmForm.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models;
  8. use app\models\Order;
  9. use yii\base\Model;
  10. use app\models\OrderTransit;
  11. use app\models\StoreCloud;
  12. use app\constants\OptionSetting;
  13. use app\models\DeliveryInfo;
  14. use app\models\LocalDeliveryCourier;
  15. use app\models\LocalDeliveryLog;
  16. use app\models\Option;
  17. class OrderConfirmForm extends Model
  18. {
  19. public $store_id;
  20. public $user_id;
  21. public $saas_id;
  22. public $order_id;
  23. public function rules()
  24. {
  25. return [
  26. [['order_id'], 'required'],
  27. ];
  28. }
  29. public function save()
  30. {
  31. if (!$this->validate()) {
  32. return $this->getErrorSummary(false)[0];
  33. }
  34. $order = Order::findOne([
  35. //'store_id' => $this->store_id,
  36. 'saas_id' => $this->saas_id,
  37. 'id' => $this->order_id,
  38. // 'trade_status' => Order::ORDER_FLOW_SEND,
  39. 'is_delete' => 0,
  40. ]);
  41. if (!$order) {
  42. return [
  43. 'code' => 1,
  44. 'msg' => '订单不存在'
  45. ];
  46. }
  47. $delivery_info = DeliveryInfo::findOne(['order_no' => $order->order_no]);
  48. $courier = LocalDeliveryCourier::findOne(['id' => $delivery_info->rider_id, 'is_delete' => 0, 'state' => 2]);
  49. if($delivery_info->is_local == DeliveryInfo::IS_LOCAL_YSE) {
  50. if($delivery_info->local_status == DeliveryInfo::LOCAL_STATUS_CONFIRM) {
  51. /* 骑手完成订单后发放收入 */
  52. //同城配送设置相关
  53. $store_id = 0;
  54. if (intval($delivery_info->is_store_delivery_type)) {
  55. $store_id = get_store_id();
  56. }
  57. $values = Option::find()->where([
  58. 'store_id' => $store_id,
  59. 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME, 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
  60. ])->select('value')->one();
  61. $local_setting = json_decode($values->value, true);
  62. if (!empty($courier)) {
  63. if ($store_id > 0) {
  64. $local_setting['default_cost']['value'] = -1;
  65. }
  66. $amount = (float)$local_setting['default_cost']['value'] == -1 ? $delivery_info->fee : (float)$local_setting['default_cost']['value'];
  67. $log = LocalDeliveryLog::saveLog($courier->saas_user_id, $amount, 1, 1, $order->id, "骑手配送收入:" . $amount . "元");
  68. if (!$log) {
  69. return [
  70. 'code' => 1,
  71. 'msg' => '发放骑手佣金出现异常'
  72. ];
  73. }
  74. }
  75. } else {
  76. return [
  77. 'code' => 1,
  78. 'msg' => '当前订单为平台自配,配送员未送达不可优先确认收货'
  79. ];
  80. }
  81. } else {
  82. if ($order->trade_status != Order::ORDER_FLOW_SEND) {
  83. return [
  84. 'code' => 1,
  85. 'msg' => '订单不存在'
  86. ];
  87. }
  88. }
  89. $order->trade_status = Order::ORDER_FLOW_CONFIRM;
  90. $order->confirm_time = time();
  91. if ($order->pay_type == 2) {
  92. $order->is_pay = 1;
  93. $order->pay_time = time();
  94. }
  95. if ($order->save()) {
  96. return [
  97. 'code' => 0,
  98. 'msg' => '已确认收货',
  99. ];
  100. } else {
  101. return [
  102. 'code' => 1,
  103. 'msg' => '确认收货失败'
  104. ];
  105. }
  106. }
  107. }