diff --git a/app/Controller/UserController.php b/app/Controller/UserController.php index 82a0825..b1a680b 100644 --- a/app/Controller/UserController.php +++ b/app/Controller/UserController.php @@ -168,209 +168,11 @@ class UserController extends AbstractController return $this->response->json($data); } - // 支付测试 - public function testpay(){ - // 发起支付 - $out_trade_no = $this->request->input('out_trade_no'); -// $generator = $this->container->get(IdGeneratorInterface::class); -// -// $WechatPay = new WechatPay(1,2); -// -// // 获取预支付交易会话标识 -// $total = 0.01 * 100; -// $prepay = $WechatPay->getJsapiPrepayId($out_trade_no,$total,"omgU35DlE-rxTAGgcBjOuc4xdcX8"); -// if (empty($prepay)){ -// return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败"); -// } -// -// // 获取小程序支付配置 -// $pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']); -// return $this->response->json($pay_config); - - // 发起退款 -// $WechatPay = new WechatPay(1,2); -// -// $params = array(); -// $params['order_inquiry_id'] = 1; -// $order_inquiry = OrderInquiry::getOne($params); -// -// -// $options = array(); -// $options['transaction_id'] = "4200001756202303145016495897"; -// $options['out_refund_no'] = "123456"; -// $options['reason'] = "退款原因"; -// $options['amount'] = [ -// 'refund' => (int)1, -// 'total' => (int)1, -// 'currency' => "CNY", -// ]; -// -// $result = $WechatPay->refund($options); -// dump($result); - - // 创建账号 - $account = new Account(); - $profile = new Profile(); - $group = new Group(); - $friend = new Friend(); - $message = new Message(); -// $result = $account->createAccount(10009,'测试患者9',"https://img.applets.igandanyiyuan.com/applet/doctor/avatar/03dc8df2-e7c0-4ad9-b87e-5133e40e0f76.jpg"); - - // 查询账号导入状态 -// $result = $account->checkAccountStatus("123456"); - - // 设置账户资料 -// $arg = array(); -// $arg['Tag_Profile_IM_Gender'] = "Gender_Type_Male"; -// $arg['Tag_Profile_IM_BirthDay'] = 19961007; -// $arg['Tag_Profile_Custom_Hname'] = "协和医院"; -// $arg['Tag_Profile_Custom_Title'] = "主任医师"; -// $result = $profile->setProfile("123456",$arg); - - // 添加用户好友分组 -// $result = $group->addUserGroup('123456'); - - // 获取用户好友分组 -// $result = $group->getUserGroup('123456'); - - // 添加好友 -// $result = $friend->addFriend("123456",'1234567',"快速问诊"); - - // 发送消息 -// $arg = array(); -//// $arg['From_Account'] = "10000"; // 发送方user_id 如系统发送,无需填写 -// $arg['To_Account'] = "10000"; // 接收方user_id -//// $arg['ForbidCallbackControl'] = ['ForbidBeforeSendMsgCallback']; -//// $arg['SendMsgControl'] = []; -// -// $arg['MsgBody'] = [ -//// [ -//// "MsgType" => "TIMTextElem", -//// "MsgContent" => [ -//// "Text" => "ceshi", -//// ], -//// ] -// [ -// "MsgType" => "TIMCustomElem", -// "MsgContent" => [ -// "Data" => "{\"message_type\":1,\"content\":\"\"}", -// "Desc" => "自定义消息", -// "Ext" => "url", -// "Sound" => "dingdong.aiff", -// ], -// ] -// ]; -// -// // 自定义消息 -// $cloud_custom_data = array(); -// $cloud_custom_data['order_inquiry_id'] = 1; -// $cloud_custom_data['is_system'] = 0; -// $cloud_custom_data['inquiry_type'] = 2; -// -// $arg['CloudCustomData'] = json_encode($cloud_custom_data,JSON_UNESCAPED_UNICODE); -// -// $result = $message->sendMessage($arg); -// -//// $result = $profile->getOneAccountPortraitList("123456"); -// -// dump($result); - - - // 专家-公益,发送im消息 -// $ImService = new ImService(); -// -// // 获取订单医生数据 -// $params = array(); -// $params['doctor_id'] = "491925054779883520"; -// $user_doctor = UserDoctor::getOne($params); -// if (empty($user_doctor)){ -// Log::getInstance()->info("医生数据错误"); -// } -// -// // 发送消息 -// $ImService->sendMessage($user_doctor['user_id'],"491923510680424449","等待医生接诊",491937904055369728); - -// -// $data = array(); -// $data['order_inquiry_id'] = 4; -// $data['to_user_id'] = 10004; -// $data['patient_name'] = "用户4"; -// $data['patient_sex'] = 2; -// $data['patient_age'] = 19; -// $data['inquiry_status'] = 1; -// $data['message_send_time'] = 1678112190; -// $data['message_seq'] = 101; -// $data['message_type'] = "TIMTextElem"; -// $data['last_message_content']['Text'] = "测试消息4"; -// -// $imService = new ImService(); -// $imService->addRecentContactRecordCache("491925054779883520", 2, 10004, $data); - - // 银行卡三要素认证 -// $BankCard = new BankCard(); -// -// $params = array(); -// $params['bankCardNo'] = "6217000010175646317"; -// $params['name'] = "吴从兴"; -// $params['idCardNo'] = "372929199610075412"; -// $res = $BankCard->checkBankCard($params); -// if (!empty($res)) { -// return fail(HttpEnumCode::HTTP_ERROR, $res); -// } - - // 对接处方平台 -// $Prescription = new Prescription(); -// $token = $Prescription->getProd(); -// dump($token); - - // 创建im账号 -// $account = new Account(); - // 创建单个账号 -// $account->createAccount("111295","测试患者1",""); -// $profile = new Profile(); -// $result = $profile->getOneAccountPortraitList("111295"); -// dump($result); -// $arg = array(); -// $arg['Tag_Profile_IM_Image'] = "https://img.applets.igandanyiyuan.com/applet/doctor/avatar/03dc8df2-e7c0-4ad9-b87e-5133e40e0f76.jpg"; -// $profile->setProfile("111295",$arg); - -// $ImService = new ImService(); -// $ImService->setUserProfile("491925054435950592"); - -// $Prescription = new Prescription(); -// $token = $Prescription->getLogisticsFee(); -// dump($token); - - -// $ImService = new ImService(); -// -// // 发送消息 -// $ImService->sendMessage("491925054435950592","492404831991414785","等待医生接诊","494837308861095936",1); - - - -// $ImService = new ImService(); -// // 发送消息 - // 自定义消息 -// $cloud_custom_data = array(); -// $cloud_custom_data['order_inquiry_id'] = "494837308861095936"; -// $cloud_custom_data['is_system'] = 1; -// $cloud_custom_data['inquiry_type'] = 1; -// -// // 消息内容 -// $message_content_data = array(); -// $message_content_data['message_type'] = 1; -// $message_content_data['content'] = "--测试--"; -// $message_content_data['desc'] = "温馨提示:您可继续补充问诊内容,便于更快确认病情,医生均在临床一线工作,还请耐心等待,医生接诊会第一时间短信通知您。"; -// $message_content = [ -// 'Data' => json_encode($message_content_data,JSON_UNESCAPED_UNICODE), -// ]; -// -// $ImService->sendMessage("491925054435950592", "492404831991414785", $message_content, "TIMCustomElem", $cloud_custom_data); -// -// $RecentContact = new RecentContact(); -// $result = $RecentContact->getRecentContactPage(); - - + // 上报用户地址 + public function postLocation(): ResponseInterface + { + $UserService = new UserService(); + $data = $UserService->postLocation(); + return $this->response->json($data); } } \ No newline at end of file diff --git a/app/Model/UserLocation.php b/app/Model/UserLocation.php new file mode 100644 index 0000000..5717387 --- /dev/null +++ b/app/Model/UserLocation.php @@ -0,0 +1,79 @@ +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 $data 新增数据 + * @return \Hyperf\Database\Model\Model|UserLocation + */ + public static function addUserLocation(array $data): \Hyperf\Database\Model\Model|UserLocation + { + return self::create($data); + } + + /** + * 修改-批量 + * @param array $params + * @param array $data + * @return int + */ + public static function editUserLocation(array $params = [], array $data = []): int + { + return self::where($params)->update($data); + } +} diff --git a/app/Services/SystemService.php b/app/Services/SystemService.php index c6d7d60..8a30d61 100644 --- a/app/Services/SystemService.php +++ b/app/Services/SystemService.php @@ -47,7 +47,6 @@ class SystemService extends BaseService return fail(); } - dump($system_inquiry_time->toArray()); $time = []; foreach ($system_inquiry_time as $item){ $start_hour = substr($item['start_time'], 0, 1); diff --git a/app/Services/UserService.php b/app/Services/UserService.php index f597bed..17f3604 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -9,10 +9,12 @@ use App\Model\User; use App\Model\User as UserModel; use App\Model\UserDoctor; use App\Model\UserDoctorInfo; +use App\Model\UserLocation; use App\Model\UserPatient; use App\Model\UserShipAddress; use App\Utils\Mask; use App\Utils\PcreMatch; +use Extend\Tencent\map\Location; use Extend\TencentIm\Profile; use Extend\Wechat\Wechat; use GuzzleHttp\Exception\GuzzleException; @@ -553,6 +555,71 @@ class UserService extends BaseService return success($popup->toArray()); } + /** + * 上报用户地址 + * @return array + */ + public function postLocation(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + $request_params = $this->request->all(); + + if (empty($request_params['lon']) || empty($request_params['lat'])){ + return success(); + } + + // 处理地址逆解析 + try { + $location = new Location(); + $result = $location->getLocation($request_params['lon'],$request_params['lat']); + if (empty($result)){ + return success(); + } + + if (empty($result['address_component'])){ + return success(); + } + + if (empty($result['address_component']['province']) || empty($result['address_component']['city'])){ + return success(); + } + + // 处理需修改/新增数据 + $data = array(); + $data['lon'] = $request_params['lon']; + $data['lat'] = $request_params['lat']; + $data['province'] = $result['address_component']['province']; + $data['city'] = $result['address_component']['city']; + $data['county'] = $result['address_component']['district'] ?: ""; + $data['address'] = $result['address_component']['street_number'] ?: ""; + + // 获取用户地理位置 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user_location = UserLocation::getOne($params); + if (empty($user_location)){ + // 新增 + $data['user_id'] = $user_info['user_id']; + $user_location = UserLocation::addUserLocation($data); + if (empty($user_location)){ + return success(); + } + }else{ + // 修改 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $res = UserLocation::editUserLocation($params,$data); + if (!$res){ + return success(); + } + } + }catch (\Exception $e){ + return success(); + } + + return success(); + } + /** * 通过user_id获取用户openid * @param string|int $user_id diff --git a/config/config.php b/config/config.php index 3197055..8b0ae64 100644 --- a/config/config.php +++ b/config/config.php @@ -11,6 +11,7 @@ declare(strict_types=1); */ use Hyperf\Contract\StdoutLoggerInterface; use Psr\Log\LogLevel; +use function Hyperf\Support\env; return [ 'app_name' => env('APP_NAME', 'gdxz'), @@ -109,4 +110,8 @@ return [ "api_url" => env('LOGISTICS_APP_URL', 'https://poll.kuaidi100.com/poll/query.do'), "salt" => env('LOGISTICS_SALT', 'gdxz2023.d'), ], + 'tencent_map' => [ // 腾讯地图 + "secret" => env('TENCENT_MAP_SECRET', 'RDQBZ-SDQ6Z-GKRX5-TG7P5-R2LN5-BWFCH'), + "key" => env('TENCENT_MAP_KEY', '6tZo4VootrcGOuYqRX9aoGdtAmuSNXd4') + ], ]; diff --git a/config/routes.php b/config/routes.php index 47dd9f2..9f66210 100644 --- a/config/routes.php +++ b/config/routes.php @@ -265,6 +265,15 @@ Router::addGroup('/patient', function () { Router::get('/lowest-price', [InquiryController::class, 'getInquiryLowestPrice']); }); + // 检测 + Router::addGroup('/detection', function () { + // 创建检测订单 + Router::post('', [InquiryController::class, 'addDetectionOrder']); + + // 获取检测机构合作医生列表 + Router::get('/doctor', [InquiryController::class, 'getDetectionDoctor']); + }); + // 医生数据 Router::addGroup('/doctor', function () { // 获取医生列表-问诊 @@ -410,6 +419,24 @@ Router::addGroup('/patient', function () { Router::delete('/{order_prescription_id:\d+}', [PatientOrderController::class, 'deletePatientPrescriptionOrder']); }); + // 检测订单 + Router::addGroup('/detection', function () { + // 获取患者检测订单列表 + Router::get('', [PatientOrderController::class, 'getPatientDetectionOrderList']); + + // 获取患者检测订单详情 + Router::get('/{order_detection_id:\d+}', [PatientOrderController::class, 'getPatientDetectionOrderInfo']); + + // 删除检测订单 + Router::delete('/{order_detection_id:\d+}', [PatientOrderController::class, 'deletePatientDetectionOrder']); + + // 取消检测订单 + Router::put('/cancel/{order_detection_id:\d+}', [PatientOrderController::class, 'putCancelPatientDetectionOrder']); + + // 检测订单取消支付 + Router::put('/cancel-pay/{order_detection_id:\d+}', [PatientOrderController::class, 'putPatientDetectionOrderCancelPay']); + }); + // 获取患者订单支付数据 Router::get('/pay', [PatientOrderController::class, 'getPatientOrderPayInfo']); @@ -552,6 +579,9 @@ Router::addGroup('/basic', function () { // 获取热门搜索关键词 Router::get('/keyword/search', [BasicDataController::class, 'getHotSearchKeyword']); + + // 获取检测疾病分类列表 + Router::get('/detection/disease', [BasicDataController::class, 'getDetectionDisease']); }); // 获取医生评价 @@ -578,6 +608,7 @@ Router::addGroup('/callback', function () { // 退款回调 Router::post('/refund', [CallBackController::class, 'wxPayInquiryRefundCallBack']); }); + // 药品 Router::addGroup('/product', function () { // 支付成功回调 @@ -586,6 +617,15 @@ Router::addGroup('/callback', function () { // 退款回调 Router::post('/refund', [CallBackController::class, 'wxPayProductRefundCallBack']); }); + + // 检测 + Router::addGroup('/detection', function () { + // 支付成功回调 + Router::post('/success', [CallBackController::class, 'wxPayDetectionSuccessCallBack']); + + // 退款回调 + Router::post('/refund', [CallBackController::class, 'wxPayDetectionRefundCallBack']); + }); }); // im回调 @@ -611,6 +651,9 @@ Router::addGroup('/user', function () { // 退出登陆 Router::put('/loginout', [UserController::class, 'putLoginout']); + + // 上报用户地址 + Router::post('/location', [UserController::class, 'postLocation']); }); // 获取患者问诊病例 diff --git a/extend/Tencent/map/Location.php b/extend/Tencent/map/Location.php new file mode 100644 index 0000000..d8b8838 --- /dev/null +++ b/extend/Tencent/map/Location.php @@ -0,0 +1,98 @@ +container = ApplicationContext::getContainer(); + $this->client = $this->container->get(Client::class); + } + + /** + * 计算签名 + * @param string $path + * @param array $query + * @return string + */ + private function getSign(string $path,array $query): string + { + ksort($query); + + // 拼接请求参数 + $queryString = urldecode(http_build_query($query)); + + // 拼接签名字符串 + $signatureStr = $path . '?' . $queryString . config("tencent_map.key"); + + // 计算签名,取MD5的小写形式 + $sig = md5($signatureStr); + + // 将签名添加到参数中 + $query['sig'] = $sig; + return $path . '?' . http_build_query($query); + } + /** + * 逆地址解析-根据经纬度获取地址 + * @param string $lon 经度,范围为 -180~180,负数表示西经 + * @param string $lat 纬度,范围为 -90~90,负数表示南纬 + * @return array + */ + public function getLocation(string $lon,string $lat): array + { + $query = [ + "key" => config("tencent_map.secret"), + "location" => $lon . "," . $lat, + ]; + + $path = "https://apis.map.qq.com" . $this->getSign("/ws/geocoder/v1",$query); + try { + $response = $this->client->get($path); + if ($response->getStatusCode() != '200') { + // 请求失败 + throw new BusinessException($response->getBody()->getContents()); + } + $body = json_decode($response->getBody(), true); + if (empty($body)) { + // 返回值为空 + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + if ($body['status'] != 0){ + throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR)); + } + + if (empty($body['result'])){ + return []; + } + + return $body['result']; + } catch (GuzzleException $e) { + throw new BusinessException($e->getMessage()); + } + } +} \ No newline at end of file