|
|
|
@ -236,11 +236,10 @@ function generateMenu(Context $ctx): void
|
|
|
|
|
* @param int $amount Количество
|
|
|
|
|
* @param ?string $date За какую дату (unixtime)
|
|
|
|
|
* @param int $page Страница
|
|
|
|
|
* @param _document $worker Сотрудник
|
|
|
|
|
*
|
|
|
|
|
* @return Cursor
|
|
|
|
|
*/
|
|
|
|
|
function requests(int $amount = 5, ?string $date = null, int $page = 1, _document $worker): Cursor
|
|
|
|
|
function requests(int $amount = 5, ?string $date = null, int $page = 1): Cursor
|
|
|
|
|
{
|
|
|
|
|
global $arangodb;
|
|
|
|
|
|
|
|
|
@ -261,12 +260,11 @@ function requests(int $amount = 5, ?string $date = null, int $page = 1, _documen
|
|
|
|
|
[
|
|
|
|
|
'query' => sprintf(
|
|
|
|
|
// d.date < %s там специально, не менять на <=
|
|
|
|
|
"FOR d IN task FILTER ((d.date >= %s && d.date < %s && d.start >= '05:00') || (d.date >= %s && d.date < %s && d.start < '05:00')) && d.worker == null && d.market != null && d.confirmed != true && d.published == true && d.completed != true && (FOR m IN market FILTER m.id == d.market && IS_ARRAY(m.bans) SORT m.created DESC, m._key DESC LIMIT 1 RETURN !POSITION(m.bans, \"%s\"))[0] SORT d.created DESC, d._key DESC LIMIT %d, %d RETURN d",
|
|
|
|
|
"FOR d IN task FILTER ((d.date >= %s && d.date < %s && d.start >= '05:00') || (d.date >= %s && d.date < %s && d.start < '05:00')) && d.worker == null && d.market != null && d.confirmed != true && d.published == true && d.completed != true SORT d.created DESC, d._key DESC LIMIT %d, %d RETURN d",
|
|
|
|
|
$from = (new DateTime("@$date"))->setTime(0, 0)->format('U'),
|
|
|
|
|
$to = (new DateTime("@$date"))->modify('+1 day')->setTime(0, 0)->format('U'),
|
|
|
|
|
$to,
|
|
|
|
|
(new DateTime("@$date"))->modify('+2 day')->setTime(0, 0)->format('U'),
|
|
|
|
|
$worker->id,
|
|
|
|
|
$offset,
|
|
|
|
|
$amount + $offset - ($page > 0)
|
|
|
|
|
),
|
|
|
|
@ -346,43 +344,37 @@ function request_confirmed(Context $ctx): void
|
|
|
|
|
// Прочитана запрашиваемая заявка
|
|
|
|
|
|
|
|
|
|
// Инициализация инстанции task в базе данных (выбранного задания)
|
|
|
|
|
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true && worker == null RETURN d", $_key));
|
|
|
|
|
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true RETURN d", $_key));
|
|
|
|
|
|
|
|
|
|
if ($task instanceof _document) {
|
|
|
|
|
// Найдена заявка (подразумевается, что не занята)
|
|
|
|
|
if ($worker ??= worker($account->getId())) {
|
|
|
|
|
// Найден сотрудник
|
|
|
|
|
|
|
|
|
|
if ($worker ??= worker($account->getId())) {
|
|
|
|
|
// Найден сотрудник
|
|
|
|
|
// Запись идентификатора нового сотрудника
|
|
|
|
|
$task->worker = $worker->id;
|
|
|
|
|
|
|
|
|
|
// Запись идентификатора нового сотрудника
|
|
|
|
|
$task->worker = $worker->id;
|
|
|
|
|
// Снятие с публикации
|
|
|
|
|
$task->published = false;
|
|
|
|
|
|
|
|
|
|
// Снятие с публикации
|
|
|
|
|
$task->published = false;
|
|
|
|
|
if (document::update($arangodb->session, $task)) {
|
|
|
|
|
// Записано обновление в базу данных
|
|
|
|
|
|
|
|
|
|
if (document::update($arangodb->session, $task)) {
|
|
|
|
|
// Записано обновление в базу данных
|
|
|
|
|
$ctx->getChatDataItem("request_all")->then(function ($requests = []) use ($ctx) {
|
|
|
|
|
// Удаление сообщений связанных с запросом
|
|
|
|
|
foreach ($requests ?? [] as $_message) $ctx->deleteMessage($_message->getChat()->getId(), $_message->getMessageId());
|
|
|
|
|
});
|
|
|
|
|
$ctx->setChatDataItem("request_all", []);
|
|
|
|
|
|
|
|
|
|
$ctx->getChatDataItem("request_all")->then(function ($requests = []) use ($ctx) {
|
|
|
|
|
// Удаление сообщений связанных с запросом
|
|
|
|
|
foreach ($requests ?? [] as $_message) $ctx->deleteMessage($_message->getChat()->getId(), $_message->getMessageId());
|
|
|
|
|
});
|
|
|
|
|
$ctx->setChatDataItem("request_all", []);
|
|
|
|
|
$ctx->getChatDataItem("request_confirmation")->then(function ($message) use ($ctx) {
|
|
|
|
|
$ctx->deleteMessage($message->getChat()->getId(), $message->getMessageId());
|
|
|
|
|
});
|
|
|
|
|
$ctx->setChatDataItem("request_confirmation_target", null);
|
|
|
|
|
|
|
|
|
|
$ctx->getChatDataItem("request_confirmation")->then(function ($message) use ($ctx) {
|
|
|
|
|
$ctx->deleteMessage($message->getChat()->getId(), $message->getMessageId());
|
|
|
|
|
});
|
|
|
|
|
$ctx->setChatDataItem("request_confirmation_target", null);
|
|
|
|
|
|
|
|
|
|
$ctx->sendMessage("✅ *Вы зарегистрировались на заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
|
|
|
|
|
generateMenu($ctx);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// End of the process
|
|
|
|
|
$ctx->endConversation();
|
|
|
|
|
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
|
|
|
|
|
$ctx->sendMessage("✅ *Вы зарегистрировались на заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
|
|
|
|
|
generateMenu($ctx);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// End of the process
|
|
|
|
|
$ctx->endConversation();
|
|
|
|
|
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
|
|
|
|
|
generateMenu($ctx);
|
|
|
|
|
});
|
|
|
|
@ -467,7 +459,7 @@ function search(Context $ctx): void
|
|
|
|
|
else {
|
|
|
|
|
// Активен аккаунт
|
|
|
|
|
|
|
|
|
|
$ctx->getChatDataItem('requests_page')->then(function ($page) use ($ctx, $arangodb, $worker) {
|
|
|
|
|
$ctx->getChatDataItem('requests_page')->then(function ($page) use ($ctx, $arangodb) {
|
|
|
|
|
// Найдена текущая страница
|
|
|
|
|
|
|
|
|
|
// Значение страницы по умолчанию
|
|
|
|
@ -476,9 +468,9 @@ function search(Context $ctx): void
|
|
|
|
|
$ctx->setChatDataItem('requests_page', 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$generate = function ($date) use ($ctx, $page, $arangodb, $worker) {
|
|
|
|
|
$generate = function ($date) use ($ctx, $page, $arangodb) {
|
|
|
|
|
// Поиск заявок в ArangoDB
|
|
|
|
|
$tasks = requests(4, (string) $date, $page, $worker);
|
|
|
|
|
$tasks = requests(4, (string) $date, $page);
|
|
|
|
|
|
|
|
|
|
// Подсчёт количества прочитанных заявок из базы данных
|
|
|
|
|
$count = $tasks->getCount();
|
|
|
|
|