package smithy import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) CreateOrderCheck(session comm.IUserSession, req *pb.SmithyCreateOrderReq) (code pb.ErrorCode) { if len(req.Order) == 0 { code = pb.ErrorCode_ReqParameterError return } return } func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.SmithyCreateOrderReq) (code pb.ErrorCode, data proto.Message) { var ( res []*cfg.Gameatn costTime int32 privilegeAddItme int32 // 特权额外增加的时间 ) code = this.CreateOrderCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } _smithy, err := this.module.modelSmithy.getSmithyList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } _skillCfg := this.module.configure.GetSmithyStoveConfigData(_smithy.StoveLv) needTime := _skillCfg.Time // 订单需要的时间 for _, order := range req.Order { if order.Count == 0 { continue } costTime += needTime * order.Count } if _smithy.Ctime == 0 { _smithy.Ctime = configure.Now().Unix() } // if !utils.IsToday(_smithy.Ctime) { // _smithy.Ctime = configure.Now().Unix() // _smithy.OrderCostTime = 0 // } _smithy.Orders = append(_smithy.Orders, req.Order...) // 直接追加订单数据 if _smithy.Clang == nil || (_smithy.Clang != nil && _smithy.Clang.ETime == 0) { for _, v := range _smithy.Orders { if v.Count > 0 { v.Count-- // 获取生产时间 _smithy.Clang = &pb.Clang{ DeskType: v.DeskType, ETime: configure.Now().Unix() + int64(needTime), STime: configure.Now().Unix(), } break } } } // 計算耗時 for _, v := range _smithy.Orders { if v.Count > 0 { v.NeedTime = needTime * v.Count } if skillLv, ok := _smithy.Skill[v.DeskType]; ok { conf := this.module.configure.GetSmithyConfigData(v.DeskType, skillLv) res = append(res, conf.Orderneed...) // 订单消耗 } } if _smithy.Clang != nil && _smithy.Clang.ETime == 0 { _smithy.Clang = nil } // 获取总的下单时长 cfgCom := this.module.configure.GetGlobalConf() if cfgCom == nil { return } _smithy.OrderCostTime += costTime privilegeAddItme = this.module.ModulePrivilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType10) if cfgCom.SmithyMaxtime+privilegeAddItme < _smithy.OrderCostTime { // 大于总时长是不允许的 code = pb.ErrorCode_GourmetMoreOrderTime return } if code = this.module.ConsumeRes(session, res, true); code != pb.ErrorCode_Success { // 消耗校验 return } // 校验通过 写数据 mapData := make(map[string]interface{}, 0) sz := make([]*pb.OrderClang, 0) for _, v := range _smithy.Orders { if v.Count != 0 { sz = append(sz, v) } } _smithy.Orders = sz mapData["orders"] = _smithy.Orders mapData["orderCostTime"] = _smithy.OrderCostTime mapData["clang"] = _smithy.Clang // 正在做的 mapData["ctime"] = _smithy.Ctime code = this.module.ModifySmithyData(session.GetUserId(), mapData) iTotal := 0 for _, v := range req.Order { iTotal += int(v.Count) } this.module.ModuleRtask.SendToRtask(session, comm.Rtype148, int32(iTotal)) session.SendMsg(string(this.module.GetType()), SmithyCreateOrderResp, &pb.SmithyCreateOrderResp{Data: _smithy}) return }