|
|
@@ -181,42 +181,107 @@ func GetWithdrawCondition(user *model.User, setting *model.FinWithdrawSetting, i |
|
|
|
IsBindAlipay: false, |
|
|
|
IsBindWx: false, |
|
|
|
} |
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
// 1.判断是否需要实名 |
|
|
|
switch setting.IsRealName { |
|
|
|
case 0: |
|
|
|
resp.IsNeedRealName = false |
|
|
|
case 1: |
|
|
|
resp.IsNeedRealName = true |
|
|
|
default: |
|
|
|
resp.IsNeedRealName = true |
|
|
|
} |
|
|
|
// 1. 首次提现判断 |
|
|
|
if isFirst { |
|
|
|
resp.IsFirst = true |
|
|
|
resp.IsCanWithdraw = true |
|
|
|
resp.NotWithdrawReason = "" |
|
|
|
|
|
|
|
var firstWithdrawSet md.FirstWithdrawSet |
|
|
|
utils.Unserialize([]byte(setting.FirstWithdrawSet), &firstWithdrawSet) |
|
|
|
|
|
|
|
// 2.判断是否实名 |
|
|
|
switch user.IsRealName { |
|
|
|
case 0: |
|
|
|
resp.IsRealName = false |
|
|
|
if resp.IsNeedRealName { |
|
|
|
// 2.1 需要实名但未实名 |
|
|
|
resp.FirstNeedRealName = func(firstWithdrawSetIsNeedRealName int) bool { |
|
|
|
if firstWithdrawSet.IsNeedRealName == 1 { |
|
|
|
return true |
|
|
|
} |
|
|
|
return false |
|
|
|
}(firstWithdrawSet.IsNeedRealName) |
|
|
|
resp.FirstWithdrawAmountLimit = firstWithdrawSet.FirstWithdrawAmountLimit |
|
|
|
} else { |
|
|
|
// 2.判断是否需要实名 |
|
|
|
switch setting.IsRealName { |
|
|
|
case 0: |
|
|
|
resp.IsNeedRealName = false |
|
|
|
case 1: |
|
|
|
resp.IsNeedRealName = true |
|
|
|
default: |
|
|
|
resp.IsNeedRealName = true |
|
|
|
} |
|
|
|
|
|
|
|
// 3.判断是否实名 |
|
|
|
switch user.IsRealName { |
|
|
|
case 0: |
|
|
|
resp.IsRealName = false |
|
|
|
if resp.IsNeedRealName { |
|
|
|
// 2.1 需要实名但未实名 |
|
|
|
resp.IsCanWithdraw = false |
|
|
|
resp.NotWithdrawReason = enum.FinWithdrawApplyWithdrawConditionDissatisfyKind. |
|
|
|
String(enum.FinWithdrawApplyWithdrawConditionDissatisfyKindNotRealName) |
|
|
|
} |
|
|
|
case 1: |
|
|
|
resp.IsRealName = true |
|
|
|
default: |
|
|
|
resp.IsRealName = false |
|
|
|
} |
|
|
|
|
|
|
|
// 4. 验证会员等级 |
|
|
|
if setting.VipLevelLimit > 0 && setting.VipLevelLimit > user.Level { |
|
|
|
resp.IsCanWithdraw = false |
|
|
|
resp.NotWithdrawReason = enum.FinWithdrawApplyWithdrawConditionDissatisfyKind. |
|
|
|
String(enum.FinWithdrawApplyWithdrawConditionDissatisfyKindNotRealName) |
|
|
|
String(enum.FinWithdrawApplyWithdrawConditionDissatisfyKindNotEnoughLevel) |
|
|
|
} |
|
|
|
case 1: |
|
|
|
resp.IsRealName = true |
|
|
|
default: |
|
|
|
resp.IsRealName = false |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 验证会员等级 |
|
|
|
if setting.VipLevelLimit > 0 && setting.VipLevelLimit > user.Level { |
|
|
|
resp.IsCanWithdraw = false |
|
|
|
resp.NotWithdrawReason = enum.FinWithdrawApplyWithdrawConditionDissatisfyKind. |
|
|
|
String(enum.FinWithdrawApplyWithdrawConditionDissatisfyKindNotEnoughLevel) |
|
|
|
//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 = "当前已无可提现次数" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//4、验证时段 |
|
|
|
now := time.Now() |
|
|
|
//6、验证时段 |
|
|
|
if setting.WithdrawTimeInterval != "" { |
|
|
|
withdrawTimeInterval := strings.Split(setting.WithdrawTimeInterval, "-") |
|
|
|
// 定义要比较的时间格式 |
|
|
@@ -243,68 +308,5 @@ func GetWithdrawCondition(user *model.User, setting *model.FinWithdrawSetting, i |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//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 { |
|
|
|
resp.IsFirst = true |
|
|
|
var firstWithdrawSet md.FirstWithdrawSet |
|
|
|
utils.Unserialize([]byte(setting.FirstWithdrawSet), &firstWithdrawSet) |
|
|
|
|
|
|
|
resp.FirstNeedRealName = func(firstWithdrawSetIsNeedRealName int) bool { |
|
|
|
if firstWithdrawSet.IsNeedRealName == 1 { |
|
|
|
return true |
|
|
|
} |
|
|
|
return false |
|
|
|
}(firstWithdrawSet.IsNeedRealName) |
|
|
|
resp.FirstWithdrawAmountLimit = firstWithdrawSet.FirstWithdrawAmountLimit |
|
|
|
} |
|
|
|
|
|
|
|
return resp |
|
|
|
} |