HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/ipsremont-demo/app/Http/Controllers/ReceiverController.php
<?php


namespace App\Http\Controllers;


use App\Models\Order;
use App\Models\Shipment;
use App\Services\ImportService;
use App\Services\Order\OrderService;
use App\Services\Shipment\ShipmentService;
use Illuminate\Support\Facades\Log;


class ReceiverController extends \Illuminate\Routing\Controller
{
    /**
     * Receive real orders from 1c
     *
     * @return false|string
     */
    public function getOrdersFrom1c()
    {
        if (env('APP_ENV') == 'local') {
            $path = storage_path() . '/orders.xml';
            if (!file_exists($path)) return false;

            $xml = file_get_contents($path);
            $xml = trim($xml);
            $xml = str_replace('&', '', $xml);
            if (empty($xml)) return false;
            $data = new \SimpleXMLElement($xml);
        } else {
            Log::channel('orders1c')->info(\request()->data);
            $data = json_decode(\request()->data);

            if (empty($data)) {
                return 0;
            }
        }

        $response = [];
        foreach ($data as $key => $item) {
            try {
                if ($item->action == ImportService::NEW) {
                    $order = Order::where('external_id', $item->code)->first();
                    if(!$order)
                        $res = OrderService::save1c($item);
                    else
                        $res = OrderService::update1c($item);
                } else {
                    $res = OrderService::update1c($item);
                }
                $result = $res['result'];
                $order_id = $res['order_id'];

                if (isset($item->track_number) && isset($item->post_type)) {
                    $shipment = Shipment::where('order_id', $order_id)->first();
                    if(!$shipment) {
                        $res_shipment = ShipmentService::save1c($item);
                        if ($res_shipment != 1)
                            $result .= ' ' . $res_shipment;
                    }
                }
            } catch (\Exception $e) {
                $result = $e->getMessage();
                $order_id = '0';
            }
            array_push($response, ['id' => $order_id, 'code' => $item->code, 'result' => $result]);
        }

        return json_encode($response);
    }
}