From e6d5ae4fcebbf61da4741673112f8bd77b3c78ab Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Fri, 15 Nov 2024 17:31:38 +0800 Subject: [PATCH] add egg energy modify price --- app/task/svc/svc_egg_energy_modify_price.go | 56 +++++++++++++++++++++ go.mod | 3 +- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/task/svc/svc_egg_energy_modify_price.go diff --git a/app/task/svc/svc_egg_energy_modify_price.go b/app/task/svc/svc_egg_energy_modify_price.go new file mode 100644 index 0000000..bcf64b5 --- /dev/null +++ b/app/task/svc/svc_egg_energy_modify_price.go @@ -0,0 +1,56 @@ +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 调整价格 + } +} diff --git a/go.mod b/go.mod index ac28abb..e805cda 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.19 //replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models -// //replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules require ( @@ -35,7 +34,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241115090315-a9a84aba8235 + code.fnuoos.com/EggPlanet/egg_models.git v0.0.5 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.3 code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible