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 == "" || 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 } var ( rewardId int32 atno []*pb.UserAtno ) //校验customer类型,因为有的类型是不能进入交易逻辑的 this.module.ModuleEquipment.RecycleEquipments(session, req.EquipIds, this.module.modelStove.StoveToolsSellUp(session.GetUserId())) cus, rewardId, 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(rewardId) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } // 发奖励 errdata, atno = this.module.DispenseAtno(session, conf.Reword, true) rsp := &pb.SmithySellResp{ CustomerId: req.CustomerId, EquipIds: req.EquipIds, Reward: atno, } if len(cus.Customers) == 0 { rsp.Customers = make(map[string]*pb.CustomerInfo) } else { rsp.Customers = cus.Customers } session.SendMsg(string(this.module.GetType()), "sell", rsp) return }