| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\adopt\models\client;
- use app\models\Goods;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\plugins\adopt\models\AdoptCostOrder;
- use app\plugins\adopt\models\AdoptOrderInfo;
- use app\utils\Notice\NoticeSend;
- use yii\base\Model;
- class CostOrderConfirmForm extends Model
- {
- public $store_id;
- public $user_id;
- public $order_id;
- public function rules()
- {
- return [
- [['order_id'], 'required'],
- ];
- }
- public function save()
- {
- if (!$this->validate()) {
- return $this->getErrorSummary(false)[0];
- }
- $adopt_cost_order = AdoptCostOrder::findOne([
- 'store_id' => $this->store_id,
- 'user_id' => $this->user_id,
- 'id' => $this->order_id,
- 'trade_status' => Order::ORDER_FLOW_SEND,
- 'is_delete' => 0,
- ]);
- if (!$adopt_cost_order) {
- return [
- 'code' => 1,
- 'msg' => '订单不存在'
- ];
- }
- $adopt_cost_order->trade_status = Order::ORDER_FLOW_CONFIRM;
- $adopt_cost_order->confirm_time = time();
- if ($adopt_cost_order->pay_type == 2) {
- $adopt_cost_order->is_pay = 1;
- $adopt_cost_order->pay_time = time();
- }
- if ($adopt_cost_order->save()) {
- /**
- * @var Order $v
- */
- $adopt_order_info = AdoptOrderInfo::find()->alias('aoi')
- ->where([
- 'aoi.order_id' => $adopt_cost_order->order_id,
- 'aoi.store_id' => $this->store_id,
- ])->one();
- if ($adopt_order_info->harvest_weight == 0) {
- $adopt_order = Order::find()->alias('o')
- ->where([
- 'o.id' => $adopt_cost_order->order_id,
- 'o.store_id' => $this->store_id,
- 'o.order_type' => 5,
- ])->one();
- $adopt_order->trade_status = Order::ORDER_FLOW_CONFIRM;
- $adopt_order->save();
- $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $this->order_id])->goods_id);
- NoticeSend::AdoptOrderStateChange($adopt_order->user_id, $adopt_order_info->mobile, $adopt_order->order_no, $goods->name, 13);
- }
- return [
- 'code' => 0,
- 'msg' => '已确认收货'
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '确认收货失败'
- ];
- }
- }
- }
|