99 lines
3.1 KiB
Go
99 lines
3.1 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.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[string]*pb.BagInfo{},
|
|
Goods: map[string]*pb.Goods{},
|
|
City: map[int32]*pb.CityInfo{},
|
|
Oldprice: map[string]int32{},
|
|
}
|
|
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {
|
|
// 创建一条数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
// 活动持续时间
|
|
sTime := int64(this.module.ModuleTools.GetGlobalConf().BusinessRewardday * 24 * 3600) // 单位s
|
|
openTime := this.module.service.GetOpentime().Unix() // 获取开服时间
|
|
subTime := configure.Now().Unix() - openTime
|
|
result.Resettime = configure.Now().Unix() - (subTime % sTime) + sTime
|
|
//result.Resettime = +int64(this.module.ModuleTools.GetGlobalConf().BusinessRewardday * 24 * 3600)
|
|
result.Citystime = configure.Now().Unix()
|
|
result.Lv = 1
|
|
result.Curcity = this.module.configure.GetCaravanInitCity() // 获取默认城市
|
|
if conf, err := this.module.configure.GetCaravanLv(result.Lv); err == 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.CaravanRankInfo, 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.CaravanRankInfo{
|
|
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
|
|
}
|