新增获取网费奖励列表
This commit is contained in:
@ -348,6 +348,84 @@ func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ListInternetCharge 网费奖励列表
|
||||
func (s *sReward) ListInternetCharge(ctx context.Context, in *model.RewardListIn) (out *model.InternetChargeRewardListOut, err error) {
|
||||
|
||||
rewardCols := dao.Rewards.Columns()
|
||||
orm := dao.Rewards.Ctx(ctx).LeftJoin(
|
||||
dao.RewardTypes.Table(),
|
||||
fmt.Sprintf(
|
||||
"%s.%s = %s.%s",
|
||||
dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId,
|
||||
dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id,
|
||||
),
|
||||
).Fields(fmt.Sprintf("%s.*,%s.name as reward_type_name", dao.Rewards.Table(), dao.RewardTypes.Table()))
|
||||
switch in.OperatorRole {
|
||||
case consts.AdminRoleCode:
|
||||
// 系统管理员只能查询 source = 1 的奖励
|
||||
orm = orm.Where(rewardCols.Source, 1)
|
||||
case consts.MerchantRoleCode, consts.StoreRoleCode:
|
||||
// 合并商户和门店角色权限校验
|
||||
var exist bool
|
||||
if in.OperatorRole == consts.MerchantRoleCode {
|
||||
exist, err = dao.MerchantAdmins.Ctx(ctx).
|
||||
Where(do.MerchantAdmins{Id: in.OperatorId}).
|
||||
LeftJoin(
|
||||
dao.Stores.Table(),
|
||||
fmt.Sprintf("%s.%s = %s.%s",
|
||||
dao.MerchantAdmins.Table(), dao.MerchantAdmins.Columns().MerchantId,
|
||||
dao.Stores.Table(), dao.Stores.Columns().MerchantId,
|
||||
),
|
||||
).
|
||||
Where(fmt.Sprintf("%s.%s = ?", dao.Stores.Table(), dao.Stores.Columns().Id), in.StoreId).
|
||||
Exist()
|
||||
} else {
|
||||
exist, err = dao.StoreAdmins.Ctx(ctx).
|
||||
Where(do.StoreAdmins{Id: in.OperatorId}).
|
||||
LeftJoin(
|
||||
dao.Stores.Table(),
|
||||
fmt.Sprintf("%s.%s = %s.%s",
|
||||
dao.StoreAdmins.Table(), dao.StoreAdmins.Columns().StoreId,
|
||||
dao.Stores.Table(), dao.Stores.Columns().Id,
|
||||
),
|
||||
).
|
||||
Where(fmt.Sprintf("%s.%s = ?", dao.Stores.Table(), dao.Stores.Columns().Id), in.StoreId).
|
||||
Exist()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, ecode.Fail.Sub("检查操作者权限异常")
|
||||
}
|
||||
if !exist {
|
||||
return nil, ecode.Params.Sub("无门店权限")
|
||||
}
|
||||
orm = orm.Where(rewardCols.Source, 2)
|
||||
default:
|
||||
return nil, ecode.Params.Sub("无效的角色")
|
||||
}
|
||||
|
||||
// ==== 其他查询条件 ====
|
||||
if in.Status != 0 {
|
||||
orm = orm.Where(fmt.Sprintf("%s.%s = ?", dao.Rewards.Table(), rewardCols.Status), in.Status)
|
||||
}
|
||||
|
||||
if in.Name != "" {
|
||||
orm = orm.WhereLike(rewardCols.Name, "%"+in.Name+"%")
|
||||
}
|
||||
|
||||
// ==== 总数统计 ====
|
||||
list := make([]model.InternetChargeReward, 0)
|
||||
var total int
|
||||
err = orm.Where(dao.Rewards.Columns().RewardTypeId, 1).Fields("rewards.name,rewards.grant_quantity").ScanAndCount(&list, &total, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &model.InternetChargeRewardListOut{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetLift 领取奖励
|
||||
// func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) {
|
||||
//
|
||||
|
||||
@ -33,6 +33,14 @@ type Reward struct {
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间(软删除)"` // 删除时间(软删除)
|
||||
}
|
||||
|
||||
type InternetChargeReward struct {
|
||||
g.Meta `orm:"table:rewards"`
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
|
||||
GrantQuantity uint64 `json:"grantQuantity" orm:"grant_quantity" description:"每次发放个数"` // 每次发放个数
|
||||
}
|
||||
|
||||
type SimpleReward struct {
|
||||
g.Meta `orm:"table:rewards"`
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
@ -156,6 +164,11 @@ type RewardListOut struct {
|
||||
Total int
|
||||
}
|
||||
|
||||
type InternetChargeRewardListOut struct {
|
||||
List []InternetChargeReward
|
||||
Total int
|
||||
}
|
||||
|
||||
// RewardCallbackIn 任务奖励领取回调入参
|
||||
type RewardCallbackIn struct {
|
||||
Uid string `json:"uid" ` // 用户账号
|
||||
|
||||
@ -20,6 +20,8 @@ type (
|
||||
Delete(ctx context.Context, in *model.RewardDeleteIn) (out *model.RewardDeleteOut, err error)
|
||||
// List 奖励列表
|
||||
List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error)
|
||||
// ListInternetCharge 网费奖励列表
|
||||
ListInternetCharge(ctx context.Context, in *model.RewardListIn) (out *model.InternetChargeRewardListOut, err error)
|
||||
// GetLift 领取奖励
|
||||
// func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) {
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user