From cd0f0419c7f5067458d8c6fe3cc10f11ea54fd16 Mon Sep 17 00:00:00 2001 From: zyh Date: Wed, 16 Oct 2024 16:27:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Order.php | 47 +++++++++++++++++++ app/common/model/Standard.php | 27 +++++++++++ app/store/controller/Order.php | 84 ++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 app/common/model/Standard.php diff --git a/app/api/controller/Order.php b/app/api/controller/Order.php index 7153db86..d4d9237e 100644 --- a/app/api/controller/Order.php +++ b/app/api/controller/Order.php @@ -25,6 +25,8 @@ use cores\exception\BaseException; use think\response\Json; use app\common\model\MerchantRemarks as MerchantRemarksModel; use app\api\service\Setting as SettingService; +use app\common\model\Standard as StandardModel; +use think\facade\Db; /** * 我的订单控制器 @@ -405,5 +407,50 @@ class Order extends Controller } + /** + * 提交审单记录 + */ + public function submitStandard(int $orderId): Json + { + $data = $this->postForm(); + $order = new OrderModel(); + $model = new StandardModel; + $storeId = $this->storeId; + $userId = $this->user['user_id']; + $data['store_id'] = $storeId; + $data['user_id'] = $userId; + $data['order_id'] = $orderId; + $data['standard_status'] = 30; + $orderDetail = Db::name('order')->where('order_id',$orderId)->field('standard_num,order_id')->find(); + $standard_num = $model->where('order_id',$orderId)->count(); + + if($orderDetail['standard_num'] == 0 && $standard_num > 0) + { + return $this->renderError('记录重复'); + } + if($orderDetail['standard_num'] == 1 && $standard_num > 2) + { + return $this->renderError('记录重复'); + } + if($orderDetail['standard_num'] >= 2) + { + return $this->renderError('记录重复'); + } + + try { + Db::startTrans(); + if ($model->insertStandard($data)) { + + Db::name('order')->where('order_id',$orderId)->Inc('standard_num',1)->update(["standard_status"=>30,"is_standard"=>0]); + Db::commit(); + return $this->renderSuccess('提交成功'); + } + } catch (\Exception $e) { + Db::rollback(); + return $this->renderError($e->getMessage()); + } + + + } } diff --git a/app/common/model/Standard.php b/app/common/model/Standard.php new file mode 100644 index 00000000..6103aabf --- /dev/null +++ b/app/common/model/Standard.php @@ -0,0 +1,27 @@ +save($data); + } +} \ No newline at end of file diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php index ebf4e51e..78b1a414 100644 --- a/app/store/controller/Order.php +++ b/app/store/controller/Order.php @@ -23,6 +23,7 @@ use app\common\model\UploadFile; use app\common\model\TransferRecord as TransferRecordModel; use app\api\model\Express as ExpressModel; use app\common\model\order\Delivery as DeliveryModel; +use app\common\model\Standard as StandardModel; /** * 订单管理 @@ -317,4 +318,87 @@ class Order extends Controller } + /** + * 审单 + * @param $orderId + * @return Json + */ + public function standard($orderId): Json + { + $model = new OrderModel; + $standardCount = new StandardModel(); + $params = $this->postForm(); + $type = $params['type']; + $orderDetail = $model->where('order_id', $orderId)->find(); + $count = $standardCount->where('order_id', $orderId)->count(); + $num = $orderDetail['standard_count'] +1; + if (!$orderDetail) { + return $this->renderError('订单不存在'); + } + //第一次审核 + if (($orderDetail['standard_count'] !=0 && $type == 10) || ($count <1 && $type == 20) ) { + return $this->renderError('审核状态不对'); + } + if($orderDetail['standard_status'] == 30) + { + return $this->renderError('请先在审单记录当中进行审核'); + } + //第二次审核 + if ($orderDetail['standard_count'] !=1 && $type == 20) { + return $this->renderError('审核状态不对'); + } + if($orderDetail['standard_count'] == 1 || $orderDetail['standard_count'] == 0){ + if ($model->where('order_id', $orderId)->update(['is_standard' => 1,"standard_count"=>$num])) { + // Db::name('order')->where('order_id',$orderId)->Inc('standard_count',1); + return $this->renderSuccess('操作成功'); + } + } + return $this->renderError($model->getError() ?: '操作失败'); + } + + /** + * 获取审单记录 + * @param $orderId + * @return Json + */ + public function getStandard(int $orderId): Json + { + $model = new StandardModel; + $list = $model->where("order_id",$orderId)->select(); + foreach ($list as $key => $value) { + $value['order_image_url'] = UploadFile::withoutGlobalScope()->where("file_id",'in',$value['order_image'])->select(); + $value['transfer_image_url'] = UploadFile::withoutGlobalScope()->where("file_id",'in',$value['transfer_image'])->select(); + } + return $this->renderSuccess(compact('list')); + } + + /** + * 修改审单记录 + * [10通过 20不通过] + * @param $standardId + * @return Json + */ + public function updateStandard(int $standardId): Json + { + $model = new StandardModel; + $standard = $model->where('id', $standardId)->find(); + if (!$standard) { + return $this->renderError('该记录不存在'); + } + if ($standard['standard_status'] == 10|| $standard['standard_status'] == 20) { + return $this->renderError('该订单以审核过了'); + } + $orderId = $standard['order_id']; + $data = $this->postForm(); + $status = $data['standard_status']; + $cause = $data['cause'] ?? ''; + $order = new OrderModel; + if ($status != 10 && $status != 20 ) { + return $this->renderError('状态错误'); + } + $model->where("id",$standardId)->update(['standard_status'=>$status ,'cause'=>$cause]); + $order->where("order_id",$orderId)->update(['standard_status'=>$status,'standard_time'=>time(),'cause'=>$cause]); + + return $this->renderSuccess('修改成功'); + } }