You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
339 lines
9.5 KiB
339 lines
9.5 KiB
package handler |
|
|
|
import ( |
|
"fmt" |
|
"server/call" |
|
"server/common" |
|
"server/db" |
|
"server/modules/backend/app" |
|
utils "server/modules/backend/util" |
|
"server/modules/backend/values" |
|
"time" |
|
|
|
"github.com/gin-gonic/gin" |
|
"github.com/liangdas/mqant/log" |
|
) |
|
|
|
func WithdrawList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.WithdrawListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if req.Type <= common.WithdrawOrderTypeZero || req.Type >= common.WithdrawOrderTypeAll { |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
table1 := `(SELECT id,uid,channel_id,pay_channel,orderid,apipayid,payaccount,amount,create_time,callback_time,status,operator from withdraw_order %s)a` |
|
table2 := `(SELECT id,platform,mobile,tag from users %s)b` |
|
table3 := `(SELECT uid,inr from player_currency)c` |
|
table4 := `(SELECT uid,total_recharge,total_recharge_count,total_withdraw,total_withdraw_count FROM recharge_info)d` |
|
|
|
// 表1的查询条件 |
|
table1Condition := fmt.Sprintf(" where event = %v and order_type = %d", common.CurrencyEventWithDraw, req.Type) |
|
if req.Start != nil { |
|
st, _ := utils.GetQueryUnix(*req.Start, "") |
|
table1Condition += fmt.Sprintf(" AND create_time >= %d ", st) |
|
} |
|
if req.End != nil { |
|
_, et := utils.GetQueryUnix("", *req.End) |
|
table1Condition += fmt.Sprintf(" AND create_time < %d ", et) |
|
} |
|
if req.Status != nil { |
|
table1Condition += fmt.Sprintf(" AND status = %d ", *req.Status) |
|
} |
|
if req.Channel != nil { |
|
table1Condition += fmt.Sprintf(" AND channel_id = %d ", *req.Channel) |
|
} |
|
if req.UID != nil { |
|
table1Condition += fmt.Sprintf(" AND uid = %d ", *req.UID) |
|
} |
|
if req.Amount != nil { |
|
table1Condition += fmt.Sprintf(" AND amount = %d ", *req.Amount) |
|
} |
|
if req.OderID != nil { |
|
table1Condition += fmt.Sprintf(" AND orderid = %s ", *req.OderID) |
|
} |
|
if req.APIPayID != nil { |
|
table1Condition += fmt.Sprintf(" AND apipayid = %s ", *req.APIPayID) |
|
} |
|
if req.PayChannel != nil { |
|
table1Condition += fmt.Sprintf(" AND pay_channel = %d ", *req.PayChannel) |
|
} |
|
if req.Operator != nil { |
|
table1Condition += fmt.Sprintf(" AND operator = %s ", *req.Operator) |
|
} |
|
|
|
// 表2的查询条件 |
|
table2Condition := "" |
|
if req.Platform != nil { |
|
table2Condition += fmt.Sprintf(" where platform = %d ", *req.Platform) |
|
} |
|
|
|
sqlCount := " SELECT COUNT(*) AS count from" |
|
sqlList := `SELECT a.id,a.uid,a.channel_id,a.pay_channel,a.orderid as OrderID,a.apipayid as APIPayID,a.payaccount,a.amount,a.create_time,a.callback_time, |
|
a.status,a.operator,b.platform,b.mobile,b.tag,c.inr,d.total_recharge,d.total_recharge_count,d.total_withdraw,d.total_withdraw_count from ` |
|
querySql := fmt.Sprintf(table1, table1Condition) + " inner join " + fmt.Sprintf(table2, table2Condition) + " on a.uid = b.id inner join " + |
|
table3 + " on a.uid = c.uid inner join " + table4 + " on a.uid = d.uid " |
|
|
|
var count int64 |
|
err := db.Mysql().QueryBySql(sqlCount+querySql, &count) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
|
|
switch req.Sort { |
|
case 1: |
|
querySql += " ORDER BY a.create_time DESC " |
|
case 2: |
|
querySql += " ORDER BY a.audit_time DESC " |
|
default: |
|
querySql += " ORDER BY a.create_time DESC " |
|
} |
|
|
|
querySql += fmt.Sprintf(" LIMIT %d, %d", (req.Page-1)*req.Num, req.Num) |
|
|
|
WithdrawOrderArr := []values.WithdrawInfo{} |
|
err = db.Mysql().QueryBySql(sqlList+querySql, &WithdrawOrderArr) |
|
if err != nil { |
|
log.Error("查询体现审核失败, error : %s", err.Error()) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
payList := map[int]string{ |
|
18: "GrePay", |
|
27: "MLPay", |
|
39: "GoPay", |
|
42: "MoonPay", |
|
43: "PayPlus", |
|
44: "LuckinPay", |
|
45: "EaniPay", |
|
} |
|
a.Data = values.WithdrawListResp{List: WithdrawOrderArr, Count: count, PayList: payList} |
|
} |
|
|
|
func WithdrawExamine(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.WithdrawExamineReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if req.Opt < 1 || req.Opt > 3 { |
|
a.Code = values.CodeParam |
|
a.Msg = "非法操作" |
|
return |
|
} |
|
one := new(common.WithdrawOrder) |
|
one.ID = uint(req.ID) |
|
err := db.Mysql().Get(one) |
|
if err != nil || one.UID == 0 { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不存在" |
|
return |
|
} |
|
if one.Event != int(common.CurrencyEventWithDraw) { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不合法" |
|
return |
|
} |
|
if one.Status != common.StatusROrderCreate && one.Status != common.StatusROrderPending { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单已审核,不能重复操作" |
|
return |
|
} |
|
|
|
u := map[string]interface{}{"audit_time": time.Now().Unix(), "operator": a.User.Account} |
|
if len(req.Remark) > 0 { |
|
u["remarks"] = req.Remark |
|
} |
|
if req.PayChannel != 0 { |
|
u["pay_channel"] = req.PayChannel |
|
u["upi"] = req.PayChannel |
|
} |
|
// 审核通过,发起提现,会在pay模块扫描提交 |
|
if req.Opt == 1 { |
|
u["status"] = common.StatusROrderWaitting |
|
} else if req.Opt == 3 { |
|
u["status"] = common.StatusROrderPending |
|
} |
|
if res := db.Mysql().C().Model(&common.WithdrawOrder{}).Where("id = ? and status = ?", req.ID, common.StatusROrderCreate).Updates(u); res.Error != nil || res.RowsAffected == 0 { |
|
log.Error("err:%v", res.Error) |
|
a.Code = values.CodeRetry |
|
a.Msg = "系统错误,审核失败" |
|
return |
|
} |
|
|
|
if req.Opt == 2 { // 拒绝 |
|
err := call.ReturnBackWithdraw(one, common.StatusROrderCreate, common.StatusROrderRefuse) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
} |
|
a.RecordEdit(values.PowerExamineWithdraw, fmt.Sprintf("审核退出订单ID:%v", req.ID)) |
|
} |
|
|
|
// WithdrawReturn 强制取消代付,直接退 |
|
func WithdrawReturn(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.WithdrawReturnReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
one := &common.WithdrawOrder{OrderID: req.OrderID} |
|
err := db.Mysql().Get(one) |
|
if err != nil { |
|
one = &common.WithdrawOrder{APIPayID: req.OrderID} |
|
err := db.Mysql().Get(one) |
|
if err != nil { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不存在" |
|
return |
|
} |
|
} |
|
if one.Event != int(common.CurrencyEventWithDraw) { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不合法" |
|
return |
|
} |
|
if one.Status == common.StatusROrderFinish { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单已完成打款,不能退回" |
|
return |
|
} |
|
|
|
err = call.ReturnBackWithdraw(one, common.StatusROrderPay, common.StatusROrderFail) |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
a.RecordEdit(values.PowerExamineWithdraw, fmt.Sprintf("退回退出订单ID:%v", req.OrderID)) |
|
} |
|
|
|
// PayCallback 后台模拟订单回调 |
|
func PayCallback(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.PayCallbackReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if req.Status != common.StatusROrderPay && req.Status != common.StatusROrderFail { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
one := &common.RechargeOrder{OrderID: req.OrderID} |
|
err := db.Mysql().Get(one) |
|
if err != nil { |
|
one = &common.RechargeOrder{APIPayID: req.OrderID} |
|
err := db.Mysql().Get(one) |
|
if err != nil { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不存在" |
|
return |
|
} |
|
} |
|
if one.Event != int(common.CurrencyEventReCharge) && one.Event != common.CurrencyEventGMRecharge { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单不合法" |
|
return |
|
} |
|
if one.Status == common.StatusROrderPay { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单已完成" |
|
return |
|
} |
|
if req.Status == common.StatusROrderFail && one.Status == common.StatusROrderFail { |
|
a.Code = values.CodeParam |
|
a.Msg = "订单已回调失败" |
|
return |
|
} |
|
status := false |
|
str := "失败" |
|
if req.Status == common.StatusROrderPay { |
|
status = true |
|
str = "成功" |
|
} |
|
err = call.RechargeCallback(one, status, "", "") |
|
if err != nil { |
|
log.Error(err.Error()) |
|
} |
|
a.RecordEdit(values.PowerExamineWithdraw, fmt.Sprintf("修改充值订单ID:%v,回调状态:%s", req.OrderID, str)) |
|
} |
|
|
|
func ShareOrderList(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.ShareOrderListReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
su, eu := utils.GetQueryUnix(req.Start, req.End) |
|
sql := fmt.Sprintf("create_time>=%d and create_time<%d", su, eu) |
|
if req.Channel > 0 { |
|
sql += fmt.Sprintf(" and channel_id = %d", req.Channel) |
|
} |
|
if req.Status != nil { |
|
sql += fmt.Sprintf(" and status = %d", *req.Status) |
|
} |
|
|
|
resp := new(values.ShareOrderListResp) |
|
a.Data = resp |
|
db.Mysql().QueryListW(int(req.Page)-1, int(req.Num), "create_time desc", &common.ShareOrder{}, &resp.List, sql) |
|
} |
|
|
|
func ShareOrderExamine(c *gin.Context) { |
|
a := app.NewApp(c) |
|
defer func() { |
|
a.Response() |
|
}() |
|
req := new(values.ShareOrderExamineReq) |
|
if !a.S(req) { |
|
return |
|
} |
|
if req.Opt != 1 && req.Opt != 2 { |
|
a.Code = values.CodeParam |
|
a.Msg = "非法操作" |
|
return |
|
} |
|
order := &common.ShareOrder{OrderID: req.OrderID} |
|
db.Mysql().Get(order) |
|
if order.Status >= common.StatusROrderFinish { |
|
a.Code = values.CodeParam |
|
return |
|
} |
|
if req.Opt == 1 { |
|
res, err := db.Mysql().UpdateResW(&common.ShareOrder{}, map[string]interface{}{"status": common.StatusROrderFinish}, fmt.Sprintf("orderid = '%s' and status = %d", req.OrderID, common.StatusROrderCreate)) |
|
if err != nil || res == 0 { |
|
log.Error("err:%v", err) |
|
a.Code = values.CodeRetry |
|
return |
|
} |
|
call.UpdateCurrencyPro(&common.UpdateCurrency{ |
|
CurrencyBalance: &common.CurrencyBalance{ |
|
UID: order.UID, |
|
Value: order.Amount, |
|
Event: common.CurrencyEventShareWithdraw, |
|
Type: common.CurrencyINR, |
|
}, |
|
}) |
|
} else if req.Opt == 2 { // 拒绝 |
|
db.Mysql().UpdateResW(&common.ShareOrder{}, map[string]interface{}{"status": common.StatusROrderFail}, fmt.Sprintf("orderid = '%s' and status = %d", req.OrderID, common.StatusROrderCreate)) |
|
} |
|
a.RecordEdit(values.PowerExamineWithdraw, fmt.Sprintf("审核分享订单ID:%v,opt:%v", req.OrderID, req.Opt)) |
|
}
|
|
|