diff --git a/app/api/controller/Order.php b/app/api/controller/Order.php index 7153db86..a5954d80 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; /** * 我的订单控制器 @@ -406,4 +408,49 @@ 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/common/model/Store.php b/app/common/model/Store.php index 5c7992e7..7218f6e8 100644 --- a/app/common/model/Store.php +++ b/app/common/model/Store.php @@ -104,6 +104,12 @@ class Store extends BaseModel } else { $list['logoImage'] = null; } + if ($list['standard_image_id']) { + $files = UploadFile::getFileList([$list['standard_image_id']]); + $list['standard_image'] = $files ? $files[0] : null; + } else { + $list['standard_image'] = null; + } } return $list ?? null; } catch (\Exception $e) { diff --git a/app/store/controller/Order.php b/app/store/controller/Order.php index a5c296f9..7f55eced 100644 --- a/app/store/controller/Order.php +++ b/app/store/controller/Order.php @@ -22,6 +22,8 @@ use app\store\model\OrderRefund as OrderRefundModel; use app\common\model\UploadFile; use app\common\model\TransferRecord as TransferRecordModel; use app\api\model\Express as ExpressModel; +use app\common\model\Standard as StandardModel; +use think\facade\Db; /** * 订单管理 @@ -303,5 +305,87 @@ class Order extends Controller return $this->renderSuccess(compact('list')); } + /** + * 审单 + * @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('修改成功'); + } }