|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/utils"
- "applet/app/utils/cache"
- "fmt"
- "time"
- )
-
- func MasterMonthSettle() {
- day := time.Now().Day()
- masterListCfgDb := db.MasterListCfgDb{}
- masterListCfgDb.Set()
- withdrawalDay := masterListCfgDb.MasterListCfgGetOneData("0", "withdrawal_day")
- if day < utils.StrToInt(withdrawalDay) {
- return
- }
- args := map[string]string{
- "p": "1",
- "size": "100",
- }
- masterAmountDb := db.MasterAmountDb{}
- masterAmountDb.Set()
- list := masterAmountDb.GetMasterAmountList(args)
- if list == nil {
- return
- }
- for _, v := range *list {
- mutexKey := fmt.Sprintf("master_month_settle:%d", v.Id)
- withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
- if err != nil {
- continue
- }
- if withdrawAvailable != "OK" {
- continue
- }
- if utils.StrToFloat64(v.LastMonthAmount) <= 0 {
- continue
- }
- masterDb := db.MasterDb{}
- masterDb.Set()
- master := masterDb.GetMasterId(v.Id)
- if master == nil {
- continue
- }
- oldAmount := v.Amount
- oldLastMonthAmount := v.LastMonthAmount
- v.Amount = utils.Float64ToStr(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(v.LastMonthAmount))
- v.LastMonthAmount = "0"
- update := masterAmountDb.MasterAmountUpdate(v.Id, &v)
- if update == false {
- continue
- }
- var tmp = model.MasterAmountFlow{
- Uid: v.Uid,
- Time: time.Now(),
- BeforeAmount: oldAmount,
- Amount: oldLastMonthAmount,
- AfterAmount: v.Amount,
- Platform: "playlet",
- Oid: utils.IntToStr(v.Id),
- Title: "短剧上月结算佣金到账",
- FlowType: "last_month_playlet_settle",
- IncomeType: 0,
- ExtendUid: master.ExtendUid,
- }
- masterAmountFlowDb := db.MasterAmountFlowDb{}
- masterAmountFlowDb.Set()
- masterAmountFlowDb.MasterAmountFlowInsert(&tmp)
-
- var tmpLastMonth = model.MasterLastMonthAmountFlow{
- Uid: v.Uid,
- Time: time.Now(),
- BeforeAmount: oldLastMonthAmount,
- Amount: oldLastMonthAmount,
- AfterAmount: v.LastMonthAmount,
- Platform: "playlet",
- Oid: utils.IntToStr(v.Id),
- Title: "短剧上月结算佣金转到余额",
- FlowType: "last_month_playlet_settle",
- IncomeType: 1,
- ExtendUid: master.ExtendUid,
- }
- masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
- masterLastMonthAmountFlowDb.Set()
- masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmpLastMonth)
-
- }
- }
|