feat: configure member dispatch delay
This commit is contained in:
@@ -82,6 +82,15 @@ func (s *sSysMemberLevel) View(ctx context.Context, in *sysin.MemberLevelViewInp
|
||||
}
|
||||
|
||||
func (s *sSysMemberLevel) Save(ctx context.Context, in *sysin.MemberLevelSaveInp) (id, versionId uint64, err error) {
|
||||
rules := g.Map{}
|
||||
if in.RuleJson != nil {
|
||||
for key, value := range in.RuleJson.Map() {
|
||||
rules[key] = value
|
||||
}
|
||||
}
|
||||
rules["auto_order_delay_min_seconds"] = in.AutoOrderDelayMinSeconds
|
||||
rules["auto_order_delay_max_seconds"] = in.AutoOrderDelayMaxSeconds
|
||||
in.RuleJson = gjson.New(rules)
|
||||
err = g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
lc, vc := dao.AppMemberLevel.Columns(), dao.AppMemberLevelVersion.Columns()
|
||||
count, e := s.model(ctx).Where(lc.LevelCode, in.LevelCode).WhereNot(lc.Id, in.Id).Count()
|
||||
@@ -253,7 +262,12 @@ func (s *sSysMemberLevel) Rollback(ctx context.Context, in *sysin.MemberLevelRol
|
||||
if level == nil {
|
||||
return 0, gerror.New("会员等级不存在")
|
||||
}
|
||||
_, versionId, err = s.Save(ctx, &sysin.MemberLevelSaveInp{Id: level.Id, LevelCode: level.LevelCode, Name: level.Name, IconAttachmentId: level.IconAttachmentId, IconUrl: level.IconUrl, UpgradeAmount: source.UpgradeAmount, GiftAmount: source.GiftAmount, DailyOrderLimit: source.DailyOrderLimit, CommissionRate: source.CommissionRate, DailyWithdrawLimit: source.DailyWithdrawLimit, RuleJson: source.RuleJson, EffectiveAt: nil, Sort: level.Sort, Status: level.Status, Remark: "回滚自 V" + fmt.Sprint(source.VersionNo) + ":" + in.Reason})
|
||||
delayMin, delayMax := 0, 0
|
||||
if source.RuleJson != nil {
|
||||
delayMin = source.RuleJson.Get("auto_order_delay_min_seconds").Int()
|
||||
delayMax = source.RuleJson.Get("auto_order_delay_max_seconds").Int()
|
||||
}
|
||||
_, versionId, err = s.Save(ctx, &sysin.MemberLevelSaveInp{Id: level.Id, LevelCode: level.LevelCode, Name: level.Name, IconAttachmentId: level.IconAttachmentId, IconUrl: level.IconUrl, UpgradeAmount: source.UpgradeAmount, GiftAmount: source.GiftAmount, DailyOrderLimit: source.DailyOrderLimit, CommissionRate: source.CommissionRate, DailyWithdrawLimit: source.DailyWithdrawLimit, AutoOrderDelayMinSeconds: delayMin, AutoOrderDelayMaxSeconds: delayMax, RuleJson: source.RuleJson, EffectiveAt: nil, Sort: level.Sort, Status: level.Status, Remark: "回滚自 V" + fmt.Sprint(source.VersionNo) + ":" + in.Reason})
|
||||
return
|
||||
}
|
||||
func (s *sSysMemberLevel) History(ctx context.Context, in *sysin.MemberLevelHistoryInp) (list []*entity.AppMemberLevelVersion, total int, err error) {
|
||||
|
||||
@@ -55,23 +55,25 @@ type MemberLevelViewModel struct {
|
||||
Published *entity.AppMemberLevelVersion `json:"published"`
|
||||
}
|
||||
type MemberLevelSaveInp struct {
|
||||
Id uint64 `json:"id"`
|
||||
VersionId uint64 `json:"versionId"`
|
||||
Version uint `json:"version"`
|
||||
LevelCode string `json:"levelCode" v:"required|max-length:32#等级编码不能为空|等级编码不能超过32个字符"`
|
||||
Name string `json:"name" v:"required|max-length:64#等级名称不能为空|等级名称不能超过64个字符"`
|
||||
IconAttachmentId uint64 `json:"iconAttachmentId"`
|
||||
IconUrl string `json:"iconUrl" v:"max-length:1000#图标地址不能超过1000个字符"`
|
||||
UpgradeAmount int64 `json:"upgradeAmount" v:"min:0#升级金额不能小于0"`
|
||||
GiftAmount int64 `json:"giftAmount" v:"min:0#赠送金额不能小于0"`
|
||||
DailyOrderLimit uint `json:"dailyOrderLimit"`
|
||||
CommissionRate uint `json:"commissionRate" v:"max:10000#佣金比例不能超过100%"`
|
||||
DailyWithdrawLimit uint `json:"dailyWithdrawLimit"`
|
||||
RuleJson *gjson.Json `json:"ruleJson"`
|
||||
EffectiveAt *gtime.Time `json:"effectiveAt"`
|
||||
Sort int `json:"sort"`
|
||||
Status int `json:"status" d:"1"`
|
||||
Remark string `json:"remark" v:"max-length:500#备注不能超过500个字符"`
|
||||
Id uint64 `json:"id"`
|
||||
VersionId uint64 `json:"versionId"`
|
||||
Version uint `json:"version"`
|
||||
LevelCode string `json:"levelCode" v:"required|max-length:32#等级编码不能为空|等级编码不能超过32个字符"`
|
||||
Name string `json:"name" v:"required|max-length:64#等级名称不能为空|等级名称不能超过64个字符"`
|
||||
IconAttachmentId uint64 `json:"iconAttachmentId"`
|
||||
IconUrl string `json:"iconUrl" v:"max-length:1000#图标地址不能超过1000个字符"`
|
||||
UpgradeAmount int64 `json:"upgradeAmount" v:"min:0#升级金额不能小于0"`
|
||||
GiftAmount int64 `json:"giftAmount" v:"min:0#赠送金额不能小于0"`
|
||||
DailyOrderLimit uint `json:"dailyOrderLimit"`
|
||||
CommissionRate uint `json:"commissionRate" v:"max:10000#佣金比例不能超过100%"`
|
||||
DailyWithdrawLimit uint `json:"dailyWithdrawLimit"`
|
||||
AutoOrderDelayMinSeconds int `json:"autoOrderDelayMinSeconds" v:"min:0#最短派单时间不能小于0"`
|
||||
AutoOrderDelayMaxSeconds int `json:"autoOrderDelayMaxSeconds" v:"min:0#最长派单时间不能小于0"`
|
||||
RuleJson *gjson.Json `json:"ruleJson"`
|
||||
EffectiveAt *gtime.Time `json:"effectiveAt"`
|
||||
Sort int `json:"sort"`
|
||||
Status int `json:"status" d:"1"`
|
||||
Remark string `json:"remark" v:"max-length:500#备注不能超过500个字符"`
|
||||
}
|
||||
|
||||
func (in *MemberLevelSaveInp) Filter(ctx context.Context) error {
|
||||
@@ -81,6 +83,9 @@ func (in *MemberLevelSaveInp) Filter(ctx context.Context) error {
|
||||
if in.UpgradeAmount > 0 && in.GiftAmount > in.UpgradeAmount {
|
||||
return gerror.New("赠送金额不能超过升级金额")
|
||||
}
|
||||
if in.AutoOrderDelayMaxSeconds < in.AutoOrderDelayMinSeconds {
|
||||
return gerror.New("最长派单时间不能小于最短派单时间")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user