| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\adopt\models\client;
- use app\models\Address;
- use app\models\Cart;
- use app\models\Goods;
- use app\models\UserCoupon;
- use app\plugins\adopt\models\AdoptCostOrder;
- use app\plugins\adopt\models\AdoptOrderInfo;
- use app\plugins\scanCodePay\models\Order;
- use app\plugins\scanCodePay\models\OrderDetail;
- // use app\utils\CloudPrint;
- use app\utils\Notice\NoticeSend;
- use app\utils\OrderNo;
- use yii\base\Model;
- use yii\helpers\Json;
- class CostOrderSubmitForm extends Model
- {
- public $user;
- public $payment;
- public $use_integral;
- public $order_id;
- public $address_id;
- public $user_id;
- public $store_id;
- public $weight;
- public $order_type;
- public $address;
- public function rules()
- {
- $rules = [
- [['payment', 'use_integral', 'order_id', 'address_id', 'user_id', 'store_id', 'order_type'], 'integer'],
- [[ 'weight'], 'number']
- ];
- return $rules;
- }
- public function save()
- {
- if (!$this->validate())
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- /**
- * @var $address Address
- */
- $order_submit_preview1 = new CostOrderSubmitPreviewForm();
- $order_submit_preview1->order_type = $this->order_type;
- $order_submit_preview1->order_id = $this->order_id;
- $order_submit_preview1->weight = $this->weight;
- $order_submit_preview1->store_id = $this->store_id;
- $order_submit_preview1->user_id = $this->user_id;
- $order_submit_preview1->address_id = $this->address_id;
- $this->address = $order_submit_preview1->getAddressData();
- $address = (object)($this->address);
- $order_id_list = [];
- $t = \Yii::$app->db->beginTransaction();
- // $order_submit_preview = new CostOrderSubmitPreviewForm();
- // $order_submit_preview->order_type = $this->order_type;
- // $order_submit_preview->order_id = $this->order_id;
- // $order_submit_preview->weight = $this->weight;
- // $order_submit_preview->store_id = $this->store_id;
- // $order_submit_preview->user_id = $this->user_id;
- $cost_detail = $order_submit_preview1->getCostDetail();
- $order = new AdoptCostOrder();
- $order->store_id = $this->store_id;
- $order->user_id = $this->user_id;
- $order->order_id = $this->order_id;
- $order->order_no = OrderNo::getOrderNo(OrderNo::ADOPT_COST_ORDER);
- $order->pay_price = $cost_detail['pay_price'];
- $order->express_price = $cost_detail['express_price'];
- $order->total_price = $cost_detail['pay_price'];
- $order->weight = $this->weight;
- $order->cost_detail = json_encode($cost_detail['cost_list']);
- $order->order_type = $this->order_type;
- // 是否是平台小程序订单
- if (is_platform()) {
- $order->is_platform = 1;
- }
- if (get_md_id()) {
- $order->md_id = get_md_id();
- }
- $order->integral = json_encode(['forehead' => 0, 'forehead_integral' => 0], JSON_UNESCAPED_UNICODE);
- $order->created_at = time();
- $order->content = '';
- $order->is_offline = 0;
- $order->version = cyy_version();
- $order->mch_id = 0;
- $order->discount = 10; // 当面付订单不享受会员折扣
- $order->remark = isset($mch['remark']) ?: '' ;
- if ($this->payment == 2) {
- $order->pay_type = 2;
- $order->is_pay = 0;
- }
- if ($this->payment == 3) {
- $order->pay_type = 3;
- $order->is_pay = 0;
- }
- $order->address = $address->province . $address->city . $address->district . $address->detail;
- $order->mobile = $address->mobile;
- $order->name = $address->name;
- $order->province_id = $address->province_id;
- $order->city_id = $address->city_id;
- $order->district_id = $address->district_id;
- $order->address_data = json_encode([
- 'province' => trim($address->province),
- 'city' => trim($address->city),
- 'district' => trim($address->district),
- 'detail' => trim($address->detail),
- 'latitude' => $address->latitude,
- 'longitude' => $address->longitude,
- ], JSON_UNESCAPED_UNICODE);
- if ($order->save()) {
- $adopt_order = AdoptOrderInfo::find()->where(['store_id' => $this->store_id, 'order_id' => $this->order_id])->one();
- $adopt_order->harvest_weight -= $this->weight;
- if (!$adopt_order->save()){
- $t->rollBack();
- return [
- 'code' => 0,
- 'msg' => $adopt_order->getErrorSummary(false)[0],
- 'data' => $adopt_order->getErrors(),
- ];
- };
- // 订单提交完成发送消息
- NoticeSend::OrderSubmit($this->user_id, $order->mobile, $order->order_no, $order->pay_price, '认养费用',2, $order->store_id);
- $order_id_list[] = $order->id;
- } else {
- $t->rollBack();
- return [
- 'code' => 0,
- 'msg' => $order->getErrorSummary(false)[0],
- 'data' => $order->getErrors(),
- ];
- }
- if (count($order_id_list) > 0) {
- $t->commit();
- $order_id = $order_id_list[0];
- // CloudPrint::doPrint($order_id, 0, $this->store_id);
- return [
- 'code' => 0,
- 'msg' => '订单提交成功',
- 'data' => (object)[
- 'order_id' => $order_id_list[0],
- 'add_time' => $order->created_at
- ],
- ];
- } else {
- $t->rollBack();
- return [
- 'order_list' => $order_id_list
- ];
- }
- }
- }
|