242 lines
7.3 KiB
PHP
242 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Model\DoctorAccount;
|
|
use App\Model\DoctorAccountDay;
|
|
use App\Model\DoctorAccountMonth;
|
|
use App\Model\DoctorBankCard;
|
|
use App\Model\OrderInquiry;
|
|
use App\Model\UserDoctor;
|
|
|
|
/**
|
|
* 医生账户
|
|
*/
|
|
class DoctorAccountService extends BaseService
|
|
{
|
|
/**
|
|
* 获取我的账户数据
|
|
* @return array
|
|
*/
|
|
public function getDoctorAccount(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$date = $this->request->input('date');
|
|
|
|
// 获取医生账户余额
|
|
$balance_account = $this->getDoctorBalanceAccount($user_info['client_user_id']);
|
|
if ($balance_account > 0){
|
|
$balance_account = $balance_account * 0.75;
|
|
}
|
|
|
|
// 月余额-已结束订单
|
|
$amount_total_month = 0;
|
|
|
|
// 月已提现金额
|
|
$withdrawal_amount_month = 0;
|
|
|
|
// 获取医生账户某月数据
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$params['year'] = date('Y',strtotime($date));
|
|
$params['month'] = date('m',strtotime($date));
|
|
$doctor_account_month = DoctorAccountMonth::getOne($params);
|
|
if (!empty($doctor_account_month)){
|
|
if (!empty($doctor_account_month['total_amount'])){
|
|
$amount_total_month = $doctor_account_month['total_amount'] * 0.75;
|
|
}
|
|
|
|
$withdrawal_amount_month = $doctor_account_month['withdrawal_amount'] ?: 0;
|
|
}
|
|
|
|
// 获取医生每日账单数据
|
|
$bill = [];
|
|
|
|
$fields = [
|
|
'total_amount_day',
|
|
'month',
|
|
'day',
|
|
];
|
|
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$params['year'] = date('Y',strtotime($date));
|
|
$params['month'] = date('m',strtotime($date));
|
|
$doctor_account_days = DoctorAccountDay::getList($params,$fields);
|
|
if (!empty($doctor_account_days)){
|
|
foreach ($doctor_account_days as $doctor_account_day){
|
|
$data = array();
|
|
$data['total_amount_day'] = $doctor_account_day['total_amount_day'] * 0.75;
|
|
$data['month'] = $doctor_account_day['month'];
|
|
$data['day'] = $doctor_account_day['day'];
|
|
$bill[] = $data;
|
|
}
|
|
unset($doctor_account_days);
|
|
}
|
|
|
|
$result = array();
|
|
$result['balance_account'] = $balance_account; // 账户余额
|
|
$result['amount_total_month'] = $amount_total_month; // 月余额
|
|
$result['withdrawal_amount_month'] = $withdrawal_amount_month; // 月已提现金额
|
|
$result['bill'] = $bill; // 账单
|
|
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取我的账户日账单明细数据
|
|
* @return array
|
|
*/
|
|
public function getDoctorAccountInfo(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
$date = $this->request->input('date');
|
|
$page = $this->request->input('page', 1);
|
|
$per_page = $this->request->input('per_page', 10);
|
|
|
|
// 获取当天开始时间
|
|
$start_date = date('Y-m-d 00:00:00',strtotime($date));
|
|
|
|
// 获取当天结束时间
|
|
$end_date = date('Y-m-d 23:59:59',strtotime($date));
|
|
|
|
$reception_time = [$start_date,$end_date];
|
|
|
|
// 获取医生当日接诊订单金额
|
|
$fields = [
|
|
'order_inquiry_id',
|
|
'inquiry_type',
|
|
'inquiry_mode',
|
|
'inquiry_status',
|
|
'inquiry_refund_status',
|
|
'inquiry_no',
|
|
'amount_total',
|
|
'payment_amount_total',
|
|
'reception_time',
|
|
'patient_name',
|
|
'patient_sex',
|
|
'patient_age',
|
|
];
|
|
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
// $params['cancel_reason'] = ;
|
|
|
|
$order_inquiry = OrderInquiry::getDoctorAccountInfoPage($params,$reception_time,$fields);
|
|
if (!empty($order_inquiry['data'])){
|
|
foreach ($order_inquiry['data'] as &$item){
|
|
$item['estimate_income'] = $item['amount_total'] * 0.75;
|
|
}
|
|
}
|
|
|
|
return success($order_inquiry);
|
|
}
|
|
|
|
// 获取提现数据
|
|
public function getDoctorWithdrawal(){
|
|
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
// 获取医生信息
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
|
|
$fields = [
|
|
'doctor_id',
|
|
'user_name',
|
|
'iden_auth_status',
|
|
'idcard_status',
|
|
'multi_point_status',
|
|
'avatar',
|
|
'is_bind_bank',
|
|
];
|
|
$user_doctor = UserDoctor::getOne($params, $fields);
|
|
if (empty($user_doctor)) {
|
|
return fail(HttpEnumCode::HTTP_ERROR, "非法医生");
|
|
}
|
|
|
|
// 检测医生身份认证
|
|
$UserDoctorService = new UserDoctorService();
|
|
$res = $UserDoctorService->checkDoctorAuth($user_doctor);
|
|
if ($res !== true){
|
|
return fail(HttpEnumCode::HTTP_ERROR, $res);
|
|
}
|
|
|
|
if ($user_doctor['is_bind_bank'] != 1){
|
|
return fail(HttpEnumCode::HTTP_ERROR, "未绑定结算银行卡");
|
|
}
|
|
|
|
// 获取医生结算银行卡
|
|
$params = array();
|
|
$params['doctor_id'] = $user_info['client_user_id'];
|
|
$doctor_bank_card = DoctorBankCard::getWithBankOne($params);
|
|
if (empty($doctor_bank_card)) {
|
|
return success();
|
|
}
|
|
|
|
$result = array();
|
|
$result['bank_card_id'] = $doctor_bank_card['bank_card_id'];
|
|
$result['bank_img_path'] = $doctor_bank_card['BasicBank']['bank_img_path'];
|
|
$result['bank_name'] = $doctor_bank_card['BasicBank']['bank_name'];
|
|
$result['bank_card_code_mask'] = $doctor_bank_card['bank_card_code_mask'];
|
|
|
|
|
|
|
|
// 获取医生账户余额
|
|
$balance_account = $this->getDoctorBalanceAccount($user_info['client_user_id']);
|
|
|
|
// 计算医生个人所得税
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* 获取医生账户余额
|
|
* @param string $doctor_id
|
|
* @return int
|
|
*/
|
|
public function getDoctorBalanceAccount(string $doctor_id): int
|
|
{
|
|
$params = array();
|
|
$params['doctor_id'] = $doctor_id;
|
|
$doctor_account = DoctorAccount::getOne($params);
|
|
if (empty($doctor_account)){
|
|
$balance_account = 0;
|
|
}else{
|
|
$balance_account = $doctor_account['balance_account'];
|
|
}
|
|
|
|
return $balance_account;
|
|
}
|
|
|
|
// /**
|
|
// * 获取医生账户某日预计收益
|
|
// * @param string $doctor_id 医生id
|
|
// * @param string $day 日期 Ymd形式
|
|
// * @return float|int|mixed|string
|
|
// */
|
|
// public function getDoctorDayAmountTotal(string $doctor_id, string $day): mixed
|
|
// {
|
|
// $params = array();
|
|
// $params['doctor_id'] = $doctor_id;
|
|
// $params['year'] = date('Y',strtotime($day));
|
|
// $params['month'] = date('m',strtotime($day));
|
|
// $params['day'] = date('d',strtotime($day));
|
|
// $total_amount_day = DoctorAccountDay::getDoctorSumTotalAmount($params);
|
|
// if (!empty($total_amount_day)){
|
|
// $total_amount_day = $total_amount_day * 0.75;
|
|
// }
|
|
//
|
|
// return $total_amount_day ?: 0;
|
|
// }
|
|
|
|
|
|
|
|
// 计算个人所得税
|
|
protected function computeIndividualIncomeTax(){
|
|
|
|
}
|
|
} |