Ejemplo n.º 1
0
 public function actionSetMsg()
 {
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     $info = CollectInteract::findOne(['userid' => $phone['id'], 'msg' => $data['msg']]);
     if ($info) {
         echo json_encode(array('flag' => 0, 'msg' => 'Already collect!'));
         return;
     }
     $to = Message::findOne(['id' => $data['msg']]);
     $model2 = new Notify();
     $model2->from = $phone['id'];
     $model2->to = $to['userid'];
     $model2->message = '收藏';
     $model2->created_at = time();
     if (!$model2->save()) {
         echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!'));
         return;
     }
     $model = new CollectInteract();
     $model->userid = $phone['id'];
     $model->msg = $data['msg'];
     $model->created_at = time();
     if ($model->save()) {
         echo json_encode(array('flag' => 1, 'msg' => 'Collect success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Collect fail!'));
     }
 }
 /**
  * Creates a new CollectInteract model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new CollectInteract();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $data['CollectInteract']['userid']]);
         $model->msg = $data['CollectInteract']['msg'];
         $model->userid = $userinfo['id'];
         $model->created_at = (string) time();
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }