添加用户提现操作
This commit is contained in:
@@ -3,13 +3,11 @@ package q_bida
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/alipayapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -48,7 +46,7 @@ func AddUserWithdrawal(ctx *jxcontext.Context, param *model.AddWithdrawalRecordR
|
||||
DistrictCode: param.DistrictCode,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(payOrder, ctx.GetUserName())
|
||||
payOrder.OrderID = fmt.Sprintf("%d", time.Now().Unix()) + ctx.GetUserID()[:8]
|
||||
payOrder.OrderID = fmt.Sprintf("%d", time.Now().Unix()) + ctx.GetUserID()[:4] + RandomString(4)
|
||||
|
||||
// 核算手续费
|
||||
if param.WithdrawalMoney < 100 {
|
||||
@@ -60,21 +58,14 @@ func AddUserWithdrawal(ctx *jxcontext.Context, param *model.AddWithdrawalRecordR
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
var aliResult *alipayapi.Withdrawal4AliPayRes
|
||||
if payOrder.WithdrawalMoney <= alipayapi.MinWithdrawalMoney {
|
||||
aliResult, err = api.AliPayAPI.Withdrawal4AliPay(&alipayapi.WithdrawalParam{
|
||||
OutBizNo: payOrder.OrderID,
|
||||
TransAmount: utils.Int2Float64(payOrder.PayMoney),
|
||||
OrderTitle: "京西生活提现成功",
|
||||
PayeeInfo: &alipayapi.PayeeInfoParam{
|
||||
Identity: param.AlipayAccount,
|
||||
Name: param.AlipayName,
|
||||
},
|
||||
Remark: payOrder.Remark,
|
||||
})
|
||||
if err := SendPayInfo2Ali(payOrder, param); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := UpdateUserMoney(payOrder, userBill); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return dao.CreateEntity(dao.GetDB(), payOrder)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteOrder 删除申请订单
|
||||
@@ -122,27 +113,8 @@ func GetOrderListByStatus(userId string, status, pageSize, pageNum int) (map[str
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type OrderListParam struct {
|
||||
PageSize int `json:"pageSize"`
|
||||
PageNum int `json:"pageNum"`
|
||||
UserId string `json:"userId"`
|
||||
UserName string `json:"userName"`
|
||||
OrderId string `json:"orderId"`
|
||||
Phone string `json:"phone"`
|
||||
OrderStatus int `json:"orderStatus"`
|
||||
StartTime string `json:"startTime"`
|
||||
EndTime string `json:"endTime"`
|
||||
}
|
||||
|
||||
type WithdrawalListRes struct {
|
||||
model.WithdrawalRecord
|
||||
Name string `json:"name"`
|
||||
Mobile string `json:"mobile"`
|
||||
AccountBalance int `json:"accountBalance"`
|
||||
}
|
||||
|
||||
// GetUserWithdrawalList 管理系统获取提现申请列表
|
||||
func GetUserWithdrawalList(param *OrderListParam) ([]*WithdrawalListRes, int, error) {
|
||||
func GetUserWithdrawalList(param *model.OrderListParam) ([]*model.WithdrawalListRes, int, error) {
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS w.* ,u.name,u.mobile,b.account_balance
|
||||
FROM withdrawal_record w
|
||||
@@ -152,7 +124,7 @@ func GetUserWithdrawalList(param *OrderListParam) ([]*WithdrawalListRes, int, er
|
||||
`
|
||||
sqlParam := make([]interface{}, 0, 0)
|
||||
sqlParam = append(sqlParam, utils.DefaultTimeValue)
|
||||
result := make([]*WithdrawalListRes, 0, 0)
|
||||
result := make([]*model.WithdrawalListRes, 0, 0)
|
||||
db := dao.GetDB()
|
||||
tx, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
@@ -202,3 +174,61 @@ func GetUserWithdrawalList(param *OrderListParam) ([]*WithdrawalListRes, int, er
|
||||
}
|
||||
return result, dao.GetLastTotalRowCountTx(tx), nil
|
||||
}
|
||||
|
||||
// ManagerExamineWithdrawal 管理员审核提现
|
||||
func ManagerExamineWithdrawal(userId, orderId string, examineStatus int, phone, remark string) error {
|
||||
// 审核不通过
|
||||
if examineStatus != model.YES && remark == "" {
|
||||
return errors.New("拒绝申请原因未填写")
|
||||
}
|
||||
|
||||
// 获取当前用户提现订单
|
||||
var order *model.WithdrawalRecord
|
||||
if err := dao.GetRow(dao.GetDB(), &order, `SELECT * FROM withdrawal_record WHERE user_id = ? and order_id = ?`, []interface{}{userId, orderId}...); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 审核不通过
|
||||
if examineStatus != model.YES {
|
||||
order.OrderStatus = model.WithdrawalRecordFail
|
||||
order.Remark = remark
|
||||
order.LastOperator = phone
|
||||
order.UpdatedAt = time.Now()
|
||||
_, err := dao.UpdateEntity(dao.GetDB(), &order, "OrderStatus", "Remark", "LastOperator", "UpdatedAt")
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取当前用户钱包余额
|
||||
userBill, err := dao.GetUserBill(dao.GetDB(), userId, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if userBill.AccountBalance < order.WithdrawalMoney {
|
||||
order.OrderStatus = model.WithdrawalRecordFail
|
||||
order.Remark = "当前用户余额,小于提现金额。请重新发起支付"
|
||||
order.LastOperator = phone
|
||||
order.UpdatedAt = time.Now()
|
||||
_, err := dao.UpdateEntity(dao.GetDB(), &order, "OrderStatus", "Remark", "LastOperator", "UpdatedAt")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return errors.New("账户余额小于可支付余额,请重新申请")
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
if err := SendPayInfo2Ali(order, &model.AddWithdrawalRecordReq{
|
||||
WithdrawalMoney: order.PayMoney,
|
||||
AlipayAccount: order.AlipayAccount,
|
||||
AlipayName: order.AlipayName,
|
||||
Lng: order.Lng,
|
||||
Lat: order.Lat,
|
||||
CityCode: order.CityCode,
|
||||
DistrictCode: order.DistrictCode,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := UpdateUserMoney(order, userBill); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user