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) }