package smithy import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" "time" "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 ) 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 = time.Now().Unix() } _smithy.Orders = append(_smithy.Orders, req.Order...) // 直接追加订单数据 //_smithy.OrderCostTime += costTime if _smithy.Clang == nil || (_smithy.Clang != nil && _smithy.Clang.ETime == 0) { if !utils.IsToday(_smithy.Ctime) { _smithy.Ctime = time.Now().Unix() _smithy.OrderCostTime = 0 } for _, v := range _smithy.Orders { if v.Count > 0 { v.Count-- // 获取生产时间 _smithy.Clang = &pb.Clang{ DeskType: v.DeskType, ETime: time.Now().Unix() + int64(needTime), STime: time.Now().Unix(), } break } } } // 計算耗時 for _, v := range _smithy.Orders { if v.Count > 0 { v.NeedTime = needTime * v.Count } } if _smithy.Clang != nil && _smithy.Clang.ETime == 0 { _smithy.Clang = nil } // 获取总的下单时长 cfgCom := this.module.configure.GetGlobalConf() if cfgCom == nil { return } if cfgCom.SmithyMaxtime < _smithy.OrderCostTime+costTime { // 大于总时长是不允许的 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 // 正在做的 code = this.module.ModifySmithyData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), SmithyCreateOrderResp, &pb.SmithyCreateOrderResp{Data: _smithy}) return }