Merge pull request 'floranet' (!2042) from 6021-floranet into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2042 Reviewed-by: Pablo Natek <pablone@verdnatura.es>
This commit is contained in:
commit
6ad6c88c2c
|
@ -0,0 +1,22 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE
|
||||
DEFINER=`root`@`localhost`
|
||||
EVENT `floranet`.`clean`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-01-01 23:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO
|
||||
BEGIN
|
||||
DELETE
|
||||
FROM `order`
|
||||
WHERE created < CURDATE()
|
||||
AND isPaid = FALSE;
|
||||
|
||||
DELETE c.*
|
||||
FROM catalogue c
|
||||
LEFT JOIN `order` o ON o.catalogueFk = c.id
|
||||
WHERE c.created < CURDATE()
|
||||
AND o.id IS NULL;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,52 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.catalogue_get;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.catalogue_get(vLanded DATE, vPostalCode VARCHAR(15))
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Returns list, price and all the stuff regarding the floranet items
|
||||
*
|
||||
* @param vLanded Delivery date
|
||||
* @param vPostalCode Delivery address postal code
|
||||
*/
|
||||
DECLARE vLastCatalogueFk INT;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT * FROM catalogue FOR UPDATE;
|
||||
|
||||
SELECT MAX(id) INTO vLastCatalogueFk
|
||||
FROM catalogue;
|
||||
|
||||
INSERT INTO catalogue(
|
||||
name,
|
||||
price,
|
||||
itemFk,
|
||||
dated,
|
||||
postalCode,
|
||||
`type`,
|
||||
image,
|
||||
description
|
||||
)
|
||||
SELECT i.name,
|
||||
i.`size`,
|
||||
i.id,
|
||||
vLanded,
|
||||
vPostalCode,
|
||||
it.name,
|
||||
CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image),
|
||||
i.description
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
WHERE it.code IN ('FNR','FNP');
|
||||
|
||||
SELECT *
|
||||
FROM catalogue
|
||||
WHERE id > IFNULL(vLastCatalogueFk,0);
|
||||
|
||||
COMMIT;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,20 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.contact_request;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost`
|
||||
PROCEDURE floranet.contact_request(
|
||||
vName VARCHAR(100),
|
||||
vPhone VARCHAR(15),
|
||||
vEmail VARCHAR(100),
|
||||
vMessage TEXT)
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Set actions for contact request.
|
||||
*
|
||||
* @param vPostalCode Delivery address postal code
|
||||
*/
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,29 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.deliveryDate_get;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `floranet`.`deliveryDate_get`(vPostalCode VARCHAR(15))
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Returns available dates for this postalCode, in the next seven days
|
||||
*
|
||||
* @param vPostalCode Delivery address postal code
|
||||
*/
|
||||
DECLARE vCurrentDayOfWeek INT;
|
||||
|
||||
SET vCurrentDayOfWeek = DAYOFWEEK(NOW());
|
||||
|
||||
SELECT DISTINCT nextDay
|
||||
FROM (
|
||||
SELECT CURDATE() + INTERVAL IF(
|
||||
apc.dayOfWeek >= vCurrentDayOfWeek,
|
||||
apc.dayOfWeek - vCurrentDayOfWeek,
|
||||
7 - apc.dayOfWeek
|
||||
) DAY nextDay,
|
||||
NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime
|
||||
FROM addressPostCode apc
|
||||
WHERE apc.postCode = vPostalCode
|
||||
HAVING nextDay > minDeliveryTime) sub;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.order_confirm;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
|
||||
CREATE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT)
|
||||
READS SQL DATA
|
||||
|
||||
BEGIN
|
||||
/** Update order.isPaid field
|
||||
*
|
||||
* @param vCatalogueFk floranet.catalogue.id
|
||||
*
|
||||
* @returns floranet.order.isPaid
|
||||
*/
|
||||
UPDATE `order`
|
||||
SET isPaid = TRUE,
|
||||
payed = NOW()
|
||||
WHERE catalogueFk = vCatalogueFk;
|
||||
|
||||
SELECT isPaid
|
||||
FROM `order`
|
||||
WHERE catalogueFk = vCatalogueFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,42 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.order_put;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.order_put(vOrder JSON)
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Get and process an order
|
||||
*
|
||||
* @param vOrder Data of the order
|
||||
*
|
||||
* Customer data: <customerName>, <email>, <customerPhone>
|
||||
*
|
||||
* Item data: <catalogueFk>, <message>
|
||||
*
|
||||
* Delivery data: <deliveryName>, <address>, <deliveryPhone>
|
||||
*
|
||||
*/
|
||||
INSERT IGNORE INTO `order`(
|
||||
catalogueFk,
|
||||
customerName,
|
||||
email,
|
||||
customerPhone,
|
||||
message,
|
||||
deliveryName,
|
||||
address,
|
||||
deliveryPhone
|
||||
)
|
||||
VALUES (JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.catalogueFk')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerName')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.email')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.customerPhone')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.message')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryName')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.address')),
|
||||
JSON_UNQUOTE(JSON_EXTRACT(vOrder,'$.deliveryPhone'))
|
||||
);
|
||||
|
||||
SELECT LAST_INSERT_ID() orderFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,19 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.sliders_get;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE floranet.sliders_get()
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Returns list of url for sliders
|
||||
*/
|
||||
SELECT
|
||||
CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url,
|
||||
i.longName
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
WHERE it.code IN ('FNR','FNP');
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
CREATE SCHEMA IF NOT EXISTS `floranet`;
|
||||
|
||||
CREATE ROLE IF NOT EXISTS 'floranet' ;
|
||||
|
||||
GRANT Create temporary tables ON floranet.* TO 'floranet';
|
||||
|
||||
GRANT Execute ON floranet.* TO 'floranet';
|
||||
|
||||
GRANT Lock tables ON floranet.* TO 'floranet';
|
||||
|
||||
CREATE USER IF NOT EXISTS 'floranet'@'%';
|
||||
|
||||
GRANT floranet TO floranet@'%';
|
|
@ -0,0 +1,61 @@
|
|||
CREATE OR REPLACE TABLE floranet.`builder` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`itemFk` int(11) NOT NULL,
|
||||
`elementFk` int(11) NOT NULL,
|
||||
`quantity` int(10) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `builder_FK` (`itemFk`),
|
||||
KEY `builder_FK_1` (`elementFk`),
|
||||
CONSTRAINT `builder_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements';
|
||||
|
||||
CREATE OR REPLACE TABLE floranet.`element` (
|
||||
`itemFk` int(11) NOT NULL,
|
||||
`typeFk` smallint(5) unsigned DEFAULT NULL,
|
||||
`size` int(11) DEFAULT NULL,
|
||||
`inkFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||
`originFk` tinyint(2) unsigned DEFAULT NULL,
|
||||
`name` varchar(30) DEFAULT NULL,
|
||||
`quantity` int(11) NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`itemFk`),
|
||||
KEY `element_FK` (`itemFk`),
|
||||
KEY `element_FK_1` (`typeFk`),
|
||||
KEY `element_FK_2` (`inkFk`),
|
||||
KEY `element_FK_3` (`originFk`),
|
||||
CONSTRAINT `element_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_2` FOREIGN KEY (`inkFk`) REFERENCES `vn`.`ink` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_3` FOREIGN KEY (`originFk`) REFERENCES `vn`.`origin` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Filtro para localizar posibles items que coincidan con la descripción';
|
||||
|
||||
ALTER TABLE floranet.builder ADD CONSTRAINT `builder_FK_1` FOREIGN KEY (`elementFk`) REFERENCES `element` (`itemFk`) ON UPDATE CASCADE;
|
||||
|
||||
CREATE OR REPLACE TABLE floranet.catalogue
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(50),
|
||||
price DECIMAL(10,2) NOT NULL,
|
||||
itemFk INT NOT NULL,
|
||||
dated DATE,
|
||||
postalCode VARCHAR(12),
|
||||
`type` VARCHAR(50),
|
||||
image VARCHAR(255),
|
||||
description TEXT,
|
||||
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
payed DATETIME,
|
||||
FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON DELETE RESTRICT ON UPDATE CASCADE);
|
||||
|
||||
|
||||
CREATE OR REPLACE TABLE floranet.`order`
|
||||
(id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
catalogueFk INT UNIQUE,
|
||||
customerName VARCHAR(100),
|
||||
email VARCHAR(100),
|
||||
customerPhone VARCHAR(15),
|
||||
message VARCHAR(255),
|
||||
deliveryName VARCHAR(100),
|
||||
address VARCHAR(200),
|
||||
deliveryPhone VARCHAR(100),
|
||||
isPaid BOOL NOT NULL DEFAULT FALSE,
|
||||
payed DATETIME,
|
||||
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (catalogueFk) REFERENCES catalogue(id) ON DELETE RESTRICT ON UPDATE CASCADE);
|
|
@ -0,0 +1,12 @@
|
|||
CREATE TABLE floranet.`addressPostCode` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`addressFk` int(11) NOT NULL,
|
||||
`postCode` varchar(30) NOT NULL,
|
||||
`hoursInAdvance` int(10) unsigned NOT NULL DEFAULT 24,
|
||||
`dayOfWeek` int(10) unsigned NOT NULL,
|
||||
`deliveryCost` decimal(10,2) NOT NULL DEFAULT 0.00,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `addressPostCode_unique` (`postCode`,`addressFk`,`dayOfWeek`),
|
||||
KEY `addressPostCode_address_FK` (`addressFk`),
|
||||
CONSTRAINT `addressPostCode_address_FK` FOREIGN KEY (`addressFk`) REFERENCES `vn`.`address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Client''s address registered for floranet network';
|
Loading…
Reference in New Issue