WITH
tmpProduct AS (
SELECT
p.product_id as id,
p.image,
IF(count(t.image),
JSON_ARRAYAGG(JSON_OBJECT('image', t.image)),
JSON_ARRAY()) AS images
FROM oc_product p
LEFT JOIN LATERAL (
SELECT image FROM oc_product_image pi
WHERE pi.product_id = p.product_id AND p.image != pi.image
ORDER BY pi.sort_order
) AS t ON true
WHERE p.status = 1
GROUP BY p.product_id
)
SELECT id, IF(image, JSON_ARRAY_APPEND(images, '$', image), images) AS images
FROM tmpProduct
SELECT
c1.category_id,
IF(count(c2.category_id), JSON_ARRAYAGG(JSON_OBJECT('id', c2.category_id, 'child', c2.child)), JSON_ARRAY()) AS child
FROM oc_category c1
LEFT JOIN LATERAL (
SELECT
c2.category_id,
IF(count(c3.category_id), JSON_ARRAYAGG(JSON_OBJECT('id', c3.category_id)), JSON_ARRAY()) AS child
FROM oc_category c2
LEFT JOIN LATERAL (
SELECT c3.category_id FROM oc_category c3
where c3.parent_id = c2.category_id
ORDER BY c3.sort_order DESC
)
AS c3 ON true
where c2.parent_id = c1.category_id
GROUP BY c2.category_id
ORDER BY c2.sort_order DESC
)
AS c2 ON true
WHERE c1.parent_id = 0
GROUP BY c1.category_id
ORDER BY c1.sort_order
const parseDate = (str, format) => {
if (!format) return new Date(str);
const mask = {};
for (const { 0: key, index } of format.matchAll(/(SSS|ss|mm|HH|DD|MM|YYYY|YY)/g)) {
mask[key] = parseInt(str.substr(index, key.length)) || 0;
}
const year = mask.YYYY || (mask.YY && `20${mask.YY}`) || 0;
const month = (mask.MM || 1) - 1;
const day = mask.DD || 0;
const hour = mask.HH || 0;
const minute = mask.mm || 0;
const second = mask.ss || 0;
const millisecond = mask.SSS || 0;
return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
};
const maxChar = str => {
const charObj = {};
let max = {char:'', count:''};
let maxChar = '';
for (let char of str) {
if (charObj[char]) {
charObj[char]++;
} else {
charObj[char] = 1;
}
if ( charObj[char] >= max.count ) {
max.char = char
max.count = charObj[char]
}
}
return max.char;
};
console.log( maxChar('abccccsddasdadwqwf'))
fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
},
credentials: "same-origin"
})
[
'gd00.55...dgfdg',
'gd0055dgfdg',
'a252.25a',
'a25225a',
'a252,25a',
'252,25a',
'a252,250',
'-d--252,2534567',
'',
'aaa',
'0',
].forEach( input => {
// Добавлены слеши для экранирования, выражение - RegExp('...').toString()
const scale = 1;
const regExp = `(-?\\d+)([.,]${ scale ? '\\d{1,' + scale + '}' : '' })?`;
const result = +( new RegExp(regExp).exec(input) || ['0'] )[0].replace(',', '.');
console.log( '"%s" → [ %s ]', input, result );
});
"gd00.55...dgfdg" → [ 0.5 ]
"gd0055dgfdg" → [ 55 ]
"a252.25a" → [ 252.2 ]
"a25225a" → [ 25225 ]
"a252,25a" → [ 252.2 ]
"252,25a" → [ 252.2 ]
"a252,250" → [ 252.2 ]
"-d--252,2534567" → [ -252.2 ]
"" → [ 0 ]
"aaa" → [ 0 ]
"0" → [ 0 ]