|
|
@@ -0,0 +1,78 @@ |
|
|
|
package service_award_dividend |
|
|
|
|
|
|
|
import ( |
|
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement" |
|
|
|
"sort" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func GetCycle(eg *xorm.Engine) map[string]string { |
|
|
|
NewServiceAwardReturnBaseDb := implement.NewServiceAwardReturnBaseDb(eg) |
|
|
|
base, _ := NewServiceAwardReturnBaseDb.GetServiceAwardReturnBase() |
|
|
|
now := time.Now() |
|
|
|
res := map[string]string{ |
|
|
|
"coin_id": zhios_order_relate_utils.IntToStr(base.CoinId), |
|
|
|
} |
|
|
|
if base != nil { |
|
|
|
ex := strings.Split(base.Day, ",") |
|
|
|
if len(ex) > 0 { |
|
|
|
day := now.Day() |
|
|
|
hasDay := 0 |
|
|
|
sort.Strings(ex) |
|
|
|
postion := 0 |
|
|
|
//31 |
|
|
|
// 16 20 30 |
|
|
|
for k, v := range ex { //判断最近的一天 now 读的是当前周期 就是比当前时间大的一个日期 last 读的是上个周期 就是比当前时间小的一个日期 |
|
|
|
if day > zhios_order_relate_utils.StrToInt(v) { //当前时间大于设置时间 |
|
|
|
if k+1 == len(ex) { |
|
|
|
postion = k + 1 |
|
|
|
} |
|
|
|
continue |
|
|
|
} |
|
|
|
if hasDay == 1 { |
|
|
|
continue |
|
|
|
} |
|
|
|
postion = k |
|
|
|
hasDay = 1 |
|
|
|
} |
|
|
|
last := postion - 1 |
|
|
|
next := postion |
|
|
|
if postion-1 < 0 { //找出上一周期的时间 |
|
|
|
last = len(ex) - 1 |
|
|
|
} else if last == len(ex)-1 { //最后一个了 |
|
|
|
next = 0 |
|
|
|
} |
|
|
|
|
|
|
|
lastDate := GetDate(now, zhios_order_relate_utils.IntToStr(last), "last") |
|
|
|
res["last"] = time.Unix(lastDate, 0).Format("20060102") |
|
|
|
nowDate := GetDate(now, zhios_order_relate_utils.IntToStr(next), "now") |
|
|
|
res["now"] = time.Unix(nowDate, 0).Format("20060102") |
|
|
|
} |
|
|
|
} |
|
|
|
return res |
|
|
|
} |
|
|
|
func GetDate(now time.Time, day, types string) int64 { |
|
|
|
year := now.Year() |
|
|
|
month := now.Month() |
|
|
|
var date int64 = 0 |
|
|
|
if types == "last" { |
|
|
|
month-- |
|
|
|
if month < 0 { |
|
|
|
month = 12 |
|
|
|
year-- |
|
|
|
} |
|
|
|
} |
|
|
|
if types == "next" { |
|
|
|
month++ |
|
|
|
if month > 12 { |
|
|
|
month = 1 |
|
|
|
year++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
date = time.Date(year, month, zhios_order_relate_utils.StrToInt(day), 0, 0, 0, 0, now.Location()).Unix() |
|
|
|
return date |
|
|
|
} |