From c1320cb71e8432b94d0312f84d39baa99a23ab77 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 22 Feb 2023 18:16:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E6=88=91=E7=9A=84=E8=B4=A6=E6=88=B7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/DoctorAccountController.php | 32 ++++++ app/Model/DoctorAccount.php | 5 +- app/Model/DoctorAccountDay.php | 74 ++++++++++++++ app/Model/DoctorAccountMonth.php | 67 ++++++++++++ app/Model/OrderInquiry.php | 5 +- app/Request/DoctorAccountRequest.php | 45 +++++++++ app/Services/DoctorAccountService.php | 112 +++++++++++++++++++++ app/Services/UserDoctorService.php | 26 ++--- config/routes.php | 7 ++ 9 files changed, 355 insertions(+), 18 deletions(-) create mode 100644 app/Controller/DoctorAccountController.php create mode 100644 app/Model/DoctorAccountDay.php create mode 100644 app/Model/DoctorAccountMonth.php create mode 100644 app/Request/DoctorAccountRequest.php create mode 100644 app/Services/DoctorAccountService.php diff --git a/app/Controller/DoctorAccountController.php b/app/Controller/DoctorAccountController.php new file mode 100644 index 0000000..e9cfd33 --- /dev/null +++ b/app/Controller/DoctorAccountController.php @@ -0,0 +1,32 @@ +container->get(DoctorAccountRequest::class); + $request->scene('getDoctorAccount')->validateResolved(); + + $DoctorAccountService = new DoctorAccountService(); + $data = $DoctorAccountService->getDoctorAccount(); + return $this->response->json($data); + } +} \ No newline at end of file diff --git a/app/Model/DoctorAccount.php b/app/Model/DoctorAccount.php index 4081b52..c5f1e3e 100644 --- a/app/Model/DoctorAccount.php +++ b/app/Model/DoctorAccount.php @@ -11,10 +11,9 @@ use Hyperf\Snowflake\Concern\Snowflake; /** * @property int $account_id 账户id * @property int $doctor_id 医生id - * @property string $total_amount 总金额(已完成订单的总金额) + * @property string $total_amount 总金额(已结束订单的总金额) * @property string $balance_account 账户余额 * @property string $withdrawal_amount 已提现金额 - * @property string $undrawn_amount 未提现金额 * @property string $income_tax 所得税金额 * @property \Carbon\Carbon $created_at 创建时间 * @property \Carbon\Carbon $updated_at 修改时间 @@ -31,7 +30,7 @@ class DoctorAccount extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['account_id', 'doctor_id', 'total_amount', 'balance_account', 'withdrawal_amount', 'undrawn_amount', 'income_tax', 'created_at', 'updated_at']; + protected array $fillable = ['account_id', 'doctor_id', 'total_amount', 'balance_account', 'withdrawal_amount', 'income_tax', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. diff --git a/app/Model/DoctorAccountDay.php b/app/Model/DoctorAccountDay.php new file mode 100644 index 0000000..31e8289 --- /dev/null +++ b/app/Model/DoctorAccountDay.php @@ -0,0 +1,74 @@ + 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'day' => 'integer', 'account_month_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + + protected string $primaryKey = "account_detail_id"; + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getOne(array $params, array $fields = ['*']): object|null + { + return self::where($params)->first($fields); + } + + /** + * 获取信息-多条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getList(array $params, array $fields = ['*']): object|null + { + return self::where($params)->get($fields); + } + + /** + * 获取total_amount_day字段总和 + * @param array $params + * @return int|mixed|string + */ + public static function getDoctorSumTotalAmount(array $params): mixed + { + return self::where($params)->sum("total_amount_day"); + } +} diff --git a/app/Model/DoctorAccountMonth.php b/app/Model/DoctorAccountMonth.php new file mode 100644 index 0000000..a31f201 --- /dev/null +++ b/app/Model/DoctorAccountMonth.php @@ -0,0 +1,67 @@ + 'integer', 'account_id' => 'integer', 'doctor_id' => 'integer', 'year' => 'integer', 'month' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + + protected string $primaryKey = "account_month_id"; + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getOne(array $params, array $fields = ['*']): object|null + { + return self::where($params)->first($fields); + } + + /** + * 获取信息-多条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getList(array $params, array $fields = ['*']): object|null + { + return self::where($params)->get($fields); + } +} diff --git a/app/Model/OrderInquiry.php b/app/Model/OrderInquiry.php index 5cda274..199c050 100644 --- a/app/Model/OrderInquiry.php +++ b/app/Model/OrderInquiry.php @@ -105,14 +105,15 @@ class OrderInquiry extends Model /** * 获取医生某天预计收益 + * 已完成-已结束 * @param array $params * @param array $reception_time 接诊时间区间 * @return int|mixed|string */ - public static function getDoctorOneDayEstimateIncome(array $params,array $reception_time): mixed + public static function getDoctorOneDayAmountTotal(array $params, array $reception_time): mixed { return self::where($params) - ->whereIn('inquiry_status',[4,5,6]) + ->whereIn('inquiry_status',[5,6]) ->whereBetween('reception_time',$reception_time) ->sum("amount_total"); } diff --git a/app/Request/DoctorAccountRequest.php b/app/Request/DoctorAccountRequest.php new file mode 100644 index 0000000..0267529 --- /dev/null +++ b/app/Request/DoctorAccountRequest.php @@ -0,0 +1,45 @@ + [ // 获取医生问诊配置 + 'date', + ], + ]; + + /** + * Determine if the user is authorized to make this request. + */ + public function authorize(): bool + { + return true; + } + + /** + * Get the validation rules that apply to the request. + */ + public function rules(): array + { + return [ + 'date' => 'required', + ]; + } + + /** + * 获取已定义验证规则的错误消息. + */ + public function messages(): array + { + return [ + 'date.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR), + ]; + } +} diff --git a/app/Services/DoctorAccountService.php b/app/Services/DoctorAccountService.php new file mode 100644 index 0000000..7cbba95 --- /dev/null +++ b/app/Services/DoctorAccountService.php @@ -0,0 +1,112 @@ +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; + } + + // 获取医生每日数据 + $fields = [ + 'total_amount_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)){ + $bill = []; + }else{ + foreach ($doctor_account_days as &$doctor_account_day){ + $doctor_account_day['total_amount_day'] = $doctor_account_day['total_amount_day'] * 0.75; + } + $bill = $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); + } + + /** + * 获取医生账户余额 + * @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; + } + +} \ No newline at end of file diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index 7b370c6..8c229c2 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -493,16 +493,12 @@ class UserDoctorService extends BaseService $user_doctor = $user_doctor->toArray(); - // 获取账户余额 - $params = array(); - $params['doctor_id'] = $user_info['client_user_id']; - $doctor_account = DoctorAccount::getOne($params); - if (!empty($doctor_account)){ - $balance_account = $doctor_account['balance_account']; - } + // 获取医生账户余额-未提现金额 + $DoctorAccountService = new DoctorAccountService(); + $balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']); - // 获取当日预计收益 当日接诊的订单金额*0.75 - $estimate_income = $this->getDoctorOneDayEstimateIncome($user_info['client_user_id'],date('Y-m-d',time())); + // 获取当日预计收益 当日接诊的订单金额 + $estimate_income = $DoctorAccountService->getDoctorDayAmountTotal($user_info['client_user_id'],date('Y-m-d',time())); $user_doctor['balance_account'] = $balance_account ?? 0; $user_doctor['estimate_income'] = $estimate_income; @@ -512,12 +508,12 @@ class UserDoctorService extends BaseService /** * 获取医生某天预计收益 - * 当日接诊的订单金额*0.75 + * 当日完成的订单金额*0.75 * @param string $doctor_id * @param string $date * @return float */ - protected function getDoctorOneDayEstimateIncome(string $doctor_id,string $date): float + public function getDoctorOneDayAmountTotal(string $doctor_id,string $date): float { // 获取当天开始时间 $start_date = date('Y-m-d 00:00:00',strtotime($date)); @@ -534,8 +530,12 @@ class UserDoctorService extends BaseService $reception_time = [$start_date,$end_date]; - $amount_total_sum = OrderInquiry::getDoctorOneDayEstimateIncome($params,$reception_time); + $amount_total_sum = OrderInquiry::getDoctorOneDayAmountTotal($params,$reception_time); - return $amount_total_sum * 0.75; + if (!empty($amount_total_sum)){ + $amount_total_sum = $amount_total_sum * 0.75; + } + + return $amount_total_sum ?: 0; } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 09b18f0..1908255 100644 --- a/config/routes.php +++ b/config/routes.php @@ -13,6 +13,7 @@ declare(strict_types=1); use App\Controller\AreaController; use App\Controller\BasicDataController; use App\Controller\DiseaseController; +use App\Controller\DoctorAccountController; use App\Controller\DoctorAuthController; use App\Controller\IndexController; use App\Controller\LoginController; @@ -95,6 +96,12 @@ Router::addGroup('/doctor', function () { Router::addGroup('/center', function () { // 获取医生个人中心数据 Router::get('', [UserDoctorController::class, 'getDoctorCenter']); + + // 医生我的账户 + Router::addGroup('/account', function () { + // 获取医生我的账户数据 + Router::get('', [DoctorAccountController::class, 'getDoctorAccount']); + }); }); // 处方