From d20d77c8eca99575478d0e360ab64524ef4672ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 20 Oct 2020 14:19:18 +0800 Subject: [PATCH] cash limit --- business/jxstore/cms/order.go | 10 +++++++++ business/jxstore/financial/financial.go | 11 ++++++++- business/jxstore/financial/pay.go | 4 ++-- business/model/bill.go | 3 +++ business/model/dao/dao_bill.go | 30 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/order.go b/business/jxstore/cms/order.go index a00ca9593..29a594c2c 100644 --- a/business/jxstore/cms/order.go +++ b/business/jxstore/cms/order.go @@ -1,6 +1,8 @@ package cms import ( + "fmt" + "git.rosy.net.cn/jx-callback/business/jxstore/financial" "git.rosy.net.cn/jx-callback/business/jxutils" @@ -82,6 +84,14 @@ func Cash(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (e if userBill.AccountBalance < order.PayPrice { return model.ErrCodeAccountBalanceNotEnough, err } + //用户一天只能提现一次 + billExpends, err := dao.GetBillExpend(db, order.UserID, model.BillTypeCash, DayTimeBegin, DayTimeEnd) + if err != nil { + return errCode, err + } + if len(billExpends) > 0 { + return errCode, fmt.Errorf("抱歉,一天只能提现一次!") + } err = payHandler.CreateRefund() return errCode, err } diff --git a/business/jxstore/financial/financial.go b/business/jxstore/financial/financial.go index 4456ae121..b1f57b459 100644 --- a/business/jxstore/financial/financial.go +++ b/business/jxstore/financial/financial.go @@ -18,6 +18,10 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) +const ( + CashPercentage = 90 +) + func (p *PayHandler) CreatePay() (err error) { switch p.PayType { case model.PayTypeTL: @@ -75,10 +79,15 @@ func (p *PayHandler) CreateRefund() (err error) { param := &wxpayapi.TransfersParam{ PartnerTradeNo: utils.Int64ToStr(p.Order.OrderID), CheckName: wxpayapi.CheckName, - Amount: p.Order.PayPrice, Desc: "冲天猴儿app提现到账", SpbillCreateIP: p.Ctx.GetRealRemoteIP(), } + //1元以下免费,以上收取10%手续费 + if p.Order.PayPrice < 100 { + param.Amount = p.Order.PayPrice + } else { + param.Amount = p.Order.PayPrice * CashPercentage / 100 //手续费10% + } if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeWxApp { param.OpenID = authInfo.GetAuthID() } diff --git a/business/jxstore/financial/pay.go b/business/jxstore/financial/pay.go index 729f0c904..69da0f50c 100644 --- a/business/jxstore/financial/pay.go +++ b/business/jxstore/financial/pay.go @@ -47,7 +47,7 @@ func OnPayFinished(order *model.Order) (err error) { case model.OrderTypeAccount: //如果是账户充值(发布任务等) //1、账户收入表明细 - if err = AddBillIncome(db, billID, order.Type, order.PayPrice); err != nil { + if err = AddBillIncome(db, billID, model.BillTypeInvest, order.PayPrice); err != nil { dao.Rollback(db) } //2、账户表账户余额增加相应值 @@ -88,7 +88,7 @@ func OnCashFinished(order *model.Order) (err error) { case model.OrderTypeAccount: //如果是账户提现 //1、账户支出明细增加一条 - if err = AddBillExpend(db, billID, order.Type, order.PayPrice); err != nil { + if err = AddBillExpend(db, billID, model.BillTypeCash, order.PayPrice); err != nil { dao.Rollback(db) } //2、账户表账户余额减少相应值 diff --git a/business/model/bill.go b/business/model/bill.go index 00e996d3f..858bda12d 100644 --- a/business/model/bill.go +++ b/business/model/bill.go @@ -6,6 +6,9 @@ const ( BillTypeMember = 3 //开通会员 BillTypeJobCancelOverdue = 4 //任务过期或取消 BillTypeJobAuditUnPassWithCancelOverdue = 5 //任务不通过时,任务已取消或过期 + + BillTypeCash = 9 //提现 + BillTypeInvest = 8 //充值 ) //账单收入表 diff --git a/business/model/dao/dao_bill.go b/business/model/dao/dao_bill.go index 10194b4af..7798f1bea 100644 --- a/business/model/dao/dao_bill.go +++ b/business/model/dao/dao_bill.go @@ -1,6 +1,8 @@ package dao import ( + "time" + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" ) @@ -21,3 +23,31 @@ func GetUserBill(db *DaoDB, userID, billID string) (userBill *model.UserBill, er err = GetRow(db, &userBill, sql, sqlParams) return userBill, err } + +func GetBillExpend(db *DaoDB, userID string, billType int, fromTime, toTime time.Time) (billExpends []*model.BillExpend, err error) { + sql := ` + SELECT b.* + FROM user_bill a + JOIN bill_expend b ON b.bill_id = a.bill_id + WHERE a.deleted_at = ? + ` + sqlParams := []interface{}{utils.DefaultTimeValue} + if userID != "" { + sql += ` AND a.user_id = ?` + sqlParams = append(sqlParams, userID) + } + if billType != 0 { + sql += ` AND b.type = ?` + sqlParams = append(sqlParams, billType) + } + if fromTime != utils.ZeroTimeValue { + sql += ` AND b.created_at >= ?` + sqlParams = append(sqlParams, fromTime) + } + if toTime != utils.ZeroTimeValue { + sql += ` AND b.created_at <= ?` + sqlParams = append(sqlParams, toTime) + } + err = GetRow(db, &billExpends, sql, sqlParams) + return billExpends, err +}