diff --git a/consume/zhios_order_settle_total.go b/consume/zhios_order_settle_total.go index aed9292..8fe6eaf 100644 --- a/consume/zhios_order_settle_total.go +++ b/consume/zhios_order_settle_total.go @@ -134,6 +134,37 @@ func handleZhiosOrderSettleTotal(msg []byte) error { return errors.New("失败") } + var userStatistics2 model.UserMonthAmount + if ordData.SettleAt == 0 { + ordData.SettleAt = int(time.Now().Unix()) + } + now := time.Unix(int64(ordData.SettleAt), 0).Format("200601") + sess.Where("uid=? and date=?", v.Uid, now).Get(&userStatistics2) + if userStatistics2.Id == 0 { + userStatistics2 = model.UserMonthAmount{ + Date: utils.StrToInt(now), + Uid: v.Uid, + } + has, err := sess.Insert(&userStatistics2) + if err != nil { + sess.Rollback() + return err + } + if has == 0 { + sess.Rollback() + return errors.New("失败") + } + } + userStatistics2.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userStatistics2.SettleAmount)+v.Amount+utils.StrToFloat64(v.AdditionalSubsidy), 4) + update2, err2 := eg.Where("id=?", userStatistics2.Id).Cols("settle_amount").Update(&userStatistics2) + if err2 != nil { + sess.Rollback() + return err2 + } + if update2 == 0 { + sess.Rollback() + return errors.New("失败") + } } } sess.Commit()