diff --git a/app/Controller/MessageNoticeController.php b/app/Controller/MessageNoticeController.php new file mode 100644 index 0000000..a253ae6 --- /dev/null +++ b/app/Controller/MessageNoticeController.php @@ -0,0 +1,24 @@ +getDoctorMessageService(); + return $this->response->json($data); + } +} \ No newline at end of file diff --git a/app/Model/MessageNotice.php b/app/Model/MessageNotice.php index 511c541..d76bcc6 100644 --- a/app/Model/MessageNotice.php +++ b/app/Model/MessageNotice.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace App\Model; - use Hyperf\Database\Model\Collection; use Hyperf\Snowflake\Concern\Snowflake; @@ -15,6 +14,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $user_type 用户类型(1:患者端 2:医师端 3:药师端) * @property int $notice_type 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息) * @property int $notice_system_type 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息) + * @property int $read_status 读取状态(0:未读 1:已读) * @property string $from_name 发送人姓名 * @property string $notice_title 消息标题 * @property string $notice_send_time 发送时间 @@ -38,7 +38,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', 'from_name', 'notice_title', 'notice_send_time', 'notice_content', 'send_status', 'send_fail_reason', 'link_type', 'notice_params', 'created_at', 'updated_at']; + 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', 'link_type', 'notice_params', 'created_at', 'updated_at']; protected string $primaryKey = "message_id"; @@ -83,4 +83,37 @@ class MessageNotice extends Model { return self::create($data); } + + /** + * 获取数据-分页 + * @param array $params + * @param array $message_notice_system_params + * @param array $fields + * @param int|null $page + * @param int|null $per_page + * @return array + */ + public static function getMessageNoticePage(array $params, array $message_notice_system_params, array $fields = ["*"], int $page = null, ?int $per_page = 10): array + { + // 获取系统消息 + $message_notice_system = MessageNoticeSystem::select($fields)->where($message_notice_system_params)->orderBy('notice_send_time', 'desc'); + + $notice_system = self::select($fields)->where($params)->orderBy('notice_send_time', 'desc'); + + // 合并查询结果为一个虚拟表 + $query = $message_notice_system->union($notice_system); + + $results = $query->orderBy('notice_send_time', 'desc') + ->paginate($per_page, $fields, "page", $page); + + $data = array(); + $data['current_page'] = $results->currentPage();// 当前页码 + $data['total'] = $results->total();//数据总数 + $data['data'] = $results->items();//数据 + $data['per_page'] = $results->perPage();//每页个数 + $data['last_page'] = $results->lastPage();//最后一页 + + return $data; + } + } diff --git a/app/Model/MessageNoticeSystem.php b/app/Model/MessageNoticeSystem.php new file mode 100644 index 0000000..af593e5 --- /dev/null +++ b/app/Model/MessageNoticeSystem.php @@ -0,0 +1,74 @@ +exists(); + } + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getOne(array $params, array $fields = ['*']): object|null + { + return self::where($params)->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); + } +} diff --git a/app/Services/LoginService.php b/app/Services/LoginService.php index 4b9d8c5..4ca4553 100644 --- a/app/Services/LoginService.php +++ b/app/Services/LoginService.php @@ -299,8 +299,8 @@ class LoginService extends BaseService $data['user_id'] = $user->user_id; $data['user_name'] = $user['user_name']; $data['status'] = 1; - $data['open_id'] = $open_id; - $data['wx_session_key'] = $session_key; + $data['open_id'] = $open_id ?? ''; + $data['wx_session_key'] = $session_key ?? ""; if ($user['user_type'] == 1) { // 患者 @@ -391,7 +391,7 @@ class LoginService extends BaseService $token_user_data = array(); $token_user_data['user_id'] = $user['user_id']; // 用户id $token_user_data['user_type'] = $user['user_type'];// 用户类型 - $token_user_data['open_id'] = $open_id;// open_id + $token_user_data['open_id'] = $open_id ?? "";// open_id $token_user_data['client_user_id'] = $client_user_id;// 对应客户端id // 发放token diff --git a/app/Services/MessageNoticeService.php b/app/Services/MessageNoticeService.php new file mode 100644 index 0000000..c26052f --- /dev/null +++ b/app/Services/MessageNoticeService.php @@ -0,0 +1,50 @@ +request->getAttribute("userInfo") ?? []; + + $page = $this->request->input('page', 1); + $per_page = $this->request->input('per_page', 10); + + $params = array(); + $params['user_id'] = $user_info['user_id']; + $params['user_type'] = 2; + $params['notice_type'] = 1; // 消息类型(1:医生服务通知 2:医生系统公告 3:患者系统消息 + $params['send_status'] = 1; + + $message_notice_system_params = array(); + $message_notice_system_params["notice_type"] = 1; + $message_notice_system_params["send_status"] = 1; + + $fields = [ + 'notice_id', + 'notice_system_type', + 'from_name', + 'notice_title', + 'notice_content', + 'send_status', + 'notice_send_time', + 'link_type', + 'notice_params', + ]; + + $result = MessageNotice::getMessageNoticePage($params,$message_notice_system_params,$fields,$page,$per_page); + + return success($result); + } +} \ No newline at end of file diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index a9d5558..793513c 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -196,6 +196,7 @@ class PatientOrderService extends BaseService $order_inquiry['user_doctor'] = []; if (!empty($order_inquiry['doctor_id'])) { $fields = [ + 'user_id', 'doctor_id', 'user_name', 'doctor_title', diff --git a/config/routes.php b/config/routes.php index 48d9617..1980650 100644 --- a/config/routes.php +++ b/config/routes.php @@ -19,6 +19,7 @@ use App\Controller\IndexController; use App\Controller\InquiryController; use App\Controller\LoginController; use App\Controller\CodeController; +use App\Controller\MessageNoticeController; use App\Controller\PatientCaseController; use App\Controller\PatientCenterController; use App\Controller\PatientDoctorController; @@ -185,6 +186,15 @@ Router::addGroup('/doctor', function () { Router::get('', [UserDoctorController::class, 'getDoctorBrief']); }); }); + + // 消息通知 + Router::addGroup('/message', function () { + // 获取医生服务消息列表-分页 + Router::get('/service', [MessageNoticeController::class, 'getDoctorMessageService']); + + // 获取医生系统公告列表-分页 + Router::get('/system', [MessageNoticeController::class, 'getDoctorMessageSystem']); + }); }); /** @@ -574,6 +584,16 @@ Router::addGroup('/address', function () { Router::delete('/{address_id:\d+}', [UserController::class, 'deleteUserAddress']); }); + +// 消息通知 +Router::addGroup('/message', function () { + // 消息已读 + Router::post('/read/{notice_id:\d+}', [UserDoctorController::class, 'getDoctorCenter']); + + // 一键消息已读 + Router::get('/read', [UserDoctorController::class, 'getDoctorCenterInfo']); +}); + // 未开发接口