新增发起提现接口
This commit is contained in:
parent
ac5467b951
commit
cde4b9b664
@ -40,11 +40,6 @@ class DoctorWithdrawal extends Model
|
||||
*/
|
||||
protected array $fillable = ['withdrawal_id', 'doctor_id', 'bank_id', 'account_name', 'bank_card_code', 'bank_card_code_four', 'applied_withdrawal_amount', 'actual_withdrawal_amount', 'income_tax', 'examine_status', 'examine_fail_reason', 'examine_time', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['withdrawal_id' => 'integer', 'doctor_id' => 'integer', 'bank_id' => 'integer', 'examine_status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
|
||||
protected string $primaryKey = "withdrawal_id";
|
||||
|
||||
/**
|
||||
@ -105,4 +100,13 @@ class DoctorWithdrawal extends Model
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return DoctorWithdrawal|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addDoctorWithdrawal(array $data): \Hyperf\Database\Model\Model|DoctorWithdrawal
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
}
|
||||
|
||||
67
app/Model/DoctorWithdrawalOrder.php
Normal file
67
app/Model/DoctorWithdrawalOrder.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $withdrawal_order_id 主键id
|
||||
* @property int $withdrawal_id 提现表id
|
||||
* @property int $doctor_id 医生id
|
||||
* @property int $order_inquiry_id 订单-问诊id
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
*/
|
||||
class DoctorWithdrawalOrder extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'doctor_withdrawal_order';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['withdrawal_order_id', 'withdrawal_id', 'doctor_id', 'order_inquiry_id', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "withdrawal_order_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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return DoctorWithdrawalOrder|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addDoctorWithdrawalOrder(array $data): \Hyperf\Database\Model\Model|DoctorWithdrawalOrder
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
}
|
||||
@ -34,11 +34,6 @@ class DoctorWord extends Model
|
||||
*/
|
||||
protected array $fillable = ['doctor_words_id', 'doctor_id', 'words_type', 'words_status', 'sort', 'words', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['doctor_words_id' => 'string', 'doctor_id' => 'integer', 'words_type' => 'integer', 'words_status' => 'integer', 'sort' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
|
||||
|
||||
protected string $primaryKey = "doctor_words_id";
|
||||
|
||||
/**
|
||||
|
||||
@ -24,7 +24,8 @@ class DoctorAccountRequest extends FormRequest
|
||||
],
|
||||
'addDoctorWithdrawal' => [ // 发起提现
|
||||
'order_inquiry_id',
|
||||
'order_inquiry_id',
|
||||
'withdrawal_amount_total',
|
||||
'bank_card_id',
|
||||
],
|
||||
];
|
||||
|
||||
@ -44,6 +45,9 @@ class DoctorAccountRequest extends FormRequest
|
||||
return [
|
||||
'date' => 'required',
|
||||
'year' => 'required',
|
||||
'order_inquiry_id' => 'required',
|
||||
'withdrawal_amount_total' => 'required',
|
||||
'bank_card_id' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,6 +59,9 @@ class DoctorAccountRequest extends FormRequest
|
||||
return [
|
||||
'date.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'year.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'order_inquiry_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'withdrawal_amount_total.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
'bank_card_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,12 +3,15 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\BasicBank;
|
||||
use App\Model\DoctorAccount;
|
||||
use App\Model\DoctorAccountDay;
|
||||
use App\Model\DoctorBankCard;
|
||||
use App\Model\DoctorWithdrawal;
|
||||
use App\Model\DoctorWithdrawalOrder;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\UserDoctor;
|
||||
use Hyperf\DbConnection\Db;
|
||||
|
||||
/**
|
||||
* 医生账户
|
||||
@ -205,10 +208,14 @@ class DoctorAccountService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
if ($balance_account > 0){
|
||||
$balance_account = floor($balance_account * 0.75 * 100) / 100;
|
||||
}
|
||||
|
||||
// 计算医生个人所得税
|
||||
$income_tax = $this->computeIndividualIncomeTax($balance_account);
|
||||
|
||||
$withdrawal_amount = floor(($balance_account * 0.75 - $income_tax) * 100) / 100;
|
||||
$withdrawal_amount = floor(($balance_account - $income_tax) * 100) / 100;
|
||||
|
||||
$income_tax = floor($income_tax * 100) / 100;
|
||||
|
||||
@ -295,6 +302,134 @@ class DoctorAccountService extends BaseService
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起提现
|
||||
* @return array
|
||||
*/
|
||||
public function addDoctorWithdrawal(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$order_inquiry_id = $this->request->input('order_inquiry_id');
|
||||
$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)){
|
||||
return fail();
|
||||
}
|
||||
|
||||
$amount_total = 0;
|
||||
foreach ($order_inquiry_id as $value){
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $value;
|
||||
$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,"存在未支付订单");
|
||||
}
|
||||
|
||||
// 计算订单总金额
|
||||
$amount_total += $order_inquiry['amount_total'];
|
||||
}
|
||||
|
||||
// 医生分成金额
|
||||
if ($amount_total > 0){
|
||||
$amount_total = floor($amount_total * 0.75 * 100) / 100;
|
||||
}
|
||||
// 计算医生个人所得税
|
||||
$income_tax = $this->computeIndividualIncomeTax($amount_total);
|
||||
|
||||
// 可提现金额
|
||||
$withdrawal_amount = floor(($amount_total - $income_tax) * 100) / 100;
|
||||
|
||||
$income_tax = floor($income_tax * 100) / 100;
|
||||
|
||||
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,"银行卡错误");
|
||||
}
|
||||
|
||||
// 获取银行数据
|
||||
$params = array();
|
||||
$params['bank_id'] = $doctor_bank_card['bank_id'];
|
||||
$basic_bank = BasicBank::getOne($params);
|
||||
if (empty($basic_bank)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"银行卡错误");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 新增医生提现表
|
||||
$data = array();
|
||||
$data['doctor_id'] = $user_info['client_user_id'];
|
||||
$data['bank_id'] = $doctor_bank_card['bank_id'];
|
||||
$data['account_name'] = $basic_bank['bank_name'];
|
||||
$data['bank_card_code'] = $basic_bank['bank_code'];
|
||||
$data['bank_card_code_four'] = substr($basic_bank['bank_code'], -4);;
|
||||
$data['applied_withdrawal_amount'] = $withdrawal_amount + $income_tax; // 提现金额
|
||||
$data['actual_withdrawal_amount'] = $withdrawal_amount; // 实际提现金额
|
||||
$data['income_tax'] = $income_tax; // 提现所得税金额
|
||||
$data['examine_status'] = 1; // 审核状态(1:审核中 2:审核通过 3:审核未通过)
|
||||
$doctor_withdrawal = DoctorWithdrawal::addDoctorWithdrawal($data);
|
||||
if (empty($doctor_withdrawal)){
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
foreach ($order_inquiry_id as $value){
|
||||
// 新增医生提现-关联订单表
|
||||
$data = array();
|
||||
$data['withdrawal_id'] = $doctor_withdrawal['withdrawal_id'];
|
||||
$data['doctor_id'] = $user_info['client_user_id'];
|
||||
$data['order_inquiry_id'] = $value;
|
||||
$doctor_withdrawal_order = DoctorWithdrawalOrder::addDoctorWithdrawalOrder($data);
|
||||
if (empty($doctor_withdrawal_order)){
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
|
||||
// 修改问诊订单提现状态
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $value;
|
||||
|
||||
$data = array();
|
||||
$data['is_withdrawal'] = 2;
|
||||
$data['withdrawal_time'] = date('Y-m-d H:i:s',time());
|
||||
OrderInquiry::edit($params,$data);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return success();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取医生账户余额
|
||||
* @param string $doctor_id
|
||||
|
||||
@ -557,14 +557,14 @@ class UserDoctorService extends BaseService
|
||||
$DoctorAccountService = new DoctorAccountService();
|
||||
$balance_account = $DoctorAccountService->getDoctorBalanceAccount($user_info['client_user_id']);
|
||||
if ($balance_account > 0) {
|
||||
$balance_account = round($balance_account,2);
|
||||
$balance_account = floor($balance_account * 100) / 100;
|
||||
}
|
||||
|
||||
// 获取医生当日接诊的订单金额
|
||||
$InquiryService = new InquiryService();
|
||||
$estimate_income = $InquiryService->getDoctorDayAmountTotal($user_info['client_user_id'], date('Y-m-d', time()));
|
||||
if (!empty($estimate_income)) {
|
||||
$estimate_income = round($estimate_income,2);
|
||||
$estimate_income = floor($estimate_income * 100) / 100;
|
||||
}
|
||||
|
||||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user