package caravan import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/utils" ) type Caravan struct { modules.ModuleBase modelCaravan *modelCaravan api *apiComp configure *configureComp } func NewModule() core.IModule { return &Caravan{} } func (this *Caravan) GetType() core.M_Modules { return comm.ModuleTroll } func (this *Caravan) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) return } func (this *Caravan) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelCaravan = this.RegisterComp(new(modelCaravan)).(*modelCaravan) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } // 接口信息 修改数据 func (this *Caravan) ModifyCaravanData(uid string, data map[string]interface{}) (code pb.ErrorCode) { err := this.modelCaravan.modifyCaravanDataByObjId(uid, data) if err != nil { code = pb.ErrorCode_DBError } return } // 初始化城市信息 func (this *Caravan) InitCaravanCityData(uid string, data *pb.DBCaravan) { list := this.configure.GetAllCaravanCity() data.City = make(map[int32]*pb.CityGoods, 0) for _, v := range list { city := &pb.CityGoods{ Like: []int32{}, Unlike: []int32{}, } if v.Citytype == 1 { // city.Like = append(city.Like, v.Special...) city.Unlike = append(city.Like, v.Exspecial...) } else { // 不喜欢的 随机 citytypenum 个 if len(v.Special) > int(v.Citytypenum) { ids := utils.RandomNumbers(0, len(v.Special), int(v.Citytypenum)) for _, id := range ids { city.Like = append(city.Like, v.Special[id]) } } else { city.Like = append(city.Like, v.Special...) } if len(v.Exspecial) > int(v.Exspecialnum) { ids := utils.RandomNumbers(0, len(v.Exspecial), int(v.Exspecialnum)) for _, id := range ids { city.Like = append(city.Like, v.Exspecial[id]) } } else { city.Unlike = append(city.Like, v.Exspecial...) } } data.City[v.Id] = city } } // 初始化货物信息 func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { items := this.configure.GetAllCaravanItem() data.Goods = make(map[int32]*pb.Goods, 0) for _, v := range items { goods := &pb.Goods{ Count: 0, // 货物数量 Period: 0, // 变动周期 CurPeriod: 1, // 当前变动周期 Price: 0, // 当前价格 Time: configure.Now().Unix(), // 刷新时间 } if len(v.Changeperiod) != 2 { continue } goods.Period = comm.GetRandNum(v.Changeperiod[0], v.Changeperiod[1]) goods.Price = v.Goodsprice data.Goods[v.Id] = goods } }