fix(order): reconcile subscriptions and grant device trials
Build docker and publish / build (20.15.1) (push) Has been cancelled
Build docker and publish / build (20.15.1) (push) Has been cancelled
This commit is contained in:
@@ -304,20 +304,17 @@ func (l *ActivateOrderLogic) reconcilePostOrderSubscriptions(ctx context.Context
|
||||
return nil
|
||||
}
|
||||
|
||||
maxExpire := survivor.ExpireTime
|
||||
now := time.Now()
|
||||
accumulatedExpire := now
|
||||
for i := range ownerSubs {
|
||||
item := ownerSubs[i]
|
||||
if item.Id == survivor.Id {
|
||||
if item.ExpireTime.After(maxExpire) {
|
||||
maxExpire = item.ExpireTime
|
||||
}
|
||||
continue
|
||||
if (item.Id == survivor.Id || orderMergeRemainingTimeStatus(item.Status)) && item.ExpireTime.After(now) {
|
||||
accumulatedExpire = accumulatedExpire.Add(item.ExpireTime.Sub(now))
|
||||
}
|
||||
|
||||
losers = append(losers, item)
|
||||
mergedIDs = append(mergedIDs, item.Id)
|
||||
if item.ExpireTime.After(maxExpire) {
|
||||
maxExpire = item.ExpireTime
|
||||
if item.Id != survivor.Id {
|
||||
losers = append(losers, item)
|
||||
mergedIDs = append(mergedIDs, item.Id)
|
||||
}
|
||||
if item.SubscribeId > 0 {
|
||||
subscribeIDsToClear[item.SubscribeId] = struct{}{}
|
||||
@@ -341,9 +338,9 @@ func (l *ActivateOrderLogic) reconcilePostOrderSubscriptions(ctx context.Context
|
||||
"status": 1,
|
||||
"finished_at": nil,
|
||||
}
|
||||
if maxExpire.After(survivor.ExpireTime) {
|
||||
survivor.ExpireTime = maxExpire
|
||||
updateFields["expire_time"] = maxExpire
|
||||
if accumulatedExpire.After(survivor.ExpireTime) {
|
||||
survivor.ExpireTime = accumulatedExpire
|
||||
updateFields["expire_time"] = accumulatedExpire
|
||||
}
|
||||
if identitySource != nil {
|
||||
if identitySource.Token != "" {
|
||||
@@ -441,6 +438,15 @@ func shouldReconcilePostOrderSubscriptions(orderInfo *order.Order) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func orderMergeRemainingTimeStatus(status uint8) bool {
|
||||
switch status {
|
||||
case 0, 1, 2:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func pickSubscriptionIdentitySource(candidates []user.Subscribe) *user.Subscribe {
|
||||
if len(candidates) == 0 {
|
||||
return nil
|
||||
@@ -1434,6 +1440,7 @@ func (l *ActivateOrderLogic) updateSubscriptionWithIAPExpire(ctx context.Context
|
||||
userSub.FinishedAt = nil
|
||||
}
|
||||
|
||||
userSub.OrderId = orderInfo.Id
|
||||
userSub.ExpireTime = newExpire
|
||||
userSub.Status = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user