| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1\admin;
- use app\models\Express;
- use app\models\Goods;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\utils\Notice\NoticeSend;
- use yii\base\Model;
- class OrderSendForm extends Model
- {
- public $store_id;
- public $order_id;
- public $express;
- public $express_no;
- public $words;
- const EXPRESS_TYPE_EXPRESS = 1;
- const EXPRESS_TYPE_PEISONG = 4;
- public function rules()
- {
- return [
- [['express', 'express_no', 'words'], 'trim'],
- [['express', 'express_no',], 'required', 'on' => 'EXPRESS'],
- [['order_id'], 'required', 'on' => 'PEISONG'],
- [['order_id'], 'required'],
- [['express', 'express_no',], 'string',],
- [['express', 'express_no',], 'default', 'value' => ''],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'express' => '快递公司',
- 'express_no' => '快递单号',
- 'words' => '商家留言',
- ];
- }
- public function save()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0],
- ];
- }
- $order = Order::findOne([
- 'is_delete' => 0,
- 'store_id' => $this->store_id,
- 'id' => $this->order_id,
- ]);
- if (!$order) {
- return [
- 'code' => 1,
- 'msg' => '订单不存在或已删除',
- ];
- }
- if ($order->is_pay == 0 && $order->pay_type != 2) {
- return [
- 'code' => 1,
- 'msg' => '订单未支付'
- ];
- }
- if ($order->apply_delete == Order::ORDER_APPLY_DELETE) {
- return [
- 'code' => 1,
- 'msg' => '该订单正在申请取消操作,请先处理'
- ];
- }
- $expressList = Express::getExpressList();
- $ok = false;
- foreach ($expressList as $value) {
- if ($value['name'] == $this->express) {
- $ok = true;
- break;
- }
- }
- if (!$ok && $this->scenario == "EXPRESS") {
- return [
- 'code' => 1,
- 'msg' => '快递公司不正确'
- ];
- }
- $order->express = $this->express;
- $order->express_no = $this->express_no;
- $order->words = $this->words;
- $order->trade_status = Order::ORDER_FLOW_SEND;
- $order->send_time = time();
- if ($order->save()) {
- $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order->id])->goods_id);
- if($order->giving_gifts_received_user_id){
- NoticeSend::OrderSend($order->giving_gifts_received_user_id, $order->mobile, $order->order_no, $goods->name, $this->express, $this->express_no, $order->order_type);
- }else{
- NoticeSend::OrderSend($order->user_id, $order->mobile, $order->order_no, $goods->name, $this->express, $this->express_no);
- }
- return [
- 'code' => 0,
- 'msg' => '发货成功',
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => '操作失败',
- ];
- }
- }
- }
|