From e41253d65d93fe4606391b35b2d452056717f496 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 22 Sep 2023 13:16:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=85=8D=E7=BD=AE=EF=BC=8C=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=85=8D=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/UserController.php | 27 +++++++ app/Model/UserSystem.php | 98 +++++++++++++++++++++++ app/Request/UserRequest.php | 9 ++- app/Services/OrderPrescriptionService.php | 80 ------------------ app/Services/UserService.php | 70 ++++++++++++++++ config/routes.php | 6 ++ 6 files changed, 209 insertions(+), 81 deletions(-) create mode 100644 app/Model/UserSystem.php diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 6de89b5..fd32538 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -189,4 +189,31 @@ class UserController extends AbstractController $data = $UserService->getLocation(); return $this->response->json($data); } + + /** + * 获取用户配置 + * @return ResponseInterface + */ + public function getUserSystem(): ResponseInterface + { + $UserService = new UserService(); + $data = $UserService->getUserSystem(); + return $this->response->json($data); + } + + /** + * 修改用户配置 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function putUserSystem(): ResponseInterface + { + $request = $this->container->get(UserRequest::class); + $request->scene('putUserSystem')->validateResolved(); + + $UserService = new UserService(); + $data = $UserService->putUserSystem(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Model/UserSystem.php b/app/Model/UserSystem.php new file mode 100644 index 0000000..7c578d1 --- /dev/null +++ b/app/Model/UserSystem.php @@ -0,0 +1,98 @@ +first($fields); + } + + /** + * 获取数据-多 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 获取是否存在 + * @param array $params + * @return bool + */ + public static function getExists(array $params): bool + { + return self::where($params)->exists(); + } + + /** + * 获取数量 + * @param array $params + * @return int + */ + public static function getCount(array $params): int + { + return self::where($params)->count(); + } + + /** + * 新增 + * @param array $data + * @return \Hyperf\Database\Model\Model|UserSystem + */ + public static function addUserSystem(array $data): \Hyperf\Database\Model\Model|UserSystem + { + return self::create($data); + } + + /** + * 修改 + * @param array $params + * @param array $data + * @return int + */ + public static function edit(array $params = [], array $data = []): int + { + return self::where($params)->update($data); + } + +} diff --git a/app/Request/UserRequest.php b/app/Request/UserRequest.php index 7c1686f..ad685c9 100644 --- a/app/Request/UserRequest.php +++ b/app/Request/UserRequest.php @@ -41,6 +41,9 @@ class UserRequest extends FormRequest 'is_default', 'tag', ], + 'putUserSystem' => [ // 修改用户配置 + 'is_accept_im_message_push', + ], ]; /** @@ -59,7 +62,6 @@ class UserRequest extends FormRequest return [ 'avatar' => 'required|url', 'user_name' => 'required', - 'province_id' => 'required_with:city_id,county_id', 'city_id' => 'required_with:county_id', 'county_id' => 'required', @@ -68,6 +70,7 @@ class UserRequest extends FormRequest 'consignee_tel' => 'required', 'is_default' => ['required','numeric','min:0','max:1'], 'tag' => ['sometimes','required','numeric','min:1','max:4'], + 'is_accept_im_message_push' => ['required','numeric','min:0','max:1'], ]; } @@ -95,6 +98,10 @@ class UserRequest extends FormRequest 'tag.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'tag.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), 'tag.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_accept_im_message_push.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_accept_im_message_push.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_accept_im_message_push.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'is_accept_im_message_push.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), ]; } } diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index e23ce8f..6c29f4c 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -124,86 +124,6 @@ class OrderPrescriptionService extends BaseService return OrderPrescription::getCount($params); } -// /** -// * 开具处方 -// * 医生-正常开具 -// * 药师-先开具药师处方,再开具医院签章 -// * @param string $order_prescription_id 处方id -// * @param string $user_id 用户id -// * @return array -// */ -// public function openPrescription1(string $order_prescription_id, string $user_id): array -// { -// try { -// // 获取用户数据 -// $params = array(); -// $params['user_id'] = $user_id; -// $user = User::getOne($params); -// if (empty($user)) { -// throw new BusinessException("用户数据错误"); -// } -// -// if ($user['user_type'] != 2 && $user['user_type'] != 3) { -// throw new BusinessException("用户类型错误"); -// } -// -// // 获取处方数据 -// $params = array(); -// $params['order_prescription_id'] = $order_prescription_id; -// $order_prescription = OrderPrescription::getOne($params); -// if (empty($order_prescription)) { -// throw new BusinessException("处方数据错误"); -// } -// -// if (empty($order_prescription['doctor_created_time'])) { -// throw new BusinessException("医生开方日期错误"); -// } -// -// $CaService = new CaService($order_prescription,$user); -// -// // 获取云证书签名+验证云证书签名 -// $CaService->getVerifyCertSign($order_prescription,1); -// -// // 医生 -// if ($user['user_type'] == 2) { -// // 生成处方图片+处方图片生成pdf -// $prescription_img_oss_path = $CaService->createPrescriptionImgPdf($order_prescription); -// } -// -// // 药师-医院签章 -// if ($user['user_type'] == 3) { -// // 获取医院云证书签名+验证云证书签名 -// $CaService->getVerifyCertSign($order_prescription,2); -// -// // 下载医生开具的处方pdf至本地 -// $CaService->downOssPdfToLocal(); -// } -// -// // 进行处方pdf签章 -// $file_id = $CaService->addSignPdf($user['user_type']); -// -// // 药师-医院签章 -// if ($user['user_type'] == 3) { -// // 药师端时,需要进行系统签章 -// // 把药师签章的pdf存储至本地文件 -// // 下载药师签章pdf图片 -// dump($file_id); -// $CaService->downCaPdfToLocal($file_id,1); -// -// // 进行处方pdf签章 -// $file_id = $CaService->addSignPdf($user['user_type']); -// } -// -// $result = array(); -// $result['prescription_img_oss_path'] = $prescription_img_oss_path ?? ""; -// $result['file_id'] = $file_id; -// return $result; -// -// } catch (\Throwable $e) { -// throw new BusinessException($e->getMessage()); -// } -// } - /** * 开具处方 * 医生-正常开具 diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 8c8f11c..209362b 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -13,6 +13,7 @@ use App\Model\UserDoctorInfo; use App\Model\UserLocation; use App\Model\UserPatient; use App\Model\UserShipAddress; +use App\Model\UserSystem; use App\Utils\Mask; use App\Utils\PcreMatch; use Extend\Tencent\map\Location; @@ -686,6 +687,75 @@ class UserService extends BaseService return success($area); } + /** + * 获取用户配置 + * @return array + */ + public function getUserSystem(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + // 定义返回数据 + $result = array( + "is_accept_im_message_push" => 0, + ); + + // 获取用户配置数据 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user_system = UserSystem::getOne($params); + if (empty($user_system)){ + return success($result); + } + + $result['is_accept_im_message_push'] = 0; + return success($result); + } + + /** + * 修改用户配置 + * @return array + */ + public function putUserSystem(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $request_params = $this->request->all(); + + // 获取用户配置数据 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user_system = UserSystem::getOne($params); + if (empty($user_system)){ + // 新增 + $data = array(); + $data['user_id'] = $user_info['user_id']; + $data['is_accept_im_message_push'] = $request_params['is_accept_im_message_push']; + $user_system = UserSystem::addUserSystem($data); + if (empty($user_system)){ + return fail(); + } + }else{ + // 修改 + $data = array(); + + if ($user_system['is_accept_im_message_push'] != $request_params['is_accept_im_message_push']){ + $data['is_accept_im_message_push'] = $request_params['is_accept_im_message_push']; + } + + if (!empty($data)){ + $params = array(); + $params['user_system_id'] = $user_system['user_system_id']; + + $res = UserSystem::edit($params,$data); + if (!$res){ + return fail(); + } + } + } + return success(); + } + + /** * 通过user_id获取用户openid * @param string|int $user_id diff --git a/config/routes.php b/config/routes.php index 9045e2a..ba62ff5 100644 --- a/config/routes.php +++ b/config/routes.php @@ -696,6 +696,12 @@ Router::addGroup('/user', function () { // 获取用户地址 Router::get('/location', [UserController::class, 'getLocation']); + + // 获取用户配置 + Router::get('/system', [UserController::class, 'getUserSystem']); + + // 修改用户配置 + Router::put('/system', [UserController::class, 'putUserSystem']); }); // 获取患者问诊病例