예제 #1
0
 /**
  * Creates a new Zan model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Zan();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $data['Zan']['myid']]);
         $model->myid = (string) $userinfo['id'];
         $model->msgid = $data['Zan']['msgid'];
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 public function actionZan()
 {
     $data = Yii::$app->request->post();
     $user = new User();
     $phone = $user->find()->select('id')->where(['phone' => $data['phone']])->one();
     $info = Zan::findOne(['myid' => $phone['id'], 'msgid' => $data['msgid']]);
     if ($info) {
         echo json_encode(array('flag' => 0, 'msg' => 'Already zan!'));
     } else {
         $model = new Zan();
         $model->myid = $phone['id'];
         $model->msgid = $data['msgid'];
         $model->save();
         $to = Message::findOne(['id' => $data['msgid']]);
         $model2 = new Notify();
         $model2->from = $phone['id'];
         $model2->to = $to['userid'];
         $model2->message = '点赞';
         $model2->created_at = time();
         $model2->save();
         echo json_encode(array('flag' => 1, 'msg' => 'Zan success!'));
     }
 }