From 27288a9dd974f963c8d82b66037b94cfa2b75865 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Thu, 23 Feb 2023 15:11:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BF=94=E5=9B=9E=E5=80=BCbi?= =?UTF-8?q?gint=E8=A2=AB=E8=BD=AC=E4=B9=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/DoctorAccountController.php | 11 ++ app/Controller/UserDoctorController.php | 2 + app/Model/BasicBank.php | 2 +- app/Model/DoctorAccountDay.php | 6 +- app/Model/DoctorAccountMonth.php | 7 +- app/Model/Hospital.php | 2 +- app/Model/HospitalDepartmentCustom.php | 2 +- app/Model/OrderInquiry.php | 35 +++++- app/Services/DoctorAccountService.php | 122 ++++++++++++++++----- app/Services/OrderInquiryService.php | 31 ++++++ app/Services/UserDoctorService.php | 47 +++++++- config/routes.php | 8 +- 12 files changed, 229 insertions(+), 46 deletions(-) diff --git a/app/Controller/DoctorAccountController.php b/app/Controller/DoctorAccountController.php index 35b40c7..c6ef923 100644 --- a/app/Controller/DoctorAccountController.php +++ b/app/Controller/DoctorAccountController.php @@ -45,4 +45,15 @@ class DoctorAccountController extends AbstractController $data = $DoctorAccountService->getDoctorAccountInfo(); return $this->response->json($data); } + + /** + * 获取提现数据 + * @return ResponseInterface + */ + public function getDoctorWithdrawal(): ResponseInterface + { + $DoctorAccountService = new DoctorAccountService(); + $data = $DoctorAccountService->getDoctorWithdrawal(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Controller/UserDoctorController.php b/app/Controller/UserDoctorController.php index 221a725..165aca9 100644 --- a/app/Controller/UserDoctorController.php +++ b/app/Controller/UserDoctorController.php @@ -153,4 +153,6 @@ class UserDoctorController extends AbstractController $data = $UserDoctorService->getDoctorCenter(); return $this->response->json($data); } + + } \ No newline at end of file diff --git a/app/Model/BasicBank.php b/app/Model/BasicBank.php index de05491..720feea 100644 --- a/app/Model/BasicBank.php +++ b/app/Model/BasicBank.php @@ -34,7 +34,7 @@ class BasicBank extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['bank_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['bank_id' => 'string', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "bank_id"; diff --git a/app/Model/DoctorAccountDay.php b/app/Model/DoctorAccountDay.php index 31e8289..c658747 100644 --- a/app/Model/DoctorAccountDay.php +++ b/app/Model/DoctorAccountDay.php @@ -14,7 +14,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $year 年(2023) * @property int $month 月(12) * @property int $day 日(01) - * @property int $account_month_id 月份账户id + * @property string $date 日期(2022-01-01) * @property string $total_amount_day 订单总金额-日 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 @@ -31,12 +31,12 @@ class DoctorAccountDay extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['account_detail_id', 'doctor_id', 'year', 'month', 'day', 'account_month_id', 'total_amount_day', 'created_at', 'updated_at']; + protected array $fillable = ['account_detail_id', 'doctor_id', 'year', 'month', 'day', 'date', 'total_amount_day', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. */ - protected array $casts = ['account_detail_id' => 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'day' => 'integer', 'account_month_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['account_detail_id' => 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'day' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "account_detail_id"; diff --git a/app/Model/DoctorAccountMonth.php b/app/Model/DoctorAccountMonth.php index a31f201..b16a228 100644 --- a/app/Model/DoctorAccountMonth.php +++ b/app/Model/DoctorAccountMonth.php @@ -10,14 +10,11 @@ use Hyperf\Snowflake\Concern\Snowflake; /** * @property int $account_month_id 主键id - * @property int $account_id 账户id * @property int $doctor_id 医生id * @property int $year 年(2023) * @property int $month 月(12) - * @property string $month_date 日期(Y-m) * @property string $total_amount 总金额 * @property string $withdrawal_amount 已提现金额 - * @property string $undrawn_amount 未提现金额 * @property string $income_tax 已提现所得税 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 @@ -34,12 +31,12 @@ class DoctorAccountMonth extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['account_month_id', 'account_id', 'doctor_id', 'year', 'month', 'month_date', 'total_amount', 'withdrawal_amount', 'undrawn_amount', 'income_tax', 'created_at', 'updated_at']; + protected array $fillable = ['account_month_id', 'doctor_id', 'year', 'month', 'total_amount', 'withdrawal_amount', 'income_tax', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. */ - protected array $casts = ['account_month_id' => 'integer', 'account_id' => 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['account_month_id' => 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "account_month_id"; diff --git a/app/Model/Hospital.php b/app/Model/Hospital.php index ac80e9f..23a7c5a 100644 --- a/app/Model/Hospital.php +++ b/app/Model/Hospital.php @@ -46,7 +46,7 @@ class Hospital extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['hospital_id' => 'integer', 'hospital_status' => 'integer', 'province_id' => 'integer', 'city_id' => 'integer', 'county_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['hospital_id' => 'string', 'hospital_status' => 'integer', 'province_id' => 'integer', 'city_id' => 'integer', 'county_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "hospital_id"; diff --git a/app/Model/HospitalDepartmentCustom.php b/app/Model/HospitalDepartmentCustom.php index e5b43e8..056be0a 100644 --- a/app/Model/HospitalDepartmentCustom.php +++ b/app/Model/HospitalDepartmentCustom.php @@ -36,7 +36,7 @@ class HospitalDepartmentCustom extends Model /** * The attributes that should be cast to native types. */ - protected array $casts = ['department_custom_id' => 'integer', 'department_id' => 'integer', 'department_status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['department_custom_id' => 'string', 'department_id' => 'integer', 'department_status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "department_custom_id"; diff --git a/app/Model/OrderInquiry.php b/app/Model/OrderInquiry.php index c42835d..9aa31c3 100644 --- a/app/Model/OrderInquiry.php +++ b/app/Model/OrderInquiry.php @@ -28,9 +28,11 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property string $pay_time 支付时间 * @property string $reception_time 接诊时间(已接诊) * @property string $complete_time 订单完成时间(问诊完成时间) + * @property string $finish_time 订单结束时间 * @property string $settlement_amount_total 订单与医生结算金额 * @property int $settlement_status 订单与医生结算状态(0:未结算 1:已结算) * @property string $settlement_time 订单与医生结算时间 + * @property string $cancel_time 订单取消时间 * @property int $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时) * @property string $cancel_remarks 取消订单备注(自动添加) * @property string $patient_name 患者姓名-就诊人 @@ -52,7 +54,7 @@ class OrderInquiry extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['order_inquiry_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'inquiry_type', 'inquiry_mode', 'inquiry_status', 'is_delete', 'inquiry_refund_status', 'inquiry_pay_channel', 'inquiry_pay_status', 'inquiry_no', 'escrow_trade_no', 'amount_total', 'payment_amount_total', 'pay_time', 'reception_time', 'complete_time', 'settlement_amount_total', 'settlement_status', 'settlement_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at']; + protected array $fillable = ['order_inquiry_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'inquiry_type', 'inquiry_mode', 'inquiry_status', 'is_delete', 'inquiry_refund_status', 'inquiry_pay_channel', 'inquiry_pay_status', 'inquiry_no', 'escrow_trade_no', 'amount_total', 'payment_amount_total', 'pay_time', 'reception_time', 'complete_time', 'finish_time', 'settlement_amount_total', 'settlement_status', 'settlement_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. @@ -104,8 +106,11 @@ class OrderInquiry extends Model } /** - * 获取医生接诊列表 - * 已完成-已结束 + * 获取医生接诊订单列表 + * 已结束-已取消 + * inquiry_status:问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + * inquiry_refund_status:问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭) + * cancel_reason:取消订单原因(0:默认 1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时) * @param array $params * @param array $reception_time 接诊时间区间 ['2023-01-02','2023-01-03'] * @param array $fields @@ -116,8 +121,12 @@ class OrderInquiry extends Model public static function getDoctorAccountInfoPage(array $params, array $reception_time,array $fields = ["*"], int $page = null, ?int $per_page = 10): mixed { $raw = self::where($params) - ->whereIn('inquiry_status',[5,6]) - ->whereBetween('reception_time',$reception_time) + ->whereIn('inquiry_status',[6,7]) + ->whereIn('inquiry_refund_status',[0,3]) + ->whereIn('cancel_reason',[0,4]) + ->whereBetween('finish_time',$reception_time) + ->orderBy('finish_time') + ->orderBy('cancel_time') ->paginate($per_page, $fields, "page", $page); $data = array(); @@ -129,4 +138,20 @@ class OrderInquiry extends Model return $data; } + + /** + * 获取医生某一时间段,某种状态的订单金额 + * @param array $params + * @param array $reception_time 接诊时间区间 + * @param array $inquiry_status_params inquiry_status字段搜索条件 + * @return int|mixed|string + */ + public static function getOrderInquiryAmountTotalSum(array $params, array $reception_time,array $inquiry_status_params): mixed + { + return self::where($params) + ->whereIn('inquiry_status',$inquiry_status_params) + ->whereBetween('reception_time',$reception_time) + ->orderBy('reception_time') + ->sum("amount_total"); + } } diff --git a/app/Services/DoctorAccountService.php b/app/Services/DoctorAccountService.php index 5f68606..484c016 100644 --- a/app/Services/DoctorAccountService.php +++ b/app/Services/DoctorAccountService.php @@ -2,10 +2,13 @@ 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; /** * 医生账户 @@ -24,8 +27,11 @@ class DoctorAccountService extends BaseService // 获取医生账户余额 $balance_account = $this->getDoctorBalanceAccount($user_info['client_user_id']); + if ($balance_account > 0){ + $balance_account = $balance_account * 0.75; + } - // 月预计收益 + // 月余额-已结束订单 $amount_total_month = 0; // 月已提现金额 @@ -38,7 +44,10 @@ class DoctorAccountService extends BaseService $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; + 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; } @@ -69,7 +78,7 @@ class DoctorAccountService extends BaseService $result = array(); $result['balance_account'] = $balance_account; // 账户余额 - $result['amount_total_month'] = $amount_total_month * 0.75; // 月预计收益 + $result['amount_total_month'] = $amount_total_month; // 月余额 $result['withdrawal_amount_month'] = $withdrawal_amount_month; // 月已提现金额 $result['bill'] = $bill; // 账单 @@ -114,8 +123,7 @@ class DoctorAccountService extends BaseService $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:转入退款) +// $params['cancel_reason'] = ; $order_inquiry = OrderInquiry::getDoctorAccountInfoPage($params,$reception_time,$fields); if (!empty($order_inquiry['data'])){ @@ -127,6 +135,64 @@ class DoctorAccountService extends BaseService 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 @@ -140,31 +206,37 @@ class DoctorAccountService extends BaseService if (empty($doctor_account)){ $balance_account = 0; }else{ - $balance_account = $doctor_account['balance_account'] * 0.75; + $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; - } +// /** +// * 获取医生账户某日预计收益 +// * @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(){ - return $total_amount_day ?: 0; } - } \ No newline at end of file diff --git a/app/Services/OrderInquiryService.php b/app/Services/OrderInquiryService.php index b9cd847..1ce1bfe 100644 --- a/app/Services/OrderInquiryService.php +++ b/app/Services/OrderInquiryService.php @@ -63,6 +63,37 @@ class OrderInquiryService extends BaseService return $accepting_inquiry_num; } + /** + * 获取医生当日接诊的订单金额 + * 状态:已接诊-已完成 + * @param string $doctor_id + * @param string $date + * @return float + */ + public function getDoctorDayAmountTotal(string $doctor_id,string $date): float + { + // 获取当天开始时间 + $start_date = date('Y-m-d 00:00:00',strtotime($date)); + + // 获取当天结束时间 + $end_date = date('Y-m-d 23:59:59',strtotime($date)); + + // 获取医生当日接诊订单金额 + $params = array(); + $params['doctor_id'] = $doctor_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:转入退款) + $params['settlement_status'] = 0; // 订单与医生结算状态(0:未结算 1:已结算) + + $reception_time = [$start_date,$end_date]; + + $inquiry_status_params = [4,5]; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + + $amount_total_sum = OrderInquiry::getOrderInquiryAmountTotalSum($params,$reception_time,$inquiry_status_params); + + return $amount_total_sum ?: 0; + } + // 创建问诊订单 public function addInquiryOrder(){ $user_info = $this->request->getAttribute("userInfo") ?? []; diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index b69c987..8259966 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -496,13 +496,54 @@ class UserDoctorService extends BaseService // 获取医生账户余额-未提现金额 $DoctorAccountService = new DoctorAccountService(); $balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']); + if ($balance_account > 0){ + $balance_account = $balance_account * 0.75; + } - // 获取当日预计收益 当日接诊的订单金额 - $estimate_income = $DoctorAccountService->getDoctorDayAmountTotal($user_info['client_user_id'],date('Y-m-d',time())); + // 获取医生当日接诊的订单金额 + $OrderInquiryService = new OrderInquiryService(); + $estimate_income = $OrderInquiryService->getDoctorDayAmountTotal($user_info['client_user_id'],date('Y-m-d',time())); + if (!empty($estimate_income)){ + $estimate_income = $estimate_income * 0.75; + } - $user_doctor['balance_account'] = $balance_account ?? 0; + $user_doctor['balance_account'] = $balance_account; $user_doctor['estimate_income'] = $estimate_income; return success($user_doctor); } + + /** + * 检测医生身份认证 + * @param object|array $user_doctor 医生表数据 + * @return bool|string string:错误信息 bool:通过 + */ + public function checkDoctorAuth(object|array $user_doctor): bool|string + { + if (empty($user_doctor)){ + throw new BusinessException(); + } + + if (isset($user_doctor['iden_auth_status'])){ + if ($user_doctor['iden_auth_status'] != 1) { + return "请先完成身份认证"; + } + } + + if (isset($user_doctor['idcard_status'])){ + if ($user_doctor['idcard_status'] != 1) { + return "请先完成实名认证"; + } + } + + if (isset($user_doctor['multi_point_status'])){ + if ($user_doctor['multi_point_status'] != 1) { + return "请先完成多点执业认证"; + } + } + + return true; + } + + } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 5ff0cbf..c8c4ef2 100644 --- a/config/routes.php +++ b/config/routes.php @@ -96,8 +96,6 @@ Router::addGroup('/doctor', function () { Router::addGroup('/center', function () { // 获取医生个人中心数据 Router::get('', [UserDoctorController::class, 'getDoctorCenter']); - - }); // 我的账户 @@ -109,6 +107,12 @@ Router::addGroup('/doctor', function () { Router::get('/info', [DoctorAccountController::class, 'getDoctorAccountInfo']); }); + // 提现 + Router::addGroup('/withdrawal', function () { + // 获取提现数据 + Router::get('', [DoctorAccountController::class, 'getDoctorWithdrawal']); + }); + // 处方 Router::addGroup('/prescription', function () { // 获取处方列表