| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\models\Order;
- use yii\base\Model;
- use app\models\OrderTransit;
- use app\models\StoreCloud;
- use app\constants\OptionSetting;
- use app\models\DeliveryInfo;
- use app\models\LocalDeliveryCourier;
- use app\models\LocalDeliveryLog;
- use app\models\Option;
- class OrderConfirmForm extends Model
- {
- public $store_id;
- public $user_id;
- public $saas_id;
- public $order_id;
- public function rules()
- {
- return [
- [['order_id'], 'required'],
- ];
- }
- public function save()
- {
- if (!$this->validate()) {
- return $this->getErrorSummary(false)[0];
- }
- $order = Order::findOne([
- //'store_id' => $this->store_id,
- 'saas_id' => $this->saas_id,
- 'id' => $this->order_id,
- // 'trade_status' => Order::ORDER_FLOW_SEND,
- 'is_delete' => 0,
- ]);
- if (!$order) {
- return [
- 'code' => 1,
- 'msg' => '订单不存在'
- ];
- }
- $delivery_info = DeliveryInfo::findOne(['order_no' => $order->order_no]);
- $courier = LocalDeliveryCourier::findOne(['id' => $delivery_info->rider_id, 'is_delete' => 0, 'state' => 2]);
- if($delivery_info->is_local == DeliveryInfo::IS_LOCAL_YSE) {
- if($delivery_info->local_status == DeliveryInfo::LOCAL_STATUS_CONFIRM) {
- /* 骑手完成订单后发放收入 */
- //同城配送设置相关
- $store_id = 0;
- if (intval($delivery_info->is_store_delivery_type)) {
- $store_id = get_store_id();
- }
- $values = Option::find()->where([
- 'store_id' => $store_id,
- 'group' => OptionSetting::LOCAL_DELIVERY_GROUP_NAME, 'name' => OptionSetting::LOCAL_DELIVERY_SETTING
- ])->select('value')->one();
- $local_setting = json_decode($values->value, true);
- if (!empty($courier)) {
- if ($store_id > 0) {
- $local_setting['default_cost']['value'] = -1;
- }
- $amount = (float)$local_setting['default_cost']['value'] == -1 ? $delivery_info->fee : (float)$local_setting['default_cost']['value'];
- $log = LocalDeliveryLog::saveLog($courier->saas_user_id, $amount, 1, 1, $order->id, "骑手配送收入:" . $amount . "元");
- if (!$log) {
- return [
- 'code' => 1,
- 'msg' => '发放骑手佣金出现异常'
- ];
- }
- }
- } else {
- return [
- 'code' => 1,
- 'msg' => '当前订单为平台自配,配送员未送达不可优先确认收货'
- ];
- }
- } else {
- if ($order->trade_status != Order::ORDER_FLOW_SEND) {
- return [
- 'code' => 1,
- 'msg' => '订单不存在'
- ];
- }
- }
- $order->trade_status = Order::ORDER_FLOW_CONFIRM;
- $order->confirm_time = time();
- if ($order->pay_type == 2) {
- $order->is_pay = 1;
- $order->pay_time = time();
- }
- if ($order->save()) {
- return [
- 'code' => 0,
- 'msg' => '已确认收货',
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '确认收货失败'
- ];
- }
- }
- }
|