170 lines
5.4 KiB
PHP
170 lines
5.4 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Model\DoctorAccount;
|
||
use App\Model\DoctorAccountDay;
|
||
use App\Model\DoctorAccountMonth;
|
||
use App\Model\OrderInquiry;
|
||
|
||
/**
|
||
* 医生账户
|
||
*/
|
||
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']);
|
||
|
||
// 月预计收益
|
||
$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)){
|
||
$amount_total_month = $doctor_account_month['total_amount'] ?: 0;
|
||
$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 * 0.75; // 月预计收益
|
||
$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['inquiry_refund_status'] = 0; // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
$params['inquiry_pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
|
||
$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);
|
||
}
|
||
|
||
/**
|
||
* 获取医生账户余额
|
||
* @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'] * 0.75;
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
} |