public function actionSetApp() { $data = Yii::$app->request->post(); $phone = User::findOne(['phone' => $data['phone']]); $info = CollectPerson::findOne(['userid' => $phone['id'], 'app' => $data['app']]); if ($info) { echo json_encode(array('flag' => 0, 'msg' => 'Already collect!')); return; } $model = new CollectPerson(); $model->userid = $phone['id']; $model->app = $data['app']; $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 CollectPerson model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new CollectPerson(); $data = Yii::$app->request->post(); if ($data != false) { $userinfo = User::findOne(['phone' => $data['CollectPerson']['userid']]); $appinfo = app::findOne(['name' => $data['CollectPerson']['app']]); $model->app = (string) $appinfo['id']; $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]); } }