修改提现数据3
This commit is contained in:
parent
a0cc55a37b
commit
ed736a7c92
@ -2,6 +2,7 @@ package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
@ -18,6 +19,14 @@ func (r *OrderDao) GetOrderById(orderId int64) (m *model.Order, err error) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (r *OrderDao) GetOrderPreloadById(orderId int64) (m *model.Order, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, orderId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddOrder 新增
|
||||
func (r *OrderDao) AddOrder(tx *gorm.DB, model *model.Order) (*model.Order, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
|
||||
@ -326,25 +326,51 @@ func (r *DoctorWithdrawalService) PutDoctorWithdrawalPayment(withdrawalId, admin
|
||||
}
|
||||
|
||||
// 修改问诊订单提现状态
|
||||
orderDao := dao.OrderDao{}
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
orderServicePackageDao := dao.OrderServicePackageDao{}
|
||||
for _, v := range doctorWithdrawalOrders {
|
||||
// 获取订单数据
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
orderInquiry, err := orderInquiryDao.GetOrderInquiryById(v.OrderInquiryId)
|
||||
order, err := orderDao.GetOrderPreloadById(v.OrderId)
|
||||
if order == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("关联订单数据错误")
|
||||
}
|
||||
|
||||
// 修改订单数据
|
||||
orderData := make(map[string]interface{})
|
||||
orderData["is_withdrawal"] = 1
|
||||
orderData["withdrawal_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
err = orderDao.EditOrderById(tx, v.OrderId, orderData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("关联订单数据错误")
|
||||
}
|
||||
|
||||
if order.OrderType == 1 {
|
||||
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)
|
||||
err = orderInquiryDao.EditOrderInquiryById(tx, order.OrderInquiry.OrderInquiryId, orderInquiryData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("操作关联订单数据失败")
|
||||
}
|
||||
}
|
||||
|
||||
if order.OrderType == 4 || order.OrderType == 5 {
|
||||
orderServicePackageData := make(map[string]interface{})
|
||||
orderServicePackageData["is_withdrawal"] = 1
|
||||
orderServicePackageData["withdrawal_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
err = orderServicePackageDao.EditOrderServicePackageById(tx, order.OrderId, orderServicePackageData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("操作关联订单数据失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
@ -358,31 +384,35 @@ func (r *DoctorWithdrawalService) getDoctorWithdrawalOrderAmountTotal(withdrawal
|
||||
return 0, errors.New("关联订单数据错误")
|
||||
}
|
||||
|
||||
orderDao := dao.OrderDao{}
|
||||
|
||||
// 总金额
|
||||
var amountTotal = decimal.NewFromFloat(0)
|
||||
for _, v := range doctorWithdrawalOrders {
|
||||
// 获取订单数据
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
orderInquiry, err := orderInquiryDao.GetOrderInquiryByOrderId(v.OrderId)
|
||||
order, err := orderDao.GetOrderPreloadById(v.OrderId)
|
||||
if err != nil {
|
||||
return 0, errors.New("订单数据错误")
|
||||
}
|
||||
|
||||
if orderInquiry.InquiryStatus != 6 {
|
||||
if order.OrderInquiry != nil {
|
||||
if order.OrderInquiry.InquiryStatus != 6 {
|
||||
return 0, errors.New("存在未结束订单,数据错误")
|
||||
}
|
||||
|
||||
if orderInquiry.IsWithdrawal == 1 {
|
||||
}
|
||||
|
||||
if order.IsWithdrawal == 1 {
|
||||
return 0, errors.New("存在已被提现订单,数据错误")
|
||||
}
|
||||
|
||||
if orderInquiry.InquiryPayStatus != 2 {
|
||||
if order.PayStatus != 2 {
|
||||
return 0, errors.New("存在支付状态错误订单,数据错误")
|
||||
}
|
||||
|
||||
var orderInquiryAmountTotal = decimal.NewFromFloat(orderInquiry.AmountTotal)
|
||||
var orderAmountTotal = decimal.NewFromFloat(order.AmountTotal)
|
||||
|
||||
amountTotal = amountTotal.Add(orderInquiryAmountTotal)
|
||||
amountTotal = amountTotal.Add(orderAmountTotal)
|
||||
}
|
||||
|
||||
// 分成比例
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user