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