95 lines
2.8 KiB
Go
95 lines
2.8 KiB
Go
package caravan
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"go_dreamfactory/utils"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
"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{},
|
|
Oldprice: map[int32]int32{},
|
|
}
|
|
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
|
|
// 创建一条数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Resettime = utils.GetZeroTime(configure.Now().Unix()) // 设置起始刷新时间
|
|
result.Citystime = 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)
|
|
}
|
|
|
|
func (this *modelCaravan) GetRankListData(rankNum int32, uid string) (list []*pb.CaravanRankData, rankid int32) {
|
|
var ipos int32
|
|
if _data, err := this.DBModel.DB.Find(comm.TableUser, bson.M{}, options.Find().SetSort(bson.M{"merchantmoney": -1}).SetLimit(int64(rankNum))); err == nil {
|
|
for _data.Next(context.TODO()) {
|
|
temp := &pb.DBUser{}
|
|
if err = _data.Decode(temp); err == nil {
|
|
ipos++
|
|
list = append(list, &pb.CaravanRankData{
|
|
Uid: temp.Uid,
|
|
Name: temp.Name,
|
|
Userlv: temp.Lv,
|
|
Avatar: temp.Avatar,
|
|
Rank: ipos,
|
|
Merchantmoney: temp.Merchantmoney,
|
|
CaravanLv: temp.CaravanLv,
|
|
})
|
|
if temp.Uid == uid {
|
|
rankid = ipos
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
}
|