Merge branch 'main' of http://1.117.67.95:3000/team/tyc-server-v2
This commit is contained in:
@@ -267,6 +267,7 @@ type (
|
|||||||
Amount float64 `json:"amount"` // 金额
|
Amount float64 `json:"amount"` // 金额
|
||||||
ActualAmount float64 `json:"actual_amount"` // 实际到账金额(扣税后)
|
ActualAmount float64 `json:"actual_amount"` // 实际到账金额(扣税后)
|
||||||
TaxAmount float64 `json:"tax_amount"` // 扣税金额
|
TaxAmount float64 `json:"tax_amount"` // 扣税金额
|
||||||
|
TaxRate float64 `json:"tax_rate"` // 扣税比例,如 0.06 表示 6%
|
||||||
Status int64 `json:"status"` // 状态
|
Status int64 `json:"status"` // 状态
|
||||||
PayeeAccount string `json:"payee_account"` // 收款账户
|
PayeeAccount string `json:"payee_account"` // 收款账户
|
||||||
Remark string `json:"remark"` // 备注
|
Remark string `json:"remark"` // 备注
|
||||||
@@ -468,9 +469,10 @@ type (
|
|||||||
|
|
||||||
// 银行卡提现审核请求
|
// 银行卡提现审核请求
|
||||||
AdminReviewBankCardWithdrawalReq {
|
AdminReviewBankCardWithdrawalReq {
|
||||||
WithdrawalId int64 `json:"withdrawal_id"` // 提现记录ID
|
WithdrawalId int64 `json:"withdrawal_id"` // 提现记录ID
|
||||||
Action int64 `json:"action"` // 操作:1-确认,2-拒绝
|
Action int64 `json:"action"` // 操作:1-确认,2-拒绝
|
||||||
Remark string `json:"remark"` // 备注(拒绝时必填)
|
Remark string `json:"remark"` // 备注(拒绝时必填)
|
||||||
|
TaxRate *float64 `json:"tax_rate,optional"` // 扣税比例,如 0.06 表示 6%,不传则默认 6%
|
||||||
}
|
}
|
||||||
|
|
||||||
// 银行卡提现审核响应
|
// 银行卡提现审核响应
|
||||||
|
|||||||
@@ -38,15 +38,20 @@ type AdminGetQueryDetailByOrderIdReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetQueryDetailByOrderIdResp {
|
type AdminGetQueryDetailByOrderIdResp {
|
||||||
Id int64 `json:"id"` // 主键ID
|
Id int64 `json:"id"` // 主键ID
|
||||||
OrderId int64 `json:"order_id"` // 订单ID
|
OrderId int64 `json:"order_id"` // 订单ID
|
||||||
UserId int64 `json:"user_id"` // 用户ID
|
UserId int64 `json:"user_id"` // 用户ID
|
||||||
ProductName string `json:"product_name"` // 产品ID
|
ProductName string `json:"product_name"` // 产品名称
|
||||||
QueryParams map[string]interface{} `json:"query_params"`
|
OrderNo string `json:"order_no"` // 商户订单号
|
||||||
QueryData []AdminQueryItem `json:"query_data"`
|
PlatformOrderId string `json:"platform_order_id"` // 支付订单号
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
PaymentStatus string `json:"payment_status"` // 支付状态
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
QueryState string `json:"query_state"` // 查询状态
|
RefundTime string `json:"refund_time"` // 退款时间(有退款时)
|
||||||
|
QueryParams map[string]interface{} `json:"query_params"`
|
||||||
|
QueryData []AdminQueryItem `json:"query_data"`
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
|
QueryState string `json:"query_state"` // 查询状态
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminQueryItem {
|
type AdminQueryItem {
|
||||||
|
|||||||
@@ -363,6 +363,7 @@ type (
|
|||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
payeeAccount string `json:"payee_account"`
|
payeeAccount string `json:"payee_account"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
|
TaxRate float64 `json:"tax_rate"` // 扣税比例,如 0.06 表示 6%
|
||||||
}
|
}
|
||||||
GetWithdrawalReq {
|
GetWithdrawalReq {
|
||||||
Page int64 `form:"page"` // 页码
|
Page int64 `form:"page"` // 页码
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ func (l *AdminGetAgentWithdrawalListLogic) AdminGetAgentWithdrawalList(req *type
|
|||||||
item.PayeeName = v.PayeeName.String
|
item.PayeeName = v.PayeeName.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从扣税记录中取扣税比例
|
||||||
|
taxModel, taxErr := l.svcCtx.AgentWithdrawalTaxModel.FindOneByWithdrawalId(l.ctx, v.Id)
|
||||||
|
if taxErr == nil {
|
||||||
|
item.TaxRate = taxModel.TaxRate
|
||||||
|
}
|
||||||
|
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
resp = &types.AdminGetAgentWithdrawalListResp{
|
resp = &types.AdminGetAgentWithdrawalListResp{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package admin_agent
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
"tyc-server/app/main/model"
|
"tyc-server/app/main/model"
|
||||||
"tyc-server/common/xerr"
|
"tyc-server/common/xerr"
|
||||||
@@ -85,9 +86,18 @@ func (l *AdminReviewBankCardWithdrawalLogic) AdminReviewBankCardWithdrawal(req *
|
|||||||
return errors.Wrapf(xerr.NewErrMsg("提现类型不正确"), "提现类型验证失败")
|
return errors.Wrapf(xerr.NewErrMsg("提现类型不正确"), "提现类型验证失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确认时使用的扣税比例:请求中传入则用传入值,否则默认 6%
|
||||||
|
taxRate := 0.06
|
||||||
|
if req.Action == ReviewActionApprove && req.TaxRate != nil {
|
||||||
|
taxRate = *req.TaxRate
|
||||||
|
if taxRate < 0 || taxRate > 1 {
|
||||||
|
return errors.Wrapf(xerr.NewErrMsg("扣税比例必须在 0~100% 之间"), "扣税比例验证失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if req.Action == ReviewActionApprove {
|
if req.Action == ReviewActionApprove {
|
||||||
// 确认提现
|
// 确认提现(可带自定义扣税比例)
|
||||||
return l.approveWithdrawal(ctx, session, record)
|
return l.approveWithdrawal(ctx, session, record, taxRate)
|
||||||
} else {
|
} else {
|
||||||
// 拒绝提现
|
// 拒绝提现
|
||||||
return l.rejectWithdrawal(ctx, session, record, req.Remark)
|
return l.rejectWithdrawal(ctx, session, record, req.Remark)
|
||||||
@@ -102,11 +112,15 @@ func (l *AdminReviewBankCardWithdrawalLogic) AdminReviewBankCardWithdrawal(req *
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确认提现
|
// 确认提现(taxRate 为扣税比例,如 0.06 表示 6%)
|
||||||
func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal) error {
|
func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal, taxRate float64) error {
|
||||||
|
// 按审核时选择的扣税比例重新计算并更新提现记录与扣税记录
|
||||||
|
if err := l.applyReviewTaxRate(ctx, session, record, taxRate); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
// 根据提现类型执行不同的操作
|
// 根据提现类型执行不同的操作
|
||||||
if record.WithdrawType == WithdrawTypeAlipay {
|
if record.WithdrawType == WithdrawTypeAlipay {
|
||||||
// 支付宝提现:先调用支付宝转账接口
|
// 支付宝提现:按更新后的实际到账金额调用支付宝转账
|
||||||
return l.approveAlipayWithdrawal(ctx, session, record)
|
return l.approveAlipayWithdrawal(ctx, session, record)
|
||||||
} else {
|
} else {
|
||||||
// 银行卡提现:直接更新状态为成功(线下转账)
|
// 银行卡提现:直接更新状态为成功(线下转账)
|
||||||
@@ -114,6 +128,32 @@ func (l *AdminReviewBankCardWithdrawalLogic) approveWithdrawal(ctx context.Conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyReviewTaxRate 按审核时选择的扣税比例更新提现记录与扣税记录
|
||||||
|
func (l *AdminReviewBankCardWithdrawalLogic) applyReviewTaxRate(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal, taxRate float64) error {
|
||||||
|
// 金额保留两位小数,避免浮点误差并与前端/支付宝一致
|
||||||
|
newTaxAmount := math.Round(record.Amount*taxRate*100) / 100
|
||||||
|
newActualAmount := math.Round((record.Amount-newTaxAmount)*100) / 100
|
||||||
|
|
||||||
|
record.TaxAmount = newTaxAmount
|
||||||
|
record.ActualAmount = newActualAmount
|
||||||
|
if _, err := l.svcCtx.AgentWithdrawalModel.Update(ctx, session, record); err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新提现记录扣税金额失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
taxModel, err := l.svcCtx.AgentWithdrawalTaxModel.FindOneByWithdrawalId(ctx, record.Id)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询扣税记录失败: %v", err)
|
||||||
|
}
|
||||||
|
taxModel.TaxRate = taxRate
|
||||||
|
taxModel.TaxAmount = newTaxAmount
|
||||||
|
taxModel.ActualAmount = newActualAmount
|
||||||
|
taxModel.TaxableAmount = record.Amount
|
||||||
|
if err := l.svcCtx.AgentWithdrawalTaxModel.UpdateWithVersion(ctx, session, taxModel); err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新扣税记录失败: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// 确认支付宝提现
|
// 确认支付宝提现
|
||||||
func (l *AdminReviewBankCardWithdrawalLogic) approveAlipayWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal) error {
|
func (l *AdminReviewBankCardWithdrawalLogic) approveAlipayWithdrawal(ctx context.Context, session sqlx.Session, record *model.AgentWithdrawal) error {
|
||||||
// 同步调用支付宝转账
|
// 同步调用支付宝转账
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ func (l *AdminGetQueryDetailByOrderIdLogic) AdminGetQueryDetailByOrderId(req *ty
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "报告查询, 获取商品信息失败, %v", err)
|
||||||
}
|
}
|
||||||
query.ProductName = product.ProductName
|
query.ProductName = product.ProductName
|
||||||
return &types.AdminGetQueryDetailByOrderIdResp{
|
|
||||||
|
resp = &types.AdminGetQueryDetailByOrderIdResp{
|
||||||
Id: query.Id,
|
Id: query.Id,
|
||||||
OrderId: query.OrderId,
|
OrderId: query.OrderId,
|
||||||
UserId: query.UserId,
|
UserId: query.UserId,
|
||||||
@@ -82,7 +83,23 @@ func (l *AdminGetQueryDetailByOrderIdLogic) AdminGetQueryDetailByOrderId(req *ty
|
|||||||
CreateTime: query.CreateTime,
|
CreateTime: query.CreateTime,
|
||||||
UpdateTime: query.UpdateTime,
|
UpdateTime: query.UpdateTime,
|
||||||
QueryState: query.QueryState,
|
QueryState: query.QueryState,
|
||||||
}, nil
|
}
|
||||||
|
// 从订单表补充:商户订单号、支付订单号、支付状态、支付时间、退款时间
|
||||||
|
orderModel, orderErr := l.svcCtx.OrderModel.FindOne(l.ctx, req.OrderId)
|
||||||
|
if orderErr == nil && orderModel != nil {
|
||||||
|
resp.OrderNo = orderModel.OrderNo
|
||||||
|
if orderModel.PlatformOrderId.Valid {
|
||||||
|
resp.PlatformOrderId = orderModel.PlatformOrderId.String
|
||||||
|
}
|
||||||
|
resp.PaymentStatus = orderModel.Status
|
||||||
|
if orderModel.PayTime.Valid {
|
||||||
|
resp.PayTime = orderModel.PayTime.Time.Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
if orderModel.RefundTime.Valid {
|
||||||
|
resp.RefundTime = orderModel.RefundTime.Time.Format("2006-01-02 15:04:05")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessQueryData 解密和反序列化 QueryData
|
// ProcessQueryData 解密和反序列化 QueryData
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ func (l *GetAgentWithdrawalLogic) GetAgentWithdrawal(req *types.GetWithdrawalReq
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理提现列表, %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理提现列表, %v", err)
|
||||||
}
|
}
|
||||||
withdrawal.CreateTime = agentWithdrawalModel.CreateTime.Format("2006-01-02 15:04:05")
|
withdrawal.CreateTime = agentWithdrawalModel.CreateTime.Format("2006-01-02 15:04:05")
|
||||||
|
// 从扣税记录中取扣税比例,供前端展示“扣了几个点”
|
||||||
|
taxModel, taxErr := l.svcCtx.AgentWithdrawalTaxModel.FindOneByWithdrawalId(l.ctx, agentWithdrawalModel.Id)
|
||||||
|
if taxErr == nil {
|
||||||
|
withdrawal.TaxRate = taxModel.TaxRate
|
||||||
|
}
|
||||||
list = append(list, withdrawal)
|
list = append(list, withdrawal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -672,15 +672,20 @@ type AdminGetQueryDetailByOrderIdReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetQueryDetailByOrderIdResp struct {
|
type AdminGetQueryDetailByOrderIdResp struct {
|
||||||
Id int64 `json:"id"` // 主键ID
|
Id int64 `json:"id"` // 主键ID
|
||||||
OrderId int64 `json:"order_id"` // 订单ID
|
OrderId int64 `json:"order_id"` // 订单ID
|
||||||
UserId int64 `json:"user_id"` // 用户ID
|
UserId int64 `json:"user_id"` // 用户ID
|
||||||
ProductName string `json:"product_name"` // 产品ID
|
ProductName string `json:"product_name"` // 产品名称
|
||||||
QueryParams map[string]interface{} `json:"query_params"`
|
OrderNo string `json:"order_no"` // 商户订单号
|
||||||
QueryData []AdminQueryItem `json:"query_data"`
|
PlatformOrderId string `json:"platform_order_id"` // 支付订单号
|
||||||
CreateTime string `json:"create_time"` // 创建时间
|
PaymentStatus string `json:"payment_status"` // 支付状态
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
QueryState string `json:"query_state"` // 查询状态
|
RefundTime string `json:"refund_time"` // 退款时间(有退款时)
|
||||||
|
QueryParams map[string]interface{} `json:"query_params"`
|
||||||
|
QueryData []AdminQueryItem `json:"query_data"`
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
|
QueryState string `json:"query_state"` // 查询状态
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetRefundStatisticsReq struct {
|
type AdminGetRefundStatisticsReq struct {
|
||||||
@@ -809,9 +814,10 @@ type AdminRetryAgentProcessResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminReviewBankCardWithdrawalReq struct {
|
type AdminReviewBankCardWithdrawalReq struct {
|
||||||
WithdrawalId int64 `json:"withdrawal_id"` // 提现记录ID
|
WithdrawalId int64 `json:"withdrawal_id"` // 提现记录ID
|
||||||
Action int64 `json:"action"` // 操作:1-确认,2-拒绝
|
Action int64 `json:"action"` // 操作:1-确认,2-拒绝
|
||||||
Remark string `json:"remark"` // 备注(拒绝时必填)
|
Remark string `json:"remark"` // 备注(拒绝时必填)
|
||||||
|
TaxRate *float64 `json:"tax_rate,optional"` // 扣税比例,如 0.06 表示 6%,不传则默认 6%
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminReviewBankCardWithdrawalResp struct {
|
type AdminReviewBankCardWithdrawalResp struct {
|
||||||
@@ -1302,6 +1308,7 @@ type AgentWithdrawalListItem struct {
|
|||||||
Amount float64 `json:"amount"` // 金额
|
Amount float64 `json:"amount"` // 金额
|
||||||
ActualAmount float64 `json:"actual_amount"` // 实际到账金额(扣税后)
|
ActualAmount float64 `json:"actual_amount"` // 实际到账金额(扣税后)
|
||||||
TaxAmount float64 `json:"tax_amount"` // 扣税金额
|
TaxAmount float64 `json:"tax_amount"` // 扣税金额
|
||||||
|
TaxRate float64 `json:"tax_rate"` // 扣税比例,如 0.06 表示 6%
|
||||||
Status int64 `json:"status"` // 状态
|
Status int64 `json:"status"` // 状态
|
||||||
PayeeAccount string `json:"payee_account"` // 收款账户
|
PayeeAccount string `json:"payee_account"` // 收款账户
|
||||||
Remark string `json:"remark"` // 备注
|
Remark string `json:"remark"` // 备注
|
||||||
@@ -2201,6 +2208,7 @@ type Withdrawal struct {
|
|||||||
Remark string `json:"remark"`
|
Remark string `json:"remark"`
|
||||||
PayeeAccount string `json:"payee_account"`
|
PayeeAccount string `json:"payee_account"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime string `json:"create_time"`
|
||||||
|
TaxRate float64 `json:"tax_rate"` // 扣税比例,如 0.06 表示 6%
|
||||||
}
|
}
|
||||||
|
|
||||||
type WithdrawalReq struct {
|
type WithdrawalReq struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user