59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package smithy
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/pb"
|
||
|
||
"google.golang.org/protobuf/proto"
|
||
)
|
||
|
||
// 贸易
|
||
|
||
func (this *apiComp) SellCheck(session comm.IUserSession, req *pb.SmithySellReq) (code pb.ErrorCode) {
|
||
if req.CustomerId == 0 || len(req.EquipIds) == 0 {
|
||
code = pb.ErrorCode_ReqParameterError
|
||
}
|
||
return
|
||
}
|
||
|
||
func (this *apiComp) Sell(session comm.IUserSession, req *pb.SmithySellReq) (code pb.ErrorCode, data proto.Message) {
|
||
if code = this.SellCheck(session, req); code != pb.ErrorCode_Success {
|
||
return
|
||
}
|
||
|
||
//校验customer类型,因为有的类型是不能进入交易逻辑的
|
||
//TODO
|
||
|
||
// cus, err := this.module.modelTrade.getDBCustomer(session.GetUserId())
|
||
// if err != nil {
|
||
// code = pb.ErrorCode_DBError
|
||
// return
|
||
// }
|
||
|
||
|
||
if imodule, err := this.service.GetModule(comm.ModuleEquipment); err == nil {
|
||
if iequip, ok := imodule.(comm.IEquipment); ok {
|
||
iequip.RecycleEquipments(session, req.EquipIds, this.module.modelStove.StoveToolsSellUp(session.GetUserId()))
|
||
}
|
||
}
|
||
|
||
_ = this.module.modelTrade.updateCustomer(session.GetUserId(), req.CustomerId)
|
||
|
||
conf := this.module.configure.GetSmithyCustomerConf(req.CustomerId)
|
||
if conf == nil {
|
||
code = pb.ErrorCode_ConfigNoFound
|
||
return
|
||
}
|
||
|
||
// 发奖励
|
||
this.module.DispenseRes(session, conf.Reword, true)
|
||
|
||
rsp := &pb.SmithySellResp{
|
||
CustomerId: req.CustomerId,
|
||
EquipIds: req.EquipIds,
|
||
}
|
||
|
||
session.SendMsg(string(this.module.GetType()), "sell", rsp)
|
||
return
|
||
}
|