Browse Source

update

master
dengbiao 1 week ago
parent
commit
22c05dd7f7
5 changed files with 138 additions and 5 deletions
  1. +1
    -1
      go.mod
  2. +2
    -0
      go.sum
  3. +3
    -4
      rule/egg_energy/give_activty_coin.go
  4. +14
    -0
      svc/sys_cfg/sys_cfg_dao.go
  5. +118
    -0
      svc/sys_cfg/sys_cfg_implement.go

+ 1
- 1
go.mod View File

@@ -44,7 +44,7 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect


+ 2
- 0
go.sum View File

@@ -2,6 +2,8 @@ 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.20241211055111-7c47b67b46d2 h1:g4zWPWExuZAG8nTmkcSJnTbxKhz5B+VANCWEsJOMGXg=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14 h1:pmSd/GlPECRYCcVKZWPuC1NksGsjUwwUZ7yctmDgP70=
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14/go.mod h1:+bDK4gfBq4LEkhh6K/A46+0urH/sgxDxnjIjlxb9HI8=
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be h1:zuleX5JnIGQpt6wDAmCFs++lLgOmE6kWo3xkJnjrSck=
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be/go.mod h1:Yuc7XnUQ15eaC0ZobcJG7XwkVTttVqp52OTanXhI1Qk=
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 h1:dqvWJqlJi0WXCwTxbWPLvSOsKPjP+iEDBVgLcAl9nOE=


+ 3
- 4
rule/egg_energy/give_activty_coin.go View File

@@ -1,12 +1,14 @@
package egg_energy

import (
db "code.fnuoos.com/EggPlanet/egg_models.git/src"
"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"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/svc/sys_cfg"
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/EggPlanet/egg_system_rules.git/utils/es"
@@ -65,10 +67,7 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm strin
go dealEcpm(user, ecpm, ch) //TODO::协程处理ecpm的变化

//TODO::奖励多少个活跃积分(根据ecpm, 新用户机制, 蛋蛋分机制)
redisConn := cache.GetPool().Get()
defer redisConn.Close()

sysCfgDb := implement.NewSysCfgDb(engine, redisConn)
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
videoRewardUnitPrice := sysCfgDb.SysCfgGetWithDb(enum.VideoRewardUnitPrice)
if videoRewardUnitPrice != "" { //处理ecpm
var coin model.VirtualCoin


+ 14
- 0
svc/sys_cfg/sys_cfg_dao.go View File

@@ -0,0 +1,14 @@
package sys_cfg

import "code.fnuoos.com/EggPlanet/egg_models.git/src/model"

type SysCfgDao interface {
SysCfgGetAll() (*[]model.SysCfg, error)
SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error)
SysCfgGetOne(key string) (*model.SysCfg, error)
SysCfgInsert(key, val, memo string) bool
SysCfgUpdate(key, val string) bool
SysCfgGetWithDb(HKey string) string
SysCfgDel(HKey string) error
SysCfgFindWithDb(keys ...string) map[string]string
}

+ 118
- 0
svc/sys_cfg/sys_cfg_implement.go View File

@@ -0,0 +1,118 @@
package sys_cfg

import (
"code.fnuoos.com/EggPlanet/egg_models.git/md"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/cache"
"fmt"
"xorm.io/xorm"
)

func NewSysCfgDb(engine *xorm.Engine) SysCfgDao {
return &SysCfgDb{
Db: engine,
}
}

type SysCfgDb struct {
Db *xorm.Engine
}

func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) {
var cfgList []model.SysCfg
if err := s.Db.Cols("key,val,memo").Find(&cfgList); err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error) {
var cfgList model.SysCfg
_, err := s.Db.Where("`key`=?", key).Get(&cfgList)
if err != nil {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) {
var cfgList model.SysCfg
if has, err := s.Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false {
return nil, zhios_order_relate_logx.Error(err)
}
return &cfgList, nil
}

func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool {
cfg := model.SysCfg{Key: key, Val: val, Memo: memo}
_, err := s.Db.InsertOne(&cfg)
if err != nil {
zhios_order_relate_logx.Error(err)
return false
}
return true
}

func (s SysCfgDb) SysCfgUpdate(key, val string) bool {
cfg := model.SysCfg{Key: key, Val: val}
_, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg)
if err != nil {
zhios_order_relate_logx.Error(err)
return false
}
s.SysCfgDel(key)
return true
}

func (s SysCfgDb) SysCfgGetWithDb(HKey string) string {
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1])
get, err := cache.HGetString(cacheKey, HKey)
if err != nil || get == "" {
cfg, err := s.SysCfgGetOne(HKey)
if err != nil || cfg == nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}

// key是否存在
cacheKeyExist := false
if cache.Exists(cacheKey) {
cacheKeyExist = true
}

// 设置缓存
_, err = cache.HSet(cacheKey, HKey, cfg.Val)
if err != nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}
if !cacheKeyExist { // 如果是首次设置 设置过期时间
_, err := cache.Expire(cacheKey, md.CfgCacheTime)
if err != nil {
_ = zhios_order_relate_logx.Error(err)
return ""
}
}
return cfg.Val
}
return get
}

func (s SysCfgDb) SysCfgDel(HKey string) error {
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1])
_, err := cache.HDel(cacheKey, HKey)
if err != nil {
return err
}
return nil
}

func (s SysCfgDb) SysCfgFindWithDb(keys ...string) map[string]string {
res := map[string]string{}
for _, v := range keys {
val := s.SysCfgGetWithDb(v)
res[v] = val
}
return res
}

Loading…
Cancel
Save