新增获取医生我的账户数据接口
This commit is contained in:
parent
2f76b0f877
commit
c1320cb71e
32
app/Controller/DoctorAccountController.php
Normal file
32
app/Controller/DoctorAccountController.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Request\DoctorAccountRequest;
|
||||||
|
use App\Request\UserDoctorRequest;
|
||||||
|
use App\Services\DoctorAccountService;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 医生账户
|
||||||
|
*/
|
||||||
|
class DoctorAccountController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取医生我的账户数据
|
||||||
|
* @return ResponseInterface
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function getDoctorAccount(): ResponseInterface
|
||||||
|
{
|
||||||
|
$request = $this->container->get(DoctorAccountRequest::class);
|
||||||
|
$request->scene('getDoctorAccount')->validateResolved();
|
||||||
|
|
||||||
|
$DoctorAccountService = new DoctorAccountService();
|
||||||
|
$data = $DoctorAccountService->getDoctorAccount();
|
||||||
|
return $this->response->json($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,10 +11,9 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
|||||||
/**
|
/**
|
||||||
* @property int $account_id 账户id
|
* @property int $account_id 账户id
|
||||||
* @property int $doctor_id 医生id
|
* @property int $doctor_id 医生id
|
||||||
* @property string $total_amount 总金额(已完成订单的总金额)
|
* @property string $total_amount 总金额(已结束订单的总金额)
|
||||||
* @property string $balance_account 账户余额
|
* @property string $balance_account 账户余额
|
||||||
* @property string $withdrawal_amount 已提现金额
|
* @property string $withdrawal_amount 已提现金额
|
||||||
* @property string $undrawn_amount 未提现金额
|
|
||||||
* @property string $income_tax 所得税金额
|
* @property string $income_tax 所得税金额
|
||||||
* @property \Carbon\Carbon $created_at 创建时间
|
* @property \Carbon\Carbon $created_at 创建时间
|
||||||
* @property \Carbon\Carbon $updated_at 修改时间
|
* @property \Carbon\Carbon $updated_at 修改时间
|
||||||
@ -31,7 +30,7 @@ class DoctorAccount extends Model
|
|||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* 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.
|
* The attributes that should be cast to native types.
|
||||||
|
|||||||
74
app/Model/DoctorAccountDay.php
Normal file
74
app/Model/DoctorAccountDay.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use Hyperf\Snowflake\Concern\Snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $account_detail_id 主键id
|
||||||
|
* @property int $doctor_id 医生id
|
||||||
|
* @property int $year 年(2023)
|
||||||
|
* @property int $month 月(12)
|
||||||
|
* @property int $day 日(01)
|
||||||
|
* @property int $account_month_id 月份账户id
|
||||||
|
* @property string $total_amount_day 订单总金额-日
|
||||||
|
* @property \Carbon\Carbon $created_at 创建时间
|
||||||
|
* @property \Carbon\Carbon $updated_at 修改时间
|
||||||
|
*/
|
||||||
|
class DoctorAccountDay extends Model
|
||||||
|
{
|
||||||
|
use Snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'doctor_account_day';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
67
app/Model/DoctorAccountMonth.php
Normal file
67
app/Model/DoctorAccountMonth.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Model;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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 修改时间
|
||||||
|
*/
|
||||||
|
class DoctorAccountMonth extends Model
|
||||||
|
{
|
||||||
|
use Snowflake;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*/
|
||||||
|
protected ?string $table = 'doctor_account_month';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -105,14 +105,15 @@ class OrderInquiry extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取医生某天预计收益
|
* 获取医生某天预计收益
|
||||||
|
* 已完成-已结束
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @param array $reception_time 接诊时间区间
|
* @param array $reception_time 接诊时间区间
|
||||||
* @return int|mixed|string
|
* @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)
|
return self::where($params)
|
||||||
->whereIn('inquiry_status',[4,5,6])
|
->whereIn('inquiry_status',[5,6])
|
||||||
->whereBetween('reception_time',$reception_time)
|
->whereBetween('reception_time',$reception_time)
|
||||||
->sum("amount_total");
|
->sum("amount_total");
|
||||||
}
|
}
|
||||||
|
|||||||
45
app/Request/DoctorAccountRequest.php
Normal file
45
app/Request/DoctorAccountRequest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Request;
|
||||||
|
|
||||||
|
use App\Constants\HttpEnumCode;
|
||||||
|
use Hyperf\Validation\Request\FormRequest;
|
||||||
|
|
||||||
|
class DoctorAccountRequest extends FormRequest
|
||||||
|
{
|
||||||
|
protected array $scenes = [
|
||||||
|
'getInquiryConfig' => [ // 获取医生问诊配置
|
||||||
|
'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),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
112
app/Services/DoctorAccountService.php
Normal file
112
app/Services/DoctorAccountService.php
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Model\DoctorAccount;
|
||||||
|
use App\Model\DoctorAccountDay;
|
||||||
|
use App\Model\DoctorAccountMonth;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 医生账户
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取医生每日数据
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -493,16 +493,12 @@ class UserDoctorService extends BaseService
|
|||||||
|
|
||||||
$user_doctor = $user_doctor->toArray();
|
$user_doctor = $user_doctor->toArray();
|
||||||
|
|
||||||
// 获取账户余额
|
// 获取医生账户余额-未提现金额
|
||||||
$params = array();
|
$DoctorAccountService = new DoctorAccountService();
|
||||||
$params['doctor_id'] = $user_info['client_user_id'];
|
$balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']);
|
||||||
$doctor_account = DoctorAccount::getOne($params);
|
|
||||||
if (!empty($doctor_account)){
|
|
||||||
$balance_account = $doctor_account['balance_account'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取当日预计收益 当日接诊的订单金额*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['balance_account'] = $balance_account ?? 0;
|
||||||
$user_doctor['estimate_income'] = $estimate_income;
|
$user_doctor['estimate_income'] = $estimate_income;
|
||||||
@ -512,12 +508,12 @@ class UserDoctorService extends BaseService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取医生某天预计收益
|
* 获取医生某天预计收益
|
||||||
* 当日接诊的订单金额*0.75
|
* 当日完成的订单金额*0.75
|
||||||
* @param string $doctor_id
|
* @param string $doctor_id
|
||||||
* @param string $date
|
* @param string $date
|
||||||
* @return float
|
* @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));
|
$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];
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13,6 +13,7 @@ declare(strict_types=1);
|
|||||||
use App\Controller\AreaController;
|
use App\Controller\AreaController;
|
||||||
use App\Controller\BasicDataController;
|
use App\Controller\BasicDataController;
|
||||||
use App\Controller\DiseaseController;
|
use App\Controller\DiseaseController;
|
||||||
|
use App\Controller\DoctorAccountController;
|
||||||
use App\Controller\DoctorAuthController;
|
use App\Controller\DoctorAuthController;
|
||||||
use App\Controller\IndexController;
|
use App\Controller\IndexController;
|
||||||
use App\Controller\LoginController;
|
use App\Controller\LoginController;
|
||||||
@ -95,6 +96,12 @@ Router::addGroup('/doctor', function () {
|
|||||||
Router::addGroup('/center', function () {
|
Router::addGroup('/center', function () {
|
||||||
// 获取医生个人中心数据
|
// 获取医生个人中心数据
|
||||||
Router::get('', [UserDoctorController::class, 'getDoctorCenter']);
|
Router::get('', [UserDoctorController::class, 'getDoctorCenter']);
|
||||||
|
|
||||||
|
// 医生我的账户
|
||||||
|
Router::addGroup('/account', function () {
|
||||||
|
// 获取医生我的账户数据
|
||||||
|
Router::get('', [DoctorAccountController::class, 'getDoctorAccount']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// 处方
|
// 处方
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user