feat: 上报异常
This commit is contained in:
parent
72483a53be
commit
1d0a4d54c0
|
|
@ -15,4 +15,7 @@ class OrderAbnormal extends Model
|
|||
];
|
||||
|
||||
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,5 +4,80 @@ namespace app\services;
|
|||
|
||||
class OrderAbnormalService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 上报异常
|
||||
* @param int $workerId
|
||||
* @param array $params
|
||||
* @return bool
|
||||
*/
|
||||
public function create(int $workerId, array $params)
|
||||
{
|
||||
$data = $this->getOrderAbnormal($workerId, $params['order_id']);
|
||||
if ($data) {
|
||||
$this->apiError('您已上报过异常,请勿重复提交');
|
||||
}
|
||||
|
||||
$abnormal = $this->getAbnormalModel()->find($params['abnormal_id']);
|
||||
if (!$abnormal) {
|
||||
$this->apiError('异常原因不存在,请重新选择');
|
||||
}
|
||||
|
||||
$worker = $this->getWorkerModel()->find($workerId);
|
||||
|
||||
$model = $this->getOrderAbnormalModel();
|
||||
$model->order_id = $params['order_id'];
|
||||
$model->status = 0;
|
||||
$model->abnormal_id = $params['abnormal_id'];
|
||||
$model->abnormal_title = $abnormal->title;
|
||||
$model->detail = $params['detail'];
|
||||
$model->type = 2;
|
||||
$model->admin_user = $worker->name;
|
||||
$model->admin_id = $workerId;
|
||||
$model->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单异常详情
|
||||
* @param int $workerId
|
||||
* @param int $orderId
|
||||
*/
|
||||
public function getOrderAbnormal(int $workerId, int $orderId)
|
||||
{
|
||||
return $this->getOrderAbnormalModel()
|
||||
->where('order_id', $orderId)
|
||||
->where('admin_id', $workerId)
|
||||
->where('type', 2)
|
||||
->field([
|
||||
'id',
|
||||
'order_id',
|
||||
'abnormal_id',
|
||||
'abnormal_title',
|
||||
'detail',
|
||||
'create_time',
|
||||
])
|
||||
->find();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,4 +19,37 @@ class OrderAbnormal extends WorkerApi
|
|||
$res = $this->getOrderAbnormalService()->create($this->user['id'], $params);
|
||||
$this->success('操作成功', $res);
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
$params = $this->request->request();
|
||||
$validate = $this->validate($params, \app\worker\validate\OrderAbnormal::class . '.info');
|
||||
if ($validate !== true) {
|
||||
$this->error($validate);
|
||||
}
|
||||
|
||||
$res = $this->getOrderAbnormalService()->getOrderAbnormal($this->user['id'], $params['order_id']);
|
||||
$this->success('操作成功', $res ?: []);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,24 @@
|
|||
|
||||
namespace app\worker\validate;
|
||||
|
||||
class OrderAbnormal
|
||||
{
|
||||
use think\Validate;
|
||||
|
||||
}
|
||||
class OrderAbnormal extends Validate
|
||||
{
|
||||
protected $rule = [
|
||||
'abnormal_id|异常原因' => 'require|number',
|
||||
'order_id|订单id' => 'require|number',
|
||||
'detail|异常详情' => 'require|max:200',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'abnormal_id.require' => '请选择异常原因',
|
||||
'detail.require' => '异常说明不能为空',
|
||||
'detail.max' => '异常说明不能超过 200 个字',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'create' => ['abnormal_id', 'order_id', 'detail'],
|
||||
'info' => ['order_id'],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user