diff --git a/app/Controller/MessageNoticeController.php b/app/Controller/MessageNoticeController.php index e9c31b8..938074a 100644 --- a/app/Controller/MessageNoticeController.php +++ b/app/Controller/MessageNoticeController.php @@ -2,7 +2,10 @@ namespace App\Controller; +use App\Request\MessageNoticeRequest; use App\Services\MessageNoticeService; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; /** @@ -54,4 +57,31 @@ class MessageNoticeController extends AbstractController $data = $MessageNoticeService->putMessageReadId(); return $this->response->json($data); } + + /** + * 一键消息已读 + * @return ResponseInterface + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function putMessageRead(): ResponseInterface + { + $request = $this->container->get(MessageNoticeRequest::class); + $request->scene('putMessageRead')->validateResolved(); + + $MessageNoticeService = new MessageNoticeService(); + $data = $MessageNoticeService->putMessageRead(); + return $this->response->json($data); + } + + /** + * 获取患者系统消息通知最后一条消息列表 + * @return ResponseInterface + */ + public function getPatientMessageServiceLast(): ResponseInterface + { + $MessageNoticeService = new MessageNoticeService(); + $data = $MessageNoticeService->getPatientMessageServiceLast(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Model/MessageNotice.php b/app/Model/MessageNotice.php index da04068..61f9012 100644 --- a/app/Model/MessageNotice.php +++ b/app/Model/MessageNotice.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace App\Model; +use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\Collection; use Hyperf\Snowflake\Concern\Snowflake; @@ -15,6 +16,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $notice_type 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息) * @property int $notice_system_type 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) * @property int $read_status 读取状态(0:未读 1:已读) + * @property int $inquiry_type 问诊类型(医生端服务通知存在 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) * @property string $from_name 发送人姓名 * @property string $notice_title 消息标题 * @property string $notice_send_time 发送时间 @@ -41,7 +43,7 @@ class MessageNotice extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['notice_id', 'user_id', 'user_type', 'notice_type', 'notice_system_type', 'read_status', 'from_name', 'notice_title', 'notice_send_time', 'notice_content', 'send_status', 'send_fail_reason', 'button_type', 'link_type', 'link_params', 'show_type', 'show_params', 'created_at', 'updated_at']; + protected array $fillable = ['notice_id', 'user_id', 'user_type', 'notice_type', 'notice_system_type', 'read_status', 'inquiry_type', 'from_name', 'notice_title', 'notice_send_time', 'notice_content', 'send_status', 'send_fail_reason', 'button_type', 'link_type', 'link_params', 'show_type', 'show_params', 'created_at', 'updated_at']; protected string $primaryKey = "message_id"; @@ -121,4 +123,26 @@ class MessageNotice extends Model { return self::where($params)->update($data); } + + /** + * 获取单条 + * @param array $params + * @param string $order_field + * @param array $fields + * @return object|null + */ + public static function getOrderOne(array $params, string $order_field,array $fields = ['*']): object|null + { + return self::where($params)->orderBy($order_field,'desc')->first($fields); + } + + /** + * 获取数量 + * @param array $params + * @return int + */ + public static function getCount(array $params): int + { + return self::where($params)->count(); + } } diff --git a/app/Request/MessageNoticeRequest.php b/app/Request/MessageNoticeRequest.php new file mode 100644 index 0000000..2150b45 --- /dev/null +++ b/app/Request/MessageNoticeRequest.php @@ -0,0 +1,54 @@ + [ + 'notice_type', + 'notice_system_type', + ], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'notice_type' => 'required|integer|min:1|max:3', + 'notice_system_type' => 'required|integer|min:0|max:4', + ]; + } + + /** + * 获取已定义验证规则的错误消息. + */ + public function messages(): array + { + return [ + 'notice_type.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_type.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_type.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_type.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_system_type.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_system_type.integer' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_system_type.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + 'notice_system_type.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + ]; + } +} diff --git a/app/Services/MessageNoticeService.php b/app/Services/MessageNoticeService.php index 67535b1..6692317 100644 --- a/app/Services/MessageNoticeService.php +++ b/app/Services/MessageNoticeService.php @@ -30,6 +30,7 @@ class MessageNoticeService extends BaseService $fields = [ 'notice_id', 'read_status', + 'inquiry_type', 'from_name', 'notice_title', 'notice_send_time', @@ -160,4 +161,84 @@ class MessageNoticeService extends BaseService return success(); } + + /** + * 一键消息已读 + * @return array + */ + public function putMessageRead(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $notice_type = $this->request->input('notice_type'); + + $data = array(); + $data['read_status'] = 1; + + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_type'] = $user_info['user_type']; + $params['notice_type'] = $notice_type; + $params['send_status'] = 1; + MessageNotice::edit($params,$data); + + return success(); + } + + /** + * 获取患者系统消息通知最后一条消息列表 + * @return array + */ + public function getPatientMessageServiceLast(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $result = array(); + + // 服务消息 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_id'] = 1; + $params['user_type'] = 1; + $params['notice_type'] = 3; // 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息 + $params['notice_system_type'] = 1; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) + $params['send_status'] = 1; + $result['service']['info'] = MessageNotice::getOrderOne($params,'notice_send_time',['*']); + $result['service']['count'] = MessageNotice::getCount($params); + + // 福利消息 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_id'] = 1; + $params['user_type'] = 1; + $params['notice_type'] = 3; // 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息 + $params['notice_system_type'] = 2; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) + $params['send_status'] = 1; + $result['benefit']['info'] = MessageNotice::getOrderOne($params,'notice_send_time',['*']); + $result['benefit']['count'] = MessageNotice::getCount($params); + + // 退款消息 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_id'] = 1; + $params['user_type'] = 1; + $params['notice_type'] = 3; // 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息 + $params['notice_system_type'] = 3; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) + $params['send_status'] = 1; + $result['refund']['info'] = MessageNotice::getOrderOne($params,'notice_send_time',['*']); + $result['refund']['count'] = MessageNotice::getCount($params); + + // 物流消息 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_id'] = 1; + $params['user_type'] = 1; + $params['notice_type'] = 3; // 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息 + $params['notice_system_type'] = 4; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) + $params['send_status'] = 1; + $result['logistics']['info'] = MessageNotice::getOrderOne($params,'notice_send_time',['*']); + $result['logistics']['count'] = MessageNotice::getCount($params); + + return success($result); + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index ff66b35..13d7afe 100644 --- a/config/routes.php +++ b/config/routes.php @@ -393,6 +393,18 @@ Router::addGroup('/patient', function () { Router::post('/pay', [PatientOrderController::class, 'addPatientOrderPay']); }); + // 消息通知 + Router::addGroup('/message', function () { + // 获取患者系统消息通知最后一条消息列表 + Router::get('/system/last', [MessageNoticeController::class, 'getPatientMessageServiceLast']); + + // 获取患者服务、福利、退款、物流消息通知列表-分页 + Router::get('/system', [MessageNoticeController::class, 'getPatientMessageSystem']); + + // 获取患者系统通知消息详情 + Router::get('/system/{notice_id:\d+}', [MessageNoticeController::class, 'getPatientMessageSystemInfo']); + }); + }); // 药师端api @@ -587,13 +599,16 @@ Router::addGroup('/address', function () { Router::delete('/{address_id:\d+}', [UserController::class, 'deleteUserAddress']); }); -// 消息通知 +// 消息 Router::addGroup('/message', function () { - // 消息已读 - Router::put('/read/{notice_id:\d+}', [MessageNoticeController::class, 'putMessageReadId']); + // 消息通知 + Router::addGroup('/notice', function () { + // 消息已读 + Router::put('/read/{notice_id:\d+}', [MessageNoticeController::class, 'putMessageReadId']); - // 一键消息已读 - Router::get('/read', [MessageNoticeController::class, 'putMessageRead']); + // 一键消息已读 + Router::get('/read', [MessageNoticeController::class, 'putMessageRead']); + }); }); // 问诊订单