|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/utils"
- "applet/app/utils/cache"
- "fmt"
- "time"
- )
-
- func LifeOrderSettle() {
- day := time.Now().Day()
- if day < 20 {
- return
- }
- month := utils.GetTimeRange("current_month")
- fmt.Println(month)
- arg := map[string]string{
- "status": "订单结算",
- "sort": "id desc",
- "is_to_settle": "1",
- "is_commission": "1",
- "to_settle_time": utils.Int64ToStr(month["start"]),
- "p": "1",
- "size": "100",
- }
- order := db.GetLifeOrderList(arg)
- if len(order) == 0 {
- return
- }
- fmt.Println(utils.SerializeStr(order))
- platformMap := map[string]string{
- "tikTok_life": "抖音本地生活",
- "csjp": "穿山甲抖音",
- "csjp_live": "穿山甲抖音直播商品",
- "kuaishou": "快手",
- "kuaishou_live": "快手直播商品",
- "meituan": "美团",
- }
- for _, v := range order {
- fmt.Println("=================00")
- // 加锁 防止并发提取
- mutexKey := fmt.Sprintf("life_order_settle3:%d", v.Id)
- withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
- if err != nil {
- fmt.Println("=================0")
-
- fmt.Println(err)
- continue
- }
- if withdrawAvailable != "OK" {
- fmt.Println("=================1")
-
- continue
- }
- if v.SettleTime > 0 {
- fmt.Println("=================2")
-
- continue
- }
- //加到上月结算
- if v.Uid == 0 {
- fmt.Println("=================3")
-
- continue
- }
- masterDb := db.MasterDb{}
- masterDb.Set()
- master := masterDb.GetMaster(utils.IntToStr(v.Uid))
- if master == nil {
- fmt.Println("=================4")
-
- continue
- }
- masterAmountDb := db.MasterAmountDb{}
- masterAmountDb.Set()
- amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(v.ExtendUid), "playlet")
- if amount == nil {
- fmt.Println("=================5")
- continue
- }
- if utils.StrToFloat64(v.RealCommission) <= 0 {
- v.SettleTime = int(time.Now().Unix())
- db.ZhimengDb.Where("id=?", v.Id).Update(&v)
- continue
- }
- oldAmount := amount.LastMonthAmount
- amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.RealCommission))
- update := masterAmountDb.MasterAmountUpdate(amount.Id, amount)
- if update == false {
- fmt.Println("=================7")
-
- continue
- }
- var tmp = model.MasterLastMonthAmountFlow{
- Uid: utils.IntToStr(master.Id),
- Time: time.Now(),
- BeforeAmount: oldAmount,
- Amount: v.RealCommission,
- AfterAmount: amount.LastMonthAmount,
- Platform: v.Pvd,
- Oid: utils.Int64ToStr(v.Oid),
- Title: platformMap[v.Pvd] + "结算",
- FlowType: v.Pvd + "_settle",
- ExtendUid: utils.IntToStr(v.ExtendUid),
- }
- masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
- masterLastMonthAmountFlowDb.Set()
- masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
- v.SettleTime = int(time.Now().Unix())
- db.ZhimengDb.Where("id=?", v.Id).Update(&v)
- }
- return
- }
|