87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package pay
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
"time"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) GetActivityCheck(session comm.IUserSession, req *pb.PayGetActivityReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) GetActivity(session comm.IUserSession, req *pb.PayGetActivityReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
activitys *pb.DBActivityGiftbag
|
|
info *pb.ActivityGiftbagItem
|
|
conf *cfg.GamePayGiftpackData
|
|
activity *pb.DBHuodong
|
|
err error
|
|
ok bool
|
|
)
|
|
if errdata = this.GetActivityCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if activitys, err = this.module.modelActivity.getUserActivitys(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if activity, ok = this.module.modelActivity.getopentime(req.Atype); !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_WarorderNoOpen,
|
|
Title: pb.ErrorCode_WarorderNoOpen.ToString(),
|
|
Message: fmt.Sprintf("Activity:%d no open", req.Atype),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info, ok = activitys.Activitys[req.Atype]; !ok {
|
|
info = &pb.ActivityGiftbagItem{
|
|
Items: make(map[int32]*pb.PayActivityGiftbagItem),
|
|
}
|
|
activitys.Activitys[req.Atype] = info
|
|
}
|
|
|
|
if info.Opentime != activity.Stime {
|
|
info.Opentime = activity.Stime
|
|
|
|
for _, v := range info.Items {
|
|
if conf, err = this.module.configure.getPayGiftpackeData(v.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if configure.Now().Sub(time.Unix(v.Lastrefresh, 0)).Hours() > 24*float64(conf.Refreshtime) {
|
|
v.Buyunm = 0
|
|
v.Lastrefresh = configure.Now().Unix()
|
|
}
|
|
}
|
|
}
|
|
info.Days = int32(utils.DiffDays(configure.Now().Unix(), info.Opentime)) + 1
|
|
if err = this.module.modelActivity.updateActivitys(session.GetUserId(), activitys); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "getactivity", &pb.PayGetActivityResp{Info: info})
|
|
return
|
|
}
|