64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package wtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ExchangeCheck(session comm.IUserSession, req *pb.WTaskExchangeReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) Exchange(session comm.IUserSession, req *pb.WTaskExchangeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
info *pb.DBWTask
|
|
conf *cfg.GameWorldDealData
|
|
err error
|
|
)
|
|
if errdata = this.ExchangeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getGameWorldDeal(req.Eid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, err = this.module.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info.Exchange[req.Eid] >= conf.Buy {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, conf.Item, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if errdata = this.module.DispenseRes(session, conf.Money, true); errdata != nil {
|
|
return
|
|
}
|
|
info.Exchange[req.Eid]++
|
|
session.SendMsg(string(this.module.GetType()), "exchange", &pb.WTaskExchangeReq{Eid: req.Eid})
|
|
return
|
|
}
|