首次激活重新计算余量时长
This commit is contained in:
parent
84e78bc808
commit
6907e59e2e
@ -451,11 +451,29 @@ func ConfirmWork(req *bundle.ConfirmWorkReq) error {
|
||||
}
|
||||
|
||||
func BundleActivate(ids []uint32) error {
|
||||
batch := []model.BundleActivate{}
|
||||
for _, v := range ids {
|
||||
batch = append(batch, model.BundleActivate{UserId: int(v), Activate: true})
|
||||
app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
||||
activate := model.BundleActivate{}
|
||||
if err := tx.Model(&model.BundleActivate{}).Where("user_id = ?", v).First(&activate).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !activate.Activate { // 第一次激活重新计算余量的开始时间和过期时间
|
||||
balance := model.BundleBalance{}
|
||||
if err := tx.Model(&model.BundleBalance{}).Where("user_id = ?", v).First(&balance).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
balance.ExpiredAt = balance.ExpiredAt.Add(time.Since(balance.StartAt))
|
||||
balance.StartAt = time.Now()
|
||||
if err := tx.Model(&model.BundleBalance{}).Save(balance).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
activate.Activate = true
|
||||
return tx.Model(&model.BundleActivate{}).Save(activate).Error
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
return app.ModuleClients.BundleDB.Model(&model.BundleActivate{}).Where("user_id = ?").Save(batch).Error
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetValueAddByOrderUUID(orderUUID string) (data []model.BundleOrderValueAdd, err error) {
|
||||
|
Loading…
Reference in New Issue
Block a user