调整任务查询,回调,奖励类型查询
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"server/api/reward/v1"
|
||||
"server/internal/model"
|
||||
"server/internal/service"
|
||||
"server/utility/gamelife"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -22,17 +23,17 @@ func (c *ControllerV1) Callback(ctx context.Context, req *v1.CallbackReq) (res *
|
||||
auth := fromCtx.Header.Get("Custom-Data-Auth")
|
||||
glog.Infof(ctx, fmt.Sprintf("appid:%s,timestamp:%s,nonce:%s,auth:%s", appid, timestamp, nonce, auth))
|
||||
|
||||
data := fmt.Sprintf("%s%s%s%s%d%d%d%s%s%s#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, auth)
|
||||
data := fmt.Sprintf("%s%s%s%s%d%d%d%s%s%s#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, gamelife.GetGamelifeClient(ctx).GetSecret())
|
||||
stateOri := md5.Sum([]byte(data))
|
||||
state := hex.EncodeToString(stateOri[:])
|
||||
myAuth := strings.ToUpper(state)
|
||||
glog.Infof(ctx, fmt.Sprintf("%s,%s,%s,%s,%d,%d,%d,%s,%s,%s,#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, auth))
|
||||
|
||||
glog.Infof(ctx, fmt.Sprintf("myAuth:%s,auth:%s", myAuth, auth))
|
||||
if myAuth != auth {
|
||||
glog.Infof(ctx, fmt.Sprintf("myAuth:%s,auth:%s", myAuth, auth))
|
||||
return &v1.CallbackRes{Errcode: 252151000, OrderId: req.OrderId, Datas: []v1.CallbackData{{PrizeCode: req.OrderId}}}, err
|
||||
}
|
||||
glog.Infof(ctx, fmt.Sprintf("%s,%s,%s,%s,%d,%d,%d,%s,%s,%s,#%s", req.Uid, req.OrderId, req.PrizeChannelId, req.PrizeId, req.PrizeType, req.PrizeSubType, req.Num, appid, timestamp, nonce, auth))
|
||||
|
||||
out, err := service.Reward().CallBack(ctx, &model.RewardCallbackIn{
|
||||
Uid: req.Uid,
|
||||
|
||||
@ -19,6 +19,7 @@ func (c *ControllerV1) GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1
|
||||
UserId: userId,
|
||||
GameId: req.GameId,
|
||||
TaskName: req.TaskName,
|
||||
TaskType: req.TaskType,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
func (c *ControllerV1) GetTaskList(ctx context.Context, req *v1.GetTaskListReq) (res *v1.GetTaskListRes, err error) {
|
||||
|
||||
userId := g.RequestFromCtx(ctx).Get("id").Int64()
|
||||
userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int64()
|
||||
list, err := service.Task().GetTaskList(ctx, &model.GetTaskListV2In{
|
||||
Gid: req.Gid,
|
||||
NetBarAccount: req.NetBarAccount,
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
func (c *ControllerV1) SyncTask(ctx context.Context, req *v1.SyncTaskReq) (res *v1.SyncTaskRes, err error) {
|
||||
go func() {
|
||||
_, err = service.Task().SyncTaskFromGamelife(ctx)
|
||||
_, err = service.Task().SyncTaskFromGamelife(context.Background())
|
||||
}()
|
||||
return &v1.SyncTaskRes{
|
||||
Message: "同步调用成功,等待数据同步,5分钟后刷新",
|
||||
|
||||
@ -29,6 +29,7 @@ type RewardTypesColumns struct {
|
||||
UpdatedAt string // 更新时间
|
||||
DeletedAt string // 软删除时间
|
||||
TencentTypeId string // 腾讯类型 id
|
||||
Source string // 来源1:系统 2:门店
|
||||
}
|
||||
|
||||
// rewardTypesColumns holds the columns for the table reward_types.
|
||||
@ -41,6 +42,7 @@ var rewardTypesColumns = RewardTypesColumns{
|
||||
UpdatedAt: "updated_at",
|
||||
DeletedAt: "deleted_at",
|
||||
TencentTypeId: "tencent_type_id",
|
||||
Source: "source",
|
||||
}
|
||||
|
||||
// NewRewardTypesDao creates and returns a new DAO object for table data access.
|
||||
|
||||
@ -33,6 +33,7 @@ type UserTasksColumns struct {
|
||||
StoreId string // 门店 id
|
||||
TaskName string // 任务名称
|
||||
GameId string // 游戏 id
|
||||
TaskType string // 1: 每日任务 3: 周期任务
|
||||
}
|
||||
|
||||
// userTasksColumns holds the columns for the table user_tasks.
|
||||
@ -49,6 +50,7 @@ var userTasksColumns = UserTasksColumns{
|
||||
StoreId: "store_id",
|
||||
TaskName: "task_name",
|
||||
GameId: "game_id",
|
||||
TaskType: "task_type",
|
||||
}
|
||||
|
||||
// NewUserTasksDao creates and returns a new DAO object for table data access.
|
||||
|
||||
@ -556,6 +556,164 @@ func (s *sReward) OperateTaskReward(ctx context.Context, in *model.OperateTaskRe
|
||||
}
|
||||
|
||||
// CallBack 奖励回调
|
||||
//
|
||||
// func (s *sReward) CallBack(ctx context.Context, in *model.RewardCallbackIn) (out *model.RewardCallbackOut, err error) {
|
||||
// var reward *model.Reward
|
||||
// var res model.RewardCallbackOut
|
||||
// res.OrderId = in.OrderId
|
||||
// res.AppId = in.AppId
|
||||
//
|
||||
// // 查询奖励
|
||||
// err = dao.Rewards.Ctx(ctx).Where(do.Rewards{PrizeId: in.PrizeId}).Scan(&reward)
|
||||
// if err != nil {
|
||||
// res.Errcode = -1
|
||||
// res.Errmsg = "查询奖励异常"
|
||||
// res.Datas = nil
|
||||
// return &res, ecode.Fail.Sub("查询奖励异常")
|
||||
// }
|
||||
//
|
||||
// if reward == nil {
|
||||
// res.Errcode = -1
|
||||
// res.Errmsg = "查询奖励为空"
|
||||
// res.Datas = nil
|
||||
// return &res, ecode.Params.Sub("查询奖励为空")
|
||||
// }
|
||||
//
|
||||
// // 判断是否过期
|
||||
// if reward.ExpireType == 1 {
|
||||
// //时间段过期
|
||||
// if reward.ValidTo.Before(gtime.Now()) {
|
||||
// res.Errcode = consts.BatchOutDate
|
||||
// res.Errmsg = consts.BatchOutDateMSG
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 日
|
||||
// now := time.Now()
|
||||
// // 当天开始时间
|
||||
// start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
// // 当天结束时间
|
||||
// end := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
||||
// // 查先询用户当日已领取
|
||||
// //dailyGetNum, err := dao.Rewards.Ctx(ctx).
|
||||
// // LeftJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id=%s.reward_id", dao.Rewards.Table(), dao.UserTaskRewards.Table())).
|
||||
// // Where(dao.Rewards.Columns().PrizeId, in.PrizeId).
|
||||
// // WhereBetween(dao.UserTaskRewards.Columns().UpdatedAt, start, end).
|
||||
// // Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).Count()
|
||||
// //
|
||||
// //// dailyGetNum, err := dao.Rewards.Ctx(ctx).
|
||||
// //// Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id=%s.reward_id", dao.Rewards.Table(),
|
||||
// //// dao.UserTaskRewards.Table())).InnerJoin(dao.RewardWaters.Table(), fmt.Sprintf("%s.external_order_id = %s.order_id", dao.UserTaskRewards.Table(), dao.RewardWaters.Table())).
|
||||
// //// Where(dao.RewardWaters.Columns().Recvuid, in.Uid).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
// //// WhereBetween(dao.UserTaskRewards.Columns().UpdatedAt, start, end).Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
// //
|
||||
// //if err != nil {
|
||||
// // res.Errcode = -1
|
||||
// // res.Errmsg = "查询用户当日领取数量失败"
|
||||
// // res.Datas = nil
|
||||
// // return &res, ecode.Fail.Sub("查询用户当日领取数量失败")
|
||||
// //}
|
||||
// //
|
||||
// //// 判断是否达到用户日限制
|
||||
// //if int(reward.UserDailyLimit) <= dailyGetNum {
|
||||
// // res.Errcode = consts.UserDayLimit
|
||||
// // res.Errmsg = consts.UserDayLimitMSG
|
||||
// //}
|
||||
// //
|
||||
// //// 查先询用户总共已领取
|
||||
// //dailyTotalNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id=%s.reward_id", dao.Rewards.Table(),
|
||||
// // dao.UserTaskRewards.Table())).InnerJoin(dao.RewardWaters.Table(), fmt.Sprintf("%s.external_order_id = %s.order_id", dao.UserTaskRewards.Table(), dao.RewardWaters.Table())).
|
||||
// // Where(dao.RewardWaters.Columns().Recvuid, in.Uid).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
// // Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
// //
|
||||
// //if err != nil {
|
||||
// // res.Errcode = -1
|
||||
// // res.Errmsg = "查询用户当日总共领取数量失败"
|
||||
// // res.Datas = nil
|
||||
// // return &res, ecode.Fail.Sub("查询用户当日总共领取数量失败")
|
||||
// //}
|
||||
// //// 判断是否达到用户总限制
|
||||
// //if int(reward.UserTotalLimit) <= dailyTotalNum {
|
||||
// // res.Errcode = consts.UserTotalLimit
|
||||
// // res.Errmsg = consts.UserTotalLimitMSG
|
||||
// //}
|
||||
// //
|
||||
// //// 查先询该批次当日已领取
|
||||
// //batchDailyGetNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
// // dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
// // WhereBetween(dao.UserTaskRewards.Columns().UpdatedAt, start, end).Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
// //if err != nil {
|
||||
// // res.Errcode = -1
|
||||
// // res.Errmsg = "查询该批次当日总共领取数量失败"
|
||||
// // res.Datas = nil
|
||||
// // return &res, ecode.Fail.Sub("查询该批次当日总共领取数量失败")
|
||||
// //}
|
||||
// //// 判断是否达到该批次日限制
|
||||
// //if int(reward.DailyTotalLimit) <= batchDailyGetNum {
|
||||
// // res.Errcode = consts.BatchDayLimit
|
||||
// // res.Errmsg = consts.BatchDayLimitMSG
|
||||
// //}
|
||||
// //
|
||||
// //// 查先询该批次总共已领取
|
||||
// //batchTotalGetNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
// // dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
// // Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
// //
|
||||
// //if err != nil {
|
||||
// // res.Errcode = -1
|
||||
// // res.Errmsg = "查询该批次总共领取数量失败"
|
||||
// // res.Datas = nil
|
||||
// // return &res, ecode.Fail.Sub("查询该批次总共领取数量失败")
|
||||
// //}
|
||||
// //// 判断是否达到该批次总共限制
|
||||
// //if int(reward.TotalLimit) <= batchTotalGetNum {
|
||||
// // res.Errcode = consts.BatchTotalLimit
|
||||
// // res.Errmsg = consts.BatchTotalLimitMSG
|
||||
// //}
|
||||
//
|
||||
// _, err = dao.RewardCallback.Ctx(ctx).OmitEmptyData().Insert(do.RewardCallback{
|
||||
// OrderId: in.OrderId,
|
||||
// PrizeId: in.PrizeId,
|
||||
// PrizeType: in.PrizeType,
|
||||
// PrizeSubType: in.PrizeSubType,
|
||||
// Uid: in.Uid,
|
||||
// Num: in.Num,
|
||||
// CustomInfo: in.CustomInfo,
|
||||
// AppId: in.AppId,
|
||||
// })
|
||||
//
|
||||
// if err != nil {
|
||||
// res.Errcode = -1
|
||||
// res.Errmsg = "存储奖励回调数据异常"
|
||||
// res.Datas = nil
|
||||
// return &res, ecode.Fail.Sub("存储奖励回调数据异常")
|
||||
// }
|
||||
//
|
||||
// // 回调成功,组装响应参数
|
||||
// var userTaskReward []*model.UserTaskRewards
|
||||
// if err = dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.%s = %s.%s",
|
||||
// dao.Rewards.Table(), dao.Rewards.Columns().Id, dao.UserTaskRewards.Table(), dao.UserTaskRewards.Columns().RewardId)).Scan(&userTaskReward); err != nil {
|
||||
// return nil, ecode.Fail.Sub("获取用户奖励记录异常")
|
||||
// }
|
||||
//
|
||||
// if userTaskReward == nil {
|
||||
// res.Errcode = -1
|
||||
// res.Errmsg = "用户奖励记录为空"
|
||||
// res.Datas = nil
|
||||
// return &res, ecode.Fail.Sub("用户奖励记录为空")
|
||||
// }
|
||||
//
|
||||
// callbackData := make([]model.CallbackData, 0)
|
||||
// for _, v := range userTaskReward {
|
||||
// callbackData = append(callbackData, model.CallbackData{
|
||||
// PrizeCode: v.InnerOrderId,
|
||||
// })
|
||||
// }
|
||||
//
|
||||
// res.Datas = callbackData
|
||||
//
|
||||
// return &res, err
|
||||
// }
|
||||
func (s *sReward) CallBack(ctx context.Context, in *model.RewardCallbackIn) (out *model.RewardCallbackOut, err error) {
|
||||
var reward *model.Reward
|
||||
var res model.RewardCallbackOut
|
||||
@ -593,76 +751,70 @@ func (s *sReward) CallBack(ctx context.Context, in *model.RewardCallbackIn) (out
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
// 当天结束时间
|
||||
end := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
||||
// 查先询用户当日已领取
|
||||
dailyGetNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id=%s.reward_id", dao.Rewards.Table(),
|
||||
dao.UserTaskRewards.Table())).InnerJoin(dao.RewardWaters.Table(), fmt.Sprintf("%s.external_order_id = %s.order_id", dao.UserTaskRewards.Table(), dao.RewardWaters.Table())).
|
||||
Where(dao.RewardWaters.Columns().Recvuid, in.Uid).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
WhereBetween(dao.UserTaskRewards.Columns().UpdatedAt, start, end).Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
|
||||
value, err := dao.Users.Ctx(ctx).Where(dao.Users.Columns().WxPopenId, fmt.Sprintf("WX_%s", in.Uid)).WhereOr(dao.Users.Columns().QqPopenId, fmt.Sprintf("QQ_%s", in.Uid)).Fields(dao.Users.Columns().Id).Value()
|
||||
if err != nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "查询用户当日领取数量失败"
|
||||
res.Errmsg = "查询用户ID异常"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("查询用户当日领取数量失败")
|
||||
return &res, ecode.Fail.Sub("查询用户ID异常")
|
||||
}
|
||||
userId := value.Int64()
|
||||
|
||||
// 判断是否达到用户日限制
|
||||
if int(reward.UserDailyLimit) <= dailyGetNum {
|
||||
// 查询当前用户当天领取总数
|
||||
userTodayNum, err := dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: userId}).LeftJoin(dao.UserTaskRewards.Table(), "utr", "utr.user_task_id = user_tasks.id").
|
||||
WhereIn("utr.status", []int{3, 6}).
|
||||
Where("utr.reward_id = ?", reward.Id).WhereBetween("utr.updated_at", start, end).Count()
|
||||
if err != nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "查询用户当天领取数量异常"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("查询用户当天领取数量异常")
|
||||
}
|
||||
if userTodayNum >= int(reward.UserDailyLimit) {
|
||||
res.Errcode = consts.UserDayLimit
|
||||
res.Errmsg = consts.UserDayLimitMSG
|
||||
}
|
||||
|
||||
// 查先询用户总共已领取
|
||||
dailyTotalNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id=%s.reward_id", dao.Rewards.Table(),
|
||||
dao.UserTaskRewards.Table())).InnerJoin(dao.RewardWaters.Table(), fmt.Sprintf("%s.external_order_id = %s.order_id", dao.UserTaskRewards.Table(), dao.RewardWaters.Table())).
|
||||
Where(dao.RewardWaters.Columns().Recvuid, in.Uid).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
|
||||
// 查询当前用户该奖励领取总数
|
||||
userTotalNum, err := dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: userId}).LeftJoin(dao.UserTaskRewards.Table(), "utr", "utr.user_task_id = user_tasks.id").
|
||||
WhereIn("utr.status", []int{3, 6}).
|
||||
Where("utr.reward_id = ?", reward.Id).Count()
|
||||
if err != nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "查询用户当日总共领取数量失败"
|
||||
res.Errmsg = "查询用户领取数量异常"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("查询用户当日总共领取数量失败")
|
||||
return &res, ecode.Fail.Sub("查询用户领取数量异常")
|
||||
}
|
||||
// 判断是否达到用户总限制
|
||||
if int(reward.UserTotalLimit) <= dailyTotalNum {
|
||||
if userTotalNum >= int(reward.UserTotalLimit) {
|
||||
res.Errcode = consts.UserTotalLimit
|
||||
res.Errmsg = consts.UserTotalLimitMSG
|
||||
}
|
||||
|
||||
// 查先询该批次当日已领取
|
||||
batchDailyGetNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
WhereBetween(dao.UserTaskRewards.Columns().UpdatedAt, start, end).Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
// 查询该奖励今天发放总数
|
||||
todayNum, err := dao.UserTaskRewards.Ctx(ctx).WhereBetween("updated_at", start, end).Where("reward_id = ?", reward.Id).WhereIn("status", []int{3, 6}).Count()
|
||||
if err != nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "查询该批次当日总共领取数量失败"
|
||||
res.Errmsg = "查询该批次今天领取数量异常"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("查询该批次当日总共领取数量失败")
|
||||
return &res, ecode.Fail.Sub("查询该批次今天领取数量异常")
|
||||
}
|
||||
// 判断是否达到该批次日限制
|
||||
if int(reward.DailyTotalLimit) <= batchDailyGetNum {
|
||||
if todayNum >= int(reward.DailyTotalLimit) {
|
||||
res.Errcode = consts.BatchDayLimit
|
||||
res.Errmsg = consts.BatchDayLimitMSG
|
||||
}
|
||||
|
||||
// 查先询该批次总共已领取
|
||||
batchTotalGetNum, err := dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where(dao.UserTaskRewards.Columns().Status, 3).WhereOr(dao.UserTaskRewards.Columns().Status, 6).
|
||||
Fields(fmt.Sprintf("%s.*,%s.*", dao.Rewards.Table(), dao.UserTaskRewards.Table())).Count()
|
||||
|
||||
// 查询该奖励所有领取总数
|
||||
totalNum, err := dao.UserTaskRewards.Ctx(ctx).Where("reward_id = ?", reward.Id).WhereIn("status", []int{3, 6}).Count()
|
||||
if err != nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "查询该批次总共领取数量失败"
|
||||
res.Errmsg = "查询该批次总共领取数量异常"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("查询该批次总共领取数量失败")
|
||||
return &res, ecode.Fail.Sub("查询该批次总共领取数量异常")
|
||||
}
|
||||
// 判断是否达到该批次总共限制
|
||||
if int(reward.TotalLimit) <= batchTotalGetNum {
|
||||
if totalNum >= int(reward.TotalLimit) {
|
||||
res.Errcode = consts.BatchTotalLimit
|
||||
res.Errmsg = consts.BatchTotalLimitMSG
|
||||
}
|
||||
|
||||
_, err = dao.RewardCallback.Ctx(ctx).OmitEmptyData().Insert(do.RewardCallback{
|
||||
OrderId: in.OrderId,
|
||||
PrizeId: in.PrizeId,
|
||||
@ -681,26 +833,26 @@ func (s *sReward) CallBack(ctx context.Context, in *model.RewardCallbackIn) (out
|
||||
return &res, ecode.Fail.Sub("存储奖励回调数据异常")
|
||||
}
|
||||
|
||||
// 回调成功,组装响应参数
|
||||
var userTaskReward []*model.UserTaskRewards
|
||||
if err = dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.%s = %s.%s",
|
||||
dao.Rewards.Table(), dao.Rewards.Columns().Id, dao.UserTaskRewards.Table(), dao.UserTaskRewards.Columns().RewardId)).Scan(&userTaskReward); err != nil {
|
||||
return nil, ecode.Fail.Sub("获取用户奖励记录异常")
|
||||
}
|
||||
|
||||
if userTaskReward == nil {
|
||||
res.Errcode = -1
|
||||
res.Errmsg = "用户奖励记录为空"
|
||||
res.Datas = nil
|
||||
return &res, ecode.Fail.Sub("用户奖励记录为空")
|
||||
}
|
||||
//// 回调成功,组装响应参数
|
||||
//var userTaskReward []*model.UserTaskRewards
|
||||
//if err = dao.Rewards.Ctx(ctx).Where(dao.Rewards.Columns().PrizeId, in.PrizeId).InnerJoin(dao.UserTaskRewards.Table(), fmt.Sprintf("%s.%s = %s.%s",
|
||||
// dao.Rewards.Table(), dao.Rewards.Columns().Id, dao.UserTaskRewards.Table(), dao.UserTaskRewards.Columns().RewardId)).Scan(&userTaskReward); err != nil {
|
||||
// return nil, ecode.Fail.Sub("获取用户奖励记录异常")
|
||||
//}
|
||||
//
|
||||
//if userTaskReward == nil {
|
||||
// res.Errcode = -1
|
||||
// res.Errmsg = "用户奖励记录为空"
|
||||
// res.Datas = nil
|
||||
// return &res, ecode.Fail.Sub("用户奖励记录为空")
|
||||
//}
|
||||
|
||||
callbackData := make([]model.CallbackData, 0)
|
||||
for _, v := range userTaskReward {
|
||||
callbackData = append(callbackData, model.CallbackData{
|
||||
PrizeCode: v.InnerOrderId,
|
||||
})
|
||||
}
|
||||
//for _, v := range userTaskReward {
|
||||
callbackData = append(callbackData, model.CallbackData{
|
||||
PrizeCode: "rewardlsseew0rt70db0lhtazmicw50082uudq",
|
||||
})
|
||||
//}
|
||||
|
||||
res.Datas = callbackData
|
||||
|
||||
|
||||
@ -354,7 +354,19 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
|
||||
}
|
||||
var userTask []*model.UserTask
|
||||
|
||||
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).WhereNot("status", 3).Scan(&userTask)
|
||||
// 根据任务类型判断是否存在该任务
|
||||
if in.TaskType == 1 {
|
||||
now := time.Now()
|
||||
// 当天开始时间
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
// 当天结束时间
|
||||
end := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location())
|
||||
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).
|
||||
WhereBetween(dao.UserTasks.Columns().CreatedAt, start, end).WhereNot("status", 3).Scan(&userTask)
|
||||
} else {
|
||||
err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: storeId, GameId: in.GameId}).WhereNot("status", 3).Scan(&userTask)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("查询用户该任务记录失败")
|
||||
}
|
||||
@ -379,6 +391,7 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge
|
||||
SerialNumber: serialNumber,
|
||||
TaskName: in.TaskName,
|
||||
GameId: in.GameId,
|
||||
TaskType: in.TaskType,
|
||||
})
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("创建用户任务记录失败")
|
||||
@ -442,7 +455,6 @@ func (s *sTask) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRe
|
||||
|
||||
// GetTaskList PC-WEB获取任务列表
|
||||
func (s *sTask) GetTaskList(ctx context.Context, in *model.GetTaskListV2In) (out *model.GetTaskListV2Out, err error) {
|
||||
|
||||
var tasks []model.Task
|
||||
var pageIdx string
|
||||
var data []model.GameTask
|
||||
@ -459,10 +471,13 @@ func (s *sTask) GetTaskList(ctx context.Context, in *model.GetTaskListV2In) (out
|
||||
return nil, ecode.Fail.Sub("解析任务信息失败")
|
||||
}
|
||||
tasks[i].Task = ""
|
||||
for _, i3 := range tasks[i].TaskRewards {
|
||||
tasks[i].GameTask.Reward = append(tasks[i].GameTask.Reward, i3.Rewards)
|
||||
}
|
||||
data = append(data, tasks[i].GameTask)
|
||||
}
|
||||
|
||||
return &model.GetTaskListV2Out{
|
||||
Data: tasks,
|
||||
Data: data,
|
||||
}, nil
|
||||
} else {
|
||||
// 已绑定
|
||||
@ -515,16 +530,18 @@ func (s *sTask) GetTaskList(ctx context.Context, in *model.GetTaskListV2In) (out
|
||||
//任务状态=1或者2不做操作,其他查询门店奖励是否全部领取
|
||||
if task.Status != 1 && task.Status != 2 {
|
||||
count, err := dao.UserTasks.Ctx(ctx).Where(dao.UserTasks.Columns().TaskId, task.TaskID).Where(dao.UserTasks.Columns().UserId, in.UserId).LeftJoin(dao.UserTaskRewards.Table(),
|
||||
fmt.Sprintf("%s.user_tasks_id = %s.id", dao.UserTaskRewards.Table(), dao.UserTasks.Table())).LeftJoin(dao.Rewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where(dao.Rewards.Columns().Source, 2).Where(dao.UserTaskRewards.Columns().Status, 2).Count()
|
||||
fmt.Sprintf("%s.user_task_id = %s.id", dao.UserTaskRewards.Table(), dao.UserTasks.Table())).LeftJoin(dao.Rewards.Table(), fmt.Sprintf("%s.id = %s.reward_id",
|
||||
dao.Rewards.Table(), dao.UserTaskRewards.Table())).Where("rewards.source", 2).Where(dao.UserTaskRewards.Columns().Status, 2).Count()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("查询用户门店任务奖励失败")
|
||||
}
|
||||
|
||||
if count > 0 {
|
||||
tasks[i].Status = 2
|
||||
result.TaskList[i].Status = 2
|
||||
//tasks[i].Status = 2
|
||||
} else {
|
||||
tasks[i].Status = 3
|
||||
result.TaskList[i].Status = 3
|
||||
//tasks[i].Status = 3
|
||||
}
|
||||
}
|
||||
//else {
|
||||
|
||||
@ -20,4 +20,5 @@ type RewardTypes struct {
|
||||
UpdatedAt *gtime.Time // 更新时间
|
||||
DeletedAt *gtime.Time // 软删除时间
|
||||
TencentTypeId interface{} // 腾讯类型 id
|
||||
Source interface{} // 来源1:系统 2:门店
|
||||
}
|
||||
|
||||
@ -24,4 +24,5 @@ type UserTasks struct {
|
||||
StoreId interface{} // 门店 id
|
||||
TaskName interface{} // 任务名称
|
||||
GameId interface{} // 游戏 id
|
||||
TaskType interface{} // 1: 每日任务 3: 周期任务
|
||||
}
|
||||
|
||||
@ -10,12 +10,13 @@ import (
|
||||
|
||||
// RewardTypes is the golang structure for table reward_types.
|
||||
type RewardTypes struct {
|
||||
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
|
||||
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
|
||||
IconUrl string `json:"iconUrl" orm:"icon_url" description:"图标链接地址"` // 图标链接地址
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间
|
||||
TencentTypeId int `json:"tencentTypeId" orm:"tencent_type_id" description:"腾讯类型 id"` // 腾讯类型 id
|
||||
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
|
||||
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
|
||||
IconUrl string `json:"iconUrl" orm:"icon_url" description:"图标链接地址"` // 图标链接地址
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间
|
||||
TencentTypeId int `json:"tencentTypeId" orm:"tencent_type_id" description:"腾讯类型 id"` // 腾讯类型 id
|
||||
Source int64 `json:"source" orm:"source" description:"来源1:系统 2:门店"` // 来源1:系统 2:门店
|
||||
}
|
||||
|
||||
@ -22,4 +22,5 @@ type UserTasks struct {
|
||||
StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id
|
||||
TaskName string `json:"taskName" orm:"task_name" description:"任务名称"` // 任务名称
|
||||
GameId int64 `json:"gameId" orm:"game_id" description:"游戏 id"` // 游戏 id
|
||||
TaskType int64 `json:"taskType" orm:"task_type" description:"1: 每日任务 3: 周期任务"` // 1: 每日任务 3: 周期任务
|
||||
}
|
||||
|
||||
@ -38,11 +38,11 @@ type GameTask struct {
|
||||
CycleEnd int64 `json:"cycle_end"`
|
||||
TargetName string `json:"target_name"`
|
||||
TargetTimes int `json:"target_times"`
|
||||
Status int `json:"status,omitempty"`
|
||||
UserTimes int64 `json:"user_times,omitempty"`
|
||||
Status int `json:"status"`
|
||||
UserTimes int64 `json:"user_times"`
|
||||
GameTaskConfig GameTaskConfig `json:"game_task_config"`
|
||||
GameTaskConfigParse GameTaskConfigParse `json:"game_task_config_parse"`
|
||||
Reward []SimpleReward `json:"reward,omitempty"`
|
||||
Reward []SimpleReward `json:"reward"`
|
||||
}
|
||||
|
||||
type GameTaskResponse struct {
|
||||
|
||||
@ -34,18 +34,23 @@ type Reward struct {
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间(软删除)"` // 删除时间(软删除)
|
||||
}
|
||||
type SimpleReward struct {
|
||||
g.Meta `orm:"table:rewards"`
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
|
||||
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID,关联 reward_types 表"` // 奖励类型ID,关联 reward_types 表
|
||||
Source int `json:"source" orm:"source" description:"奖励来源,1=系统奖励(对接腾讯),2=门店追加"` // 奖励来源,1=系统奖励(对接腾讯),2=门店追加
|
||||
GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
|
||||
ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
|
||||
ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式:1=时间段过期,2=领取后过期"` // 过期方式:1=时间段过期,2=领取后过期
|
||||
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间(expire_type=1时)"` // 有效期开始时间(expire_type=1时)
|
||||
ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间(expire_type=1时)"` // 有效期结束时间(expire_type=1时)
|
||||
ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期(expire_type=2时)"` // 领取后多少天过期(expire_type=2时)
|
||||
|
||||
g.Meta `orm:"table:rewards"`
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
|
||||
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID,关联 reward_types 表"` // 奖励类型ID,关联 reward_types 表
|
||||
Source int `json:"source" orm:"source" description:"奖励来源,1=系统奖励(对接腾讯),2=门店追加"` // 奖励来源,1=系统奖励(对接腾讯),2=门店追加
|
||||
GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
|
||||
ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
|
||||
ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式:1=时间段过期,2=领取后过期"` // 过期方式:1=时间段过期,2=领取后过期
|
||||
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间(expire_type=1时)"` // 有效期开始时间(expire_type=1时)
|
||||
ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间(expire_type=1时)"` // 有效期结束时间(expire_type=1时)
|
||||
ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期(expire_type=2时)"` // 领取后多少天过期(expire_type=2时)
|
||||
DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限(NULL表示不限制)"` // 每日发放总限(NULL表示不限制)
|
||||
TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限(NULL表示不限制)"` // 奖励总限(NULL表示不限制)
|
||||
UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制(NULL表示不限制)"` // 用户每日领取限制(NULL表示不限制)
|
||||
UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制(NULL表示不限制)"` // 用户领取总次数限制(NULL表示不限制)
|
||||
ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量
|
||||
//GrantQuantity uint64 `json:"grantQuantity" orm:"grant_quantity" description:"每次发放个数"` // 每次发放个数
|
||||
}
|
||||
|
||||
// RewardCreateIn 创建奖励入参
|
||||
|
||||
@ -6,13 +6,14 @@ import (
|
||||
|
||||
// RewardType 奖励类型表
|
||||
type RewardType struct {
|
||||
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
|
||||
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
|
||||
IconUrl string `json:"iconUrl" orm:"icon_url" description:"图标链接地址"` // 图标链接地址
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间
|
||||
Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称
|
||||
Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码
|
||||
IconUrl string `json:"iconUrl" orm:"icon_url" description:"图标链接地址"` // 图标链接地址
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间
|
||||
TencentTypeId int `json:"tencentTypeId" orm:"tencent_type_id" description:"腾讯奖励类型ID"`
|
||||
}
|
||||
|
||||
// RewardTypeCreateIn 创建奖励类型入参
|
||||
|
||||
@ -26,9 +26,9 @@ type UserTask struct {
|
||||
|
||||
type TaskReward struct {
|
||||
g.Meta `orm:"table:task_rewards"`
|
||||
TaskId string `json:"-" orm:"task_id"`
|
||||
RewardId int64 `json:"-" orm:"reward_id"`
|
||||
Rewards Reward `json:"reward" orm:"with:id=reward_id"`
|
||||
TaskId string `json:"-" orm:"task_id"`
|
||||
RewardId int64 `json:"-" orm:"reward_id"`
|
||||
Rewards SimpleReward `json:"reward" orm:"with:id=reward_id"`
|
||||
}
|
||||
|
||||
type UserTask2 struct {
|
||||
@ -88,6 +88,7 @@ type GetTaskIn struct {
|
||||
UserId int `json:"userId"`
|
||||
TaskName string `json:"taskName"`
|
||||
GameId int `json:"gid"`
|
||||
TaskType int `json:"taskType"`
|
||||
}
|
||||
|
||||
type GetTaskOut struct {
|
||||
|
||||
Reference in New Issue
Block a user