调整奖励领取接口
This commit is contained in:
@ -605,9 +605,40 @@ func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *mode
|
|||||||
glog.Info(ctx, "调用 tencent开始")
|
glog.Info(ctx, "调用 tencent开始")
|
||||||
activity, err2 := gamelife.GetGamelifeClient(ctx).RequestActivity(ctx, &model.QQNetbarActivityIn{PopenId: in.PopenId, ServiceName: consts.GetGift, GiftParam: giftParam})
|
activity, err2 := gamelife.GetGamelifeClient(ctx).RequestActivity(ctx, &model.QQNetbarActivityIn{PopenId: in.PopenId, ServiceName: consts.GetGift, GiftParam: giftParam})
|
||||||
|
|
||||||
if err2 != nil {
|
//if err2 != nil {
|
||||||
|
if err2 != nil && err2.Error() == "奖励领取超出限制,-1" {
|
||||||
|
// 修改奖励领取状态为5
|
||||||
|
_, err2 = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{Id: in.Id}).Data(do.UserTaskRewards{
|
||||||
|
Status: consts.RewardFailedStatus,
|
||||||
|
}).Update()
|
||||||
|
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, ecode.Fail.Sub("修改用奖励领取状态失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断奖励是否领完,修改用户任务记录为 2
|
||||||
|
exist, err2 := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: in.UserTaskId}).WhereIn(dao.UserTaskRewards.Columns().Status, []int{2, 3}).Exist()
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, ecode.Fail.Sub("查询用户任务奖励失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !exist {
|
||||||
|
// 修改用户任务记录为 2
|
||||||
|
_, err2 = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{Id: in.UserTaskId}).Data(do.UserTasks{
|
||||||
|
Status: 2,
|
||||||
|
}).Update()
|
||||||
|
|
||||||
|
if err2 != nil {
|
||||||
|
return nil, ecode.Fail.Sub("修改用户任务状态失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, ecode.RewardExceedLimited
|
||||||
|
} else if err2 != nil {
|
||||||
return nil, err2
|
return nil, err2
|
||||||
}
|
}
|
||||||
|
//return nil, err2
|
||||||
|
//}
|
||||||
glog.Info(ctx, "调用 tencent结束")
|
glog.Info(ctx, "调用 tencent结束")
|
||||||
fmt.Print(activity)
|
fmt.Print(activity)
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
package ecode
|
package ecode
|
||||||
|
|
||||||
var (
|
var (
|
||||||
OK = New(0, "操作成功")
|
OK = New(0, "操作成功")
|
||||||
Sub = New(1, "") // 自定义错误信息
|
Sub = New(1, "") // 自定义错误信息
|
||||||
Fail = New(2, "服务器内部错误")
|
Fail = New(2, "服务器内部错误")
|
||||||
InvalidOperation = New(3, "非法的操作请求")
|
InvalidOperation = New(3, "非法的操作请求")
|
||||||
Params = New(4, "请求参数错误")
|
Params = New(4, "请求参数错误")
|
||||||
Logout = New(5, "用户未登录")
|
Logout = New(5, "用户未登录")
|
||||||
Disabled = New(6, "账户已被禁用")
|
Disabled = New(6, "账户已被禁用")
|
||||||
Denied = New(7, "没有权限执行该操作")
|
Denied = New(7, "没有权限执行该操作")
|
||||||
Expire = New(8, "token已过期")
|
Expire = New(8, "token已过期")
|
||||||
Auth = New(1000, "账户名或密码不正确")
|
Auth = New(1000, "账户名或密码不正确")
|
||||||
Password = New(1001, "密码不正确")
|
Password = New(1001, "密码不正确")
|
||||||
EmailExist = New(1002, "该邮箱已被注册")
|
EmailExist = New(1002, "该邮箱已被注册")
|
||||||
|
RewardExceedLimited = New(-1, "奖励领取数量超出限制")
|
||||||
)
|
)
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package gamelife
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"server/internal/dao"
|
"server/internal/dao"
|
||||||
@ -423,6 +424,22 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
|
|||||||
if err != nil || resp.IsError() {
|
if err != nil || resp.IsError() {
|
||||||
return nil, ecode.Fail.Sub("请求出现异常")
|
return nil, ecode.Fail.Sub("请求出现异常")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断是否为 -1 的异常
|
||||||
|
type RespData struct {
|
||||||
|
Ret int `json:"ret"`
|
||||||
|
ErrMsg string `json:"err_msg"`
|
||||||
|
ErrDesc string `json:"err_desc"`
|
||||||
|
}
|
||||||
|
var respData RespData
|
||||||
|
if err = json.Unmarshal(resp.Body(), &respData); err != nil {
|
||||||
|
return nil, ecode.Fail.Sub("解析请求结果失败")
|
||||||
|
}
|
||||||
|
if respData.Ret == -1 {
|
||||||
|
glog.Info(ctx, "奖励领取超出限制,-1")
|
||||||
|
return nil, errors.New("奖励领取超出限制,-1")
|
||||||
|
}
|
||||||
|
|
||||||
if result == nil {
|
if result == nil {
|
||||||
return nil, ecode.Fail.Sub("请求结果为空")
|
return nil, ecode.Fail.Sub("请求结果为空")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user