蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

57 lines
1.5 KiB

  1. package svc
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/utils"
  5. "applet/app/utils/cache"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  7. "code.fnuoos.com/EggPlanet/egg_system_rules.git"
  8. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  10. "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc"
  11. "fmt"
  12. "xorm.io/xorm"
  13. )
  14. // EggEnergyModifyPrice 蛋蛋能量-价格调整
  15. func EggEnergyModifyPrice(engine *xorm.Engine) {
  16. fmt.Println("modify_price...")
  17. defer func() {
  18. if err := recover(); err != nil {
  19. fmt.Println(err)
  20. return
  21. }
  22. }()
  23. // 1. 获取并解析价格设置
  24. conn := cache.GetPool().Get()
  25. cfgDb := implement.NewSysCfgDb(engine, conn)
  26. settingStr, err1 := cfgDb.SysCfgGetOne(enum.PriceSetting)
  27. if err1 != nil {
  28. fmt.Println("EggEnergyModifyPrice_ERR:::::", err1.Error())
  29. return
  30. }
  31. var setting md.PriceSettingStruct
  32. utils.Unserialize([]byte(settingStr.Val), &setting)
  33. // 2. 查询当前价格
  34. egg_system_rules.Init(cfg.RedisAddr)
  35. eggEnergyCoreData, cb, err2 := svc.GetEggEnergyCoreData(engine)
  36. if err2 != nil {
  37. fmt.Println("EggEnergyModifyPrice_ERR:::::", err2.Error())
  38. return
  39. }
  40. if cb != nil {
  41. defer cb() // 释放锁
  42. }
  43. // 3.判断价格是否在范围内
  44. if eggEnergyCoreData.NowPrice > setting.PriceBelowValue && eggEnergyCoreData.NowPrice < setting.PriceBelowValue {
  45. // 3.1 在价格范围内
  46. return
  47. } else {
  48. // 3.2 不在价格范围内 调整价格
  49. // todo 调整价格
  50. }
  51. }