@@ -0,0 +1,58 @@
|
||||
package withdrawctrl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"91porn-server/app/service/withdrawser"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/rchgutil"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GoldFishCallBack 金鱼结构回调函数
|
||||
func GoldFishCallBack(ctx *gin.Context) {
|
||||
if err := func() error {
|
||||
exchg := rchgutil.GoldFishExchangeRes{}
|
||||
if err := ctx.ShouldBindJSON(&exchg); err != nil {
|
||||
log.Error(fmt.Sprintf("GoldFish callback parameter bind fail error:%+v:", err))
|
||||
return err
|
||||
}
|
||||
e := rchgutil.GoldFishExchange{}
|
||||
log.Info(fmt.Sprintf("GoldFish callback parameter data:%+v:", exchg))
|
||||
buf := bytes.Buffer{}
|
||||
buf.WriteString(strconv.Itoa(exchg.Code))
|
||||
buf.WriteString(exchg.Mark)
|
||||
buf.WriteString(exchg.MercID)
|
||||
buf.WriteString(exchg.Money)
|
||||
buf.WriteString(exchg.OID)
|
||||
buf.WriteString(exchg.Status)
|
||||
buf.WriteString(exchg.TradeNo)
|
||||
buf.WriteString(e.GetAppSecret())
|
||||
if !rchgutil.VerifySign(exchg.Sign, buf.String()) {
|
||||
log.Error("GoldFish callback sign verify fail")
|
||||
return errors.New("check sign fail")
|
||||
}
|
||||
moneyf, err := strconv.ParseFloat(exchg.Money, 64)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("GoldFish callback ParseFloat fail error:%+v:", err))
|
||||
return err
|
||||
}
|
||||
moneyf = moneyf * 100
|
||||
money := int64(moneyf)
|
||||
exchg.TradeNo = rchgutil.EChgIDDisassemble(exchg.TradeNo)
|
||||
if err = withdrawser.ExchgCallBack(exchg.TradeNo, exchg.OID, money, exchg.Status, exchg.Mark); err != nil {
|
||||
log.Error(fmt.Sprintf("GoldFish RechargeCallBack fail error:%+v:", err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}(); err != nil {
|
||||
ctx.String(http.StatusBadRequest, "fail")
|
||||
return
|
||||
}
|
||||
ctx.String(http.StatusOK, "success")
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package withdrawctrl
|
||||
|
||||
import (
|
||||
"91porn-server/app/service/withdrawser"
|
||||
"91porn-server/common"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/stderr"
|
||||
"91porn-server/models/commod"
|
||||
"91porn-server/models/v/txnactmod"
|
||||
"91porn-server/models/v/usermod"
|
||||
"91porn-server/models/v/wdordmod"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Withdraw doc
|
||||
// @Summary 提现
|
||||
// @Description 提现
|
||||
// @Tags 钱包
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param money formData int true "提现金额"
|
||||
// @Param payType formData string true "提现方式(alipay,bankcard)"
|
||||
// @Param withdrawType formData int true "提现类型(0代理提现/1金币提现)"
|
||||
// @Param actName formData string true "交易账户持有人"
|
||||
// @Param act formData string true "交易账户"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /withdraw [post]
|
||||
func Withdraw(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNoToken, err.Error())
|
||||
return
|
||||
}
|
||||
p := wdordmod.WithdrawReq{}
|
||||
if err = ctx.ShouldBind(&p); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
//类型校验
|
||||
if p.PayType != wdordmod.TypeBankCard && p.PayType != wdordmod.TypeAlipay && p.PayType != wdordmod.TypeUsdt {
|
||||
common.ServeJSON(ctx, stderr.ExchangeCodeInvalid, err.Error())
|
||||
return
|
||||
}
|
||||
w := wdordmod.WithdrawOrder{
|
||||
UID: uid,
|
||||
UserIP: common.GetIP(ctx),
|
||||
Money: p.Money,
|
||||
PayType: p.PayType,
|
||||
ActName: p.ActName,
|
||||
Act: p.Act,
|
||||
ProductType: p.ProductType,
|
||||
}
|
||||
if p.PayType == wdordmod.TypeBankCard {
|
||||
user, err := usermod.FindUserByUID(uid)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNetWorkBusy, err)
|
||||
return
|
||||
}
|
||||
if user.BankActName != "" && user.BankActName != p.ActName {
|
||||
common.ServeJSON(ctx, stderr.DifferentBankActName, err)
|
||||
return
|
||||
}
|
||||
typeAct := txnactmod.Bank
|
||||
act, err := txnactmod.FindOne(txnactmod.Query{
|
||||
Act: &(p.Act),
|
||||
AType: &typeAct,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("txnactmod.FindOne", log.Any("req", p), log.E(err))
|
||||
common.ServeJSON(ctx, stderr.ErrNetWorkBusy, err)
|
||||
return
|
||||
}
|
||||
if act.ID.IsZero() {
|
||||
log.Warn("zero act id", log.Any("req", p), log.Any("act", act))
|
||||
common.ServeJSON(ctx, stderr.ErrNetWorkBusy, "")
|
||||
return
|
||||
}
|
||||
w.BankCode = act.BankCode
|
||||
}
|
||||
if p.Name != nil {
|
||||
w.Name = *p.Name
|
||||
}
|
||||
if p.DevID != nil {
|
||||
w.DevID = *p.DevID
|
||||
}
|
||||
if p.WithdrawType != nil {
|
||||
w.WithdrawType = *p.WithdrawType
|
||||
} else {
|
||||
w.WithdrawType = 1
|
||||
}
|
||||
if err = withdrawser.WithDraw(&w); err != nil {
|
||||
switch err.Error() {
|
||||
case "Insufficient balance":
|
||||
log.Error("WithDraw Insufficient balance", log.Any("error==>", err.Error()))
|
||||
common.ServeJSON(ctx, stderr.InsufficientBalance, err.Error())
|
||||
return
|
||||
case "PayType Insufficient balance":
|
||||
log.Error("WithDraw PayType Insufficient balance", log.Any("error==>", err.Error()))
|
||||
common.ServeJSON(ctx, stderr.InsufficientBalance, err.Error())
|
||||
return
|
||||
case "illegal withdraw amount":
|
||||
log.Error("Withdraw illegal withdraw amount", log.Any("order", w), log.E(err))
|
||||
common.ServeJSON(ctx, stderr.WithDrawIllegalAmount, err.Error())
|
||||
return
|
||||
default:
|
||||
common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, nil)
|
||||
}
|
||||
|
||||
// WithdrawOrder doc
|
||||
// @Summary 查看提现订单
|
||||
// @Description 查看提现订单
|
||||
// @Tags 钱包
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param pageNumber formData int true "页码"
|
||||
// @Param pageSize formData int true "条数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /withdraw/order [get]
|
||||
func WithdrawOrder(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNoToken, err.Error())
|
||||
return
|
||||
}
|
||||
var arg struct {
|
||||
commod.Page
|
||||
}
|
||||
if err = ctx.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
total, data, hasNext, err := wdordmod.FindOrdersByUID(uid, arg.PageNumber, arg.PageSize)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, map[string]interface{}{
|
||||
"total": total,
|
||||
"result": data,
|
||||
"list": data,
|
||||
"hasNext": hasNext,
|
||||
})
|
||||
}
|
||||
|
||||
// GetType doc
|
||||
// @Summary 提现方式获取
|
||||
// @Description
|
||||
// @Tags 钱包
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Param payType formData string true "提现方式(银行卡/支付宝)"
|
||||
// @Param pageSize formData int true "条数"
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /app/withdraw/type [get]
|
||||
func GetType(ctx *gin.Context) {
|
||||
uid, err := common.GetUID(ctx)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrNoToken, err.Error())
|
||||
return
|
||||
}
|
||||
var arg struct {
|
||||
Type string `json:"payType" form:"payType"`
|
||||
}
|
||||
if err := ctx.ShouldBind(&arg); err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
u, err := usermod.FindUserByUID(uid)
|
||||
if err != nil || u == nil {
|
||||
common.ServeJSON(ctx, stderr.ErrParamError, err.Error())
|
||||
return
|
||||
}
|
||||
data, err := withdrawser.WithdrawType(u.SnapVip, arg.Type)
|
||||
if err != nil {
|
||||
common.ServeJSON(ctx, stderr.ErrServerUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
common.ServeJSON(ctx, stderr.Success, data)
|
||||
}
|
||||
|
||||
// GetWithdrawCfg doc
|
||||
// @Summary 提现配置获取
|
||||
// @Description
|
||||
// @Tags 钱包
|
||||
// @Accept mpfd,json
|
||||
// @Produce json,html
|
||||
// @Success 200 {string} json "{"msg": "操作成功"}"
|
||||
// @Failure 400 {string} json "{"msg": "操作失败"}"
|
||||
// @Router /withdraw/cfg [get]
|
||||
func GetWithdrawCfg(ctx *gin.Context) {
|
||||
data := withdrawser.GetWithdrawCfg()
|
||||
common.ServeJSON(ctx, stderr.Success, data)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package withdrawctrl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"91porn-server/app/service/withdrawser"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/rchgutil"
|
||||
"91porn-server/common/stderr"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// YinseCallBack
|
||||
func YinseCallBack(ctx *gin.Context) {
|
||||
name := ctx.Param("name")
|
||||
if name == "goldfish" {
|
||||
GoldFishCallBack(ctx)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, func() (msg rchgutil.ExchgBackMsg) {
|
||||
exchg := rchgutil.ExchgBack{}
|
||||
msg.Code = int(stderr.Failure)
|
||||
if err := ctx.ShouldBindJSON(&exchg); err != nil {
|
||||
msg.Err = fmt.Sprintf("GoldFish callback parameter bind fail error:%+v:", err)
|
||||
log.Error(msg.Err)
|
||||
return
|
||||
}
|
||||
log.Info(fmt.Sprintf("GoldFish callback parameter data:%+v:", exchg))
|
||||
exchg.TradeNo = rchgutil.EChgIDDisassemble(exchg.TradeNo)
|
||||
if err := withdrawser.ExchgCallBack(exchg.TradeNo, exchg.OID, exchg.Money, exchg.Status, exchg.Mark); err != nil {
|
||||
msg.Err = fmt.Sprintf("GoldFish RechargeCallBack fail error:%+v:", err)
|
||||
log.Error(msg.Err)
|
||||
return
|
||||
}
|
||||
msg.Code = int(stderr.Success)
|
||||
return
|
||||
}())
|
||||
}
|
||||
Reference in New Issue
Block a user