diff --git a/app/Services/IndexService.php b/app/Services/IndexService.php index 2ba2081..be3f2bc 100644 --- a/app/Services/IndexService.php +++ b/app/Services/IndexService.php @@ -12,6 +12,8 @@ use App\Model\PharmacistAuditStatistic; use App\Model\User; use App\Model\UserDoctor as UserDoctorModel; use App\Model\UserPharmacist; +use Hyperf\Utils\Parallel; +use Hyperf\Utils\WaitGroup; /** * 首页模块 @@ -129,37 +131,65 @@ class IndexService extends BaseService { $user_info = $this->request->getAttribute("userInfo") ?? []; + $wg = new WaitGroup(); + $wg->add(4); + // 获取banner - $params = array(); - $params["app_type"] = 1; - $params["client_type"] = 1; - $params["banner_place"] = 1; - $params["banner_status"] = 1; - $banner = BannerModel::getList($params); - if (!empty($banner)){ - foreach ($banner as &$item){ - $item['banner_path'] = addAliyunOssWebsite($item['banner_path']); + $banner = []; + co(function () use ($wg, &$banner) { + $params = array(); + $params["app_type"] = 1; + $params["client_type"] = 1; + $params["banner_place"] = 1; + $params["banner_status"] = 1; + $banner = BannerModel::getList($params); + if (!empty($banner)){ + foreach ($banner as &$item){ + $item['banner_path'] = addAliyunOssWebsite($item['banner_path']); + } } - } + + // 计数器减一 + $wg->done(); + }); // 获取模块 - $params = array(); - $params["app_type"] = 1; - $params["client_type"] = 1; - $params["module_place"] = 1; - $params["module_status"] = 1; - $module = ModuleModel::getList($params); + $module = []; + co(function () use ($wg, &$module) { + $params = array(); + $params["app_type"] = 1; + $params["client_type"] = 1; + $params["module_place"] = 1; + $params["module_status"] = 1; + $module = ModuleModel::getList($params); - $PatientDoctorService = new PatientDoctorService(); + // 计数器减一 + $wg->done(); + }); // 我的医生 $my_doctor = []; - if (!empty($user_info)) { - $my_doctor = $PatientDoctorService->getIndexPatientDoctorLimit($user_info['client_user_id']); - } + co(function () use ($wg, &$my_doctor,$user_info) { + $PatientDoctorService = new PatientDoctorService(); + + if (!empty($user_info)) { + $my_doctor = $PatientDoctorService->getIndexPatientDoctorLimit($user_info['client_user_id']); + } + // 计数器减一 + $wg->done(); + }); // 推荐医生 - $recommend_doctor = $PatientDoctorService->getIndexRecommendDoctorLimit(); + $recommend_doctor = []; + co(function () use ($wg, &$recommend_doctor) { + $PatientDoctorService = new PatientDoctorService(); + + $recommend_doctor = $PatientDoctorService->getIndexRecommendDoctorLimit(); + // 计数器减一 + $wg->done(); + }); + + $wg->wait(); $result = array(); $result["banner"] = $banner ?? [];// banner