334 lines
11 KiB
PHP
334 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Exception\BusinessException;
|
|
use App\Model\BasicBank;
|
|
use App\Model\DiseaseClassExpertise;
|
|
use App\Model\DoctorBankCard;
|
|
use App\Model\DoctorExpertise;
|
|
use App\Model\OrderInquiry;
|
|
use App\Model\UserDoctor;
|
|
use App\Model\UserDoctorInfo;
|
|
use App\Utils\Mask;
|
|
use Hyperf\DbConnection\Db;
|
|
|
|
class UserDoctorService extends BaseService
|
|
{
|
|
/**
|
|
* 获取医生专长列表
|
|
* 身份认证
|
|
* @return array
|
|
*/
|
|
public function getAuthDoctorExpertise(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
// 获取医生已选择专长
|
|
$doctor_selected_expertise = $this->getDoctorSelectedExpertise($user_info['client_user_id']);
|
|
|
|
$expertise_ids = [];
|
|
|
|
if (!empty($doctor_selected_expertise)) {
|
|
$expertise_ids = array_column($doctor_selected_expertise, 'expertise_id');
|
|
}
|
|
|
|
// 获取全部专长
|
|
$fields = [
|
|
'expertise_id',
|
|
'expertise_name',
|
|
'expertise_sort',
|
|
];
|
|
$disease_class_expertise = DiseaseClassExpertise::getOrderList([], $fields);
|
|
|
|
foreach ($disease_class_expertise as &$item) {
|
|
$item['is_selected'] = 0;
|
|
if (in_array($item['expertise_id'], $expertise_ids)) {
|
|
$item['is_selected'] = 1;
|
|
}
|
|
}
|
|
|
|
return success($disease_class_expertise);
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取医生已选择专长
|
|
* @param string $doctor_id
|
|
* @return array
|
|
*/
|
|
public function getDoctorSelectedExpertise(string $doctor_id): array
|
|
{
|
|
if (empty($doctor_id)) {
|
|
throw new BusinessException("缺少医生id");
|
|
}
|
|
|
|
$params = array();
|
|
$params['doctor_id'] = $doctor_id;
|
|
$doctor_expertise = DoctorExpertise::getDiseaseClassExpertiseList($params);
|
|
if (!empty($doctor_expertise)) {
|
|
foreach ($doctor_expertise as &$data) {
|
|
if (!empty($data['DiseaseClassExpertise'])) {
|
|
$data['expertise_name'] = $data['DiseaseClassExpertise']['expertise_name'];
|
|
}
|
|
unset($data['DiseaseClassExpertise']);
|
|
}
|
|
}
|
|
|
|
return $doctor_expertise->toArray();
|
|
}
|
|
|
|
/**
|
|
* 获取医生银行卡
|
|
* @return array
|
|
*/
|
|
public function getDoctorBankCard(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$doctor_bank_card = DoctorBankCard::getWithBankOne($params);
|
|
if (empty($doctor_bank_card)) {
|
|
return success();
|
|
}
|
|
|
|
$data = array();
|
|
$data['bank_card_id'] = $doctor_bank_card['bank_card_id'];
|
|
$data['bank_img_path'] = $doctor_bank_card['BasicBank']['bank_img_path'];
|
|
$data['bank_name'] = $doctor_bank_card['BasicBank']['bank_name'];
|
|
$data['bank_card_code_mask'] = $doctor_bank_card['bank_card_code_mask'];
|
|
|
|
unset($doctor_bank_card);
|
|
|
|
return success($data);
|
|
}
|
|
|
|
/**
|
|
* 获取医生银行卡详情信息
|
|
* @return array
|
|
*/
|
|
public function getDoctorBankCardInfo(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$bank_card_id = $this->request->input('bank_card_id');// 医生银行卡id
|
|
|
|
// 获取医生详情数据
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
|
|
$fields = [
|
|
'doctor_info_id',
|
|
'doctor_id',
|
|
'card_name',
|
|
'card_num_mask',
|
|
];
|
|
$user_doctor_info = UserDoctorInfo::getOne($params, $fields);
|
|
if (empty($user_doctor_info)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "请先实名认证");
|
|
}
|
|
|
|
$result = array();
|
|
$result['info'] = array();
|
|
$result['bank'] = array();
|
|
|
|
$info = array();
|
|
$info['card_name'] = $user_doctor_info['card_name'];
|
|
$info['card_num_mask'] = $user_doctor_info['card_num_mask'];
|
|
|
|
if (!empty($bank_card_id)) {
|
|
// 获取添加的银行卡信息
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$params['bank_card_id'] = $bank_card_id;
|
|
$doctor_bank_card = DoctorBankCard::getWithBankOne($params);
|
|
if (empty($doctor_bank_card)) {
|
|
return fail();
|
|
}
|
|
|
|
$bank = array();
|
|
$bank['bank_card_id'] = $doctor_bank_card['bank_card_id'];
|
|
$bank['bank_id'] = $doctor_bank_card['bank_id'];
|
|
$bank['bank_name'] = $doctor_bank_card['BasicBank']['bank_name'];
|
|
$bank['bank_card_code'] = $doctor_bank_card['bank_card_code'];// 银行卡号
|
|
$bank['province_id'] = $doctor_bank_card['province_id'];
|
|
$bank['province'] = $doctor_bank_card['province'];
|
|
$bank['city_id'] = $doctor_bank_card['city_id'];
|
|
$bank['city'] = $doctor_bank_card['city'];
|
|
$bank['county_id'] = $doctor_bank_card['county_id'];
|
|
$bank['county'] = $doctor_bank_card['county'];
|
|
}
|
|
|
|
$result['info'] = $info;// 用户数据
|
|
$result['bank'] = $bank ?? [];// 银行卡数据
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 新增绑定医生银行卡
|
|
* @return array
|
|
*/
|
|
public function addDoctorBankCard(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$bank_id = $this->request->input('bank_id');
|
|
$bank_card_code = $this->request->input('bank_card_code');
|
|
$province_id = $this->request->input('province_id');
|
|
$city_id = $this->request->input('city_id');
|
|
$county_id = $this->request->input('county_id');
|
|
|
|
// 验证银行
|
|
$params = array();
|
|
$params['bank_id'] = $bank_id;
|
|
$basic_bank = BasicBank::getOne($params);
|
|
if (empty($basic_bank)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "开户行错误");
|
|
}
|
|
|
|
// 验证省市区
|
|
$areaService = new AreaService();
|
|
$area = $areaService->getAreaById($province_id, $city_id, $county_id);
|
|
if (empty($area)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "地区选择错误");
|
|
}
|
|
|
|
// 获取医生银行卡
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$doctor_bank_card = DoctorBankCard::getOne($params);
|
|
if (!empty($doctor_bank_card)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "已绑定银行卡");
|
|
}
|
|
|
|
// 获取医生信息
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
|
|
$fields = [
|
|
'doctor_id',
|
|
'is_bind_bank',
|
|
];
|
|
$user_doctor = UserDoctor::getOne($params, $fields);
|
|
if (empty($user_doctor)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "非法医生");
|
|
}
|
|
|
|
if ($user_doctor['is_bind_bank'] == 1) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "已绑定银行卡");
|
|
}
|
|
|
|
// 处理银行卡掩码
|
|
$bank_card_code_mask = Mask::maskBankCard($bank_card_code);
|
|
|
|
// 验证银行卡
|
|
|
|
Db::beginTransaction();
|
|
|
|
try {
|
|
// 新增医生银行卡
|
|
$data = array();
|
|
$data['doctor_id'] = $user_info['client_user_id'];
|
|
$data['bank_id'] = $bank_id;
|
|
$data['bank_card_code'] = $bank_card_code;
|
|
$data['bank_card_code_mask'] = $bank_card_code_mask;
|
|
$data['province_id'] = $province_id;
|
|
$data['province'] = $area['province']['area_name'];
|
|
$data['city_id'] = $city_id;
|
|
$data['city'] = $area['city']['area_name'];
|
|
$data['county_id'] = $county_id;
|
|
$data['county'] = $area['county']['area_name'];
|
|
$doctor_bank_card = DoctorBankCard::addDoctorBankCard($data);
|
|
if (empty($doctor_bank_card)) {
|
|
Db::rollBack();
|
|
return fail(HttpEnumCode::SERVER_ERROR);
|
|
}
|
|
|
|
// 修改医生表绑定银行卡状态
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
|
|
$data = array();
|
|
$data['is_bind_bank'] = 1;
|
|
UserDoctor::editUserDoctor($params, $data);
|
|
|
|
Db::commit();
|
|
} catch (\Exception $e) {
|
|
Db::rollBack();
|
|
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
|
}
|
|
|
|
return success();
|
|
}
|
|
|
|
public function putDoctorBankCard()
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$bank_card_id = $this->request->route('bank_card_id');
|
|
$bank_id = $this->request->input('bank_id');
|
|
$bank_card_code = $this->request->input('bank_card_code');
|
|
$province_id = $this->request->input('province_id');
|
|
$city_id = $this->request->input('city_id');
|
|
$county_id = $this->request->input('county_id');
|
|
|
|
// 获取医生银行卡
|
|
$params = array();
|
|
$params['bank_card_id'] = $bank_card_id;
|
|
$doctor_bank_card = DoctorBankCard::getOne($params);
|
|
if (empty($doctor_bank_card)) {
|
|
return fail();
|
|
}
|
|
|
|
// 检测上次修改时间
|
|
$updated_at = strtotime($doctor_bank_card['updated_at']);
|
|
$moonth_start = strtotime(date("Y-m-01")); // 当月开始时间
|
|
$moonth_end = strtotime(date("Y-m-t")); // 当月结束时间
|
|
|
|
if ($updated_at >= $moonth_start && $updated_at <= $moonth_end) {
|
|
// 银行卡一月只能修改一次
|
|
return fail(HttpEnumCode::HTTP_ERROR, "银行卡每月只能修改一次");
|
|
}
|
|
|
|
// 验证银行
|
|
$params = array();
|
|
$params['bank_id'] = $bank_id;
|
|
$basic_bank = BasicBank::getOne($params);
|
|
if (empty($basic_bank)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "开户行错误");
|
|
}
|
|
|
|
// 验证省市区
|
|
$areaService = new AreaService();
|
|
$area = $areaService->getAreaById($province_id, $city_id, $county_id);
|
|
if (empty($area)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "地区选择错误");
|
|
}
|
|
|
|
// 处理银行卡掩码
|
|
$bank_card_code_mask = Mask::maskBankCard($bank_card_code);;
|
|
|
|
// 验证银行卡
|
|
|
|
// 修改银行卡
|
|
$params = array();
|
|
$params['bank_card_id'] = $bank_card_id;
|
|
|
|
$data = array();
|
|
$data['bank_id'] = $bank_id;
|
|
$data['bank_card_code'] = $bank_card_code;
|
|
$data['bank_card_code_mask'] = $bank_card_code_mask;
|
|
$data['province_id'] = $province_id;
|
|
$data['province'] = $area['province']['area_name'];
|
|
$data['city_id'] = $city_id;
|
|
$data['city'] = $area['city']['area_name'];
|
|
$data['county_id'] = $county_id;
|
|
$data['county'] = $area['county']['area_name'];
|
|
$data['updated_at'] = date('Y-m-d H:i:s',time());
|
|
DoctorBankCard::editDoctorBankCard($params,$data);
|
|
|
|
return success();
|
|
}
|
|
} |