cash limit

This commit is contained in:
苏尹岚
2020-10-20 14:19:18 +08:00
parent 150ec0701c
commit d20d77c8ec
5 changed files with 55 additions and 3 deletions

View File

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

View File

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

View File

@@ -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、账户表账户余额减少相应值

View File

@@ -6,6 +6,9 @@ const (
BillTypeMember = 3 //开通会员
BillTypeJobCancelOverdue = 4 //任务过期或取消
BillTypeJobAuditUnPassWithCancelOverdue = 5 //任务不通过时,任务已取消或过期
BillTypeCash = 9 //提现
BillTypeInvest = 8 //充值
)
//账单收入表

View File

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