From fc288e1c49f2179a597cbc092d8edab92c3ff442 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 24 Jul 2020 15:51:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=AF=84=E4=BB=B7=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20TODO=20LIST=EF=BC=9A=201=E3=80=81=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E3=80=81=E5=B8=82=E5=9C=BA=E3=80=81=E6=9C=8D=E5=8A=A1=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=202=E3=80=81=E4=BF=9D=E5=AD=98=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/ErrorCode.php | 5 ++++ app/Controller/ServiceEvaluateController.php | 15 +++++++++++- .../Handler/ValidationExceptionHandler.php | 11 +++------ app/Model/ServiceEvaluate.php | 22 ++++++++++++++++++ app/Request/EvaluateRequest.php | 23 ++++++++++++++++--- app/Service/ServiceEvaluateService.php | 18 +++++++++++++-- .../ServiceEvaluateServiceInterface.php | 2 +- 7 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 app/Model/ServiceEvaluate.php diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php index 7b18ba6..a7fee16 100644 --- a/app/Constants/ErrorCode.php +++ b/app/Constants/ErrorCode.php @@ -28,4 +28,9 @@ class ErrorCode extends AbstractConstants * @Message("Params Invalid!") */ const PARAMS_INVALID = 900; + + /** + * @Message("Save failure!"); + */ + const SAVE_FAILURE = 100; } diff --git a/app/Controller/ServiceEvaluateController.php b/app/Controller/ServiceEvaluateController.php index bacaa7f..f1d08e8 100644 --- a/app/Controller/ServiceEvaluateController.php +++ b/app/Controller/ServiceEvaluateController.php @@ -2,6 +2,8 @@ namespace App\Controller; +use App\Constants\ErrorCode; +use App\Exception\BusinessException; use App\Request\EvaluateRequest; use App\Service\ServiceEvaluateServiceInterface; use Hyperf\Di\Annotation\Inject; @@ -16,10 +18,21 @@ class ServiceEvaluateController extends BaseController /** * 提交评价 + * + * 评价内容: + * 服务态度评分、服务质量评分、满意度评分、评价内容 + * 关联信息: + * 服务专员ID、市场ID、评价的用户ID + * 查询信息: + * 用户注册/创建时间 + * */ public function evaluate(EvaluateRequest $validator) { - return $this->success($this->evaluateService->evaluate($this->request)); + // TODO 数据保存失败的返回处理 + $ret = $this->evaluateService->evaluate(); + return $this->success($ret); + } } \ No newline at end of file diff --git a/app/Exception/Handler/ValidationExceptionHandler.php b/app/Exception/Handler/ValidationExceptionHandler.php index c95ac4f..cc2384c 100644 --- a/app/Exception/Handler/ValidationExceptionHandler.php +++ b/app/Exception/Handler/ValidationExceptionHandler.php @@ -7,17 +7,10 @@ use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; use Hyperf\Validation\ValidationException; use Psr\Http\Message\ResponseInterface; -// use Hyperf\Di\Annotation\Inject; -// use Hyperf\HttpServer\Contract\ResponseInterface as Response; use Throwable; class ValidationExceptionHandler extends ExceptionHandler { - // /** - // * @Inject - // * @var Response - // */ - // private $reponse; public function handle(Throwable $throwable, ResponseInterface $response) { @@ -30,7 +23,9 @@ class ValidationExceptionHandler extends ExceptionHandler "message" => $throwable->validator->errors()->first() ]); - return $response->withStatus($throwable->status)->withBody(new SwooleStream($content)); + return $response->withHeader('Content-Type', 'application/json') + ->withStatus($throwable->status) + ->withBody(new SwooleStream($content)); } public function isValid(Throwable $throwable): bool diff --git a/app/Model/ServiceEvaluate.php b/app/Model/ServiceEvaluate.php new file mode 100644 index 0000000..8d1e89a --- /dev/null +++ b/app/Model/ServiceEvaluate.php @@ -0,0 +1,22 @@ + 'required|nonempty', + 'c_attitude' => 'required|nonempty|integer', + 'c_service' => 'required|nonempty|integer', + 'c_quality' => 'required|nonempty|integer', + 'content' => 'required|nonempty|between:15,150', + 'user_id' => 'required|nonempty|integer', + 'service_personnel_id' => 'required|nonempty|integer', + 'market_id' => 'required|nonempty|integer', ]; } public function messages(): array { return [ - 'user_id.required' => ':attribute参数缺失', - 'user_id.nonempty' => ':attribute信息异常', + 'user_id.*' => ':attribute信息不正确', + 'service_personnel_id.*' => ':attribute信息不正确', + 'market_id.*' => ':attribute信息不正确', + 'c_attitude.*' => ':attribute信息不正确', + 'c_service.*' => ':attribute信息不正确', + 'c_quality.*' => ':attribute信息不正确', + 'content.*' => ':attribute信息不正确', ]; } @@ -38,6 +49,12 @@ class EvaluateRequest extends FormRequest { return [ 'user_id' => '用户', + 'service_personnel_id' => '服务专员', + 'market_id' => '服务专员市场', + 'c_attitude' => '服务态度评分', + 'c_service' => '服务值评分', + 'c_quality' => '服务质量评分', + 'content' => '服务评价', ]; } } diff --git a/app/Service/ServiceEvaluateService.php b/app/Service/ServiceEvaluateService.php index fd49991..838e914 100644 --- a/app/Service/ServiceEvaluateService.php +++ b/app/Service/ServiceEvaluateService.php @@ -2,13 +2,27 @@ namespace App\Service; +use App\Model\ServiceEvaluate; +use Hyperf\DbConnection\Db; use Hyperf\HttpServer\Contract\RequestInterface; +use Hyperf\Di\Annotation\Inject; class ServiceEvaluateService implements ServiceEvaluateServiceInterface { - public function evaluate(RequestInterface $request) + /** + * @Inject + * @var RequestInterface + */ + private $request; + + public function evaluate() { - return $request->all(); + $data = $this->request->all(); + + $data['user_created_at'] = Db::table('ims_cjdc_user') + ->where(['id' => $data['user_id']]) + ->value('join_time'); + return ServiceEvaluate::create($data); } } \ No newline at end of file diff --git a/app/Service/ServiceEvaluateServiceInterface.php b/app/Service/ServiceEvaluateServiceInterface.php index eda4f7c..0cadebe 100644 --- a/app/Service/ServiceEvaluateServiceInterface.php +++ b/app/Service/ServiceEvaluateServiceInterface.php @@ -7,6 +7,6 @@ use Hyperf\HttpServer\Contract\RequestInterface; interface ServiceEvaluateServiceInterface { - public function evaluate(RequestInterface $request); + public function evaluate(); } \ No newline at end of file