profit_record.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package services
  2. import (
  3. "app/commons/constant"
  4. "app/commons/model/entity"
  5. "github.com/shopspring/decimal"
  6. "gorm.io/gorm"
  7. )
  8. // 批量查询收益记录
  9. func (s *CommonService) BatchUserProfitRecord(db *gorm.DB) ([]*entity.UserProfitRecord, error) {
  10. return FindAllWithBatch[entity.UserProfitRecord](db)
  11. }
  12. // 构建收益记录
  13. func (s *CommonService) BuildUserProfitRecord(rewardInfo *entity.ProfitInfo, bs *constant.BusinessType) *entity.UserProfitRecord {
  14. return &entity.UserProfitRecord{
  15. RawUserId: rewardInfo.RawUserId,
  16. RawUserUid: rewardInfo.RawUserUid,
  17. RewardUserId: rewardInfo.RewardUserId,
  18. RewardUserUid: rewardInfo.RewardUserUid,
  19. RewardSymbol: rewardInfo.RewardSymbol,
  20. SymbolUsdPrice: rewardInfo.SymbolUsdPrice,
  21. CapitalUsd: rewardInfo.CapitalUsd,
  22. RewardRatio: rewardInfo.RewardRatio,
  23. RewardUsdValue: rewardInfo.RewardUsdValue,
  24. RewardQuantity: rewardInfo.RewardQuantity,
  25. BusinessNumber: bs.BusinessNumber,
  26. BusinessName: bs.BusinessName,
  27. ContextValue: bs.ContextValue,
  28. ContextName: bs.ContextName,
  29. RewardPeriod: rewardInfo.RewardPeriod,
  30. RewardDate: rewardInfo.RewardDate,
  31. State: entity.ProfitSendStateWaiting,
  32. Describe: bs.Desc,
  33. }
  34. }
  35. // 修改收益表
  36. func (s *CommonService) ActionUserProfitQuotaWithBsId(txDB *gorm.DB, userId int64, bsId int, tokenProfit, usdProfit decimal.Decimal) error {
  37. updateFields := map[string]interface{}{
  38. "total_profit_quantity": gorm.Expr("total_profit_quantity+?", tokenProfit),
  39. "total_profit_usd": gorm.Expr("total_profit_usd + ?", usdProfit),
  40. }
  41. switch bsId {
  42. // 静态奖励
  43. case constant.BsCurrentStaticProfit:
  44. updateFields["static_profit_quantity"] = gorm.Expr("static_profit_quantity+?", tokenProfit)
  45. updateFields["static_profit_usd_amount"] = gorm.Expr("static_profit_usd_amount+?", usdProfit)
  46. break
  47. // 动态奖励
  48. case constant.BsDynamicLevelWeightedProfit, constant.BsDynamicLevelAvgProfit:
  49. updateFields["dynamic_profit_quantity"] = gorm.Expr("dynamic_profit_quantity+?", tokenProfit)
  50. updateFields["dynamic_profit_usd_amount"] = gorm.Expr("dynamic_profit_usd_amount+?", usdProfit)
  51. break
  52. // 节点奖励
  53. case constant.BsPartnerNodeProfit:
  54. updateFields["node_profit_quantity"] = gorm.Expr("node_profit_quantity+?", tokenProfit)
  55. updateFields["node_profit_usd_amount"] = gorm.Expr("node_profit_usd_amount+?", usdProfit)
  56. break
  57. default:
  58. break
  59. }
  60. err := txDB.Model(&entity.UserProfit{}).Where("user_id", userId).Updates(updateFields).Error
  61. return err
  62. }