Cupom MGM

 avatar
unknown
mysql
3 years ago
2.6 kB
2
Indexable
# Coupon Type
-- Cashback Operation Wayne
INSERT INTO wayne.operation (code, start_at, end_at, active, config) VALUES
("BECASHR$15MGM", "2021-01-18 15:03:47.617069000", "2023-12-31 00:00:00", "1", '[{"type":"BECASH","credit":{"value":15,"accumulative":true,"to_value_type":"BRL","from_value_type":"BRL"},"compensation":{"days":0,"has_dependency":true},"expiration_days":1e+16}]');

-- Cadastrar tipos de cupom
INSERT INTO stark.coupon_type (code, description, metadata) VALUES
('GENERAL', "Cupom padão", null),
('MGM', "Member get Member", '{"rules":[{"id":"user.required"}]}');

SELECT * from stark.coupon_type ct order by 1 desc;

# Coupon
-- Atualizar os cupons já existentes para o tipo "GENERAL"
UPDATE stark.coupon c
SET c.coupon_type_id = (SELECT id from stark.coupon_type ct where ct.code = "GENERAL");

SELECT * FROM stark.coupon c order by 1 desc;

# Coupon Type Attributes
-- Criar atributos para regra do tipo de cupom
INSERT INTO stark.`attribute` (code, `type`, description) VALUES
('COUPON_MINIMUM_VALUE', 'number', 'Valor minimo que o carrinho deve ter para poder aplicar o cupom.'),
('COUPON_CASHBACK', 'json', 'Cashback que será gerado ao comprar com este cupom'),
('COUPON_DEFAULT_PROMOTION', 'json', 'Promoção padrão para o tipo de cupom'),
('COUPON_CHANGELOG_GENERATE', 'number', 'Gerar um changelog no metadata do cupom ao edita-lo.'),
('COUPON_FIRST_ORDER', 'boolean', 'Validar se é o primeiro pedido pago do usuário.');

SELECT * FROM stark.`attribute` a order by 1 desc;

INSERT INTO stark.coupon_type_attribute (coupon_type_id, attribute_id, value, active, `sequence`) VALUES
((SELECT id from stark.coupon_type ct where ct.code = "MGM"), (SELECT id from stark.`attribute` a where a.code = "COUPON_MINIMUM_VALUE"), '250', '1', '0'),
((SELECT id from stark.coupon_type ct where ct.code = "MGM"), (SELECT id from stark.`attribute` a where a.code = "COUPON_FIRST_ORDER"), '1', '1', '0'),
((SELECT id from stark.coupon_type ct where ct.code = "MGM"), (SELECT id from stark.`attribute` a where a.code = "COUPON_DEFAULT_PROMOTION"), '{"price_discount_type": "ABSOLUTE", "price_discount": "25", "freight_discount":"0"}', '1', '0'),
((SELECT id from stark.coupon_type ct where ct.code = "MGM"), (SELECT id from stark.`attribute` a where a.code = "COUPON_CHANGELOG_GENERATE"), '1', '1', '0'),
((SELECT id from stark.coupon_type ct where ct.code = "MGM"), (SELECT id from stark.`attribute` a where a.code = "COUPON_CASHBACK"), '{"cashback":{"operation":"BECASHR$15MGM","target":"CREATOR"}}', '1', '0');

SELECT * FROM stark.coupon_type_attribute cta order by 1 desc;



Editor is loading...