lszyh
zyh 2 months ago
parent 5f7794f840
commit cd0f0419c7
  1. 47
      app/api/controller/Order.php
  2. 27
      app/common/model/Standard.php
  3. 84
      app/store/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());
}
}
}

@ -0,0 +1,27 @@
<?php
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
/**
* 审单记录表模型
* Class Store
* @package app\common\model
*/
class Standard extends BaseModel
{
// 定义表名
protected $name = 'standard';
// 定义主键
protected $pk = 'id';
public function insertStandard(array $data)
{
return $this->save($data);
}
}

@ -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('修改成功');
}
}

Loading…
Cancel
Save