v.1.7 update
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\Folders;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Component\Models\OrderBot;
|
||||
use App\Component\Models\Settings;
|
||||
use App\Component\Models\Tasks;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
@@ -22,7 +22,7 @@ class Bot extends HRCCommand implements HRCCommandInterface {
|
||||
$ordersinfo = Tasks::where('method', '=', 'orderinfo')->get();
|
||||
$delete_params = ['closed', 'deleted'];
|
||||
foreach ($ordersinfo as $more) {
|
||||
$order = Orders::where('id', '=', $more['more'])->whereIn('status', $delete_params)->get();
|
||||
$order = OrderBot::where('id', '=', $more['more'])->whereIn('status', $delete_params)->get();
|
||||
foreach ($order as $value) {
|
||||
$delete = Tasks::where('method', '=', 'orderinfo')->where('more', '=', $value['id'])->delete();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getclientfile';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->first();
|
||||
$terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->first();
|
||||
$tmp_dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\tmp\\" . $terminal['key'] . "\\";
|
||||
$dirname = __DIR__ . "\\..\\..\\..\\Exchange\\" . $terminal['key'] . "\\";
|
||||
$code = '';
|
||||
@@ -57,24 +57,25 @@ class ClientFile extends HRCCommand implements HRCCommandInterface {
|
||||
'filedate' => $file,
|
||||
];
|
||||
}
|
||||
$clientsCount = Client::count();
|
||||
$urlThread = $input['th'];
|
||||
$mainThreads = 4;
|
||||
$countPerThread = ceil($clientsCount / $mainThreads);
|
||||
$offset = ($urlThread - 1) * $countPerThread;
|
||||
$clients = Client::with('clientPhone:client_guid,phone')->skip($offset)->take($countPerThread)->get();
|
||||
|
||||
$clientsCount = Client::count();
|
||||
$urlThread = $input['th'];
|
||||
$mainThreads = 4;
|
||||
$countPerThread = ceil($clientsCount / $mainThreads);
|
||||
$offset = ($urlThread - 1) * $countPerThread;
|
||||
$clients = Client::with('clientPhone:client_guid')->skip($offset)->take($countPerThread)->get();
|
||||
|
||||
if (!is_dir($tmp_dirname)) {
|
||||
mkdir($tmp_dirname, 0755, 'w+');
|
||||
}
|
||||
$filename = str_replace(' ', '_', date("d.m.Y H.i.s")) . '_' . $urlThread . '.tmp';
|
||||
$handle = fopen($tmp_dirname . $filename, 'w+');
|
||||
fputs($handle, chr(0xEF) . chr(0xBB) . chr(0xBF)); // BOM
|
||||
$filename = str_replace('_', ' ', $filename);
|
||||
foreach ($clients as $row) {
|
||||
if (($row['clientPhone']->phone !== '') && ($row['clientPhone']->phone !== '+375 ( ) - -')) {
|
||||
$row = array($row['name'], $row['clientPhone']->phone);
|
||||
fputcsv($handle, $row, ';');
|
||||
if (!is_dir($tmp_dirname)) {
|
||||
mkdir($tmp_dirname, 0755, 'w+');
|
||||
}
|
||||
$filename = str_replace(' ', '_', date("d.m.Y H.i.s")) . '_' . $urlThread . '.tmp';
|
||||
$handle = fopen($tmp_dirname . $filename, 'w+');
|
||||
$filename = str_replace('_', ' ', $filename);
|
||||
foreach ($clients as $row) {
|
||||
if (($row['clientPhone']->phone !== '') && ($row['clientPhone']->phone !== '+375 ( ) - -')) {
|
||||
$row = array($row['name'], $row['clientPhone']->phone);
|
||||
fputcsv($handle, $row, ';');
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($handle);
|
||||
|
||||
@@ -15,9 +15,22 @@ class CreateClient extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postcreateclient';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
if (isset($input['group_id'])) {
|
||||
$group = ClientsGroup::where('id', '=', $input['group_id'])->first();
|
||||
} else {
|
||||
$group['code'] = 0;
|
||||
}
|
||||
|
||||
if (!isset($input['email'])) {
|
||||
$input['email'] = '';
|
||||
}
|
||||
|
||||
if (!isset($input['address'])) {
|
||||
$input['address'] = '';
|
||||
}
|
||||
|
||||
$total = Client::where('name', '=', $input['name'])->count();
|
||||
if ($input['is_special_price'] == 'true') {
|
||||
if (isset($input['is_special_price']) && $input['is_special_price'] == 'true') {
|
||||
$specialPrice = 1;
|
||||
} else {
|
||||
$specialPrice = 0;
|
||||
@@ -51,23 +64,32 @@ class CreateClient extends HRCCommand implements HRCCommandInterface {
|
||||
$clientPhone->phone = $phone;
|
||||
$clientPhone->client_guid = $client->user_code;
|
||||
|
||||
$clientBarcode = new ClientsBarcode;
|
||||
$clientBarcode->code_id = urldecode($input['barcode']);
|
||||
$clientBarcode->name = '';
|
||||
$clientBarcode->client_guid = $client->user_code;
|
||||
$clientBarcode->value = urldecode($input['barcode']);
|
||||
$clientBarcode->block = 0;
|
||||
$clientBarcode->symptom_block = 0;
|
||||
|
||||
$clientBarcode->save();
|
||||
$clientEmail->save();
|
||||
$clientAddress->save();
|
||||
$client->save();
|
||||
$clientPhone->save();
|
||||
if (isset($input['barcode']) && $input['barcode'] > 0) {
|
||||
$client->barcode_type = 1;
|
||||
$clientBarcode = new ClientsBarcode;
|
||||
$clientBarcode->code_id = urldecode($input['barcode']);
|
||||
$clientBarcode->name = '';
|
||||
$clientBarcode->client_guid = $client->user_code;
|
||||
$clientBarcode->value = urldecode($input['barcode']);
|
||||
$clientBarcode->block = 0;
|
||||
$clientBarcode->symptom_block = 0;
|
||||
$client->save();
|
||||
$clientPhone->save();
|
||||
$clientEmail->save();
|
||||
$clientAddress->save();
|
||||
$clientBarcode->save();
|
||||
} else {
|
||||
$client->barcode_type = 0;
|
||||
$client->save();
|
||||
$clientPhone->save();
|
||||
$clientEmail->save();
|
||||
$clientAddress->save();
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Клиент создан',
|
||||
'client' => $client,
|
||||
];
|
||||
}
|
||||
}
|
||||
129
commands/GETOrder.php
Normal file
129
commands/GETOrder.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Client;
|
||||
use App\Component\Models\ClientsAddress;
|
||||
use App\Component\Models\ClientsPhone;
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\OrderItems;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETOrder extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getorder';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
if (isset($input['task'])) {
|
||||
if ($input['task'] == 'single' && isset($input['order_id'])) {
|
||||
$order = Orders::where('id', '=', $input['order_id'])->first();
|
||||
|
||||
if (isset($order->client_id) && $order->client_id !== null && $order->client_id !== '') {
|
||||
$client = Client::where('user_code', '=', $order->client_id)->first();
|
||||
$client = $client->name;
|
||||
$client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_phone = $client_phone->phone;
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_address = $client_address->address;
|
||||
} else {
|
||||
$client = '';
|
||||
$client_phone = '';
|
||||
$client_address = '';
|
||||
}
|
||||
|
||||
$orderItems = OrderItems::where('order_id', '=', $order->id)->whereNull('modifier_id')->get();
|
||||
$modOut = array();
|
||||
if (isset($orderItems)) {
|
||||
foreach ($orderItems as $key => $item) {
|
||||
$itemName = Dishes::where('code', '=', $item->item_id)->first();
|
||||
$itemName = $itemName->name;
|
||||
$itemModifiers = OrderItems::where('order_id', '=', $order->id)->where('parent_id', '=', $item->id)->whereNotNull('modifier_id')->get();
|
||||
if (isset($itemModifiers)) {
|
||||
foreach ($itemModifiers as $key => $itemModifier) {
|
||||
$modifier = Modifier::where('id', '=', $itemModifier->modifier_id)->first();
|
||||
if ($modifier->dish_code == 0 && $modifier->unit_id == 0) {
|
||||
$modOut[] = array('' => , );
|
||||
}
|
||||
}
|
||||
}
|
||||
$output[] = array('id' => $item->id,
|
||||
'num' => $key + 1,
|
||||
'order_id' => $item->order_id,
|
||||
'item_id' => $item->item_id,
|
||||
'item_name' => $itemName,
|
||||
'item_count' => $item->item_count,
|
||||
'item_price' => $item->item_price,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$output = [];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ №' . $order->id,
|
||||
'order' => $order,
|
||||
'orderItems' => $output,
|
||||
'client_name' => $client,
|
||||
'client_phone' => $client_phone,
|
||||
'client_address' => $client_address,
|
||||
'totalCount' => $order->total_count,
|
||||
'totalPrice' => $order->total_price,
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'list') {
|
||||
$orders = Orders::all();
|
||||
foreach ($orders as $key => $order) {
|
||||
$client = Client::where('user_code', '=', $order->client_id)->first();
|
||||
$client_phone = ClientsPhone::where('client_guid', '=', $order->client_id)->first();
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $order->client_id)->first();
|
||||
if (isset($client)) {
|
||||
$output[] = array('id' => $order->id, 'client_name' => $client->name, 'client_phone' => $client_phone->phone, 'client_address' => $client_address->address, 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send);
|
||||
} else {
|
||||
$output[] = array('id' => $order->id, 'client_name' => '', 'client_phone' => '', 'client_address' => '', 'total_count' => $order->total_count, 'total_price' => $order->total_price, 'is_send' => $order->is_send);
|
||||
}
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Список заказов',
|
||||
'orders' => $output,
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'clientsearch' && $input['search']) {
|
||||
$input['search'] = urldecode($input['search']);
|
||||
$phone = '+375 (' . substr($input['search'], 0, 2) . ') ' . substr($input['search'], 2, 3) . '-' . substr($input['search'], 5, 2) . '-' . substr($input['search'], 7, 2);
|
||||
$clients = ClientsPhone::where('phone', '=', $phone)->get();
|
||||
if (isset($clients)) {
|
||||
foreach ($clients as $key => $client) {
|
||||
$client_name = Client::where('user_code', '=', $client->client_guid)->first();
|
||||
$client_name = $client_name->name;
|
||||
$client_address = ClientsAddress::where('client_guid', '=', $client->client_guid)->first();
|
||||
$client_phone = $client->phone;
|
||||
$client_guid = $client->client_guid;
|
||||
$output[] = array('guid' => $client_guid, 'name' => $client_name, 'phone' => $client_phone, 'address' => $client_address->address);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($clients)) {
|
||||
$clients = [];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Список клиентов',
|
||||
'clients' => $output,
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
20
commands/HelloWorld.php
Normal file
20
commands/HelloWorld.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\User;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class HelloWorld extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'gethello';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$users = User::all();
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'users' => $users,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ class Import extends HRCCommand implements HRCCommandInterface {
|
||||
$search_response = curl_exec($search);
|
||||
curl_close($search);
|
||||
$responses = json_decode($search_response, TRUE)['files'];
|
||||
|
||||
foreach ($responses as $key => $response) {
|
||||
if (array_key_exists('filename', $response)) {
|
||||
$fulldate = date_parse_from_format('d-m-Y-H-i-s', $response['filename']);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Orders;
|
||||
use App\Component\Models\OrderBot;
|
||||
use App\Component\Models\Report;
|
||||
use App\Component\Models\Shifts;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
@@ -19,7 +19,7 @@ class OutOrders extends HRCCommand implements HRCCommandInterface {
|
||||
$out = array('id' => $shift['id'], 'opened' => $shift['opened'], 'closed' => $shift['closed']);
|
||||
}
|
||||
}
|
||||
$orders = Orders::select('id', 'order', 'created_at')->where('created_at', '>', $out['opened'])->where('created_at', '<=', $out['closed'])->get();
|
||||
$orders = OrderBot::select('id', 'order', 'created_at')->where('created_at', '>', $out['opened'])->where('created_at', '<=', $out['closed'])->get();
|
||||
$count_items = 0;
|
||||
if (is_array($orders) || is_object($orders)) {
|
||||
foreach ($orders as $order) {
|
||||
@@ -73,7 +73,7 @@ class OutOrders extends HRCCommand implements HRCCommandInterface {
|
||||
$end_t = strtotime($input['end_date']) - 1;
|
||||
$start = date('Y-m-d H:i:s', $start_t);
|
||||
$end = date('Y-m-d H:i:s', $end_t);
|
||||
$orders = Orders::select('id', 'order', 'created_at')->where('created_at', '>', $start)->where('created_at', '<=', $end)->get();
|
||||
$orders = OrderBot::select('id', 'order', 'created_at')->where('created_at', '>', $start)->where('created_at', '<=', $end)->get();
|
||||
$count_items = 0;
|
||||
if (is_array($orders) || is_object($orders)) {
|
||||
foreach ($orders as $order) {
|
||||
|
||||
107
commands/POSTOrder.php
Normal file
107
commands/POSTOrder.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\OrderItems;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class POSTOrder extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postorder';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
if (isset($input['task'])) {
|
||||
if ($input['task'] == 'create') {
|
||||
$order = new Orders;
|
||||
$order->staff_id = 1;
|
||||
$order->is_send = 0;
|
||||
$order->save();
|
||||
$order = Orders::where('id', '=', $order->id)->first();
|
||||
$orderItems = OrderItems::where('order_id', '=', $order->id)->get();
|
||||
if (!isset($orderItems)) {
|
||||
$orderItems = [];
|
||||
}
|
||||
return [
|
||||
'status' => 'success',
|
||||
'order' => $order,
|
||||
'orderItems' => $orderItems,
|
||||
'message' => 'Заказ создан',
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'delete' && isset($input['id'])) {
|
||||
$order = Orders::where('id', '=', $input['id'])->first();
|
||||
if ($order->total_count > 0) {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Разрешено удаление только пустых заказов.',
|
||||
];
|
||||
} else {
|
||||
$order->delete();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ удален',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($input['task'] == 'update' && isset($input['order_id'])) {
|
||||
$order = Orders::find($input['order_id']);
|
||||
if (isset($input['item']) && $input['item'] == 'add') {
|
||||
$orderItem = new OrderItems;
|
||||
$orderItem->order_id = $input['order_id'];
|
||||
$orderItem->item_id = $input['item_id'];
|
||||
$orderItem->item_count = $input['item_count'];
|
||||
$item_price = Dishes::where('code', '=', $input['item_id'])->first();
|
||||
$orderItem->item_price = $item_price->cosht;
|
||||
$orderItem->staff_id = 1;
|
||||
$orderItem->save();
|
||||
}
|
||||
if (isset($input['client_id'])) {
|
||||
if ($input['client_id'] !== null) {
|
||||
$order->client_id = $input['client_id'];
|
||||
} else {
|
||||
$order->client_id = null;
|
||||
}
|
||||
|
||||
}
|
||||
if (isset($input['item_count'])) {
|
||||
$order->total_count = $order->total_count + $input['item_count'];
|
||||
$order->total_price = $order->total_price + ($item_price->cosht * $input['item_count']);
|
||||
}
|
||||
|
||||
$order->is_send = 0;
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ обновлен',
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'complete' && isset($input['id'])) {
|
||||
$order = Orders::find($input['id']);
|
||||
$order->is_send = 1;
|
||||
if (isset($input['client_id'])) {
|
||||
$order->client_id = $input['client_id'];
|
||||
}
|
||||
$order->is_delivery = $input['is_delivery'];
|
||||
$order->is_pickup = $input['is_pickup'];
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ отправлен',
|
||||
];
|
||||
}
|
||||
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
88
commands/POSTOrderItem.php
Normal file
88
commands/POSTOrderItem.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\OrderItems;
|
||||
use App\Component\Models\Orders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class POSTOrderItem extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'postorderitem';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
if (isset($input['task']) && isset($input['order_id'])) {
|
||||
if ($input['task'] == 'create' && isset($input['order_id'])) {
|
||||
$order_item = new OrderItems;
|
||||
$order_item->order_id = $input['order_id'];
|
||||
$order_item->item_id = $input['item_id'];
|
||||
$order_item->item_count = $input['item_count'];
|
||||
$order_item->item_price = $input['item_price'];
|
||||
$order_item->staff_id = 1;
|
||||
$order_item->save();
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'order' => $order_item,
|
||||
'message' => 'Товар добавлен в заказ №' . $input['order_id'],
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'delete' && isset($input['id'])) {
|
||||
$order_item = OrderItems::where('order_id', '=', $input['order_id'])->where('id', '=', $input['id'])->first();
|
||||
$order_item->delete();
|
||||
$order = Orders::where('id', '=', $input['order_id'])->first();
|
||||
$orderItems = OrderItems::where('order_id', '=', $input['order_id'])->get();
|
||||
$totalCount = 0;
|
||||
$totalPrice = 0;
|
||||
foreach ($orderItems as $key => $item) {
|
||||
$totalCount = $totalCount + $item->item_count;
|
||||
$totalPrice = $totalPrice + $item->item_count * $item->item_price;
|
||||
}
|
||||
$order->total_count = $totalCount;
|
||||
$order->total_price = $totalPrice;
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Позиция удалена',
|
||||
];
|
||||
}
|
||||
|
||||
if ($input['task'] == 'update' && isset($input['id']) && isset($input['item_count'])) {
|
||||
$order_item = OrderItems::where('order_id', '=', $input['order_id'])->where('id', '=', $input['id'])->first();
|
||||
if ($input['item_count'] == 0) {
|
||||
$order_item->delete();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Позиция удалена',
|
||||
];
|
||||
} else {
|
||||
$order_item->item_count = $input['item_count'];
|
||||
$order_item->save();
|
||||
|
||||
$order = Orders::where('id', '=', $input['order_id'])->first();
|
||||
$orderItems = OrderItems::where('order_id', '=', $input['order_id'])->get();
|
||||
$totalCount = 0;
|
||||
$totalPrice = 0;
|
||||
foreach ($orderItems as $key => $item) {
|
||||
$totalCount = $totalCount + $item->item_count;
|
||||
$totalPrice = $totalPrice + $item->item_count * $item->item_price;
|
||||
}
|
||||
$order->total_count = $totalCount;
|
||||
$order->total_price = $totalPrice;
|
||||
$order->save();
|
||||
return [
|
||||
'status' => 'success',
|
||||
'message' => 'Заказ обновлен',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'error_message' => 'Проверьте введенные данные',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user