package services import ( "app/commons/constant" "app/commons/model/entity" "github.com/shopspring/decimal" "gorm.io/gorm" ) // 批量查询收益记录 func (s *CommonService) BatchUserProfitRecord(db *gorm.DB) ([]*entity.UserProfitRecord, error) { return FindAllWithBatch[entity.UserProfitRecord](db) } // 构建收益记录 func (s *CommonService) BuildUserProfitRecord(rewardInfo *entity.ProfitInfo, bs *constant.BusinessType) *entity.UserProfitRecord { return &entity.UserProfitRecord{ RawUserId: rewardInfo.RawUserId, RawUserUid: rewardInfo.RawUserUid, RewardUserId: rewardInfo.RewardUserId, RewardUserUid: rewardInfo.RewardUserUid, RewardSymbol: rewardInfo.RewardSymbol, SymbolUsdPrice: rewardInfo.SymbolUsdPrice, CapitalUsd: rewardInfo.CapitalUsd, RewardRatio: rewardInfo.RewardRatio, RewardUsdValue: rewardInfo.RewardUsdValue, RewardQuantity: rewardInfo.RewardQuantity, BusinessNumber: bs.BusinessNumber, BusinessName: bs.BusinessName, ContextValue: bs.ContextValue, ContextName: bs.ContextName, RewardPeriod: rewardInfo.RewardPeriod, RewardDate: rewardInfo.RewardDate, State: entity.ProfitSendStateWaiting, Describe: bs.Desc, } } // 修改收益表 func (s *CommonService) ActionUserProfitQuotaWithBsId(txDB *gorm.DB, userId int64, bsId int, tokenProfit, usdProfit decimal.Decimal) error { updateFields := map[string]interface{}{ "total_profit_quantity": gorm.Expr("total_profit_quantity+?", tokenProfit), "total_profit_usd": gorm.Expr("total_profit_usd + ?", usdProfit), } switch bsId { // 静态奖励 case constant.BsCurrentStaticProfit: updateFields["static_profit_quantity"] = gorm.Expr("static_profit_quantity+?", tokenProfit) updateFields["static_profit_usd_amount"] = gorm.Expr("static_profit_usd_amount+?", usdProfit) break // 动态奖励 case constant.BsDynamicLevelWeightedProfit, constant.BsDynamicLevelAvgProfit: updateFields["dynamic_profit_quantity"] = gorm.Expr("dynamic_profit_quantity+?", tokenProfit) updateFields["dynamic_profit_usd_amount"] = gorm.Expr("dynamic_profit_usd_amount+?", usdProfit) break // 节点奖励 case constant.BsPartnerNodeProfit: updateFields["node_profit_quantity"] = gorm.Expr("node_profit_quantity+?", tokenProfit) updateFields["node_profit_usd_amount"] = gorm.Expr("node_profit_usd_amount+?", usdProfit) break default: break } err := txDB.Model(&entity.UserProfit{}).Where("user_id", userId).Updates(updateFields).Error return err }