/** * регистрация юзера по имейл * если регистрация для покупки, то передаются параметры рекомендатель и урл * @param type $affiliate_id * @param type $url_id * @return type * @throws \yii\web\NotFoundHttpException */ public function actionUser($affiliate_id = null, $url_id = null) { $request = Yii::$app->request; $model = new \app\models\registration\UserForm(); if ($request->isAjax && $model->load($request->post())) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load($request->post()) && $model->validate()) { $user = User::findByUsername($model->email); if (!$user) { $user = $model->save(); } $user->setCookie(); if ($affiliate_id === null || $url_id === null) { Yii::$app->session->setFlash('success', 'Регистрация успешна. Пароль выслан на почту'); return $this->goHome(); } $url = Url::findOne($url_id); if (!$url) { throw new \yii\web\NotFoundHttpException('Урл не найден'); } $user->purchase($affiliate_id, $url); return $this->redirect($url->link); } return $this->render('user', ['model' => $model]); }
/** * ЦСКА */ public function actionCskanews() { $cska = Yii::$app->params['cska']; $bot = new BotApi($cska['token']); $host = 'https://www.sports.ru'; $dom = Html::load($cska['html']); $divs = $dom->getElementsByTagName('div'); foreach ($divs as $div) { if ($div->getAttribute('class') == 'news') { $links = $div->getElementsByTagName('a'); foreach ($links as $link) { if ($link->getAttribute('class') == 'short-text') { $url = Url::findOne(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]); if ($url === null) { $message = $link->nodeValue . "\n" . $host . $link->getAttribute('href'); try { $bot->sendMessage($cska['chat_id'], $message); } catch (Exception $e) { echo $e->getMessage() . "\n"; } $url = new Url(['channel' => 'cska', 'url' => $host . $link->getAttribute('href')]); $url->save(); } } } } } }
/** * переход покупателя по реф ссылке * @param type $affiliate_id рекомендатель * @param type $url_id ид ссылки * @return type * @throws \yii\web\NotFoundHttpException */ public function actionCreate($affiliate_id, $url_id) { $user_id = null; if (!Yii::$app->user->isGuest) { $user_id = Yii::$app->user->identity->id; } else { $user_id = Yii::$app->request->cookies->getValue('user_id'); } if ($user_id === null) { return $this->redirect(['registration/user', 'affiliate_id' => $affiliate_id, 'url_id' => $url_id]); } else { $url = Url::findOne($url_id); if (!$url) { throw new \yii\web\NotFoundHttpException('Урл не найден'); } $user = User::findOne($user_id); $user->purchase($affiliate_id, $url); return $this->redirect($url->link); } }
public static function getByUrl($url) { return Url::findOne(['short' => $url]); }
/** * Finds the Url model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Url the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Url::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }