Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -55,8 +55,11 @@ type StoreLoginReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StoreLoginRes struct {
|
type StoreLoginRes struct {
|
||||||
g.Meta `mime:"application/json"`
|
g.Meta `mime:"application/json"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
StoreId int64 `json:"storeId"`
|
||||||
|
StoreName string `json:"storeName"`
|
||||||
|
NetbarAccount string `json:"netbarAccount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Quan8AutologinReq struct {
|
type Quan8AutologinReq struct {
|
||||||
|
|||||||
@ -298,10 +298,12 @@ type GetGoodsDetailsRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OperateTaskRewardReq struct {
|
type OperateTaskRewardReq struct {
|
||||||
g.Meta `path:"/reward/taskReward" method:"post" tags:"Backend/Reward" summary:"(系统管理员、商户管理员、门店管理员)添加任务奖励"`
|
g.Meta `path:"/reward/taskReward" method:"post" tags:"Backend/Reward" summary:"(系统管理员、商户管理员、门店管理员)添加任务奖励"`
|
||||||
Type int `json:"type" v:"required#操作类型只能为1或2,1是添加、2是删除" dc:"操作类型"`
|
Type int `json:"type" v:"required#操作类型只能为1或2,1是添加、2是删除" dc:"操作类型"`
|
||||||
TaskId string `json:"taskId" v:"required#任务id不能为空" dc:"任务Id"`
|
TaskId string `json:"taskId" v:"required#任务id不能为空" dc:"任务Id"`
|
||||||
RewardId int64 `json:"rewardId" v:"required#奖励id不能为空" dc:"奖励Id"`
|
RewardId int64 `json:"rewardId" v:"required#奖励id不能为空" dc:"奖励Id"`
|
||||||
|
StoreId int64 `json:"storeId" dc:"门店Id"`
|
||||||
|
NetbarAccount string `json:"netbarAccount" dc:"网吧账号"`
|
||||||
}
|
}
|
||||||
type OperateTaskRewardRes struct {
|
type OperateTaskRewardRes struct {
|
||||||
Success bool `json:"success" dc:"是否成功"`
|
Success bool `json:"success" dc:"是否成功"`
|
||||||
|
|||||||
@ -4,3 +4,11 @@ const (
|
|||||||
SystemReward = iota + 1
|
SystemReward = iota + 1
|
||||||
StoreReward
|
StoreReward
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var PlatformRewards = map[int]string{
|
||||||
|
12: "https://api-test.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret", // Q币
|
||||||
|
16: "https://api.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret", // 虚拟道具
|
||||||
|
31: "https://api.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret", // 宝箱
|
||||||
|
22: "https://api.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret", // 红包
|
||||||
|
11: "https://api.nes.smoba.qq.com/pvpesport.sgamenes.commcgi.commcgi/GetExplatSecret", // 实物
|
||||||
|
}
|
||||||
|
|||||||
@ -13,5 +13,5 @@ func (c *ControllerV1) StoreLogin(ctx context.Context, req *v1.StoreLoginReq) (r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &v1.StoreLoginRes{Token: out.Token}, nil
|
return &v1.StoreLoginRes{Token: out.Token, StoreId: out.StoreId, StoreName: out.StoreName, NetbarAccount: out.NetbarAccount}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,7 @@ func (c *ControllerV1) OperateTaskReward(ctx context.Context, req *v1.OperateTas
|
|||||||
fromCtx := g.RequestFromCtx(ctx)
|
fromCtx := g.RequestFromCtx(ctx)
|
||||||
operatorId := fromCtx.GetCtxVar("id").Int64()
|
operatorId := fromCtx.GetCtxVar("id").Int64()
|
||||||
operatorRole := fromCtx.GetCtxVar("role").String()
|
operatorRole := fromCtx.GetCtxVar("role").String()
|
||||||
out, err := service.Reward().OperateTaskReward(ctx, &model.OperateTaskRewardIn{OperatorId: operatorId, OperatorRole: operatorRole, RewardId: req.RewardId, TaskId: req.TaskId, Type: req.Type})
|
out, err := service.Reward().OperateTaskReward(ctx, &model.OperateTaskRewardIn{OperatorId: operatorId, OperatorRole: operatorRole, RewardId: req.RewardId, TaskId: req.TaskId, Type: req.Type, StoreId: req.StoreId, NetbarAccount: req.NetbarAccount})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import (
|
|||||||
"server/utility/ecode"
|
"server/utility/ecode"
|
||||||
"server/utility/encrypt"
|
"server/utility/encrypt"
|
||||||
"server/utility/jwt"
|
"server/utility/jwt"
|
||||||
|
"server/utility/sms"
|
||||||
"server/utility/snowid"
|
"server/utility/snowid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -106,8 +107,17 @@ func (s *sMerchantAdmin) Code(ctx context.Context, in *model.MerchantAdminCodeIn
|
|||||||
return nil, ecode.Fail.Sub("该手机号已被注册")
|
return nil, ecode.Fail.Sub("该手机号已被注册")
|
||||||
}
|
}
|
||||||
// TODO 调用验证码服务发送验证码
|
// TODO 调用验证码服务发送验证码
|
||||||
|
client, b := sms.GetClient("aliyunsms")
|
||||||
|
if !b {
|
||||||
|
return nil, ecode.Fail.Sub("获取短信服务失败")
|
||||||
|
}
|
||||||
|
digits := grand.Digits(6)
|
||||||
|
if _, err = client.SendCode(ctx, &model.SMSCodeIn{Phone: in.Phone, Code: digits}); err != nil {
|
||||||
|
return nil, ecode.Fail.Sub("发送验证码失败")
|
||||||
|
}
|
||||||
|
|
||||||
// 插入缓存,过期时间为 5 分钟
|
// 插入缓存,过期时间为 5 分钟
|
||||||
if err = g.Redis().SetEX(ctx, "merchant_admin_code:"+in.Phone, grand.Digits(6), 5*60); err != nil {
|
if err = g.Redis().SetEX(ctx, "merchant_admin_code:"+in.Phone, digits, 5*60); err != nil {
|
||||||
return nil, ecode.Fail.Sub("插入验证码缓存失败")
|
return nil, ecode.Fail.Sub("插入验证码缓存失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +192,7 @@ func (s *sMerchantAdmin) Register(ctx context.Context, in *model.MerchantAdminRe
|
|||||||
IsPrimary: true,
|
IsPrimary: true,
|
||||||
Username: in.Username,
|
Username: in.Username,
|
||||||
RoleId: merchantRoleId,
|
RoleId: merchantRoleId,
|
||||||
Status: consts.MerchantAdministratorEnable,
|
Status: consts.MerchantAdministratorDisable,
|
||||||
}).Insert(); err != nil {
|
}).Insert(); err != nil {
|
||||||
return ecode.Fail.Sub("插入商户管理员数据失败")
|
return ecode.Fail.Sub("插入商户管理员数据失败")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -858,10 +858,10 @@ func (s *sReward) OperateTaskReward(ctx context.Context, in *model.OperateTaskRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if in.Type == 1 {
|
if in.Type == 1 {
|
||||||
_, err := dao.TaskRewards.Ctx(ctx).Data(do.TaskRewards{TaskId: in.TaskId, RewardId: in.RewardId}).Insert()
|
_, err := dao.TaskRewards.Ctx(ctx).Data(do.TaskRewards{TaskId: in.TaskId, RewardId: in.RewardId, NetbarAccount: in.NetbarAccount, StoreId: in.StoreId}).OmitEmptyData().Insert()
|
||||||
return &model.OperateTaskRewardOut{Success: true}, err
|
return &model.OperateTaskRewardOut{Success: true}, err
|
||||||
} else {
|
} else {
|
||||||
_, err := dao.TaskRewards.Ctx(ctx).Where(do.TaskRewards{TaskId: in.TaskId, RewardId: in.RewardId}).Delete()
|
_, err := dao.TaskRewards.Ctx(ctx).Where(do.TaskRewards{TaskId: in.TaskId, RewardId: in.RewardId, NetbarAccount: in.NetbarAccount, StoreId: in.StoreId}).OmitEmptyWhere().Delete()
|
||||||
return &model.OperateTaskRewardOut{Success: true}, err
|
return &model.OperateTaskRewardOut{Success: true}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ func (s *sStore) List(ctx context.Context, in *model.StoreListIn) (out *model.St
|
|||||||
// 1. 初始化返回数据
|
// 1. 初始化返回数据
|
||||||
list := make([]model.Store, 0)
|
list := make([]model.Store, 0)
|
||||||
var total int
|
var total int
|
||||||
if err = dao.Stores.Ctx(ctx).Page(in.Page, in.Size).ScanAndCount(&list, &total, false); err != nil {
|
if err = dao.Stores.Ctx(ctx).Page(in.Page, in.Size).Where(do.Stores{MerchantId: in.MerchantId}).ScanAndCount(&list, &total, false); err != nil {
|
||||||
return nil, ecode.Fail.Sub("门店列表获取失败")
|
return nil, ecode.Fail.Sub("门店列表获取失败")
|
||||||
}
|
}
|
||||||
return &model.StoreListOut{
|
return &model.StoreListOut{
|
||||||
|
|||||||
@ -61,6 +61,11 @@ func (s *sStoreAdmin) Login(ctx context.Context, in *model.StoreAdminLoginIn) (o
|
|||||||
if !encrypt.ComparePassword(one[dao.StoreAdmins.Columns().PasswordHash].String(), in.Password) {
|
if !encrypt.ComparePassword(one[dao.StoreAdmins.Columns().PasswordHash].String(), in.Password) {
|
||||||
return nil, ecode.Params.Sub("密码错误")
|
return nil, ecode.Params.Sub("密码错误")
|
||||||
}
|
}
|
||||||
|
var store entity.Stores
|
||||||
|
if err = dao.Stores.Ctx(ctx).WherePri(one[dao.StoreAdmins.Columns().StoreId]).Scan(&store); err != nil {
|
||||||
|
return nil, ecode.Fail.Sub("查询门店失败")
|
||||||
|
}
|
||||||
|
|
||||||
value, err := dao.Roles.Ctx(ctx).WherePri(one[dao.StoreAdmins.Columns().RoleId].Int()).Fields(dao.Roles.Columns().Code).Value()
|
value, err := dao.Roles.Ctx(ctx).WherePri(one[dao.StoreAdmins.Columns().RoleId].Int()).Fields(dao.Roles.Columns().Code).Value()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ecode.Fail.Sub("查询角色失败")
|
return nil, ecode.Fail.Sub("查询角色失败")
|
||||||
@ -71,7 +76,10 @@ func (s *sStoreAdmin) Login(ctx context.Context, in *model.StoreAdminLoginIn) (o
|
|||||||
return nil, ecode.Fail.Sub("生成token失败")
|
return nil, ecode.Fail.Sub("生成token失败")
|
||||||
}
|
}
|
||||||
out = &model.StoreAdminLoginOut{
|
out = &model.StoreAdminLoginOut{
|
||||||
Token: token,
|
Token: token,
|
||||||
|
StoreId: store.Id,
|
||||||
|
StoreName: store.Name,
|
||||||
|
NetbarAccount: store.NetbarAccount,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -686,132 +686,76 @@ func (s *sTask) GetTaskList(ctx context.Context, in *model.GetTaskListV2In) (out
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ecode.Fail.Sub("获取任务奖励列表失败")
|
return nil, ecode.Fail.Sub("获取任务奖励列表失败")
|
||||||
}
|
}
|
||||||
|
orm := dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: v.TaskID})
|
||||||
if int(v.UserTimes) >= v.TargetTimes && v.Status == 1 {
|
if v.GameTaskConfig.TimeType == 1 {
|
||||||
completedTime := gtime.Now()
|
// 每日任务
|
||||||
// 判断当前用户完成情况,已完成根据任务、用户,任务类型检查是否存在用户任务记录
|
start := gtime.Now().StartOfDay()
|
||||||
orm := dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: v.TaskID})
|
end := gtime.Now().EndOfDay()
|
||||||
if v.GameTaskConfig.TimeType == 1 {
|
orm = orm.WhereBetween(dao.UserTasks.Columns().CreatedAt, start, end)
|
||||||
// 每日任务
|
}
|
||||||
start := gtime.Now().StartOfDay()
|
one, err := orm.Fields(dao.UserTasks.Columns().Id, dao.UserTasks.Columns().UserTimes).One()
|
||||||
end := gtime.Now().EndOfDay()
|
if err != nil {
|
||||||
orm = orm.WhereBetween(dao.UserTasks.Columns().CreatedAt, start, end)
|
return nil, ecode.Fail.Sub("获取用户任务失败")
|
||||||
}
|
}
|
||||||
value, err := orm.Fields(dao.UserTasks.Columns().Id).Value()
|
if one.IsEmpty() || one["id"].IsEmpty() {
|
||||||
if err != nil {
|
result.TaskList[i].Status = 1
|
||||||
return nil, ecode.Fail.Sub("获取用户任务失败")
|
} else {
|
||||||
}
|
if v.Status == 2 {
|
||||||
|
if v.UserTimes-one["user_times"].Int64() >= v.TargetTimes {
|
||||||
if value.IsEmpty() {
|
completeTime := gtime.Now()
|
||||||
// 不存在创建用户任务完成记录,同时组装用户可领取奖励数据,
|
// 判断是否完成任务,修改奖励下发记录状态为 2
|
||||||
glog.Info(ctx, "用户不存在创建用户任务完成记录,同时组装用户可领取奖励数据")
|
if err := dao.UserTasks.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||||
if err = dao.UserTaskRewards.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
if _, err := dao.UserTasks.Ctx(ctx).WherePri(one["id"].Int64()).Data(do.UserTasks{Status: 3}).Update(); err != nil {
|
||||||
storeId, err := dao.Stores.Ctx(ctx).Fields(dao.Stores.Columns().Id).Where(do.Stores{NetbarAccount: in.NetBarAccount}).Value()
|
return ecode.Fail.Sub("修改用户任务状态失败")
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("获取门店信息失败")
|
|
||||||
}
|
|
||||||
if storeId.IsEmpty() {
|
|
||||||
return ecode.Fail.Sub("获取门店信息失败")
|
|
||||||
}
|
|
||||||
serialNumber, err := snowid.GetSnowClient().GenerateSerialNumber()
|
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("生成流水号异常")
|
|
||||||
}
|
|
||||||
id, err := dao.UserTasks.Ctx(ctx).Data(do.UserTasks{
|
|
||||||
UserId: in.UserId,
|
|
||||||
TaskId: v.TaskID,
|
|
||||||
StoreId: storeId.Int(),
|
|
||||||
Status: 3,
|
|
||||||
SerialNumber: serialNumber,
|
|
||||||
TaskName: v.Title,
|
|
||||||
GameId: in.Gid,
|
|
||||||
TaskType: v.GameTaskConfig.TimeType,
|
|
||||||
}).InsertAndGetId()
|
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("创建用户任务记录失败")
|
|
||||||
}
|
|
||||||
result.TaskList[i].UserTaskId = id
|
|
||||||
insertData := make([]do.UserTaskRewards, 0)
|
|
||||||
// 首先拼装平台奖励
|
|
||||||
for _, prize := range v.PrizeList {
|
|
||||||
for _, goods := range prize.GoodsList {
|
|
||||||
if goods.GoodsType == 37 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
insertData = append(insertData, do.UserTaskRewards{
|
|
||||||
UserTaskId: id,
|
|
||||||
RewardName: goods.GoodsName,
|
|
||||||
Status: consts.RewardPendingStatus,
|
|
||||||
IssueQuantity: goods.Num,
|
|
||||||
Source: 1,
|
|
||||||
RewardTypeId: goods.GoodsType,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 拼装门店奖励数据
|
|
||||||
if len(result.TaskList[i].Rewards) > 0 {
|
|
||||||
for _, reward := range result.TaskList[i].Rewards {
|
|
||||||
var quantity uint64
|
|
||||||
quantity, err = CalculateNetfeeRewardQuantity(ctx, in.UserId, in.StoreId, &reward, completedTime)
|
|
||||||
if err != nil {
|
|
||||||
quantity = reward.GrantQuantity
|
|
||||||
}
|
|
||||||
in := do.UserTaskRewards{
|
|
||||||
RewardId: reward.Id,
|
|
||||||
UserTaskId: id,
|
|
||||||
RewardName: reward.Name,
|
|
||||||
Status: consts.RewardPendingStatus,
|
|
||||||
IssueQuantity: quantity,
|
|
||||||
Source: 2,
|
|
||||||
RewardTypeId: reward.RewardTypeId,
|
|
||||||
}
|
|
||||||
if reward.RewardTypeId == 37 {
|
|
||||||
in.Source = 1
|
|
||||||
}
|
|
||||||
insertData = append(insertData, in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, err = dao.UserTaskRewards.Ctx(ctx).Data(insertData).Insert(); err != nil {
|
|
||||||
return ecode.Fail.Sub("创建用户任务奖励记录失败")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
result.TaskList[i].UserTaskId = value.Int64()
|
|
||||||
// 存在该任务记录,则判断该任务记录对应的奖励是否都已领取,需要修改任务状态
|
|
||||||
glog.Info(ctx, "用户存在该任务记录,则判断该任务记录对应的奖励是否都已领取,需要修改任务状态")
|
|
||||||
if v.Status != 1 && v.Status != 2 {
|
|
||||||
count, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: value.Int()}).WhereIn(dao.UserTasks.Columns().Status, []int{2, 3, 5}).Count()
|
|
||||||
if err != nil {
|
|
||||||
return nil, ecode.Fail.Sub("查询用户门店任务奖励失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
if count > 0 {
|
all, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: one["id"].Int64()}).Fields(dao.UserTaskRewards.Columns().Id, dao.UserTaskRewards.Columns().RewardId).All()
|
||||||
result.TaskList[i].Status = 2
|
if err != nil {
|
||||||
} else {
|
return ecode.Fail.Sub("获取用户任务奖励失败")
|
||||||
result.TaskList[i].Status = 3
|
}
|
||||||
|
for _, record := range all {
|
||||||
|
updateData := do.UserTaskRewards{Status: consts.RewardPendingStatus}
|
||||||
|
rewardTypeCode, err2 := dao.Rewards.Ctx(ctx).WherePri(record["reward_id"].Int64()).
|
||||||
|
InnerJoin(
|
||||||
|
dao.RewardTypes.Table(),
|
||||||
|
fmt.Sprintf("%s.%s = %s.%s",
|
||||||
|
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id,
|
||||||
|
dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId,
|
||||||
|
),
|
||||||
|
).Fields(dao.RewardTypes.Columns().Code).Value()
|
||||||
|
if err2 != nil {
|
||||||
|
return ecode.Fail.Sub("获取用户任务奖励失败")
|
||||||
|
}
|
||||||
|
if rewardTypeCode.String() == consts.NetfeeCode {
|
||||||
|
if quantity, err := CalculateNetfeeRewardQuantity(ctx, in.UserId, in.StoreId, record["reward_id"].Int64(), completeTime); err == nil && quantity != 0 {
|
||||||
|
updateData.IssueQuantity = quantity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := dao.UserTaskRewards.Ctx(ctx).Data(updateData).Update(); err != nil {
|
||||||
|
return ecode.Fail.Sub("修改用户任务奖励失败")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
result.TaskList[i].Status = 2
|
||||||
|
} else {
|
||||||
|
result.TaskList[i].Status = 1
|
||||||
}
|
}
|
||||||
if err = dao.UserTaskRewards.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
result.TaskList[i].UserTimes -= one["user_times"].Int64()
|
||||||
_, err = dao.UserTasks.Ctx(ctx).WherePri(value.Int64()).Where(dao.UserTasks.Columns().Status).WhereNot(dao.UserTasks.Columns().Status, 2).Update(do.UserTasks{
|
} else if v.Status == 3 {
|
||||||
Status: 3,
|
// 查询该用户任务记录奖励都已发放
|
||||||
})
|
count, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: one["id"].Int64()}).Where(dao.UserTaskRewards.Columns().Status, []int{2, 3, 5}).Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ecode.Fail.Sub("修改用户任务状态失败")
|
return nil, ecode.Fail.Sub("查询用户门店任务奖励失败")
|
||||||
}
|
}
|
||||||
_, err = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: value.Int()}).Where(dao.UserTaskRewards.Columns().Status, 1).Update(do.UserTaskRewards{
|
|
||||||
Status: 2,
|
if count > 0 {
|
||||||
})
|
result.TaskList[i].Status = 2
|
||||||
if err != nil {
|
|
||||||
return ecode.Fail.Sub("修改用户任务奖励状态失败")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.PageIdx = result.PageIdx
|
out.PageIdx = result.PageIdx
|
||||||
@ -926,19 +870,44 @@ func (s *sTask) SyncTaskFromGamelife(ctx context.Context) (out *model.SyncTaskOu
|
|||||||
//delete(taskMap, "PrizeList")
|
//delete(taskMap, "PrizeList")
|
||||||
//delete(taskMap, "prize_list")
|
//delete(taskMap, "prize_list")
|
||||||
delete(taskMap, "reward")
|
delete(taskMap, "reward")
|
||||||
|
if err := dao.Tasks.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||||
_, err = dao.Tasks.Ctx(ctx).Data(do.Tasks{
|
_, err = dao.Tasks.Ctx(ctx).Data(do.Tasks{
|
||||||
TaskId: task.TaskID,
|
TaskId: task.TaskID,
|
||||||
StoreId: store["id"].Int(),
|
StoreId: store["id"].Int(),
|
||||||
GameId: game["game_id"].Int(),
|
GameId: game["game_id"].Int(),
|
||||||
NetbarAcconut: store["netbar_account"].String(),
|
NetbarAcconut: store["netbar_account"].String(),
|
||||||
Task: gconv.Bytes(taskMap),
|
Task: gconv.Bytes(taskMap),
|
||||||
}).Insert()
|
}).Insert()
|
||||||
if err != nil {
|
for _, prize := range task.PrizeList {
|
||||||
|
for _, goods := range prize.GoodsList {
|
||||||
|
if goods.GoodsType == 37 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if id, err := dao.Rewards.Ctx(ctx).Data(do.Rewards{
|
||||||
|
ImageUrl: consts.PlatformRewards[goods.GoodsType],
|
||||||
|
Name: goods.GoodsName,
|
||||||
|
RewardTypeId: goods.GoodsType,
|
||||||
|
GameId: game["game_id"].Int(),
|
||||||
|
Status: 1,
|
||||||
|
GrantQuantity: goods.Num,
|
||||||
|
Source: 1,
|
||||||
|
}).InsertAndGetId(); err == nil {
|
||||||
|
if _, err := dao.TaskRewards.Ctx(ctx).Data(do.TaskRewards{
|
||||||
|
TaskId: task.TaskID,
|
||||||
|
RewardId: id,
|
||||||
|
}).Insert(); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
glog.Errorf(ctx, "插入任务失败,task_id=%s,网吧=%s,游戏=%s,错误=%v",
|
glog.Errorf(ctx, "插入任务失败,task_id=%s,网吧=%s,游戏=%s,错误=%v",
|
||||||
task.TaskID, store["netbar_account"].String(), game["game_name"].String(), err)
|
task.TaskID, store["netbar_account"].String(), game["game_name"].String(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
insertCount++
|
insertCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,21 +920,7 @@ func (s *sTask) SyncTaskFromGamelife(ctx context.Context) (out *model.SyncTaskOu
|
|||||||
wg.Wait()
|
wg.Wait()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId int64, reward *model.SimpleReward, completedTime *gtime.Time) (uint64, error) {
|
func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId, rewardId int64, completedTime *gtime.Time) (uint64, error) {
|
||||||
const rewardTypeCode = consts.NetfeeCode
|
|
||||||
|
|
||||||
// 判断是否是门店网费奖励
|
|
||||||
exist, err := dao.RewardTypes.Ctx(ctx).
|
|
||||||
WherePri(reward.RewardTypeId).
|
|
||||||
Where(do.RewardTypes{Code: rewardTypeCode}).
|
|
||||||
Exist()
|
|
||||||
if err != nil {
|
|
||||||
return 0, ecode.Fail.Sub("获取奖励类型失败")
|
|
||||||
}
|
|
||||||
if !exist {
|
|
||||||
// 不是网费奖励,返回当前奖励默认值
|
|
||||||
return reward.GrantQuantity, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取当前小时 & 星期几(0=周日)
|
// 获取当前小时 & 星期几(0=周日)
|
||||||
hour := completedTime.Hour()
|
hour := completedTime.Hour()
|
||||||
@ -992,7 +947,7 @@ func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId in
|
|||||||
return 0, ecode.Fail.Sub("获取会员等级失败")
|
return 0, ecode.Fail.Sub("获取会员等级失败")
|
||||||
}
|
}
|
||||||
if levelId.IsEmpty() {
|
if levelId.IsEmpty() {
|
||||||
return reward.GrantQuantity, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取区域ID
|
// 获取区域ID
|
||||||
@ -1004,7 +959,7 @@ func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId in
|
|||||||
return 0, ecode.Fail.Sub("获取区域失败")
|
return 0, ecode.Fail.Sub("获取区域失败")
|
||||||
}
|
}
|
||||||
if areaId.IsEmpty() {
|
if areaId.IsEmpty() {
|
||||||
return reward.GrantQuantity, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取门店该区域、等级、奖励配置
|
// 获取门店该区域、等级、奖励配置
|
||||||
@ -1013,7 +968,7 @@ func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId in
|
|||||||
StoreId: storeId,
|
StoreId: storeId,
|
||||||
AreaId: areaId.Int(),
|
AreaId: areaId.Int(),
|
||||||
MemberLevelId: levelId.Int(),
|
MemberLevelId: levelId.Int(),
|
||||||
RewardId: reward.Id,
|
RewardId: rewardId,
|
||||||
}).
|
}).
|
||||||
Fields(dao.StoreNetfeeAreaLevel.Columns().PriceData).
|
Fields(dao.StoreNetfeeAreaLevel.Columns().PriceData).
|
||||||
Value()
|
Value()
|
||||||
@ -1023,7 +978,7 @@ func CalculateNetfeeRewardQuantity(ctx context.Context, userId int64, storeId in
|
|||||||
|
|
||||||
// 若配置为空,返回默认值
|
// 若配置为空,返回默认值
|
||||||
if priceDataStr.IsEmpty() {
|
if priceDataStr.IsEmpty() {
|
||||||
return reward.GrantQuantity, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 priceData
|
// 解析 priceData
|
||||||
|
|||||||
@ -37,7 +37,7 @@ type GameTask struct {
|
|||||||
CycleStart int64 `json:"cycle_start"`
|
CycleStart int64 `json:"cycle_start"`
|
||||||
CycleEnd int64 `json:"cycle_end"`
|
CycleEnd int64 `json:"cycle_end"`
|
||||||
TargetName string `json:"target_name"`
|
TargetName string `json:"target_name"`
|
||||||
TargetTimes int `json:"target_times"`
|
TargetTimes int64 `json:"target_times"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
UserTimes int64 `json:"user_times"`
|
UserTimes int64 `json:"user_times"`
|
||||||
GameTaskConfig GameTaskConfig `json:"game_task_config"`
|
GameTaskConfig GameTaskConfig `json:"game_task_config"`
|
||||||
|
|||||||
@ -291,12 +291,13 @@ type GetGoodsDetailsOut struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OperateTaskRewardIn struct {
|
type OperateTaskRewardIn struct {
|
||||||
OperatorId int64
|
OperatorId int64
|
||||||
OperatorRole string
|
OperatorRole string
|
||||||
TaskId string
|
TaskId string
|
||||||
RewardId int64
|
RewardId int64
|
||||||
Type int // 1: 任务添加奖励 2: 任务删除奖励
|
Type int // 1: 任务添加奖励 2: 任务删除奖励
|
||||||
StoreId int64 // 当前操作门店, 当操作为门店或者是商户时
|
StoreId int64 // 当前操作门店, 当操作为门店或者是商户时
|
||||||
|
NetbarAccount string
|
||||||
}
|
}
|
||||||
type OperateTaskRewardOut struct {
|
type OperateTaskRewardOut struct {
|
||||||
Success bool
|
Success bool
|
||||||
|
|||||||
@ -14,7 +14,10 @@ type StoreAdminLoginIn struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StoreAdminLoginOut struct {
|
type StoreAdminLoginOut struct {
|
||||||
Token string
|
Token string
|
||||||
|
StoreId int64
|
||||||
|
StoreName string
|
||||||
|
NetbarAccount string
|
||||||
}
|
}
|
||||||
type StoreAdminListIn struct {
|
type StoreAdminListIn struct {
|
||||||
Page int
|
Page int
|
||||||
|
|||||||
Reference in New Issue
Block a user