private function notifyOrderInfo(NotifyOrder $notify) { $this->log('consume notify', $notify->getAttributes()); $customerId = $notify->customer_id; $orderId = $notify->order_id; $customer = Customer::instance()->initByExternalId($customerId); if (!$customer) { $this->log('Customer is not initialized', ['customer_id' => $customerId]); return; } if (!$customer->get()->email) { $this->log('Email is empty', ['customer_id' => $customerId]); $notify->sent = 1; $notify->save(); return; } $password = $customer->get()->credential->agbis_password; if (!$password) { $this->log('Customer password is not exists', ['customer_id' => $customerId]); return; } if (isset($this->keys[$customerId])) { $key = $this->keys[$customerId]; } else { try { $user = $this->api->Login_con('+7' . $customer->get()->phone, $password); } catch (ApiException $e) { $this->log($e->getMessage(), [$customerId]); $notify->sent = 1; $notify->save(); return; } $this->keys[$customerId] = $user->key; $key = $user->key; } $order = $this->api->getOrder($orderId, $key); $services = (new OrderServiceComponent())->parseOrderService($orderId, $key); $email = $customer->get()->email; $name = $customer->get()->name; $this->log('ready data send', ['services' => count($services)]); try { $attach = self::createClothesFile($order, $services, $name); Mailer::notifyNewOrder($order, $services, $email, $name, $attach); $notify->sent = 1; $notify->save(); OrderRequest::markAsCompleted($customer->get()->phone, $orderId); } catch (\Exception $e) { $this->log('send mail error', ['email' => $customer->get()->email, 'id' => $customer->get()->id, 'message' => $e->getMessage()]); } }
/** * список текущих заказов * * @return \Illuminate\Http\JsonResponse */ public function orders() { try { $api = new Api(); $orders = $api->Orders()['orders']; } catch (ApiException $e) { return $this->responseException($e); } $orders = $this->filterCurrentOrders($orders); $qnt = count($orders); $customer = Customer::instance()->initByExternalId($api->id()); $requests = OrderRequest::orderBy('id', 'desc')->whereState(0)->wherePhone($customer->get()->phone)->get(); $lastOrder = current($orders); $lastOrderTime = date('Y-m-d H:i:s', strtotime($lastOrder['date_in'])); if (!empty($requests[0]) && $requests[0]->created_at <= $lastOrderTime) { OrderRequest::markAsCompleted($customer->get()->phone, $lastOrder['id']); $requests = []; } $browser = View::make('ac::orders', ['orders' => $orders, 'requests' => $requests])->render(); $mobile = View::make('ac::orders_mobile', ['orders' => $orders])->render(); return Response::json(compact('browser', 'mobile', 'qnt')); }