Merge branch 'fix' into 'staging'
add activationLimit See merge request pena-services/codeword!18
This commit is contained in:
commit
5846da07fc
@ -433,6 +433,9 @@ components:
|
|||||||
type: integer
|
type: integer
|
||||||
nullable: true
|
nullable: true
|
||||||
description: Количество активаций промокода
|
description: Количество активаций промокода
|
||||||
|
ActivationLimit:
|
||||||
|
type: integer
|
||||||
|
description: Лимит, есть или нет если 0 то нет
|
||||||
Delete:
|
Delete:
|
||||||
type: boolean
|
type: boolean
|
||||||
nullable: true
|
nullable: true
|
||||||
@ -455,6 +458,9 @@ components:
|
|||||||
activationCount:
|
activationCount:
|
||||||
type: integer
|
type: integer
|
||||||
description: Количество активаций промокода
|
description: Количество активаций промокода
|
||||||
|
activationLimit:
|
||||||
|
type: integer
|
||||||
|
description: Лимит, есть или нет если 0 то нет
|
||||||
bonus:
|
bonus:
|
||||||
type: object
|
type: object
|
||||||
description: Бонус
|
description: Бонус
|
||||||
|
@ -40,6 +40,8 @@ func (p *PromoCodeController) CreatePromoCode(c *fiber.Ctx) error {
|
|||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "codeword is required"})
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "codeword is required"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.ActivationLimit = req.ActivationCount
|
||||||
|
|
||||||
createdPromoCode, err := p.promoCodeService.CreatePromoCode(c.Context(), &req)
|
createdPromoCode, err := p.promoCodeService.CreatePromoCode(c.Context(), &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger.Error("Failed to create promocode", zap.Error(err))
|
p.logger.Error("Failed to create promocode", zap.Error(err))
|
||||||
@ -64,6 +66,8 @@ func (p *PromoCodeController) EditPromoCode(c *fiber.Ctx) error {
|
|||||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "promocode ID is required"})
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "promocode ID is required"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.ActivationLimit = req.ActivationCount
|
||||||
|
|
||||||
editedPromoCode, err := p.promoCodeService.EditPromoCode(c.Context(), &req)
|
editedPromoCode, err := p.promoCodeService.EditPromoCode(c.Context(), &req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.logger.Error("Failed to edit promocode", zap.Error(err))
|
p.logger.Error("Failed to edit promocode", zap.Error(err))
|
||||||
|
@ -12,6 +12,7 @@ type PromoCode struct {
|
|||||||
Greetings string `json:"greetings" bson:"greetings"` // текст, выдаваемый пользователю в ответ на активацию промокода
|
Greetings string `json:"greetings" bson:"greetings"` // текст, выдаваемый пользователю в ответ на активацию промокода
|
||||||
DueTo int64 `json:"dueTo" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
|
DueTo int64 `json:"dueTo" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
|
||||||
ActivationCount int64 `json:"activationCount" bson:"activationCount"` // предел количества активаций промокода
|
ActivationCount int64 `json:"activationCount" bson:"activationCount"` // предел количества активаций промокода
|
||||||
|
ActivationLimit int64 `json:"activationLimit" bson:"activationLimit"` // лимит если 0 то без лимита
|
||||||
Bonus struct {
|
Bonus struct {
|
||||||
Privilege struct {
|
Privilege struct {
|
||||||
PrivilegeID string `json:"privilegeID" bson:"privilegeID"` // айдишник привилегии, которая будет выдаваться
|
PrivilegeID string `json:"privilegeID" bson:"privilegeID"` // айдишник привилегии, которая будет выдаваться
|
||||||
@ -38,6 +39,7 @@ type ReqEditPromoCode struct {
|
|||||||
|
|
||||||
DueTo *int64 `json:"dueTo,omitempty" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
|
DueTo *int64 `json:"dueTo,omitempty" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
|
||||||
ActivationCount *int64 `json:"activationCount,omitempty" bson:"activationCount"` // предел количества активаций промокода
|
ActivationCount *int64 `json:"activationCount,omitempty" bson:"activationCount"` // предел количества активаций промокода
|
||||||
|
ActivationLimit *int64 `json:"activationLimit,omitempty" bson:"activationLimit"` // лимит если 0 то без лимита
|
||||||
|
|
||||||
Delete *bool `json:"delete,omitempty" bson:"delete"`
|
Delete *bool `json:"delete,omitempty" bson:"delete"`
|
||||||
|
|
||||||
|
@ -95,6 +95,9 @@ func (r *PromoCodeRepository) EditPromoCode(ctx context.Context, req *models.Req
|
|||||||
if req.ActivationCount != nil {
|
if req.ActivationCount != nil {
|
||||||
updateFields["activationCount"] = *req.ActivationCount
|
updateFields["activationCount"] = *req.ActivationCount
|
||||||
}
|
}
|
||||||
|
if req.ActivationLimit != nil {
|
||||||
|
updateFields["activationLimit"] = *req.ActivationLimit
|
||||||
|
}
|
||||||
if req.Delete != nil {
|
if req.Delete != nil {
|
||||||
updateFields["delete"] = *req.Delete
|
updateFields["delete"] = *req.Delete
|
||||||
}
|
}
|
||||||
@ -221,12 +224,12 @@ func (r *PromoCodeRepository) ActivatePromo(ctx context.Context, req *models.Act
|
|||||||
if req.Codeword != "" {
|
if req.Codeword != "" {
|
||||||
filter = bson.M{
|
filter = bson.M{
|
||||||
"codeword": req.Codeword,
|
"codeword": req.Codeword,
|
||||||
"delete": false,
|
"delete": false,
|
||||||
}
|
}
|
||||||
} else if req.FastLink != "" {
|
} else if req.FastLink != "" {
|
||||||
filter = bson.M{
|
filter = bson.M{
|
||||||
"fastLinks": req.FastLink,
|
"fastLinks": req.FastLink,
|
||||||
"delete": false,
|
"delete": false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,18 +98,18 @@ func (s *PromoCodeService) ActivatePromo(ctx context.Context, req *models.Activa
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
//todo такая реализация проверок кажется довольно массивной, думаю как то это стоит сделать параллельно обхаживая все условия
|
//todo такая реализация проверок кажется довольно массивной, думаю как то это стоит сделать параллельно обхаживая все условия
|
||||||
if promoCode.DueTo < time.Now().Unix() && promoCode.DueTo > 0 {
|
if promoCode.DueTo < time.Now().Unix() && promoCode.DueTo > 0 && promoCode.ActivationLimit != 0 {
|
||||||
err := s.promoCodeRepo.IncreaseActivationCount(ctx, promoCode.ID)
|
err := s.promoCodeRepo.IncreaseActivationCount(ctx, promoCode.ID)
|
||||||
fmt.Println("SKER21", err)
|
fmt.Println("SKER21", err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("%w: expired on %s", repository.ErrPromoCodeExpired, time.Unix(promoCode.DueTo, 0).Format(time.RFC3339))
|
return "", fmt.Errorf("%w: expired on %s", repository.ErrPromoCodeExpired, time.Unix(promoCode.DueTo, 0).Format(time.RFC3339))
|
||||||
}
|
}
|
||||||
|
|
||||||
if promoCode.DueTo == 0 && promoCode.ActivationCount < 0 {
|
if promoCode.DueTo == 0 && promoCode.ActivationCount < 0 && promoCode.ActivationLimit != 0 {
|
||||||
err := s.promoCodeRepo.IncreaseActivationCount(ctx, promoCode.ID)
|
err := s.promoCodeRepo.IncreaseActivationCount(ctx, promoCode.ID)
|
||||||
fmt.Println("SKER22", err)
|
fmt.Println("SKER22", err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -167,24 +167,24 @@ func (s *PromoCodeService) ActivatePromo(ctx context.Context, req *models.Activa
|
|||||||
Layer: promoCode.Bonus.Discount.Layer,
|
Layer: promoCode.Bonus.Discount.Layer,
|
||||||
Description: "",
|
Description: "",
|
||||||
Condition: &discount.DiscountCondition{
|
Condition: &discount.DiscountCondition{
|
||||||
Coupon: &promoCode.Codeword,
|
Coupon: &promoCode.Codeword,
|
||||||
User: &userID,
|
User: &userID,
|
||||||
Group: &promoCode.Bonus.Discount.Target,
|
Group: &promoCode.Bonus.Discount.Target,
|
||||||
Product: &promoCode.Bonus.Discount.Target,
|
Product: &promoCode.Bonus.Discount.Target,
|
||||||
UserType: &emptyString,
|
UserType: &emptyString,
|
||||||
PurchasesAmount: &zero,
|
PurchasesAmount: &zero,
|
||||||
CartPurchasesAmount: &zero,
|
CartPurchasesAmount: &zero,
|
||||||
Term: &zero,
|
Term: &zero,
|
||||||
Usage: &zero,
|
Usage: &zero,
|
||||||
PriceFrom: &zero,
|
PriceFrom: &zero,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if promoCode.Bonus.Discount.Layer == 1 {
|
if promoCode.Bonus.Discount.Layer == 1 {
|
||||||
discountRequest.Target = &discount.DiscountCalculationTarget{
|
discountRequest.Target = &discount.DiscountCalculationTarget{
|
||||||
Products: []*discount.ProductTarget{{
|
Products: []*discount.ProductTarget{{
|
||||||
ID: promoCode.Bonus.Discount.Target,
|
ID: promoCode.Bonus.Discount.Target,
|
||||||
Factor: promoCode.Bonus.Discount.Factor,
|
Factor: promoCode.Bonus.Discount.Factor,
|
||||||
}},
|
}},
|
||||||
Overhelm: &disOverHelm,
|
Overhelm: &disOverHelm,
|
||||||
}
|
}
|
||||||
@ -193,11 +193,11 @@ func (s *PromoCodeService) ActivatePromo(ctx context.Context, req *models.Activa
|
|||||||
if promoCode.Bonus.Discount.Layer == 2 {
|
if promoCode.Bonus.Discount.Layer == 2 {
|
||||||
discountRequest.Target = &discount.DiscountCalculationTarget{
|
discountRequest.Target = &discount.DiscountCalculationTarget{
|
||||||
TargetGroup: &promoCode.Bonus.Discount.Target,
|
TargetGroup: &promoCode.Bonus.Discount.Target,
|
||||||
Factor: promoCode.Bonus.Discount.Factor,
|
Factor: promoCode.Bonus.Discount.Factor,
|
||||||
Overhelm: &disOverHelm,
|
Overhelm: &disOverHelm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = s.discountClient.CreateDiscount(ctx, discountRequest)
|
_, err = s.discountClient.CreateDiscount(ctx, discountRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to create discount", zap.Error(err))
|
s.logger.Error("Failed to create discount", zap.Error(err))
|
||||||
|
Loading…
Reference in New Issue
Block a user