package svc import ( "applet/app/cfg" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_system_rules.git" "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" "fmt" "xorm.io/xorm" ) // EggEnergyModifyPrice 蛋蛋能量-价格调整 func EggEnergyModifyPrice(engine *xorm.Engine) { fmt.Println("modify_price...") defer func() { if err := recover(); err != nil { fmt.Println(err) return } }() // 1. 获取并解析价格设置 conn := cache.GetPool().Get() cfgDb := implement.NewSysCfgDb(engine, conn) settingStr, err1 := cfgDb.SysCfgGetOne(enum.PriceSetting) if err1 != nil { fmt.Println("EggEnergyModifyPrice_ERR:::::", err1.Error()) return } var setting md.PriceSettingStruct utils.Unserialize([]byte(settingStr.Val), &setting) // 2. 查询当前价格 egg_system_rules.Init(cfg.RedisAddr) eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(engine) if err2 != nil { fmt.Println("EggEnergyModifyPrice_ERR:::::", err2.Error()) return } if cb != nil { defer cb() // 释放锁 } // 3.判断价格是否在范围内 if eggEnergyCoreData.NowPrice > setting.PriceBelowValue && eggEnergyCoreData.NowPrice < setting.PriceBelowValue { // 3.1 在价格范围内 return } else { // 3.2 不在价格范围内 调整价格 // todo 调整价格 } }