200 lines
9.1 KiB
PHP
200 lines
9.1 KiB
PHP
<?php
|
||
|
||
namespace App\Commands;
|
||
|
||
use App\Component\Models\ExchangeActions;
|
||
use App\Component\Models\ExchangeDeleted;
|
||
use App\Component\Models\ExchangeItems;
|
||
use App\Component\Models\ExchangeOrders;
|
||
use App\Component\Models\ExchangeShifts;
|
||
use App\Component\Models\ShiftOnlineActions;
|
||
use App\Component\Models\ShiftOnlineDeleted;
|
||
use App\Component\Models\ShiftOnlineItems;
|
||
use App\Component\Models\ShiftOnlineOrders;
|
||
use App\Component\Models\Shifts;
|
||
use App\Component\Models\TerminalUpdate;
|
||
use App\Console\Commands\HRCCommand;
|
||
use App\Console\Commands\HRCCommandInterface;
|
||
|
||
class POSTRestoreShift extends HRCCommand implements HRCCommandInterface {
|
||
protected $signature = 'postrestoreshift';
|
||
|
||
public function command($input, $output = null) {
|
||
function dirDel($dir) {
|
||
$d = opendir($dir);
|
||
while (($entry = readdir($d)) !== false) {
|
||
if ($entry != "." && $entry != "..") {
|
||
if (is_dir($dir . "/" . $entry)) {
|
||
dirDel($dir . "/" . $entry);
|
||
} else {
|
||
unlink($dir . "/" . $entry);
|
||
}
|
||
}
|
||
}
|
||
closedir($d);
|
||
rmdir($dir);
|
||
}
|
||
$shift_id = $input['shift_id'];
|
||
$cache_dir = __DIR__ . "\\..\\..\\..\\Cache\\";
|
||
dirDel($cache_dir);
|
||
|
||
$nowTime = time();
|
||
$update = true;
|
||
|
||
$exchange_shifts = ExchangeShifts::where('id', '=', $shift_id)->first();
|
||
$exchange_orders = ExchangeOrders::where('shift_id', '=', $shift_id)->get();
|
||
$exchange_items = ExchangeItems::where('shift_id', '=', $shift_id)->get();
|
||
$exchange_actions = ExchangeActions::where('shift_id', '=', $shift_id)->get();
|
||
$exchange_deleted = ExchangeDeleted::where('shift_id', '=', $shift_id)->get();
|
||
$terminal_online = TerminalUpdate::where('method', 'online')->where('terminal_id', $exchange_shifts['terminal_id'])->first();
|
||
$baseTime = date_create($terminal_online['next_at']);
|
||
$baseTime = date_format($baseTime, 'U');
|
||
$old_date = date_create($terminal_online['next_at']);
|
||
date_modify($old_date, '+1 hour');
|
||
$new_date = date_format($old_date, 'Y-m-d H:i:s');
|
||
if (($nowTime + ($terminal_online['period']*60) >= $baseTime) {
|
||
$new_terminal_online = TerminalUpdate::find($terminal_online['id']);
|
||
$new_terminal_online->next_at = $new_date;
|
||
$new_terminal_online->save();
|
||
}
|
||
|
||
if ($update) {
|
||
$online_shift = Shifts::first();
|
||
if ($online_shift['z_number'] != $shift_id) {
|
||
//clear shifts
|
||
Shifts::truncate();
|
||
$shift = new Shifts;
|
||
$shift->opened = $exchange_shifts['opened'];
|
||
$shift->closed = $exchange_shifts['closed'];
|
||
$shift->who_open = $exchange_shifts['who_open'];
|
||
$shift->who_close = $exchange_shifts['who_close'];
|
||
$shift->z_number = $exchange_shifts['id'];
|
||
$shift->save();
|
||
|
||
//clear shift_online_orders
|
||
ShiftOnlineOrders::truncate();
|
||
foreach ($exchange_orders as $key => $exchange_order) {
|
||
$shift_online_order = new ShiftOnlineOrders;
|
||
$shift_online_order->cash = $exchange_order["cash"];
|
||
$shift_online_order->check_number = $exchange_order["check_number"];
|
||
$shift_online_order->clearing = $exchange_order["clearing"];
|
||
$shift_online_order->client_code = $exchange_order["client_code"];
|
||
$shift_online_order->client_count = $exchange_order["clients_count"];
|
||
if ($exchange_order["closed"] == '0000-00-00 00:00:00') {
|
||
$exchange_order["closed"] = '1970-01-01 00:00:00';
|
||
}
|
||
$shift_online_order->closed = $exchange_order["closed"];
|
||
$shift_online_order->code = $exchange_order["code"];
|
||
$shift_online_order->credit = $exchange_order["credit"];
|
||
$shift_online_order->full_sum = $exchange_order["full_sum"];
|
||
$shift_online_order->guid = $exchange_order["guid"];
|
||
$shift_online_order->is_block = $exchange_order["is_block"];
|
||
$shift_online_order->is_closed = $exchange_order["is_closed"];
|
||
$shift_online_order->is_deleted = $exchange_order["is_deleted"];
|
||
$shift_online_order->is_edit = $exchange_order["is_edit"];
|
||
$shift_online_order->is_printed = $exchange_order["is_printed"];
|
||
$shift_online_order->is_returned = $exchange_order["is_returned"];
|
||
$shift_online_order->is_self = $exchange_order["is_self"];
|
||
$shift_online_order->is_waited = $exchange_order["is_waited"];
|
||
if ($exchange_order["manual_discount"] == '') {
|
||
$exchange_order["manual_discount"] = 0;
|
||
} else {
|
||
$exchange_order["manual_discount"] = $exchange_order["manual_discount"] + 0;
|
||
}
|
||
$shift_online_order->manual_discount = $exchange_order["manual_discount"];
|
||
$shift_online_order->opened = $exchange_order["opened"];
|
||
$shift_online_order->order_sum = $exchange_order["order_sum"];
|
||
$shift_online_order->params_code = $exchange_order["params_id"];
|
||
$shift_online_order->place_name = $exchange_order["place_name"];
|
||
$shift_online_order->presale = $exchange_order["presale"];
|
||
$shift_online_order->sale_sum = $exchange_order["sale_sum"];
|
||
$shift_online_order->self = $exchange_order["self"];
|
||
$shift_online_order->table_name = $exchange_order["table_name"];
|
||
$shift_online_order->table_place = $exchange_order["table_place"];
|
||
$shift_online_order->terminal_id = $exchange_order["terminal_id"];
|
||
$shift_online_order->version_type = $exchange_order["version_type"];
|
||
$shift_online_order->who_close = $exchange_order["who_close"];
|
||
$shift_online_order->who_open = $exchange_order["who_open"];
|
||
$shift_online_order->save();
|
||
}
|
||
|
||
ShiftOnlineItems::truncate();
|
||
foreach ($exchange_items as $key => $exchange_item) {
|
||
$shift_online_item = new ShiftOnlineItems;
|
||
$shift_online_item->code = $exchange_item["code"];
|
||
$shift_online_item->cof = $exchange_item["cof"];
|
||
$shift_online_item->count = $exchange_item["count"];
|
||
$shift_online_item->count_real = $exchange_item["count_real"];
|
||
$shift_online_item->count_return = $exchange_item["count_return"];
|
||
$shift_online_item->dish_code = $exchange_item["dishes_code"];
|
||
$shift_online_item->menu_code = $exchange_item["menu_code"];
|
||
if ($exchange_item["modificator_code"] > 0) {
|
||
$shift_online_item->modificator_code = 1;
|
||
} else {
|
||
$shift_online_item->modificator_code = 0;
|
||
}
|
||
$shift_online_item->order_code = $exchange_item["order_code"];
|
||
$shift_online_item->parent_id = $exchange_item["parent_id"];
|
||
$shift_online_item->real_price = $exchange_item["real_price"];
|
||
$shift_online_item->sale_price = $exchange_item["sale_price"];
|
||
$shift_online_item->special_price = $exchange_item["special_price"];
|
||
$shift_online_item->terminal_id = $exchange_item["terminal_id"];
|
||
$shift_online_item->units_code = $exchange_item["units_id"];
|
||
$shift_online_item->save();
|
||
}
|
||
|
||
ShiftOnlineActions::truncate();
|
||
foreach ($exchange_actions as $key => $exchange_action) {
|
||
$shift_online_action = new ShiftOnlineActions;
|
||
$shift_online_action->type_action = $exchange_action["action_type"];
|
||
$shift_online_action->more = $exchange_action["more"];
|
||
$shift_online_action->order_code = $exchange_action["order_code"];
|
||
$shift_online_action->order_position = $exchange_action["order_position"];
|
||
$shift_online_action->reason = $exchange_action["reason"];
|
||
$shift_online_action->terminal_id = $exchange_action["terminal_id"];
|
||
$shift_online_action->time = $exchange_action["time"];
|
||
$shift_online_action->value = $exchange_action["value"];
|
||
$shift_online_action->who = $exchange_action["who"];
|
||
$shift_online_action->workcode = $exchange_action["work_code"];
|
||
$shift_online_action->workgroup = $exchange_action["work_group"];
|
||
$shift_online_action->save();
|
||
}
|
||
|
||
ShiftOnlineDeleted::truncate();
|
||
foreach ($exchange_deleted as $key => $exchange_deleted_item) {
|
||
$shift_online_deleted_item = new ShiftOnlineDeleted;
|
||
$shift_online_deleted_item->code = $exchange_deleted_item["code"];
|
||
$shift_online_deleted_item->count = $exchange_deleted_item["count"];
|
||
$shift_online_deleted_item->dishes_code = $exchange_deleted_item["dishes_code"];
|
||
$shift_online_deleted_item->item_id = $exchange_deleted_item["item_id"];
|
||
$shift_online_deleted_item->menu_code = $exchange_deleted_item["menu_code"];
|
||
$shift_online_deleted_item->order_code = $exchange_deleted_item["order_code"];
|
||
$shift_online_deleted_item->real_price = $exchange_deleted_item["real_price"];
|
||
$shift_online_deleted_item->sale_price = $exchange_deleted_item["sale_price"];
|
||
$shift_online_deleted_item->terminal_id = $exchange_deleted_item["terminal_id"];
|
||
$shift_online_deleted_item->units_id = $exchange_deleted_item["units_id"];
|
||
$shift_online_deleted_item->save();
|
||
}
|
||
$exc_time = time();
|
||
$diff_time = $exc_time - $nowTime;
|
||
$terminal_online = TerminalUpdate::where('method', 'online')->where('terminal_id', $exchange_shifts['terminal_id'])->first();
|
||
return [
|
||
'status' => 'success',
|
||
'message' => 'Данные автоматически синхронизируются с POS-системой ' . $terminal_online['next_at'],
|
||
];
|
||
} else {
|
||
return [
|
||
'status' => 'error',
|
||
'more' => 'Смена уже восстановлена',
|
||
'stop_at' => 'Stop at check z_number',
|
||
];
|
||
}
|
||
} else {
|
||
return [
|
||
'status' => 'error',
|
||
'more' => 'Смена уже восстановлена',
|
||
'stop_at' => 'Stop at check time',
|
||
];
|
||
}
|
||
}
|
||
} |