新增 确认打款 修正修改提现审核状态金额相关数据
This commit is contained in:
parent
9c0d7e94b7
commit
72d37f6a25
@ -203,3 +203,32 @@ func (r *DoctorWithdrawal) PutDoctorWithdrawalExamine(c *gin.Context) {
|
|||||||
|
|
||||||
responses.Ok(c)
|
responses.Ok(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutDoctorWithdrawalPayment 确认打款
|
||||||
|
func (r *DoctorWithdrawal) PutDoctorWithdrawalPayment(c *gin.Context) {
|
||||||
|
id := c.Param("withdrawal_id")
|
||||||
|
if id == "" {
|
||||||
|
responses.FailWithMessage("缺少参数", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 id 转换为 int64 类型
|
||||||
|
withdrawalId, err := strconv.ParseInt(id, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
responses.Fail(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 后台用户id
|
||||||
|
adminUserId := c.GetInt64("UserId")
|
||||||
|
|
||||||
|
// 业务处理
|
||||||
|
doctorWithdrawaService := service.DoctorWithdrawaService{}
|
||||||
|
_, err = doctorWithdrawaService.PutDoctorWithdrawalPayment(withdrawalId, adminUserId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses.Ok(c)
|
||||||
|
}
|
||||||
|
|||||||
@ -526,8 +526,8 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
// 修改提现审核状态
|
// 修改提现审核状态
|
||||||
withdrawalGroup.PUT("/examine/:withdrawal_id", api.DoctorWithdrawal.PutDoctorWithdrawalExamine)
|
withdrawalGroup.PUT("/examine/:withdrawal_id", api.DoctorWithdrawal.PutDoctorWithdrawalExamine)
|
||||||
|
|
||||||
// 修改打款状态
|
// 确认打款
|
||||||
withdrawalGroup.PUT("/payment/:withdrawal_id", api.OrderPrescription.GetOrderPrescriptionPage)
|
withdrawalGroup.PUT("/payment/:withdrawal_id", api.DoctorWithdrawal.PutDoctorWithdrawalPayment)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 银行卡管理
|
// 银行卡管理
|
||||||
|
|||||||
@ -112,8 +112,8 @@ func (r *DoctorWithdrawaService) PutDoctorWithdrawalIncome(req requests.PutDocto
|
|||||||
|
|
||||||
// 提现申请修改数据-提现金额固定不动,修改个人所得税,实际提现金额跟随变动
|
// 提现申请修改数据-提现金额固定不动,修改个人所得税,实际提现金额跟随变动
|
||||||
doctorWithdrawalData := make(map[string]interface{})
|
doctorWithdrawalData := make(map[string]interface{})
|
||||||
doctorWithdrawalData["income_tax"] = req.IncomeTax // 提现所得税金额
|
|
||||||
doctorWithdrawalData["actual_withdrawal_amount"] = actualWithdrawalAmount // 实际提现金额
|
doctorWithdrawalData["actual_withdrawal_amount"] = actualWithdrawalAmount // 实际提现金额
|
||||||
|
doctorWithdrawalData["income_tax"] = req.IncomeTax // 提现所得税金额
|
||||||
err := doctorWithdrawalDao.EditDoctorWithdrawalById(tx, doctorWithdrawal.WithdrawalId, doctorWithdrawalData)
|
err := doctorWithdrawalDao.EditDoctorWithdrawalById(tx, doctorWithdrawal.WithdrawalId, doctorWithdrawalData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -173,31 +173,29 @@ func (r *DoctorWithdrawaService) PutDoctorWithdrawalExamine(req requests.PutDoct
|
|||||||
return false, errors.New(err.Error())
|
return false, errors.New(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取医生账户数据
|
||||||
|
doctorAccountDao := dao.DoctorAccountDao{}
|
||||||
|
doctorAccount, err := doctorAccountDao.GetDoctorAccountByDoctorId(doctorWithdrawal.DoctorId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("医生账户数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取医生分成总金额
|
||||||
|
amountTotal, err := r.getDoctorWithdrawalOrderAmountTotal(withdrawalId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新计算医生个人所得税
|
||||||
|
incomeTax := utils.ComputeIndividualIncomeTax(amountTotal)
|
||||||
|
|
||||||
|
// 重新计算实际提现金额
|
||||||
|
withdrawalAmount := amountTotal - incomeTax
|
||||||
|
|
||||||
// 返还医生账户金额-审核不通过
|
// 返还医生账户金额-审核不通过
|
||||||
if req.ExamineStatus == 3 {
|
if req.ExamineStatus == 3 {
|
||||||
// 获取医生账户数据
|
|
||||||
doctorAccountDao := dao.DoctorAccountDao{}
|
|
||||||
doctorAccount, err := doctorAccountDao.GetDoctorAccountByDoctorId(doctorWithdrawal.DoctorId)
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return false, errors.New("医生账户数据错误")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取提现关联订单医生分成总金额
|
|
||||||
amountTotal, err := r.getDoctorWithdrawalOrderAmountTotal(withdrawalId)
|
|
||||||
if err != nil {
|
|
||||||
tx.Rollback()
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新计算医生个人所得税
|
|
||||||
incomeTax := utils.ComputeIndividualIncomeTax(amountTotal)
|
|
||||||
|
|
||||||
// 重新计算实际提现金额
|
|
||||||
withdrawalAmount := math.Floor((amountTotal-incomeTax)*0.75*100) / 100
|
|
||||||
|
|
||||||
incomeTax = math.Floor(incomeTax*100) / 100
|
|
||||||
|
|
||||||
// 账户余额-增加
|
// 账户余额-增加
|
||||||
maps := make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
maps["account_id"] = doctorAccount.AccountId
|
maps["account_id"] = doctorAccount.AccountId
|
||||||
@ -207,10 +205,19 @@ func (r *DoctorWithdrawaService) PutDoctorWithdrawalExamine(req requests.PutDoct
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 提现金额-减少
|
||||||
|
maps = make(map[string]interface{})
|
||||||
|
maps["account_id"] = doctorAccount.AccountId
|
||||||
|
err = doctorAccountDao.Dec(tx, maps, amountTotal, "applied_withdrawal_amount")
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
// 实际提现金额-减少
|
// 实际提现金额-减少
|
||||||
maps = make(map[string]interface{})
|
maps = make(map[string]interface{})
|
||||||
maps["account_id"] = doctorAccount.AccountId
|
maps["account_id"] = doctorAccount.AccountId
|
||||||
err = doctorAccountDao.Dec(tx, maps, withdrawalAmount, "applied_withdrawal_amount")
|
err = doctorAccountDao.Dec(tx, maps, withdrawalAmount, "actual_withdrawal_amount")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, err
|
return false, err
|
||||||
@ -258,6 +265,74 @@ func (r *DoctorWithdrawaService) PutDoctorWithdrawalExamine(req requests.PutDoct
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PutDoctorWithdrawalPayment 确认打款
|
||||||
|
func (r *DoctorWithdrawaService) PutDoctorWithdrawalPayment(withdrawalId, adminUserId int64) (bool, error) {
|
||||||
|
doctorWithdrawalDao := dao.DoctorWithdrawalDao{}
|
||||||
|
doctorWithdrawal, _ := doctorWithdrawalDao.GetDoctorWithdrawalById(withdrawalId)
|
||||||
|
if doctorWithdrawal == nil {
|
||||||
|
return false, errors.New("数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断审核状态
|
||||||
|
if doctorWithdrawal.ExamineStatus != 2 {
|
||||||
|
return false, errors.New("请先确认打款金额并审核")
|
||||||
|
}
|
||||||
|
|
||||||
|
if doctorWithdrawal.PaymentStatus == 1 {
|
||||||
|
return false, errors.New("已打款,请勿再次操作")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 开始事务
|
||||||
|
tx := global.Db.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 提现申请修改数据
|
||||||
|
doctorWithdrawalData := make(map[string]interface{})
|
||||||
|
doctorWithdrawalData["payment_status"] = 1
|
||||||
|
doctorWithdrawalData["payment_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
doctorWithdrawalData["payment_by"] = adminUserId
|
||||||
|
err := doctorWithdrawalDao.EditDoctorWithdrawalById(tx, doctorWithdrawal.WithdrawalId, doctorWithdrawalData)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取医生提现-关联订单数据
|
||||||
|
doctorWithdrawalOrderDao := dao.DoctorWithdrawalOrderDao{}
|
||||||
|
doctorWithdrawalOrders, err := doctorWithdrawalOrderDao.GetDoctorWithdrawalOrderByWithdrawalId(withdrawalId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("关联订单数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改问诊订单提现状态
|
||||||
|
for _, v := range doctorWithdrawalOrders {
|
||||||
|
// 获取订单数据
|
||||||
|
orderInquiryDao := dao.OrderInquiryDao{}
|
||||||
|
orderInquiry, err := orderInquiryDao.GetOrderInquiryById(v.OrderInquiryId)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("关联订单数据错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
orderInquiryData := make(map[string]interface{})
|
||||||
|
orderInquiryData["is_withdrawal"] = 1
|
||||||
|
orderInquiryData["withdrawal_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||||
|
err = orderInquiryDao.EditOrderInquiryById(tx, orderInquiry.OrderInquiryId, orderInquiryData)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("操作关联订单数据失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 获取提现关联订单医生分成总金额
|
// 获取提现关联订单医生分成总金额
|
||||||
func (r *DoctorWithdrawaService) getDoctorWithdrawalOrderAmountTotal(withdrawalId int64) (float64, error) {
|
func (r *DoctorWithdrawaService) getDoctorWithdrawalOrderAmountTotal(withdrawalId int64) (float64, error) {
|
||||||
// 获取医生提现-关联订单数据
|
// 获取医生提现-关联订单数据
|
||||||
@ -292,10 +367,7 @@ func (r *DoctorWithdrawaService) getDoctorWithdrawalOrderAmountTotal(withdrawalI
|
|||||||
amountTotal = amountTotal + orderInquiry.AmountTotal
|
amountTotal = amountTotal + orderInquiry.AmountTotal
|
||||||
}
|
}
|
||||||
|
|
||||||
// 医生分成金额
|
amountTotal = amountTotal * 0.75
|
||||||
if amountTotal > 0 {
|
|
||||||
amountTotal = math.Floor(amountTotal*0.75*100) / 100
|
|
||||||
}
|
|
||||||
|
|
||||||
return amountTotal, nil
|
return amountTotal, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user