94 lines
2.3 KiB
Go
94 lines
2.3 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
|
|
confs []*cfg.GameWorldDealData
|
|
need []*cfg.Gameatn
|
|
money []*cfg.Gameatn
|
|
award []*pb.UserAtno
|
|
err error
|
|
)
|
|
if errdata = this.ExchangeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if confs, 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
|
|
}
|
|
|
|
for i, v := range req.Eid {
|
|
if info.Exchange[v] >= confs[i].Buy {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
need = append(need, confs[i].Item...)
|
|
money = append(money, confs[i].Money...)
|
|
|
|
info.Exchange[v]++
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, money, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if errdata, award = this.module.DispenseAtno(session, need, true); errdata != nil {
|
|
return
|
|
}
|
|
// for _, v := range need {
|
|
// award = append(award, &pb.UserAssets{
|
|
// A: v.A,
|
|
// T: v.T,
|
|
// N: v.N,
|
|
// })
|
|
// }
|
|
|
|
if err = this.module.modelwtask.Change(session.GetUserId(), map[string]interface{}{
|
|
"exchange": info.Exchange,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "exchange", &pb.WTaskExchangeResp{Eid: req.Eid, Award: award})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), "WTaskExchangeReq", award)
|
|
})
|
|
return
|
|
}
|