```
refactor(item): 优化物品添加逻辑并移除冗余代码 - 修改 ItemAdd 方法签名,从可变参数改为两个独立参数 itemId 和 itemCnt - 移除了对 model.ItemInfo 的依赖,简化调用方式 - 更新所有调用 ItemAdd 的地方以适配新接口 - 删除未使用的 imports 和注释掉的旧配置加载逻辑 - 修复购买物品时金币扣除与物品发放的一致性问题 - 增加玩家操作消耗塞尔豆的扣费逻辑(如宠物治疗、技能设置等) 此变更提升了代码简洁性和一致性,并增强了业务逻辑的准确性。 ```
This commit is contained in:
@@ -39,7 +39,7 @@ var (
|
||||
MapConfig Maps //地图配置
|
||||
// ItemsConfig Items //物品配置
|
||||
// EffectArgsConfig EffectArg //arg参数
|
||||
TalkConfig TalkRoot //任务配置
|
||||
//TalkConfig TalkRoot //任务配置
|
||||
// //Monster MonsterRoot //野怪配置
|
||||
MonsterMap map[int]TMapConfig
|
||||
//Skill MovesTbl //技能配置
|
||||
@@ -71,7 +71,7 @@ func Initfile() {
|
||||
|
||||
})
|
||||
|
||||
TalkConfig = getXml[TalkRoot](path + "talk.xml")
|
||||
//TalkConfig = getXml[TalkRoot](path + "talk.xml")
|
||||
|
||||
MonsterMap = utils.ToMap(getXml[MonsterRoot](path+"地图配置野怪.xml").Maps, func(m TMapConfig) int {
|
||||
return m.ID
|
||||
|
||||
@@ -186,8 +186,8 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
EXP: exp * 2,
|
||||
}
|
||||
if refpet.Item != 0 {
|
||||
|
||||
items.ItemList = c.ItemAdd(model.ItemInfo{
|
||||
c.ItemAdd(refpet.Item, uint32(grand.Intn(2)+1))
|
||||
items.ItemList = append(items.ItemList, model.ItemInfo{
|
||||
ItemId: refpet.Item,
|
||||
ItemCnt: uint32(grand.Intn(2) + 1),
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@@ -15,8 +14,8 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
tt, ok := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if ok && tt.Price != 0 && c.UseCoins(data.Count*uint32(tt.Price)) {
|
||||
|
||||
r := c.ItemAdd(model.ItemInfo{ItemId: data.ItemId, ItemCnt: data.Count})
|
||||
if len(r) != 0 {
|
||||
r := c.ItemAdd(data.ItemId, data.Count)
|
||||
if r {
|
||||
return &item.BuyOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Level: 1,
|
||||
@@ -25,6 +24,7 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
}, 0
|
||||
}
|
||||
//购买失败,返还豆子
|
||||
|
||||
c.Info.Coins += data.Count * uint32(tt.Price)
|
||||
}
|
||||
|
||||
@@ -34,22 +34,22 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
||||
var rrr []model.ItemInfo
|
||||
|
||||
for _, v := range data.ItemIds {
|
||||
_, ok := xmlres.ItemsMAP[int(v)]
|
||||
iteminfo, ok := xmlres.ItemsMAP[int(v)]
|
||||
|
||||
if ok {
|
||||
rrr = append(rrr, model.ItemInfo{ItemId: uint32(v), ItemCnt: 1})
|
||||
if !c.UseCoins(uint32(iteminfo.Price)) {
|
||||
break
|
||||
}
|
||||
if c.ItemAdd(v, 1) {
|
||||
c.Info.Coins -= uint32(iteminfo.Price)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
r := c.ItemAdd(rrr...)
|
||||
if len(r) != 0 {
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
@@ -57,22 +57,25 @@ func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (
|
||||
}
|
||||
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
||||
r := xmlres.GoldProductMap[int(data.ProductID)]
|
||||
|
||||
if !c.UseGold(uint32(data.Count) * uint32(gconv.Uint32(r.Price)*100)) {
|
||||
usegold := uint32(data.Count) * uint32(gconv.Uint32(r.Price)*100)
|
||||
if !c.UseGold(usegold) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
r1 := c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
|
||||
isbuycot := len(r1)
|
||||
|
||||
usegold := uint32(uint32(len(r1))) * uint32(gconv.Uint32(r.Price)*100)
|
||||
c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold)
|
||||
|
||||
isbuycot := c.ItemAdd(uint32(gconv.Uint32(r.ItemID)), uint32(data.Count))
|
||||
if isbuycot {
|
||||
c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold)
|
||||
result = &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
PayGold: usegold,
|
||||
Reserved: 0,
|
||||
}
|
||||
}
|
||||
result = &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
PayGold: uint32(isbuycot) * uint32(gconv.Uint32(r.Price)),
|
||||
PayGold: 0,
|
||||
Reserved: 0,
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
@@ -62,5 +62,6 @@ func (h *Controller) PlayerPetCure(data *nono.PetCureInboundInfo, c *player.Play
|
||||
c.Info.PetList[i].Cure()
|
||||
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (re
|
||||
if !c.UseCoins(100) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
|
||||
c.Info.Coins -= 50
|
||||
_, onpet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
@@ -42,6 +42,7 @@ func (h Controller) Skill_Sort(data *pet.C2S_Skill_Sort, c *player.Player) (resu
|
||||
if !c.UseCoins(100) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
_, onpet, ok := c.FindPet(data.CapTm)
|
||||
if ok {
|
||||
var newskill []model.SkillInfo
|
||||
|
||||
@@ -1,72 +1,54 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
dict "blazing/modules/dict/service"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &item.TalkCountOutboundInfo{}
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
|
||||
tt, ok := t[data.ID]
|
||||
if ok {
|
||||
result.GiftCount = tt
|
||||
}
|
||||
return false
|
||||
})
|
||||
cid, ok := c.Service.Talk.Cheak(c.Info.MapID, int(data.ID))
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrResourceUnavailable
|
||||
}
|
||||
result.GiftCount = uint32(cid)
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
var talkcacche = make(map[string]uint32)
|
||||
//var talkcacche = make(map[string]uint32)
|
||||
|
||||
func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) (result *item.DayTalkInfo, err errorcode.ErrorCode) {
|
||||
result = &item.DayTalkInfo{}
|
||||
result.OutList = make([]item.CateInfo, 0)
|
||||
for _, te := range xmlres.TalkConfig.Energies {
|
||||
if te.MapID == uint64(c.Info.MapID) && te.Type == uint64(data.ID) { //
|
||||
|
||||
_, ok := talkcacche[te.Name]
|
||||
if !ok {
|
||||
for _, v := range xmlres.ItemsMAP {
|
||||
if v.Name == te.Name {
|
||||
talkcacche[te.Name] = uint32(v.ID)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
randomNum := grand.Intn(10) + 1
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
if t == nil {
|
||||
t = make(map[uint32]uint32)
|
||||
|
||||
}
|
||||
_, ok := t[data.ID]
|
||||
if !ok {
|
||||
t[data.ID] = 0
|
||||
}
|
||||
|
||||
t[data.ID] += 1
|
||||
if t[data.ID] < uint32(te.CollectCnt) {
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: uint32(talkcacche[te.Name]), Count: uint32(randomNum)})
|
||||
c.ItemAdd(model.ItemInfo{ItemId: uint32(talkcacche[te.Name]), ItemCnt: uint32(randomNum)})
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
_, ok := c.Service.Talk.Cheak(c.Info.MapID, int(data.ID))
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrResourceUnavailable
|
||||
}
|
||||
//更新次数
|
||||
config := service.TalkConfigServiceS.GetCache(int(data.ID))
|
||||
|
||||
for _, v := range config {
|
||||
count := grand.N(int(v.ItemMinCount), int(v.ItemMaxCount))
|
||||
|
||||
r := dict.DictInfoServiceS.DataID("fusion")
|
||||
trueitemid := gconv.Uint32(r[gconv.Uint32(v.ItemID)].Remark)
|
||||
ret := c.ItemAdd(trueitemid, uint32(count))
|
||||
if ret {
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: trueitemid, Count: uint32(count)})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
c.Service.Talk.Update(int(data.ID))
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/task"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -74,7 +72,6 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
|
||||
if tt == nil {
|
||||
return result, 0 //通过PUB/SUB回包
|
||||
}
|
||||
result.ItemList = tt.ItemList
|
||||
|
||||
if tt.PetTypeId != 0 {
|
||||
r := model.GenPetInfo(int(tt.PetTypeId), 31, -1, 0, 0, 50)
|
||||
@@ -84,9 +81,13 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
|
||||
result.CaptureTime = r.CatchTime //这个写到后面,方便捕捉时间被修改后造成的时间不对问题
|
||||
}
|
||||
|
||||
ret := c.ItemAdd(result.ItemList...) //获取成功的条目
|
||||
for _, v := range tt.ItemList {
|
||||
ret := c.ItemAdd(v.ItemId, v.ItemCnt) //获取成功的条目
|
||||
if ret {
|
||||
result.ItemList = append(result.ItemList, v)
|
||||
}
|
||||
|
||||
copier.CopyWithOption(&result.ItemList, &ret, copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
||||
}
|
||||
|
||||
return result, 0 //通过PUB/SUB回包
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
|
||||
if !c.UseCoins(200) { //如果花不了200,直接返回
|
||||
return
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
c.Info.Color = data.Color
|
||||
c.Info.Texture = 0
|
||||
result = &user.ChangeColorOutboundInfo{
|
||||
@@ -82,6 +83,7 @@ func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *pl
|
||||
if !c.UseCoins(200) { //如果花不了200,直接返回
|
||||
return
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
c.Info.Texture = data.Id
|
||||
c.Info.Color = data.Color
|
||||
result = &user.ChangeDoodleOutboundInfo{
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"blazing/modules/base/service"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
blservice "blazing/modules/blazing/service"
|
||||
"context"
|
||||
@@ -84,7 +83,7 @@ func (p *Player) UseCoins(t uint32) bool {
|
||||
if p.Info.Coins < t {
|
||||
return false
|
||||
}
|
||||
p.Info.Coins = p.Info.Coins - t
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
@@ -282,56 +281,50 @@ func replaceOneNumber(original [3]int) ([3]int, int, int) {
|
||||
}
|
||||
|
||||
// 添加物品 返回成功添加的物品
|
||||
func (p *Player) ItemAdd(t ...model.ItemInfo) (result []model.ItemInfo) {
|
||||
var ttt []model.ItemInfo
|
||||
for _, v := range t {
|
||||
func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) {
|
||||
|
||||
switch v.ItemId {
|
||||
case 1: //塞尔豆
|
||||
p.Info.Coins = p.Info.Coins + v.ItemCnt
|
||||
switch ItemId {
|
||||
case 1: //塞尔豆
|
||||
p.Info.Coins = p.Info.Coins + ItemCnt
|
||||
return true
|
||||
case 3: //累计经验
|
||||
p.Info.ExpPool = p.Info.ExpPool + ItemCnt
|
||||
return true
|
||||
|
||||
case 3: //累计经验
|
||||
p.Info.ExpPool = p.Info.ExpPool + v.ItemCnt
|
||||
case 5: //金豆ItemAdd
|
||||
p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+ItemCnt*100))
|
||||
return true
|
||||
|
||||
case 5: //金豆ItemAdd
|
||||
p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+v.ItemCnt*100))
|
||||
|
||||
default:
|
||||
ttt = append(ttt, v)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, v := range ttt {
|
||||
itemx, ok := xmlres.ItemsMAP[int(v.ItemId)]
|
||||
default:
|
||||
itemx, ok := xmlres.ItemsMAP[int(ItemId)]
|
||||
if !ok {
|
||||
cool.Loger.Error(context.TODO(), "物品不存在", v.ItemId)
|
||||
cool.Loger.Error(context.TODO(), "物品不存在", ItemId)
|
||||
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
continue
|
||||
return false
|
||||
|
||||
}
|
||||
if itemx.Max == 0 {
|
||||
itemx.Max = 1
|
||||
}
|
||||
|
||||
if p.Service.Item.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) {
|
||||
if p.Service.Item.CheakItem(ItemId)+ItemCnt > uint32(itemx.Max) {
|
||||
|
||||
println(p.Info.UserID, "物品超过拥有最大限制", v.ItemId)
|
||||
println(p.Info.UserID, "物品超过拥有最大限制", ItemId)
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrTooManyOfItem)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
continue
|
||||
return false
|
||||
}
|
||||
p.Service.Item.AddItem(v.ItemId, v.ItemCnt)
|
||||
result = append(result, v)
|
||||
|
||||
p.Service.Item.AddItem(ItemId, ItemCnt)
|
||||
return true
|
||||
}
|
||||
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
func (player1 *Player) Kick() {
|
||||
|
||||
@@ -57,16 +57,16 @@ func (*Talk) GroupName() string {
|
||||
// }
|
||||
// }
|
||||
|
||||
// ResourceConfig 资源配置信息(对应XML中的配置)
|
||||
type ResourceConfig struct {
|
||||
Type uint32 `json:"type"` // 资源类型ID
|
||||
MapID uint32 `json:"map_id"` // 所在地图ID
|
||||
Name string `json:"name"` // 资源名称
|
||||
CollectType string `json:"collect_type"` // 采集类型
|
||||
MaxDailyCnt uint32 `json:"max_daily_cnt"` // 每日最大采集次数
|
||||
Unit string `json:"unit"` // 单位
|
||||
Dir uint32 `json:"dir"` // 方向
|
||||
}
|
||||
// // ResourceConfig 资源配置信息(对应XML中的配置)
|
||||
// type ResourceConfig struct {
|
||||
// Type uint32 `json:"type"` // 资源类型ID
|
||||
// MapID uint32 `json:"map_id"` // 所在地图ID
|
||||
// Name string `json:"name"` // 资源名称
|
||||
// CollectType string `json:"collect_type"` // 采集类型
|
||||
// MaxDailyCnt uint32 `json:"max_daily_cnt"` // 每日最大采集次数
|
||||
// Unit string `json:"unit"` // 单位
|
||||
// Dir uint32 `json:"dir"` // 方向
|
||||
// }
|
||||
|
||||
// 初始化创建表
|
||||
func init() {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
dictmodel "blazing/modules/dict/model"
|
||||
"blazing/modules/dict/service"
|
||||
"context"
|
||||
"strings"
|
||||
@@ -38,11 +36,8 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
|
||||
cacheKey := strings.Join(gconv.Strings(Material1[:]), ":")
|
||||
println(cacheKey, "获取融合id")
|
||||
fusions := service.DictInfoServiceS.DataRemark("fusion")
|
||||
|
||||
fusions := utils.ToMap(service.NewDictInfoService().DataOne("fusion"), func(t dictmodel.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.Remark) //物品id转id
|
||||
})
|
||||
for _, v := range Material1 {
|
||||
_, ok := fusions[v]
|
||||
if !ok {
|
||||
@@ -70,15 +65,13 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
return effect, nil
|
||||
}, 0)
|
||||
|
||||
effect2s := utils.ToMap(service.NewDictInfoService().DataOne("effect"), func(t dictmodel.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.ID)
|
||||
})
|
||||
effect2s := service.DictInfoServiceS.DataID("effect")
|
||||
effect := ret.Interface().(*model.PetFusionMaterial)
|
||||
|
||||
if err != nil {
|
||||
r := grand.Intn(len(service.NewDictInfoService().DataOne("effect")) - 1)
|
||||
return gconv.Uint32(service.NewDictInfoService().DataOne("effect")[r].Remark)
|
||||
for _, v := range effect2s {
|
||||
return gconv.Uint32(v.Remark)
|
||||
}
|
||||
|
||||
}
|
||||
r := grand.Intn(4)
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/dict/service"
|
||||
)
|
||||
|
||||
type TalkService struct {
|
||||
@@ -22,23 +23,34 @@ func NewTalkService(id uint32) *TalkService {
|
||||
|
||||
//实现挖矿次数确认
|
||||
|
||||
func (s *TalkService) Cheak(flag int) bool {
|
||||
func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
|
||||
|
||||
m1 := s.GModel(s.Model)
|
||||
|
||||
var talks *model.Talk
|
||||
m1.Where("talk_id", flag).Scan(&talks)
|
||||
if talks == nil {
|
||||
return true //如果表里没有记载数据,那么就可以直接挖矿
|
||||
return 0, true //如果表里没有记载数据,那么就可以直接挖矿
|
||||
}
|
||||
|
||||
//因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录
|
||||
if !IsToday(talks.UpdateTime) {
|
||||
|
||||
talks.Count = 0
|
||||
m1.Save(talks)
|
||||
return true
|
||||
return int(talks.Count), true
|
||||
}
|
||||
|
||||
maps := service.DictInfoServiceS.DataRemark("mapid")
|
||||
|
||||
if uint32(maps[mapid].ID) != TalkConfigServiceS.GetCache(flag)[0].MapID {
|
||||
return 0, false //没在地图
|
||||
}
|
||||
if talks.Count >= TalkConfigServiceS.GetCache(flag)[0].DailyCollectCount {
|
||||
return 0, false
|
||||
}
|
||||
return int(talks.Count), true //int(config.MaxDailyCnt - talks.Count)
|
||||
|
||||
}
|
||||
func (s *TalkService) Update(flag int) {
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ type TalkConfigService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
var TalkConfigServiceS = NewTalkConfigService()
|
||||
|
||||
func NewTalkConfigService() *TalkConfigService {
|
||||
return &TalkConfigService{
|
||||
|
||||
@@ -19,3 +21,10 @@ func NewTalkConfigService() *TalkConfigService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig {
|
||||
var config []model.MineralCollectionConfig
|
||||
cool.DBM(s.Model).Where("type", flag).Scan(&config)
|
||||
return config
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func init() {
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/dict/info",
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewDictInfoService(),
|
||||
Service: service.DictInfoServiceS,
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
@@ -34,7 +34,7 @@ type DictInfoDataReq struct {
|
||||
|
||||
// Data 方法 获得字典数据
|
||||
func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) {
|
||||
service := service.NewDictInfoService()
|
||||
service := service.DictInfoServiceS
|
||||
data, err := service.Data(ctx, req.Types)
|
||||
res = cool.Ok(data)
|
||||
return
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"blazing/common/utils"
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/modules/dict/model"
|
||||
@@ -54,7 +55,7 @@ func (s *DictInfoService) Data(ctx context.Context, types []string) (data interf
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *DictInfoService) DataOne(types string) (data []model.DictInfo) {
|
||||
func (s *DictInfoService) DataRemark(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
@@ -72,10 +73,42 @@ func (s *DictInfoService) DataOne(types string) (data []model.DictInfo) {
|
||||
m := cool.DBM(dictInfoModel)
|
||||
var ress []model.DictInfo
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
return ress, nil
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.Remark) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
return ret.Interface().([]model.DictInfo)
|
||||
return ret.Interface().(map[uint32]model.DictInfo)
|
||||
|
||||
}
|
||||
func (s *DictInfoService) DataID(types string) (data map[uint32]model.DictInfo) {
|
||||
var (
|
||||
dictInfoModel = model.NewDictInfo()
|
||||
dictTypeModel = model.NewDictType()
|
||||
)
|
||||
ret, _ := cacheDict.GetOrSetFunc(context.Background(), types, func(context.Context) (interface{}, error) {
|
||||
// 如果typeData为空, 则返回空
|
||||
var ty *model.DictType
|
||||
mType := cool.DBM(dictTypeModel)
|
||||
mType.Where("key in (?)", types).Scan(&ty)
|
||||
|
||||
// 如果typeData为空, 则返回空
|
||||
if ty == nil {
|
||||
return []model.DictInfo{}, nil
|
||||
}
|
||||
m := cool.DBM(dictInfoModel)
|
||||
var ress []model.DictInfo
|
||||
m.Where("typeId", ty.ID).Scan(&ress)
|
||||
fusions := utils.ToMap(ress, func(t model.DictInfo) uint32 {
|
||||
|
||||
return gconv.Uint32(t.ID) //物品id转id
|
||||
})
|
||||
return fusions, nil
|
||||
}, 0)
|
||||
|
||||
return ret.Interface().(map[uint32]model.DictInfo)
|
||||
|
||||
}
|
||||
|
||||
@@ -122,6 +155,8 @@ func delChildDict(id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var DictInfoServiceS = NewDictInfoService()
|
||||
|
||||
// NewDictInfoService 初始化 DictInfoService
|
||||
func NewDictInfoService() *DictInfoService {
|
||||
return &DictInfoService{
|
||||
|
||||
Reference in New Issue
Block a user