diff --git a/application/common/model/OrderAbnormal.php b/application/common/model/OrderAbnormal.php index 2c2968c..62e67ba 100644 --- a/application/common/model/OrderAbnormal.php +++ b/application/common/model/OrderAbnormal.php @@ -15,4 +15,7 @@ class OrderAbnormal extends Model ]; + protected $autoWriteTimestamp = 'datetime'; + + protected $dateFormat = 'Y-m-d H:i:s'; } diff --git a/application/services/OrderAbnormalService.php b/application/services/OrderAbnormalService.php index cd05776..bf953eb 100644 --- a/application/services/OrderAbnormalService.php +++ b/application/services/OrderAbnormalService.php @@ -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(); + } } + + + + + + + + + + + + + + + + + + + + + diff --git a/application/worker/controller/OrderAbnormal.php b/application/worker/controller/OrderAbnormal.php index 85e12a6..33ba4da 100644 --- a/application/worker/controller/OrderAbnormal.php +++ b/application/worker/controller/OrderAbnormal.php @@ -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 ?: []); + } } + + + + + + + + + + + + + + + + + + + + + diff --git a/application/worker/validate/OrderAbnormal.php b/application/worker/validate/OrderAbnormal.php index bf7e099..0c635a6 100644 --- a/application/worker/validate/OrderAbnormal.php +++ b/application/worker/validate/OrderAbnormal.php @@ -2,7 +2,24 @@ namespace app\worker\validate; -class OrderAbnormal -{ +use think\Validate; -} \ No newline at end of file +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'], + ]; +}