Add methods to retrieve and analyze product sales data, send department statistics to Slack, and implement scheduled messaging logic
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\entra;
|
||||
use classes\redis;
|
||||
use objects\departments_o;
|
||||
use traits\route_t;
|
||||
|
||||
class exampleRoute
|
||||
@@ -13,7 +15,35 @@ class exampleRoute
|
||||
{
|
||||
$this->get('/example', function () {
|
||||
global $response;
|
||||
$response->success(['message' => 'Hello World!']);
|
||||
// This is very quite hack-y but it works for now
|
||||
// Check if it's monday
|
||||
if ((int)date('N') === 1) {
|
||||
// Check if the time is between 06:00 and 17:00
|
||||
if (!redis->exists('system:last_sent_monday_message') && (date('H') >= 6 && date('H') < 17)) {
|
||||
// Set the key to expire in 24 hours
|
||||
redis->set('system:last_sent_monday_message', date('Y-m-d H:i:s'));
|
||||
redis->expire('system:last_sent_monday_message', 86400);
|
||||
// Send the messages
|
||||
$departments = [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
];
|
||||
foreach ($departments as $department_id) {
|
||||
$department = (new departments_o())->select((int)$department_id);
|
||||
$days = 7;
|
||||
// The time should be from 00:00:00 of the start date to 23:59:59 of the end date
|
||||
$date_end = date('Y-m-d 23:59:59', strtotime("-1 days")); // Yesterday (sunday) at 23:59:59
|
||||
$date_start = date('Y-m-d 00:00:00', strtotime("-$days days")); // $days ago at 00:00:00
|
||||
$department->sendPeriodStatisticsToSlack($date_start, $date_end);
|
||||
}
|
||||
}
|
||||
}
|
||||
$response->success(['message' => 'Hello World!', 'time' => date('Y-m-d H:i:s'), 'date' => (int)date('N')]);
|
||||
});
|
||||
|
||||
$this->get('/debug', function () {
|
||||
|
||||
Reference in New Issue
Block a user