修正医生体现数据
This commit is contained in:
@@ -13,6 +13,8 @@ use App\Model\DoctorWithdrawalOrder;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderServicePackage;
|
||||
use App\Model\OrderServicePackageDetail;
|
||||
use App\Model\OrderServicePackageRefund;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserDoctorInfo;
|
||||
@@ -33,13 +35,13 @@ class DoctorAccountService extends BaseService
|
||||
|
||||
$year = $this->request->input('date');
|
||||
|
||||
$date = date('Y-m-d',time());
|
||||
$date = date('Y-m-d', time());
|
||||
|
||||
// 获取医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
if (empty($user_doctor)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@@ -47,22 +49,22 @@ class DoctorAccountService extends BaseService
|
||||
$OrderServicePackageService = new OrderServicePackageService();
|
||||
|
||||
// 获取医生当日的接诊订单金额
|
||||
$doctor_today_inquiry_total = $inquiryService->getDoctorDayAmountTotal($user_doctor['doctor_id'],$date,$user_doctor['is_platform_deep_cooperation']);
|
||||
$doctor_today_inquiry_total = $inquiryService->getDoctorDayAmountTotal($user_doctor['doctor_id'], $date, $user_doctor['is_platform_deep_cooperation']);
|
||||
|
||||
// 获取医生当日的服务包订单问诊金额-开始时间
|
||||
$doctor_today_service_package_total = $OrderServicePackageService->getDoctorDayAmountTotal($user_doctor['doctor_id'],$date);
|
||||
$doctor_today_service_package_total = $OrderServicePackageService->getDoctorDayAmountTotal($user_doctor['doctor_id'], $date);
|
||||
|
||||
// 医生当日的订单金额
|
||||
$doctor_today_total = bcadd($doctor_today_inquiry_total,$doctor_today_service_package_total,2);
|
||||
$doctor_today_total = bcadd($doctor_today_inquiry_total, $doctor_today_service_package_total, 2);
|
||||
|
||||
// 获取医生当日已完成未结束的问诊订单金额
|
||||
$doctor_day_inquiry_completed_amount_total = $inquiryService->getDoctorDayCompletedAmountTotal($user_doctor['doctor_id'],$date,$user_doctor['is_platform_deep_cooperation']);
|
||||
$doctor_day_inquiry_completed_amount_total = $inquiryService->getDoctorDayCompletedAmountTotal($user_doctor['doctor_id'], $date, $user_doctor['is_platform_deep_cooperation']);
|
||||
|
||||
// 获取医生当日未完成的服务包订单问诊金额-结束时间
|
||||
$doctor_day_service_package_completed_amount_total = $OrderServicePackageService->getDoctorDayNoFinishAmountTotal($user_doctor['doctor_id'],$date);
|
||||
$doctor_day_service_package_completed_amount_total = $OrderServicePackageService->getDoctorDayNoFinishAmountTotal($user_doctor['doctor_id'], $date);
|
||||
|
||||
// 已完成待入账金额
|
||||
$doctor_day_completed_amount_total = bcadd($doctor_day_inquiry_completed_amount_total,$doctor_day_service_package_completed_amount_total,2);
|
||||
$doctor_day_completed_amount_total = bcadd($doctor_day_inquiry_completed_amount_total, $doctor_day_service_package_completed_amount_total, 2);
|
||||
|
||||
// 获取医生账户余额
|
||||
$balance_account = 0;
|
||||
@@ -83,7 +85,7 @@ class DoctorAccountService extends BaseService
|
||||
if (!empty($doctor_account_days)) {
|
||||
foreach ($doctor_account_days as $doctor_account_day) {
|
||||
$data = array();
|
||||
$data['total_amount'] = bcmul((string)$doctor_account_day['total_amount'],1,2);
|
||||
$data['total_amount'] = bcmul((string)$doctor_account_day['total_amount'], 1, 2);
|
||||
$data['month'] = $doctor_account_day['month'];
|
||||
$bill[] = $data;
|
||||
}
|
||||
@@ -91,9 +93,9 @@ class DoctorAccountService extends BaseService
|
||||
}
|
||||
|
||||
$result = array();
|
||||
$result['doctor_today_inquiry_total'] = bcmul((string)$doctor_today_total,"0.75",2); // 今日预计收入
|
||||
$result['doctor_day_completed_amount_total'] = bcmul((string)$doctor_day_completed_amount_total ,"0.75",2); // 今日已完成收入
|
||||
$result['balance_account'] = bcmul((string)$balance_account ,"1",2); // 账户余额
|
||||
$result['doctor_today_inquiry_total'] = bcmul((string)$doctor_today_total, "0.75", 2); // 今日预计收入
|
||||
$result['doctor_day_completed_amount_total'] = bcmul((string)$doctor_day_completed_amount_total, "0.75", 2); // 今日已完成收入
|
||||
$result['balance_account'] = bcmul((string)$balance_account, "1", 2); // 账户余额
|
||||
$result['bill'] = $bill; // 账单
|
||||
|
||||
return success($result);
|
||||
@@ -115,15 +117,15 @@ class DoctorAccountService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
if (empty($user_doctor)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||||
|
||||
// 获取当月开始时间
|
||||
$start_date = date('Y-m-01 00:00:00',strtotime($date));
|
||||
$start_date = date('Y-m-01 00:00:00', strtotime($date));
|
||||
|
||||
// 获取当月结束时间
|
||||
// 获取给定月份的下一个月的第一天,然后减去一天得到当月的最后一天
|
||||
@@ -131,45 +133,13 @@ class DoctorAccountService extends BaseService
|
||||
|
||||
$date_params = [$start_date, $end_date];
|
||||
|
||||
$results = Order::getDoctorCreatedDateOrderInquiryPage($params,$date_params,$user_doctor['is_platform_deep_cooperation'],['*'],$page,$per_page);
|
||||
$results = Order::getDoctorCreatedDateOrderInquiryPage($params, $date_params, $user_doctor['is_platform_deep_cooperation'], ['*'], $page, $per_page);
|
||||
if (!empty($results['data'])) {
|
||||
foreach ($results['data'] as &$result) {
|
||||
// 入账金额
|
||||
$result['estimate_income'] = bcmul((string)$result['amount_total'],"0.75",2);
|
||||
|
||||
// 入账状态-问诊订单
|
||||
if (!empty($result['OrderInquiry'])){
|
||||
if ($result['OrderInquiry']['inquiry_status'] == 4 || $result['OrderInquiry']['inquiry_status'] == 5){
|
||||
$result['entry_status'] = 1;// 入账中
|
||||
}elseif ($result['OrderInquiry']['inquiry_status'] == 6){
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
}elseif ($result['OrderInquiry']['inquiry_status'] == 7){
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $result['OrderInquiry']['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)){
|
||||
$refund_total = 0;
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund){
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
|
||||
if (($result['OrderInquiry']['payment_amount_total'] - $refund_total) > 0){
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
}else{
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($result['OrderInquiry']['cancel_reason'])){
|
||||
$result['cancel_remarks'] = inquiryCancelReasonToPushString($result['OrderInquiry']['cancel_reason']);
|
||||
}
|
||||
}else{
|
||||
$result['entry_status'] = 0;// 未知
|
||||
// 填入字段
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
if (!empty($result['OrderInquiry']['cancel_reason'])) {
|
||||
$result['cancel_remarks'] = inquiryCancelReasonToPushString($result['OrderInquiry']['cancel_reason']);
|
||||
}
|
||||
|
||||
$result['patient_name'] = $result['OrderInquiry']['patient_name'];
|
||||
@@ -182,36 +152,7 @@ class DoctorAccountService extends BaseService
|
||||
$result['inquiry_mode'] = $result['OrderInquiry']['inquiry_mode'];
|
||||
}
|
||||
|
||||
// 入账状态-服务包订单
|
||||
if (!empty($result['OrderServicePackage'])){
|
||||
if ($result['OrderServicePackage']['order_service_status'] == 3){
|
||||
$result['entry_status'] = 1;// 入账中
|
||||
}elseif ($result['OrderServicePackage']['order_service_status'] == 4){
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
}elseif ($result['OrderServicePackage']['order_service_status'] == 5){
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)){
|
||||
$refund_total = 0;
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund){
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
|
||||
if (($result['OrderServicePackage']['payment_amount_total'] - $refund_total) > 0){
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
}else{
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$result['entry_status'] = 0;// 未知
|
||||
}
|
||||
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
$result['patient_name'] = $result['OrderServicePackage']['patient_name'];
|
||||
$result['patient_name_mask'] = $result['OrderServicePackage']['patient_name_mask'];
|
||||
$result['patient_sex'] = $result['OrderServicePackage']['patient_sex'];
|
||||
@@ -220,6 +161,116 @@ class DoctorAccountService extends BaseService
|
||||
$result['finish_time'] = $result['OrderServicePackage']['finish_time'];
|
||||
}
|
||||
|
||||
// 默认退款金额为0;
|
||||
$result['refund_total'] = 0;
|
||||
// 计算退款金额
|
||||
if ($result['refund_status'] == 3){
|
||||
// 问诊订单
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $result['OrderInquiry']['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund) {
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
|
||||
// 服务包订单
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund) {
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算预计收入
|
||||
if ($result['order_type'] == 1){
|
||||
$result['estimate_income'] = bcmul(
|
||||
bcsub(
|
||||
$result['OrderInquiry']['amount_total'],
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
if ($result['order_type'] == 4 || $result['order_type'] == 5){
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (!empty($order_service_package_detail)){
|
||||
|
||||
$result['estimate_income'] = bcmul( // 可提现费用
|
||||
bcsub( // 退款费用
|
||||
bcmul( // 问诊费用
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理入账状态
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
if ($result['OrderInquiry']['inquiry_status'] == 4 || $result['OrderInquiry']['inquiry_status'] == 5) {
|
||||
$result['entry_status'] = 1;// 入账中
|
||||
} elseif ($result['OrderInquiry']['inquiry_status'] == 6) {
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
} elseif ($result['OrderInquiry']['inquiry_status'] == 7) {
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
|
||||
if (($result['OrderInquiry']['amount_total'] - $result['refund_total']) > 0) {
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
} else {
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
}
|
||||
} else {
|
||||
$result['entry_status'] = 0;// 未知
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
if ($result['OrderServicePackage']['order_service_status'] == 3) {
|
||||
$result['entry_status'] = 1;// 入账中
|
||||
} elseif ($result['OrderServicePackage']['order_service_status'] == 4) {
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
} elseif ($result['OrderServicePackage']['order_service_status'] == 5) {
|
||||
if (($result['OrderServicePackage']['amount_total'] - $result['refund_total']) > 0) {
|
||||
$result['entry_status'] = 2;// 入账成功
|
||||
} else {
|
||||
$result['entry_status'] = 3;// 入账失败
|
||||
}
|
||||
} else {
|
||||
$result['entry_status'] = 0;// 未知
|
||||
}
|
||||
}
|
||||
|
||||
unset($result['OrderInquiry']);
|
||||
unset($result['OrderServicePackage']);
|
||||
}
|
||||
@@ -291,32 +342,22 @@ class DoctorAccountService extends BaseService
|
||||
$amount_total = 0;
|
||||
|
||||
// 获取医生账户总表
|
||||
|
||||
// 获取医生账户余额
|
||||
$InquiryService = new InquiryService();
|
||||
if ($user_doctor['is_platform_deep_cooperation'] == 0){
|
||||
$order_inquiry = $InquiryService->getDoctorCanWithdrawalInquiryOrder($user_info['client_user_id']);
|
||||
}else{
|
||||
$order_inquiry = $InquiryService->getCooperationDoctorCanWithdrawalInquiryOrder($user_info['client_user_id']);
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$doctor_account = DoctorAccount::getOne($params);
|
||||
if (!empty($doctor_account)) {
|
||||
$amount_total = $doctor_account['balance_account'];
|
||||
}
|
||||
|
||||
if (!empty($order_inquiry)){
|
||||
foreach ($order_inquiry as $value){
|
||||
$amount_total = bcadd((string)$amount_total,(string)$value["amount_total"],2);
|
||||
}
|
||||
}
|
||||
|
||||
$amount_total = bcmul((string)$amount_total,"0.75",2);
|
||||
|
||||
// 计算医生个人所得税
|
||||
$income_tax = $this->computeIndividualIncomeTax($amount_total);
|
||||
|
||||
$withdrawal_amount = bcsub($amount_total,$income_tax,2);
|
||||
$withdrawal_amount = bcsub($amount_total, $income_tax, 2);
|
||||
|
||||
$income_tax = bcmul($income_tax,1,2);
|
||||
$income_tax = bcmul($income_tax, 1, 2);
|
||||
|
||||
$result = array();
|
||||
$result['bank'] = $bank;//银行数据
|
||||
$result['bank'] = $bank; //银行数据
|
||||
$result['amount_total'] = $amount_total; // 账户余额
|
||||
$result['withdrawal_amount'] = $withdrawal_amount; // 提现金额
|
||||
$result['income_tax'] = $income_tax; // 个人所得税
|
||||
@@ -324,6 +365,63 @@ class DoctorAccountService extends BaseService
|
||||
return success($result);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取可提现问诊订单列表
|
||||
// * @return array
|
||||
// */
|
||||
// public function getDoctorWithdrawalOrderList(): array
|
||||
// {
|
||||
// $user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
//
|
||||
// $page = $this->request->input('page', 1);
|
||||
// $per_page = $this->request->input('per_page', 10);
|
||||
//
|
||||
// // 获取医生信息
|
||||
// $params = array();
|
||||
// $params['doctor_id'] = $user_info['client_user_id'];
|
||||
// $user_doctor = UserDoctor::getOne($params);
|
||||
// if (empty($user_doctor)) {
|
||||
// return fail();
|
||||
// }
|
||||
//
|
||||
// $fields = [
|
||||
// 'order_inquiry_id',
|
||||
// 'inquiry_type',
|
||||
// 'inquiry_mode',
|
||||
// 'inquiry_status',
|
||||
// 'inquiry_refund_status',
|
||||
// 'inquiry_no',
|
||||
// 'amount_total',
|
||||
// 'payment_amount_total',
|
||||
// 'reception_time',
|
||||
// 'finish_time',
|
||||
// 'patient_name',
|
||||
// 'patient_sex',
|
||||
// 'patient_age',
|
||||
// ];
|
||||
//
|
||||
// $params = array();
|
||||
// $params['doctor_id'] = $user_info['client_user_id'];
|
||||
// $params['inquiry_refund_status'] = 0; // inquiry_refund_status:问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
//
|
||||
// $inquiry_status_params = [6]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
//
|
||||
// $inquiry_type_not_params = [];
|
||||
// if ($user_doctor['is_platform_deep_cooperation'] == 0) {
|
||||
// $inquiry_type_not_params = [2, 4];
|
||||
// }
|
||||
//
|
||||
// $order_inquiry = OrderInquiry:: getDoctorOrderInquiryPage($params, $inquiry_status_params, $inquiry_type_not_params, $fields, $page, $per_page);
|
||||
//
|
||||
// if (!empty($order_inquiry['data'])) {
|
||||
// foreach ($order_inquiry['data'] as &$item) {
|
||||
// $item['expected_amount_total'] = floor($item['amount_total'] * 0.75 * 100) / 100;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return success($order_inquiry);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取可提现问诊订单列表
|
||||
* @return array
|
||||
@@ -343,44 +441,119 @@ class DoctorAccountService extends BaseService
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 获取医生当日接诊订单金额
|
||||
$fields = [
|
||||
'order_inquiry_id',
|
||||
'inquiry_type',
|
||||
'inquiry_mode',
|
||||
'inquiry_status',
|
||||
'inquiry_refund_status',
|
||||
'inquiry_no',
|
||||
'amount_total',
|
||||
'payment_amount_total',
|
||||
'reception_time',
|
||||
'finish_time',
|
||||
'patient_name',
|
||||
'patient_sex',
|
||||
'patient_age',
|
||||
];
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$params['inquiry_refund_status'] = 0; // inquiry_refund_status:问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$params['is_withdrawal'] = 0;
|
||||
|
||||
$inquiry_status_params = [6]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$results = Order:: getDoctorWithdrawalOrderList($params, $user_doctor['is_platform_deep_cooperation'], ['*'], $page, $per_page);
|
||||
|
||||
if (!empty($results['data'])) {
|
||||
foreach ($results['data'] as &$result) {
|
||||
// 填入字段
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
if (!empty($result['OrderInquiry']['cancel_reason'])) {
|
||||
$result['cancel_remarks'] = inquiryCancelReasonToPushString($result['OrderInquiry']['cancel_reason']);
|
||||
}
|
||||
|
||||
if ($user_doctor['is_platform_deep_cooperation'] == 0){
|
||||
$order_inquiry = OrderInquiry:: getDoctorOrderInquiryPage($params,$inquiry_status_params, $fields,$page,$per_page);
|
||||
}else{
|
||||
$inquiry_type_not_params = [2,4];
|
||||
$order_inquiry = OrderInquiry:: getCooperationDoctorOrderInquiryPage($params,$inquiry_status_params,$inquiry_type_not_params, $fields,$page,$per_page);
|
||||
}
|
||||
$result['patient_name'] = $result['OrderInquiry']['patient_name'];
|
||||
$result['patient_name_mask'] = $result['OrderInquiry']['patient_name_mask'];
|
||||
$result['patient_sex'] = $result['OrderInquiry']['patient_sex'];
|
||||
$result['patient_age'] = $result['OrderInquiry']['patient_age'];
|
||||
$result['start_time'] = $result['OrderInquiry']['reception_time'];
|
||||
$result['finish_time'] = $result['OrderInquiry']['finish_time'];
|
||||
$result['inquiry_type'] = $result['OrderInquiry']['inquiry_type'];
|
||||
$result['inquiry_mode'] = $result['OrderInquiry']['inquiry_mode'];
|
||||
}
|
||||
|
||||
if (!empty($order_inquiry['data'])) {
|
||||
foreach ($order_inquiry['data'] as &$item) {
|
||||
$item['expected_amount_total'] = floor($item['amount_total'] * 0.75 * 100) / 100;
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
$result['patient_name'] = $result['OrderServicePackage']['patient_name'];
|
||||
$result['patient_name_mask'] = $result['OrderServicePackage']['patient_name_mask'];
|
||||
$result['patient_sex'] = $result['OrderServicePackage']['patient_sex'];
|
||||
$result['patient_age'] = $result['OrderServicePackage']['patient_age'];
|
||||
$result['start_time'] = $result['OrderServicePackage']['start_time'];
|
||||
$result['finish_time'] = $result['OrderServicePackage']['finish_time'];
|
||||
}
|
||||
|
||||
// 默认退款金额为0;
|
||||
$result['refund_total'] = 0;
|
||||
// 计算退款
|
||||
if ($result['refund_status'] == 3){
|
||||
// 问诊订单
|
||||
if (!empty($result['OrderInquiry'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $result['OrderInquiry']['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund) {
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
|
||||
// 服务包订单
|
||||
if (!empty($result['OrderServicePackage'])) {
|
||||
// 获取退款数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)) {
|
||||
$refund_total = 0;
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund) {
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$result['refund_total'] = $refund_total;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算可提现金额
|
||||
if ($result['order_type'] == 1){
|
||||
$result['expected_amount_total'] = bcmul(
|
||||
bcsub(
|
||||
$result['OrderInquiry']['amount_total'],
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
if ($result['order_type'] == 4 || $result['order_type'] == 5){
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $result['OrderServicePackage']['order_service_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (!empty($order_service_package_detail)){
|
||||
$result['expected_amount_total'] = bcmul( // 可提现费用
|
||||
bcsub( // 退款费用
|
||||
bcmul( // 问诊费用
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$result['refund_total'],
|
||||
3
|
||||
),
|
||||
0.75,
|
||||
2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
unset($result['OrderInquiry']);
|
||||
unset($result['OrderServicePackage']);
|
||||
}
|
||||
}
|
||||
|
||||
return success($order_inquiry);
|
||||
return success($results);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,21 +565,21 @@ class DoctorAccountService extends BaseService
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$year = $this->request->input('year');
|
||||
$page = $this->request->input('page',1);
|
||||
$per_page = $this->request->input('per_page',10);
|
||||
$page = $this->request->input('page', 1);
|
||||
$per_page = $this->request->input('per_page', 10);
|
||||
|
||||
// 获取当年开始时间
|
||||
$start_date = $year.'-1-1 00:00:00';
|
||||
$start_date = $year . '-1-1 00:00:00';
|
||||
|
||||
// 获取当年结束时间
|
||||
$end_date = $year.'-12-31 23:59:59';
|
||||
$end_date = $year . '-12-31 23:59:59';
|
||||
|
||||
$created_at_params = [$start_date, $end_date];
|
||||
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$doctor_withdrawal = DoctorWithdrawal::getDatePage($params,$created_at_params,['*'],$page,$per_page);
|
||||
if (empty($doctor_withdrawal['data'])){
|
||||
$doctor_withdrawal = DoctorWithdrawal::getDatePage($params, $created_at_params, ['*'], $page, $per_page);
|
||||
if (empty($doctor_withdrawal['data'])) {
|
||||
return success();
|
||||
}
|
||||
|
||||
@@ -422,20 +595,20 @@ class DoctorAccountService extends BaseService
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||||
$order_no = $this->request->input('order_no');
|
||||
$withdrawal_amount_total = $this->request->input('withdrawal_amount_total');
|
||||
$bank_card_id = $this->request->input('bank_card_id');
|
||||
|
||||
$order_inquiry_id = explode(',',$order_inquiry_id);
|
||||
if (empty($order_inquiry_id)){
|
||||
$order_nos = explode(',', $order_no);
|
||||
if (empty($order_nos)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
$app_env = config('app_env');
|
||||
if ($app_env != "dev"){
|
||||
if ($app_env != "dev") {
|
||||
// 正式环境高于300元才可以提现
|
||||
if ($withdrawal_amount_total < 300){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"提现金额小于300元");
|
||||
if ($withdrawal_amount_total < 300) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "提现金额小于300元");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,46 +616,137 @@ class DoctorAccountService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
|
||||
$start_time = date('Y-m-01',time());
|
||||
$end_time = date('Y-m-t 24:00:00',time());
|
||||
$created_at = [$start_time,$end_time];
|
||||
$start_time = date('Y-m-01', time());
|
||||
$end_time = date('Y-m-t 24:00:00', time());
|
||||
$created_at = [$start_time, $end_time];
|
||||
|
||||
$doctor_withdrawal = DoctorWithdrawal::getOneLatestTime($params,$created_at,['*'],);
|
||||
if (!empty($doctor_withdrawal)){
|
||||
$doctor_withdrawal = DoctorWithdrawal::getOneLatestTime($params, $created_at, ['*'],);
|
||||
if (!empty($doctor_withdrawal)) {
|
||||
return fail("每月只允许提现一次");
|
||||
}
|
||||
|
||||
$amount_total = 0;
|
||||
foreach ($order_inquiry_id as $value){
|
||||
foreach ($order_nos as $order_no) {
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $value;
|
||||
$params['order_no'] = $order_no;
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"存在不可提现订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 6){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"提现失败");
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在不可提现订单");
|
||||
}
|
||||
|
||||
// 验证订单提现状态
|
||||
if ($order_inquiry['is_withdrawal'] != 0){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"存在已提现订单");
|
||||
if ($order['is_withdrawal'] != 0) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在已提现订单");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"存在未支付订单");
|
||||
// 问诊订单
|
||||
if ($order['order_type'] == 1){
|
||||
$params = array();
|
||||
$params['order_id'] = $order['order_id'];
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在不可提现订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 6) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "提现失败");
|
||||
}
|
||||
|
||||
// 验证订单提现状态
|
||||
if ($order_inquiry['is_withdrawal'] != 0) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在已提现订单");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在未支付订单");
|
||||
}
|
||||
|
||||
// 订单退款金额
|
||||
$refund_total = 0;
|
||||
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_inquiry['inquiry_no'];
|
||||
$order_inquiry_refunds = OrderInquiryRefund::getList($params);
|
||||
if (!empty($order_inquiry_refunds)) {
|
||||
foreach ($order_inquiry_refunds as $order_inquiry_refund) {
|
||||
$refund_total = $refund_total + $order_inquiry_refund['refund_total'];
|
||||
}
|
||||
}
|
||||
|
||||
$amount_total = bcadd(
|
||||
$amount_total,
|
||||
bcsub(
|
||||
$order_inquiry['amount_total'],
|
||||
$refund_total,
|
||||
3
|
||||
),
|
||||
3
|
||||
);
|
||||
}
|
||||
|
||||
// 计算订单总金额
|
||||
$amount_total = bcadd($amount_total,$order_inquiry["amount_total"],2);
|
||||
// 服务包订单
|
||||
if ($order['order_type'] == 4 || $order['order_type'] == 5){
|
||||
$params = array();
|
||||
$params['order_id'] = $order['order_id'];
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$order_service_package = OrderServicePackage::getOne($params);
|
||||
if (empty($order_service_package)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在不可提现订单");
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_service_package['order_service_status'] != 4 || $order_service_package['order_service_status'] != 5) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "提现失败");
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if ($order_service_package['pay_status'] != 2) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在未支付订单");
|
||||
}
|
||||
|
||||
// 获取退款数据
|
||||
$refund_total = 0;
|
||||
|
||||
$params = array();
|
||||
$params['order_service_no'] = $order_service_package['order_service_no'];
|
||||
$order_service_package_refunds = OrderServicePackageRefund::getList($params);
|
||||
if (!empty($order_service_package_refunds)) {
|
||||
foreach ($order_service_package_refunds as $order_service_package_refund) {
|
||||
$refund_total = $refund_total + $order_service_package_refund['refund_total'];
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单详情数据
|
||||
$params = array();
|
||||
$params['order_service_no'] = $order_service_package['order_service_no'];
|
||||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||||
if (empty($order_service_package_detail)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "提现失败");
|
||||
}
|
||||
|
||||
// 计算本次问诊服务包问诊金额
|
||||
$amount_total = bcadd(
|
||||
(string)$amount_total,
|
||||
bcsub(
|
||||
bcmul(
|
||||
(string)$order_service_package_detail['service_count'],
|
||||
(string)$order_service_package_detail['single_inquiry_price'],
|
||||
3
|
||||
),
|
||||
$refund_total,
|
||||
3
|
||||
),
|
||||
3
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 提现金额
|
||||
$amount_total = $amount_total * 0.75;
|
||||
$amount_total = bcmul((string)$amount_total,0.75,2);
|
||||
|
||||
// 计算医生个人所得税
|
||||
$income_tax = $this->computeIndividualIncomeTax($amount_total);
|
||||
@@ -490,28 +754,28 @@ class DoctorAccountService extends BaseService
|
||||
// 实际提现金额
|
||||
$withdrawal_amount = $amount_total - $income_tax;
|
||||
|
||||
if ($withdrawal_amount > 0){
|
||||
if ($withdrawal_amount > 0) {
|
||||
$withdrawal_amount = floor($withdrawal_amount * 100) / 100;
|
||||
}
|
||||
|
||||
if ($withdrawal_amount_total != $withdrawal_amount){
|
||||
return fail(HttpEnumCode::SERVER_ERROR,"金额不符合");
|
||||
if ($withdrawal_amount_total != $withdrawal_amount) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "金额不符合");
|
||||
}
|
||||
|
||||
// 检测提现银行卡
|
||||
$params = array();
|
||||
$params['bank_card_id'] = $bank_card_id;
|
||||
$doctor_bank_card = DoctorBankCard::getOne($params);
|
||||
if (empty($doctor_bank_card)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"银行卡错误");
|
||||
if (empty($doctor_bank_card)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "银行卡错误");
|
||||
}
|
||||
|
||||
// 获取银行数据
|
||||
$params = array();
|
||||
$params['bank_id'] = $doctor_bank_card['bank_id'];
|
||||
$basic_bank = BasicBank::getOne($params);
|
||||
if (empty($basic_bank)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"银行卡错误");
|
||||
if (empty($basic_bank)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "银行卡错误");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
@@ -522,16 +786,16 @@ class DoctorAccountService extends BaseService
|
||||
$data['account_name'] = $basic_bank['bank_name'];
|
||||
$data['bank_card_code'] = $doctor_bank_card['bank_card_code'];
|
||||
$data['bank_card_code_four'] = substr($doctor_bank_card['bank_card_code'], -4);
|
||||
if ($amount_total > 0){
|
||||
$data['applied_withdrawal_amount'] = floor($amount_total * 100) / 100; // 提现金额
|
||||
if ($amount_total > 0) {
|
||||
$data['applied_withdrawal_amount'] = floor($amount_total * 100) / 100; // 提现金额
|
||||
}
|
||||
$data['actual_withdrawal_amount'] = $withdrawal_amount; // 实际提现金额
|
||||
if ($income_tax > 0){
|
||||
$data['income_tax'] = floor($income_tax * 100) / 100; // 提现所得税金额
|
||||
if ($income_tax > 0) {
|
||||
$data['income_tax'] = floor($income_tax * 100) / 100; // 提现所得税金额
|
||||
}
|
||||
$data['examine_status'] = 1; // 审核状态(1:审核中 2:审核通过 3:审核未通过)
|
||||
$doctor_withdrawal = DoctorWithdrawal::addDoctorWithdrawal($data);
|
||||
if (empty($doctor_withdrawal)){
|
||||
if (empty($doctor_withdrawal)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
@@ -548,53 +812,71 @@ class DoctorAccountService extends BaseService
|
||||
$data['county_id'] = $doctor_bank_card['county_id'];
|
||||
$data['county'] = $doctor_bank_card['county'];
|
||||
$doctor_withdrawal_bank = DoctorWithdrawalBank::addDoctorWithdrawalBank($data);
|
||||
if (empty($doctor_withdrawal_bank)){
|
||||
if (empty($doctor_withdrawal_bank)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
foreach ($order_inquiry_id as $value){
|
||||
foreach ($order_nos as $order_no) {
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "存在不可提现订单");
|
||||
}
|
||||
|
||||
// 新增医生提现-关联订单表
|
||||
$data = array();
|
||||
$data['withdrawal_id'] = $doctor_withdrawal['withdrawal_id'];
|
||||
$data['doctor_id'] = $user_info['client_user_id'];
|
||||
$data['order_inquiry_id'] = $value;
|
||||
$data['order_id'] = $order['order_id'];
|
||||
$doctor_withdrawal_order = DoctorWithdrawalOrder::addDoctorWithdrawalOrder($data);
|
||||
if (empty($doctor_withdrawal_order)){
|
||||
if (empty($doctor_withdrawal_order)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 修改问诊订单提现状态
|
||||
// 修改订单提现状态
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $value;
|
||||
$params['order_no'] = $order_no;
|
||||
|
||||
$data = array();
|
||||
$data['is_withdrawal'] = 2;
|
||||
$data['withdrawal_time'] = date('Y-m-d H:i:s',time());
|
||||
OrderInquiry::edit($params,$data);
|
||||
$data['withdrawal_time'] = date('Y-m-d H:i:s', time());
|
||||
Order::edit($params,$data);
|
||||
|
||||
// 修改问诊订单提现状态
|
||||
$params = array();
|
||||
$params['order_id'] = $order['order_id'];;
|
||||
|
||||
$data = array();
|
||||
$data['is_withdrawal'] = 2;
|
||||
$data['withdrawal_time'] = date('Y-m-d H:i:s', time());
|
||||
OrderInquiry::edit($params, $data);
|
||||
}
|
||||
|
||||
// 账户表锁定
|
||||
$params = array();
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
// 账户余额
|
||||
DoctorAccount::dec($params,'balance_account',$amount_total);
|
||||
DoctorAccount::dec($params, 'balance_account', $amount_total);
|
||||
|
||||
// 提现金额
|
||||
DoctorAccount::inc($params,'applied_withdrawal_amount',$amount_total);
|
||||
DoctorAccount::inc($params, 'applied_withdrawal_amount', $amount_total);
|
||||
|
||||
// 实际提现金额
|
||||
DoctorAccount::inc($params,'actual_withdrawal_amount',$withdrawal_amount);
|
||||
DoctorAccount::inc($params, 'actual_withdrawal_amount', $withdrawal_amount);
|
||||
|
||||
// 所得税金额
|
||||
DoctorAccount::inc($params,'income_tax',$income_tax);
|
||||
DoctorAccount::inc($params, 'income_tax', $income_tax);
|
||||
|
||||
Db::commit();
|
||||
return success();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -654,7 +936,7 @@ class DoctorAccountService extends BaseService
|
||||
}
|
||||
|
||||
// 实际纳税金额
|
||||
if ($income > 4000){
|
||||
if ($income > 4000) {
|
||||
$income = $income * 0.8;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user