61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
package caravan
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelCaravan struct {
|
|
modules.MCompModel
|
|
module *Caravan
|
|
}
|
|
|
|
func (this *modelCaravan) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableCaravan)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Caravan)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err error) {
|
|
result = &pb.DBCaravan{
|
|
Id: "",
|
|
Uid: uid,
|
|
UseCount: 0,
|
|
Items: map[int32]*pb.BagInfo{},
|
|
Goods: map[int32]*pb.Goods{},
|
|
City: map[int32]*pb.CityInfo{},
|
|
}
|
|
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
|
|
// 创建一条数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Resettime = configure.Now().Unix() // 设置起始刷新时间
|
|
result.Lv = 1
|
|
result.Curcity = this.module.configure.GetCaravanInitCity() // 获取默认城市
|
|
if conf := this.module.configure.GetCaravanLv(1); conf != nil {
|
|
result.Baglimit = conf.Bagtop
|
|
}
|
|
this.module.InitCaravanCityData(uid, result) // 初始1级
|
|
this.module.InitCaravanItemData(uid, result)
|
|
this.Add(uid, result)
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
func (this *modelCaravan) modifyCaravanDataByObjId(uid string, data map[string]interface{}) error {
|
|
return this.Change(uid, data)
|
|
}
|