go_dreamfactory/modules/caravan/api_getlist.go
2023-05-26 16:24:47 +08:00

44 lines
1.3 KiB
Go

package caravan
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
)
//参数校验
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.CaravanGetListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListReq) (code pb.ErrorCode, data *pb.ErrorData) {
var (
resp *pb.CaravanGetListResp
)
resp = &pb.CaravanGetListResp{}
if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelCaravan.getCaravanList(session.GetUserId())
if configure.Now().Unix() >= list.Resettime || err == mgo.MongodbNil { // 初始化门票和虚拟币
if conf, err := this.module.configure.GetCaravanLv(list.Lv); err == nil {
this.module.ModuleItems.CleanItemById(session, conf.Tickettop.T) // 清理之前的门票数据
} else {
data.Message = err.Error()
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.InitCaravanTicket(session, list.Lv); code != pb.ErrorCode_Success {
return
}
}
// 刷新城市货物信息
this.module.refreshCaravanCityInfo(session.GetUserId(), list)
resp.Data = list
session.SendMsg(string(this.module.GetType()), "getlist", resp)
return
}