package smithy import ( "errors" "go_dreamfactory/comm" "go_dreamfactory/pb" ) // 贸易 func (this *apiComp) SellCheck(session comm.IUserSession, req *pb.SmithySellReq) (errdata *pb.ErrorData) { if req.CustomerId == 0 || len(req.EquipIds) == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } func (this *apiComp) Sell(session comm.IUserSession, req *pb.SmithySellReq) (errdata *pb.ErrorData) { if errdata = this.SellCheck(session, req); errdata != nil { return } //校验customer类型,因为有的类型是不能进入交易逻辑的 this.module.ModuleEquipment.RecycleEquipments(session, req.EquipIds, this.module.modelStove.StoveToolsSellUp(session.GetUserId())) cus, err := this.module.modelTrade.updateCustomer(session.GetUserId(), req.CustomerId) if err != nil { var customErr = new(comm.CustomError) if errors.As(err, &customErr) { this.module.Debug(customErr.Code.String()) } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } } conf, err := this.module.configure.GetSmithyCustomerConf(req.CustomerId) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } // 发奖励 this.module.DispenseRes(session, conf.Reword, true) rsp := &pb.SmithySellResp{ CustomerId: req.CustomerId, EquipIds: req.EquipIds, } if cus != nil { rsp.Customers = cus.Customers } else { rsp.Customers = []*pb.CustomerInfo{} } session.SendMsg(string(this.module.GetType()), "sell", rsp) return }