示例#1
0
 /**
  * личный кабинет
  *
  * @return \Illuminate\View\View
  */
 public function index()
 {
     if (Input::get('orderNumber')) {
         return Redirect::to('/account');
     }
     Customer::instance()->closeIfNotMember();
     $promo = null;
     $mainPage = Config::get('app.url');
     $langReplace = App::getLocale() == 'ru' ? 'index' : App::getLocale();
     $mainPage = str_replace('#lang#', $langReplace, $mainPage);
     try {
         $api = new Api();
         if (!$api->key()) {
             return \Redirect::to($mainPage);
         }
         $user = $api->ContrInfo();
         $promo = $this->promoInfo($user, $promo);
         //$token = PaymentCloud::getToken($user['id']);
         $agbisKey = $api->key();
         $customer = Customer::instance()->initByExternalId($user['id']);
         if (!$customer->get()) {
             Reporter::errorLostExternalCustomer($user['id'], $user);
             $customer->cleanup();
             $api->cleanup();
             return \Redirect::to($mainPage);
         }
         $saveCard = $customer->isSaveCard();
         $cards = PaymentCloud::getCustomersCards($api->id());
     } catch (ApiException $e) {
         return \Redirect::to($mainPage);
     }
     $invite = new InviteComponent();
     return View::make('ac::index', ['user' => $user, 'promo' => $promo, 'agbisKey' => $agbisKey, 'saveCard' => $saveCard, 'invite_url' => $invite->url(), 'cards' => $cards]);
 }
示例#2
0
文件: Flash.php 项目: evo9/dryharder
 private function getInviteMessage()
 {
     $result = ['status' => false];
     $lastView = CustomerFlash::findLast(1, $this->user->id);
     if (!$lastView) {
         $lastView = new CustomerFlash();
         $lastView->flash_id = 1;
         $lastView->customer_id = $this->user->id;
         $lastView->qnt = 1;
         $lastView->save();
         $result['status'] = true;
     }
     // только три раза
     if ($lastView->qnt >= 3) {
         return $result;
     }
     // не чаще, чем раз в час
     if (time() - strtotime($lastView->updated_at) < 60 * 60) {
         return $result;
     }
     $lastView->qnt++;
     $lastView->save();
     $result['status'] = true;
     $invite = new InviteComponent();
     $result['params'] = ['invite_url' => $invite->url()];
     return $result;
 }
示例#3
0
 private function routes()
 {
     // сохраняем куку кода приглашения и редиректим на главную
     Route::get('/welcome/{lang}/{code}.html', function ($lang, $code) {
         $invite = new InviteComponent();
         $lang = in_array($lang, ['ru', 'en']) ? $lang : 'ru';
         App::setLocale($lang);
         return $invite->storeEntry($code);
     });
     Route::get('/welcome/{code}.html', function ($code) {
         $invite = new InviteComponent();
         return $invite->storeEntry($code);
     });
 }
示例#4
0
 /**
  * регистрация
  * @return \Response
  */
 public function register()
 {
     Validation::prepareInput(['phone']);
     // всегда обязательные поля
     $fields = ['name', 'phone', 'email'];
     // регистрация может быть основна на адресе,
     // который был определен по промокоду
     if (\Input::get('address_id')) {
         $fields[] = 'address_id';
     } elseif (\Input::get('address')) {
         $fields[] = 'address';
     } else {
         // или при регистрации указывается полный адрес
         $fields[] = 'city';
         $fields[] = 'street';
         $fields[] = 'house';
         $fields[] = 'room';
         $fields[] = 'float';
     }
     $validator = Validation::validator($fields);
     if ($validator->fails()) {
         return $this->responseError($validator, 'Некорректные данные');
     }
     try {
         $api = new Api();
         $message = $api->RegistrNew(\Input::only($fields));
         // инвайт
         $invite = new InviteComponent();
         $cookie = $invite->registerInviteExternal($validator->getData()['phone']);
         $response = $this->responseSuccess([], $message);
         if ($cookie) {
             $response->withCookie($cookie);
         }
         return $response;
     } catch (\Exception $e) {
         return $this->responseException($e, 'Не удалось обработать данные');
     }
 }