|
|
@@ -70,7 +70,7 @@ func handleEggCanalUserVirtualCoinFlowAggregationConsume(msg []byte) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
aggregationDb := implement.NewUserVirtualCoinFlowAggregationDb(db.Db) |
|
|
|
now := time.Now() |
|
|
|
now := time.Now().AddDate(0, 0, 1) |
|
|
|
|
|
|
|
if canalMsg.Data[0].CoinId == utils2.IntToStr(basicSetting.PersonEggEnergyCoinId) { |
|
|
|
userVirtualCoinFlowAggregation, err1 := aggregationDb.UserVirtualCoinFlowAggregationGetOneByParams(map[string]interface{}{ |
|
|
@@ -100,7 +100,7 @@ func handleEggCanalUserVirtualCoinFlowAggregationConsume(msg []byte) error { |
|
|
|
amount, _ := decimal.NewFromString(canalMsg.Data[0].Amount) |
|
|
|
todayData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.TodayData) |
|
|
|
thisWeekData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.ThisWeekData) |
|
|
|
thisMonthData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.ThisWeekData) |
|
|
|
thisMonthData, _ := decimal.NewFromString(userVirtualCoinFlowAggregation.ThisMonthData) |
|
|
|
userVirtualCoinFlowAggregation.TodayData = todayData.Add(amount).String() |
|
|
|
userVirtualCoinFlowAggregation.ThisWeekData = thisWeekData.Add(amount).String() |
|
|
|
userVirtualCoinFlowAggregation.ThisMonthData = thisMonthData.Add(amount).String() |
|
|
@@ -110,6 +110,74 @@ func handleEggCanalUserVirtualCoinFlowAggregationConsume(msg []byte) error { |
|
|
|
return err2 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 更新 user_egg_energy_aggregation |
|
|
|
uid := utils2.StrToInt64(canalMsg.Data[0].Uid) |
|
|
|
year, week := now.ISOWeek() |
|
|
|
_, month, day := now.Date() |
|
|
|
energyAggregationDb := implement.NewUserEggEnergyAggregationDb(db.Db) |
|
|
|
energyAggregation, err3 := energyAggregationDb.UserEggEnergyAggregationGetOneByTime(day, week, int(month), year, uid) |
|
|
|
if err3 != nil { |
|
|
|
return err3 |
|
|
|
} |
|
|
|
amount, _ := decimal.NewFromString(canalMsg.Data[0].Amount) |
|
|
|
if energyAggregation == nil { |
|
|
|
// 不存在当天数据 创建新数据 |
|
|
|
nowStr := now.Format("2006-01-02 15:04:05") |
|
|
|
m := model.UserEggEnergyAggregation{ |
|
|
|
Uid: uid, |
|
|
|
TodayData: canalMsg.Data[0].Amount, |
|
|
|
Day: day, |
|
|
|
Week: week, |
|
|
|
Month: int(month), |
|
|
|
Year: year, |
|
|
|
CreateAt: nowStr, |
|
|
|
UpdateAt: nowStr, |
|
|
|
} |
|
|
|
|
|
|
|
// 读取最新数据 |
|
|
|
lastEnergyAggregation, err4 := energyAggregationDb.UserEggEnergyAggregationGetLastOneByUid(uid) |
|
|
|
if err4 != nil { |
|
|
|
return err4 |
|
|
|
} |
|
|
|
// 判断是否上条数据是否在本周 |
|
|
|
if lastEnergyAggregation != nil { |
|
|
|
if lastEnergyAggregation.Week == week && lastEnergyAggregation.Year == year { |
|
|
|
// 周数相同 累加上周数据 |
|
|
|
thisWeekData, _ := decimal.NewFromString(lastEnergyAggregation.ThisWeekData) |
|
|
|
m.ThisWeekData = thisWeekData.Add(amount).String() |
|
|
|
} else { |
|
|
|
m.ThisWeekData = amount.String() |
|
|
|
} |
|
|
|
if lastEnergyAggregation.Month == int(month) && lastEnergyAggregation.Year == year { |
|
|
|
// 月份相同 累加上月数据 |
|
|
|
thisMonthData, _ := decimal.NewFromString(lastEnergyAggregation.ThisMonthData) |
|
|
|
m.ThisMonthData = thisMonthData.Add(amount).String() |
|
|
|
} else { |
|
|
|
m.ThisMonthData = amount.String() |
|
|
|
} |
|
|
|
} else { |
|
|
|
m.ThisWeekData = amount.String() |
|
|
|
m.ThisMonthData = amount.String() |
|
|
|
} |
|
|
|
|
|
|
|
_, err5 := energyAggregationDb.UserEggEnergyAggregationInsert(&m) |
|
|
|
if err5 != nil { |
|
|
|
return err5 |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 存在当天数据累加数据 |
|
|
|
todayData, _ := decimal.NewFromString(energyAggregation.TodayData) |
|
|
|
thisWeekData, _ := decimal.NewFromString(energyAggregation.ThisWeekData) |
|
|
|
thisMonthData, _ := decimal.NewFromString(energyAggregation.ThisMonthData) |
|
|
|
energyAggregation.TodayData = todayData.Add(amount).String() |
|
|
|
energyAggregation.ThisWeekData = thisWeekData.Add(amount).String() |
|
|
|
energyAggregation.ThisMonthData = thisMonthData.Add(amount).String() |
|
|
|
_, err5 := energyAggregationDb.UserEggEnergyAggregationUpdate(energyAggregation.Id, energyAggregation, "today_data", "this_week_data", "this_month_data") |
|
|
|
if err5 != nil { |
|
|
|
return err5 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return nil |
|
|
|