@@ -182,7 +182,7 @@ func WithdrawApply(c *gin.Context) { | |||||
e.OutErr(c, e.ERR, "支付宝用户信息未授权") | e.OutErr(c, e.ERR, "支付宝用户信息未授权") | ||||
return | return | ||||
} | } | ||||
if aliInfo.OpenId != "" { | |||||
if aliInfo.OpenId == "" { | |||||
e.OutErr(c, e.ERR, "支付宝用户授权信息有误") | e.OutErr(c, e.ERR, "支付宝用户授权信息有误") | ||||
return | return | ||||
} | } | ||||
@@ -367,7 +367,7 @@ func GetWithdrawCondition(c *gin.Context) { | |||||
//1. 判断是否为第一次提现 | //1. 判断是否为第一次提现 | ||||
isFirst := false | isFirst := false | ||||
has, err := db.Db.Where("uid = ?", user.Id).Get(model.FinWithdrawApply{}) | |||||
has, err := db.Db.Where("uid = ?", user.Id).Get(&model.FinWithdrawApply{}) | |||||
if !has { //第一次提现 | if !has { //第一次提现 | ||||
isFirst = true | isFirst = true | ||||
} | } | ||||
@@ -32,12 +32,15 @@ type WithdrawApplyReq struct { | |||||
} | } | ||||
type GetWithdrawConditionResp struct { | type GetWithdrawConditionResp struct { | ||||
IsNeedRealName bool `json:"is_need_real_name"` // 是否需要实名 | |||||
IsRealName bool `json:"is_real_name"` // 是否实名 | |||||
IsBindAlipay bool `json:"is_bind_alipay"` // 是否绑定阿里账户 | |||||
IsBindWx bool `json:"is_bind_wx"` // 是否绑定微信账户 | |||||
IsCanWithdraw bool `json:"is_can_withdraw"` // 是否能提现 | |||||
NotWithdrawReason string `json:"not_withdraw_reason"` // 不能提现原因 | |||||
IsFirst bool `json:"is_first"` // 是否第一次提现 | |||||
FirstNeedRealName bool `json:"first_need_real_name"` // 第一次提现是否需要实名 | |||||
FirstWithdrawAmountLimit string `json:"first_withdraw_amount_limit"` // 第一次提现金额限制 | |||||
IsNeedRealName bool `json:"is_need_real_name"` // 是否需要实名 | |||||
IsRealName bool `json:"is_real_name"` // 是否实名 | |||||
IsBindAlipay bool `json:"is_bind_alipay"` // 是否绑定阿里账户 | |||||
IsBindWx bool `json:"is_bind_wx"` // 是否绑定微信账户 | |||||
IsCanWithdraw bool `json:"is_can_withdraw"` // 是否能提现 | |||||
NotWithdrawReason string `json:"not_withdraw_reason"` // 不能提现原因 | |||||
} | } | ||||
type BindAlipayAccountReq struct { | type BindAlipayAccountReq struct { | ||||
@@ -244,15 +244,68 @@ func GetWithdrawCondition(user *model.User, setting *model.FinWithdrawSetting, i | |||||
} | } | ||||
} | } | ||||
// 5. 首次提现判断 | |||||
//5、验证“提现频率” | |||||
var frequency md.WithdrawFrequencySettingStruct | |||||
utils.Unserialize([]byte(setting.FrequencySet), &frequency) | |||||
if frequency.Duration == 2 { | |||||
day := now.Weekday() | |||||
if !utils.InArr(utils.IntToStr(int(day)), frequency.Num) { | |||||
resp.IsCanWithdraw = false | |||||
resp.NotWithdrawReason = "非可提现日期" | |||||
} | |||||
} | |||||
if frequency.Duration == 3 { | |||||
day := now.Day() | |||||
if !utils.InArr(utils.IntToStr(day), frequency.Num) { | |||||
resp.IsCanWithdraw = false | |||||
resp.NotWithdrawReason = "非可提现日期" | |||||
} | |||||
} | |||||
if setting.WithdrawNumsLimit > 0 { | |||||
var withdrawNums int64 | |||||
var startOfDay, endOfDay time.Time | |||||
if frequency.Duration == 1 { //按天 | |||||
startOfDay = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) | |||||
endOfDay = startOfDay.Add(24 * time.Hour) | |||||
} | |||||
if frequency.Duration == 2 { //按周 | |||||
startOfDay = utils.GetStartOfWeek(now) | |||||
endOfDay = startOfDay.Add(7 * 24 * time.Hour) | |||||
} | |||||
if frequency.Duration == 3 { //按月 | |||||
startOfDay = utils.GetFirstDateOfMonth(now) | |||||
endOfDay = utils.GetLastDateOfMonth(now) | |||||
} | |||||
withdrawNums, err := db.Db.Where("create_at >= ?", startOfDay.Format("2006-01-02 15:04:05")). | |||||
And("create_at < ?", endOfDay.Format("2006-01-02 15:04:05")). | |||||
And("uid =?", user.Id). | |||||
And("state != 3"). //失败不计入 | |||||
Count(&model.FinWithdrawApply{}) | |||||
if err != nil { | |||||
resp.IsCanWithdraw = false | |||||
resp.NotWithdrawReason = err.Error() | |||||
} | |||||
if int(withdrawNums) >= setting.WithdrawNumsLimit { | |||||
resp.IsCanWithdraw = false | |||||
resp.NotWithdrawReason = "当前已无可提现次数" | |||||
} | |||||
} | |||||
// 6. 首次提现判断 | |||||
if isFirst { | if isFirst { | ||||
resp.IsFirst = true | |||||
var firstWithdrawSet md.FirstWithdrawSet | var firstWithdrawSet md.FirstWithdrawSet | ||||
utils.Unserialize([]byte(setting.FirstWithdrawSet), &firstWithdrawSet) | utils.Unserialize([]byte(setting.FirstWithdrawSet), &firstWithdrawSet) | ||||
if firstWithdrawSet.IsNeedRealName == 0 { | |||||
resp.IsNeedRealName = false | |||||
resp.IsCanWithdraw = true | |||||
resp.NotWithdrawReason = "" | |||||
} | |||||
resp.FirstNeedRealName = func(firstWithdrawSetIsNeedRealName int) bool { | |||||
if firstWithdrawSet.IsNeedRealName == 1 { | |||||
return true | |||||
} | |||||
return false | |||||
}(firstWithdrawSet.IsNeedRealName) | |||||
resp.NotWithdrawReason = "" | |||||
resp.FirstWithdrawAmountLimit = firstWithdrawSet.FirstWithdrawAmountLimit | |||||
resp.IsCanWithdraw = true | |||||
} | } | ||||
return resp | return resp | ||||
@@ -9,22 +9,60 @@ srv_addr: ':4000' | |||||
redis_addr: '127.0.0.1:6379' | redis_addr: '127.0.0.1:6379' | ||||
redis_password: '' | redis_password: '' | ||||
#db: | |||||
# host: '119.23.182.117:3306' | |||||
# name: 'egg' | |||||
# user: 'root' | |||||
# psw: 'Fnuo123com@' | |||||
# show_log: true | |||||
# max_lifetime: 30 | |||||
# max_open_conns: 100 | |||||
# max_idle_conns: 100 | |||||
# path: 'tmp/%s.log' | |||||
db: | db: | ||||
host: '119.23.182.117:3306' | |||||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||||
name: 'egg' | name: 'egg' | ||||
user: 'root' | |||||
psw: 'Fnuo123com@' | |||||
user: 'canal' | |||||
psw: 'DengBiao@1997' | |||||
show_log: true | show_log: true | ||||
max_lifetime: 30 | max_lifetime: 30 | ||||
max_open_conns: 100 | max_open_conns: 100 | ||||
max_idle_conns: 100 | max_idle_conns: 100 | ||||
path: 'tmp/%s.log' | path: 'tmp/%s.log' | ||||
#db_back: | |||||
# host: '119.23.182.117:3306' | |||||
# name: 'egg-data-back-up' | |||||
# user: 'root' | |||||
# psw: 'Fnuo123com@' | |||||
# show_log: true | |||||
# path: 'tmp/%s.log' | |||||
db_back: | |||||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||||
name: 'egg-data-back-up' | |||||
user: 'canal' | |||||
psw: 'DengBiao@1997' | |||||
show_log: true | |||||
path: 'tmp/%s.log' | |||||
#im_db: | |||||
# host: '119.23.182.117:3306' | |||||
# name: 'egg-im' | |||||
# user: 'root' | |||||
# psw: 'Fnuo123com@' | |||||
# show_log: true | |||||
# max_lifetime: 30 | |||||
# max_open_conns: 100 | |||||
# max_idle_conns: 100 | |||||
# path: 'tmp/%s.log' | |||||
im_db: | im_db: | ||||
host: '119.23.182.117:3306' | |||||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||||
name: 'egg-im' | name: 'egg-im' | ||||
user: 'root' | |||||
psw: 'Fnuo123com@' | |||||
user: 'canal' | |||||
psw: 'DengBiao@1997' | |||||
show_log: true | show_log: true | ||||
max_lifetime: 30 | max_lifetime: 30 | ||||
max_open_conns: 100 | max_open_conns: 100 | ||||