471 lines
12 KiB
PHP
471 lines
12 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Model\BasicAgreement;
|
||
use App\Model\BasicBank;
|
||
use App\Model\BasicDoctorTitle;
|
||
use App\Model\BasicJob;
|
||
use App\Model\BasicNation;
|
||
use App\Model\DiseaseClass;
|
||
use App\Model\DiseaseClassDetection;
|
||
use App\Model\DiseaseClassExpertise;
|
||
use App\Model\DiseaseClassIcd;
|
||
use App\Model\Hospital;
|
||
use App\Model\HospitalDepartmentCustom;
|
||
use App\Model\HotSearchKeyword;
|
||
use App\Model\OperationManual;
|
||
use App\Model\Product;
|
||
use Hyperf\Redis\Redis;
|
||
use Psr\Container\ContainerExceptionInterface;
|
||
use Psr\Container\NotFoundExceptionInterface;
|
||
|
||
/**
|
||
* 基础数据服务类
|
||
*/
|
||
class BasicDataService extends BaseService
|
||
{
|
||
/**
|
||
* 获取医院数据
|
||
* @return array
|
||
*/
|
||
public function getHospital(): array
|
||
{
|
||
$hospital_name = $this->request->input('hospital_name');
|
||
$province_id = $this->request->input('province_id');
|
||
$city_id = $this->request->input('city_id');
|
||
$county_id = $this->request->input('county_id');
|
||
|
||
$params = array();
|
||
$params[] = ['hospital_status', '=', 1];
|
||
|
||
if (!empty($hospital_name)) {
|
||
$params[] = ['hospital_name', 'like', '%' . $hospital_name . '%'];
|
||
}
|
||
|
||
if (!empty($province_id)) {
|
||
$params[] = ['province_id', '=', $province_id];
|
||
}
|
||
|
||
if (!empty($city_id)) {
|
||
$params[] = ['city_id', '=', $city_id];
|
||
}
|
||
|
||
if (!empty($county_id)) {
|
||
$params[] = ['county_id', '=', $county_id];
|
||
}
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
];
|
||
|
||
$hospital = Hospital::getList($params, $fields);
|
||
if (empty($hospital)) {
|
||
return success();
|
||
}
|
||
|
||
return success($hospital->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取自定义科室数据
|
||
* @return array
|
||
*/
|
||
public function getCustomDepartment(): array
|
||
{
|
||
$params = array();
|
||
$params['department_status'] = 1;
|
||
|
||
$fields = [
|
||
'department_custom_id',
|
||
'department_custom_name',
|
||
];
|
||
$hospital_department_custom = HospitalDepartmentCustom::getList($params, $fields);
|
||
if (empty($hospital_department_custom)) {
|
||
return success();
|
||
}
|
||
|
||
return success($hospital_department_custom->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取银行列表
|
||
* @return array
|
||
*/
|
||
public function getBank(): array
|
||
{
|
||
$basic_bank = BasicBank::getList([]);
|
||
if (empty($basic_bank)) {
|
||
return success();
|
||
}
|
||
|
||
return success($basic_bank->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取操作手册列表
|
||
* @return array
|
||
*/
|
||
public function getOperationManual(): array
|
||
{
|
||
$fields = [
|
||
'manual_id',
|
||
'title',
|
||
];
|
||
|
||
$params = array();
|
||
$params['status'] = 1;
|
||
|
||
$operation_manual = OperationManual::getList($params,$fields);
|
||
if (empty($operation_manual)) {
|
||
return success();
|
||
}
|
||
|
||
return success($operation_manual->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取操作手册详情
|
||
* @return array
|
||
*/
|
||
public function getOperationManualInfo(): array
|
||
{
|
||
$manual_id = $this->request->route('manual_id');
|
||
|
||
$params = array();
|
||
$params['manual_id'] = $manual_id;
|
||
$params['status'] = 1;
|
||
|
||
$operation_manual = OperationManual::getOne($params);
|
||
if (empty($operation_manual)) {
|
||
return fail();
|
||
}
|
||
|
||
return success($operation_manual->toArray());
|
||
}
|
||
|
||
/**
|
||
* 搜索疾病分类
|
||
* @return array
|
||
*/
|
||
public function getDiseaseSearch(): array
|
||
{
|
||
$disease_class_name = $this->request->input('disease_class_name');
|
||
|
||
$fields = [
|
||
'disease_class_id',
|
||
'disease_class_name',
|
||
];
|
||
$params = array();
|
||
$params[] = ["disease_class_status", 1];
|
||
$params[] = ["disease_class_enable", 1];
|
||
$params[] = ['disease_class_name', 'like', '%' . $disease_class_name . '%'];
|
||
$disease_class = DiseaseClass::getList($params, $fields);
|
||
if (empty($disease_class)){
|
||
$params = array();
|
||
$params[] = ["disease_class_status", 1];
|
||
$params[] = ["disease_class_enable", 1];
|
||
$disease_class = DiseaseClass::getList($params, $fields);
|
||
if(empty($disease_class)){
|
||
return success();
|
||
}
|
||
}
|
||
|
||
|
||
return success($disease_class->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取常见疾病分类
|
||
* @return array
|
||
*/
|
||
public function getDiseaseHot(): array
|
||
{
|
||
$fields = [
|
||
'disease_class_id',
|
||
'disease_class_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params[] = ["disease_class_status", 1];
|
||
$params[] = ["disease_class_enable", 1];
|
||
$params[] = ['is_hot', 1];
|
||
$disease_class = DiseaseClass::getLimit($params, 10, $fields);
|
||
|
||
return empty($disease_class) ? success() : success($disease_class->toArray());
|
||
}
|
||
|
||
/**
|
||
* 专长列表
|
||
* @return array
|
||
*/
|
||
public function getDiseaseExpertiseList(): array
|
||
{
|
||
$params = array();
|
||
$fields = [
|
||
'expertise_id',
|
||
'expertise_name',
|
||
];
|
||
$disease_class_expertise = DiseaseClassExpertise::getOrderList($params, $fields);
|
||
return success($disease_class_expertise);
|
||
}
|
||
|
||
/**
|
||
* 搜索商品
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function getProductSearch(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$product_keyword = $this->request->input('product_keyword',"");
|
||
|
||
$fields = [
|
||
'product_id',
|
||
'product_platform_id',
|
||
'prescription_num',
|
||
'product_name',
|
||
'product_price',
|
||
'product_cover_img',
|
||
'product_spec',
|
||
'manufacturer',
|
||
'single_unit',
|
||
'single_use',
|
||
'packaging_unit',
|
||
'frequency_use',
|
||
'available_days',
|
||
];
|
||
|
||
$params = array();
|
||
$params['product_status'] = 1;
|
||
$params['is_delete'] = 0;
|
||
$product = Product::getSearchKeywordList($params, $product_keyword,$fields);
|
||
if (empty($product)) {
|
||
return success();
|
||
}
|
||
|
||
// 获取购物车缓存数据
|
||
$redis = $this->container->get(Redis::class);
|
||
|
||
$redis_key = "shopping_cart" . $user_info['client_user_id'];
|
||
$shopping_cart = $redis->get($redis_key);
|
||
if (!empty($shopping_cart)){
|
||
$shopping_cart = json_decode($shopping_cart,true);
|
||
}
|
||
|
||
foreach ($product as &$item) {
|
||
$item['product_cover_img'] = addAliyunOssWebsite($item['product_cover_img']);
|
||
|
||
$item['product_name'] = $item['product_name'] . ' ' . $item['product_spec'];
|
||
$item['stock'] = 0;
|
||
if (!empty($item['ProductPlatformAmount'])){
|
||
$item['stock'] = $item['ProductPlatformAmount']['stock'];
|
||
}
|
||
|
||
unset($item['ProductPlatformAmount']);
|
||
|
||
// 处理购物车商品数据
|
||
$item['shopping_cart_num'] = 0;
|
||
if (!empty($shopping_cart)){
|
||
foreach ($shopping_cart as $value){
|
||
if ($item['product_id'] == $value['product_id']){
|
||
$item['shopping_cart_num'] = $value['shopping_cart_num'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return success($product->toArray());
|
||
}
|
||
|
||
/**
|
||
* 搜索平台疾病分类
|
||
* @return array
|
||
*/
|
||
public function getDiseaseIcdSearch(): array
|
||
{
|
||
$icd_keyword = $this->request->input('icd_keyword','');
|
||
|
||
$fields = [
|
||
'icd_id',
|
||
'icd_name',
|
||
];
|
||
$params = array();
|
||
$params['icd_status'] = 1;// 状态(0:删除 1:正常)
|
||
$params['icd_enable'] = 1;// 是否启用(0:否 1:是)
|
||
$disease_class_icd = DiseaseClassIcd::getSearchKeywordLimit($params, $icd_keyword, $fields);
|
||
if (empty($disease_class_icd)){
|
||
return success();
|
||
}
|
||
|
||
return success($disease_class_icd->toArray());
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取民族数据
|
||
* @return array
|
||
*/
|
||
public function getNation(): array
|
||
{
|
||
$params = array();
|
||
$basic_nation = BasicNation::getList($params);
|
||
if (empty($basic_nation)){
|
||
return success();
|
||
}
|
||
return success($basic_nation->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取职业数据
|
||
* @return array
|
||
*/
|
||
public function getJob(): array
|
||
{
|
||
$params = array();
|
||
$basic_job = BasicJob::getList($params);
|
||
if (empty($basic_job)){
|
||
return success();
|
||
}
|
||
return success($basic_job->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取协议内容
|
||
* @return array
|
||
*/
|
||
public function getAgreementInfo(): array
|
||
{
|
||
$agreement_id = $this->request->route('agreement_id');
|
||
|
||
$params = array();
|
||
$params['agreement_id'] = $agreement_id;
|
||
$params['agreement_status'] = 1;
|
||
$basic_agreement = BasicAgreement::getOne($params);
|
||
if (empty($basic_agreement)){
|
||
return success(NULL);
|
||
}
|
||
|
||
return success($basic_agreement->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取医生职称数据
|
||
* @return array
|
||
*/
|
||
public function getDoctorTitle(): array
|
||
{
|
||
$params = array();
|
||
|
||
$fields = [
|
||
'doctor_title_id',
|
||
'doctor_title_name',
|
||
];
|
||
$basic_doctor_title = BasicDoctorTitle::getList($params,$fields);
|
||
if (empty($basic_doctor_title)){
|
||
return success();
|
||
}
|
||
return success($basic_doctor_title->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取热门搜索关键词
|
||
* @return array
|
||
*/
|
||
public function getHotSearchKeyword(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$client_type = $this->request->input('client_type');
|
||
$keyword_place = $this->request->input('keyword_place');
|
||
|
||
$params = array();
|
||
$params['client_type'] = $client_type;
|
||
$params['keyword_status'] = 1;
|
||
$params['keyword_place'] = $keyword_place;
|
||
|
||
$fields = [
|
||
'keyword_name'
|
||
];
|
||
$hot_search_keyword = HotSearchKeyword::getList($params,$fields);
|
||
if (empty($hot_search_keyword)){
|
||
return success();
|
||
}
|
||
|
||
return success($hot_search_keyword->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取检测疾病分类列表
|
||
* @return array
|
||
*/
|
||
public function getDetectionDiseaseList(): array
|
||
{
|
||
$detection_project_id = $this->request->route('detection_project_id',1);
|
||
|
||
$params = array();
|
||
$params['detection_project_id'] = $detection_project_id;
|
||
$params['status'] = 1;
|
||
$params['enable'] = 1;
|
||
$disease_class_detections = DiseaseClassDetection::getList($params);
|
||
if (empty($disease_class_detections)){
|
||
return success();
|
||
}
|
||
|
||
return success($disease_class_detections->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取商品数据-分页
|
||
* @return array
|
||
*/
|
||
public function getProductPage(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$keyword = $this->request->input('keyword',"");
|
||
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
$fields = [
|
||
'product_id',
|
||
'product_platform_id',
|
||
'product_name',
|
||
'product_price',
|
||
'product_cover_img',
|
||
'product_spec',
|
||
'manufacturer',
|
||
'single_unit',
|
||
'single_use',
|
||
'packaging_unit',
|
||
'frequency_use',
|
||
'available_days',
|
||
];
|
||
|
||
$params = array();
|
||
$params['product_status'] = 1;
|
||
$params['is_delete'] = 0;
|
||
$product = Product::getWithAmountPage($params, $keyword,$fields, $page, $per_page);
|
||
if (empty($product['data'])) {
|
||
return success($product);
|
||
}
|
||
|
||
foreach ($product['data'] as &$item) {
|
||
$item['product_cover_img'] = addAliyunOssWebsite($item['product_cover_img']);
|
||
|
||
$item['product_name'] = $item['product_name'] . ' ' . $item['product_spec'];
|
||
$item['stock'] = 0;
|
||
if (!empty($item['ProductPlatformAmount'])){
|
||
$item['stock'] = $item['ProductPlatformAmount']['stock'];
|
||
}
|
||
|
||
unset($item['ProductPlatformAmount']);
|
||
}
|
||
|
||
return success($product);
|
||
}
|
||
} |