diff --git a/enum/user_virtual_amount_flow.go b/enum/user_virtual_amount_flow.go index 367d430..cd4571a 100644 --- a/enum/user_virtual_amount_flow.go +++ b/enum/user_virtual_amount_flow.go @@ -11,6 +11,8 @@ const ( EggPointCoinToExchangeToTeamEggEnergy PersonEggGetByEnergyEggPointCoin TeamEggGetByEnergyEggPointCoin + TeamEggEnergyReleaseToPersonEggEnergy + PersonEggGetByTeamEggEnergyRelease ) func (kind UserVirtualAmountFlowTransferType) String() string { @@ -26,9 +28,13 @@ func (kind UserVirtualAmountFlowTransferType) String() string { case EggPointCoinToExchangeToTeamEggEnergy: return "团队蛋蛋积分兑换" case PersonEggGetByEnergyEggPointCoin: - return "个人蛋蛋积分兑换蛋蛋能量" + return "兑换到个人蛋蛋能量" case TeamEggGetByEnergyEggPointCoin: - return "团队蛋蛋积分兑换蛋蛋能量" + return "兑换到团队蛋蛋能量" + case TeamEggEnergyReleaseToPersonEggEnergy: + return "团队蛋蛋能量释放" + case PersonEggGetByTeamEggEnergyRelease: + return "释放到个人蛋蛋能量" default: return "未知状态" } diff --git a/go.mod b/go.mod index 92213b8..2404c3e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module code.fnuoos.com/EggPlanet/egg_system_rules.git go 1.19 // go.mod文件中 -replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models +//replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models require ( code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 @@ -11,4 +11,4 @@ require ( xorm.io/xorm v1.3.1 ) -require code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112032738-ca9b07ba7b24 // indirect +require code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112135742-0200baa0a923 // indirect diff --git a/go.sum b/go.sum index 9d0a348..799b340 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,9 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112032738-ca9b07ba7b24 h1:zH+UExmxPnD0vUTy2aGXG/sGH+g/oLtMXbO/c8iRDz4= code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112032738-ca9b07ba7b24/go.mod h1:Ktgi+Hk87UlF7/7wg1BvQnAbXWxGa3y+OqDXSD0AA4Q= +code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112090248-0a49428505eb/go.mod h1:Ktgi+Hk87UlF7/7wg1BvQnAbXWxGa3y+OqDXSD0AA4Q= +code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112135742-0200baa0a923 h1:07C/4B2J6M5gjclRoSqqkO7UPEXn1V41sADCH1OThfc= +code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241112135742-0200baa0a923/go.mod h1:Ktgi+Hk87UlF7/7wg1BvQnAbXWxGa3y+OqDXSD0AA4Q= code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY= code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.4-0.20241017011352-f7f92494c0f4/go.mod h1:nT2x13YFgrS3tS1fDyUR6q/GNIK+hPw7bdzZXz99SM0= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/rule/egg_energy/auto_release_green_energy.go b/rule/egg_energy/auto_release_green_energy.go index 6f55d01..1ea44a3 100644 --- a/rule/egg_energy/auto_release_green_energy.go +++ b/rule/egg_energy/auto_release_green_energy.go @@ -1,9 +1,11 @@ package egg_energy import ( - "code.fnuoos.com/EggPlanet/egg_system_rules.git/db" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/db/model" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache" zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/logx" "errors" @@ -13,10 +15,10 @@ import ( "xorm.io/xorm" ) -const LockKey = "auto_release_exchange_green_energy_lock_key" +const LockKey = "auto_release_exchange_team_egg_energy_lock_key" -// AutoReleaseExchangeGreenEnergy 结算绿色能量自动释放成可用绿色能量 -func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err error) { +// AutoReleaseExchangeTeamEggEnergy 团队蛋蛋能量自动释放成可用绿色能量 +func AutoReleaseExchangeTeamEggEnergy(engine *xorm.Engine, masterId string) (err error) { now := time.Now() fmt.Println(now.Hour()) if !(now.Hour() > 1 && now.Hour() < 8) { @@ -34,21 +36,26 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e } cache.SetEx(LockKey, "running", 3600*8) //8小时 - //1、查找 `one_circles_green_energy_basic_setting` 基础设置 && `one_circles_public_platoon_basic_setting` 基础设置 - oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ + //1、查找`egg_energy_basic_setting` 基础设置 + eggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(engine) + eggEnergyBasicSetting, err := eggEnergyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ "key": "is_open", "value": 1, }) if err != nil { return } + if eggEnergyBasicSetting.SettlementQuantity == 0 { + err = errors.New("结算百分比未设置!") + return + } - settlementQuantity := oneCirclesGreenEnergyBasicSetting.SettlementQuantity + settlementQuantity := eggEnergyBasicSetting.SettlementQuantity fmt.Println("settlementQuantity>>>>>>>>>>>>", settlementQuantity) //2、当前 "可用"绿色能量可以兑换的用户数据 var list1 []model.UserVirtualAmount - err = engine.Where("coin_id = ?", oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId).And("amount > ?", 0).Find(&list1) + err = engine.Where("coin_id = ?", eggEnergyBasicSetting.TeamEggEnergyCoinId).And("amount > ?", 0).Find(&list1) if err != nil { fmt.Println("err:::::1111", err) return @@ -70,40 +77,35 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e }() session.Begin() - //4.2给相应的用户加上个人的绿色积分(可用数量) - err = DealUserCoin(session, md.DealUserCoinReq{ - Kind: "add", - Mid: masterId, - Title: md.OneCirclesSettlementGreenEnergyExchangeGreenEnergy, - TransferType: md.OneCirclesSettlementGreenEnergyExchangeGreenEnergyForUserVirtualCoinFlow, - OrdId: "", - CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, + //4.2给相应的用户减少团队蛋蛋能量 + err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{ + Kind: "sub", + Title: enum.TeamEggEnergyReleaseToPersonEggEnergy.String(), + TransferType: int(enum.TeamEggEnergyReleaseToPersonEggEnergy), + CoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId, Uid: v.Uid, Amount: settlementQuantityAmount, }) if err != nil { _ = session.Rollback() - fmt.Println("err:::::22222", err) + fmt.Println("err:::::33333", err) continue } - //4.2给相应的用户减少个人的绿色积分(结算数量) - err = DealUserCoin(session, md.DealUserCoinReq{ - Kind: "sub", - Mid: masterId, - Title: md.OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy, - TransferType: md.OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergyForUserVirtualCoinFlow, - OrdId: "", - CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, + //4.3给相应的用户增加个人的蛋蛋能量 + err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{ + Kind: "add", + Title: enum.PersonEggGetByTeamEggEnergyRelease.String(), + TransferType: int(enum.PersonEggGetByTeamEggEnergyRelease), + CoinId: eggEnergyBasicSetting.PersonEggEnergyCoinId, Uid: v.Uid, Amount: settlementQuantityAmount, }) if err != nil { _ = session.Rollback() - fmt.Println("err:::::33333", err) + fmt.Println("err:::::22222", err) continue } - err = session.Commit() if err != nil { _ = session.Rollback() diff --git a/rule/egg_energy/enum/egg_energy_fund_data.go b/rule/egg_energy/enum/egg_energy_fund_data.go new file mode 100644 index 0000000..7b6781d --- /dev/null +++ b/rule/egg_energy/enum/egg_energy_fund_data.go @@ -0,0 +1,23 @@ +package enum + +// EggEnergyFundDataKind 蛋蛋能量-资金数据-种类 +type EggEnergyFundDataKind int + +const ( + CompanySubsidies EggEnergyFundDataKind = iota + 1 + InvestmentByInvestors + MarketExpectations +) + +func (kind EggEnergyFundDataKind) String() string { + switch kind { + case CompanySubsidies: + return "公司补贴" + case InvestmentByInvestors: + return "资方投资" + case MarketExpectations: + return "市场期望" + default: + return "未知状态" + } +} diff --git a/rule/egg_energy/green_energy_settlement.go b/rule/egg_energy/green_energy_settlement.go index 0ab1547..1077a25 100644 --- a/rule/egg_energy/green_energy_settlement.go +++ b/rule/egg_energy/green_energy_settlement.go @@ -1,11 +1,8 @@ package egg_energy import ( - "code.fnuoos.com/EggPlanet/egg_system_rules.git/db" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/db/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/one_circles/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/one_circles/md" + db "code.fnuoos.com/EggPlanet/egg_models.git/src" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" diff --git a/rule/egg_energy/star_level_dividends.go b/rule/egg_energy/star_level_dividends.go index 119b8f1..346dee6 100644 --- a/rule/egg_energy/star_level_dividends.go +++ b/rule/egg_energy/star_level_dividends.go @@ -5,6 +5,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" egg_system_rules "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache" zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/logx" @@ -288,8 +289,24 @@ func SettlementStarLevelDividends(engine *xorm.Engine, masterId string, ch *rabb } //6、 减少“星级分红”中的绿色能量 - totalDividend, _ := totalDividendValue.Float64() - err = DealAvailableGreenEnergyCoin(session, int(enum.SettlementStarLevelDividends), totalDividend, 0, enum.SettlementStarLevelDividends.String(), nil, "", masterId) + totalDividend := totalDividendValue.String() + eggEnergyCoreData, cb, err := svc.GetEggEnergyCoreData(engine) + if err != nil { + return err + } + if cb != nil { + defer cb() // 释放锁 + } + err = DealAvailableEggEnergyCoin(session, int(enum.SettlementStarLevelDividends), eggEnergyCoreData, md2.DealAvailableEggEnergyCoinReq{ + Amount: totalDividend, + AmountFee: "", + BeforePrice: eggEnergyCoreData.NowPrice, + AfterPrice: eggEnergyCoreData.NowPrice, + BeforePlanetTotalValue: eggEnergyCoreData.PlanetTotalValue, + AfterPlanetTotalValue: eggEnergyCoreData.PlanetTotalValue, + BeforeEnergyTotalNums: eggEnergyCoreData.NowEnergyTotalNums, + AfterEnergyTotalNums: eggEnergyCoreData.NowEnergyTotalNums, + }) if err != nil { _ = session.Rollback() fmt.Println("err:::::9999999", err) diff --git a/rule/public_platoon_user_relation_commission.go b/rule/public_platoon_user_relation_commission.go index 9519154..a5709b4 100644 --- a/rule/public_platoon_user_relation_commission.go +++ b/rule/public_platoon_user_relation_commission.go @@ -4,6 +4,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache" "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/logx" @@ -17,7 +18,7 @@ import ( ) // AddPublicPlatoonUserRelationCommission 新增公排用户关系记录 -func AddPublicPlatoonUserRelationCommission(engine *xorm.Engine, AddPublicPlatoonUserRelationCommissionReqList []*md.AddPublicPlatoonUserRelationCommissionReq) (map[string]*model.PublicPlatoonUserRelation, error) { +func AddPublicPlatoonUserRelationCommission(engine *xorm.Engine, AddPublicPlatoonUserRelationCommissionReqList []*md2.AddPublicPlatoonUserRelationCommissionReq) (map[string]*model.PublicPlatoonUserRelation, error) { var resp = map[string]*model.PublicPlatoonUserRelation{} //查找 `public_platoon_basic_setting` 基础设置 publicPlatoonBasicSettingDb := implement.NewPublicPlatoonBasicSettingDb(engine) @@ -280,13 +281,13 @@ func PublicPlatoon(engine *xorm.Engine, uid, recommendUid int64, PublicPlatoonBa var fatherUidStr string if m1.FatherUid == "" { //TODO::顶级 - fatherUidStr = egg_system_rules.IntToStr(m1.Id) + fatherUidStr = egg_system_rules.Int64ToStr(m1.Id) } else { fatherUids := strings.Split(m1.FatherUid, "-") if len(fatherUids) >= PublicPlatoonBasicSetting.SeveralRows { - fatherUidStr = egg_system_rules.IntToStr(m1.Id) + "-" + strings.Join(fatherUids[0:PublicPlatoonBasicSetting.SeveralRows:len(fatherUids)], "-") + fatherUidStr = egg_system_rules.Int64ToStr(m1.Id) + "-" + strings.Join(fatherUids[0:PublicPlatoonBasicSetting.SeveralRows:len(fatherUids)], "-") } else { - fatherUidStr = egg_system_rules.IntToStr(m1.Id) + "-" + m1.FatherUid + fatherUidStr = egg_system_rules.Int64ToStr(m1.Id) + "-" + m1.FatherUid } }