Exemplo n.º 1
0
 /**
  * 标签关注
  *
  * @param unknown $id            
  * @return Ambigous <\yii\web\Response, \yii\web\$this, \yii\web\Response>
  */
 public function actionAttention($id)
 {
     $tag = Tag::findOne($id);
     if (!$tag) {
         return $this->redirect(['/main/index']);
     }
     if (!($userId = Yii::$app->user->identity->getId())) {
         return $this->redirect(['detail', 'id' => $id]);
     }
     $atten = Attention::find()->where(['keyId' => $id, 'userId' => $userId, 'type' => 4])->all();
     if (count($atten) > 0) {
         return $this->redirect(['detail', 'id' => $id]);
     }
     $model = new Attention();
     $model->userId = Yii::$app->user->identity->getId();
     $model->keyId = $id;
     $model->attenTime = date('Y-m-d H:i:s', time());
     $model->type = 4;
     if ($model->save() && $this->addAttentionNum($id)) {
         return $this->redirect(['detail', 'id' => $id]);
     }
 }
Exemplo n.º 2
0
 /**
  * 添加关注
  *
  * @param 主表main的Id $id            
  * @return 关注成功返回至入口页
  */
 public function actionAttention($id)
 {
     $main = Main::findOne($id);
     if (!$main) {
         return $this->redirect(['index']);
     }
     if (!($userId = Yii::$app->user->identity->getId())) {
         return $this->redirect(['index']);
     }
     $atten = Attention::find()->where(['keyId' => $id, 'userId' => $userId, 'type' => $main->type]);
     if ($atten !== null) {
         return $this->getRedirect($main->type, $id);
     }
     $model = new Attention();
     $model->userId = Yii::$app->user->identity->getId();
     $model->keyId = $id;
     $model->attenTime = date('Y-m-d H:i:s', time());
     $model->type = $main->type;
     if ($model->save() && $this->addAttentionNum($id)) {
         return $this->getRedirect($main->type, $id);
     }
 }