实现网费奖励下发和回调接口
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"server/internal/consts"
|
||||
"server/internal/dao"
|
||||
@ -15,6 +16,8 @@ import (
|
||||
"server/internal/service"
|
||||
"server/utility/ecode"
|
||||
"server/utility/gamelife"
|
||||
"server/utility/mqtt"
|
||||
"server/utility/mqtt/emqx"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@ -657,7 +660,7 @@ func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *mode
|
||||
}
|
||||
}
|
||||
|
||||
if in.Source == 1 && in.RewradTypeId == 37 || in.Source == 2 {
|
||||
if in.Source == 1 && in.RewradTypeId == 37 {
|
||||
// 增加奖励已领取数量
|
||||
_, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.RewardId}).Increment(dao.Rewards.Columns().ReceivedNum, 1)
|
||||
if err != nil {
|
||||
@ -704,6 +707,63 @@ func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *mode
|
||||
}
|
||||
} else {
|
||||
// 门店奖励处理
|
||||
value, err := dao.RewardTypes.Ctx(ctx).WherePri(in.RewradTypeId).Value()
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("获取奖励类型失败")
|
||||
}
|
||||
if value.IsEmpty() {
|
||||
return nil, ecode.Params.Sub("奖励类型不存在")
|
||||
}
|
||||
switch value.String() {
|
||||
case consts.NetfeeCode:
|
||||
dao.UserTaskRewards.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
xyUserId, err := dao.Users.Ctx(ctx).WherePri(in.UserId).Fields(dao.Users.Columns().XyUserId).Value()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if xyUserId.IsEmpty() {
|
||||
return ecode.Params.Sub("该用户暂未绑定8圈账号,无法发放网费奖励")
|
||||
}
|
||||
|
||||
// 增加奖励已领取数量
|
||||
_, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.RewardId}).Increment(dao.Rewards.Columns().ReceivedNum, 1)
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("获取奖励领取记录异常")
|
||||
}
|
||||
|
||||
// 修改用户任务奖励记录状态
|
||||
_, err = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{Id: in.Id}).Data(do.UserTaskRewards{
|
||||
Status: consts.RewardExchangeStatus,
|
||||
}).Update()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务奖励记录状态异常")
|
||||
}
|
||||
|
||||
client, b := mqtt.GetClient("emqx")
|
||||
if !b {
|
||||
return ecode.Fail.Sub("获取mqtt客户端异常")
|
||||
}
|
||||
downData := emqx.DownData{CMD: consts.CmdUserFee, Data: struct {
|
||||
XyUserId string `json:"xy_user_id"`
|
||||
Money int `json:"money"`
|
||||
Note string `json:"note"`
|
||||
OrderId string `json:"order_id"`
|
||||
}{
|
||||
XyUserId: xyUserId.String(),
|
||||
Money: in.GrantQuantity,
|
||||
Note: fmt.Sprintf("用户领取 id 为 %d,下发记录 id 为 %d 的网费", in.RewardId, in.Id),
|
||||
OrderId: gconv.String(in.Id),
|
||||
}}
|
||||
marshal, err := json.Marshal(downData)
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("json.Marshal异常")
|
||||
}
|
||||
if err = client.Publish(fmt.Sprintf(consts.DOWNDataTopic, in.StoreId), marshal); err != nil {
|
||||
return ecode.Fail.Sub("Publish异常")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
@ -1115,3 +1175,41 @@ func (s *sReward) GetUserClaimList(ctx context.Context, in *model.GetUserClaimLi
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sReward) NetfeeCallback(ctx context.Context, in *model.NetfeeCallbackIn) (out *model.NetfeeCallbackOut, err error) {
|
||||
if err = dao.UserTaskRewards.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
value, err := dao.UserTaskRewards.Ctx(ctx).WherePri(in.OrderId).Fields(dao.UserTaskRewards.Columns().UserTaskId).Value()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("查询用户任务奖励失败")
|
||||
}
|
||||
if value.IsEmpty() {
|
||||
return ecode.Fail.Sub("查询用户任务奖励失败")
|
||||
}
|
||||
count, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: value.Int64()}).WhereIn(dao.UserTaskRewards.Columns().Status, []int{2, 3, 5}).Count()
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("查询用户任务奖励失败")
|
||||
}
|
||||
|
||||
if count == 1 {
|
||||
// 修改任务记录状态2
|
||||
_, err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{Id: value.Int64()}).Data(do.UserTasks{
|
||||
Status: 2,
|
||||
}).Update()
|
||||
|
||||
if err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务状态失败")
|
||||
}
|
||||
}
|
||||
if _, err := dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{
|
||||
Status: consts.RewardSuccessStatus,
|
||||
}).Update(); err != nil {
|
||||
return ecode.Fail.Sub("修改用户任务奖励状态失败")
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &model.NetfeeCallbackOut{Success: true}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user