/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CollectPerson::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     //$value = 0;
     if ($params != false && !empty($params['CollectPersonSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['CollectPersonSearch'] as $name => $value1) {
             if ($name === 'app' && $value1 != null) {
                 $appinfo = app::findOne(['name' => $params['CollectPersonSearch']['app']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
             if ($name === 'userid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['CollectPersonSearch']['userid']]);
                 $this->userinc = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->userinc = 0;
                 }
             }
         }
     }
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['userid' => $this->userinc, 'created_at' => $this->created_at, 'app' => $this->value]);
     return $dataProvider;
 }
 public function actionCancelApp()
 {
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     $info = CollectPerson::findOne(['userid' => $phone['id'], 'app' => $data['app']]);
     if ($info) {
         $info->delete();
         echo json_encode(array('flag' => 1, 'msg' => 'Cancel collect success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Cancel collect fail!'));
     }
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCollectPeople()
 {
     return $this->hasMany(CollectPerson::className(), ['userid' => 'id']);
 }
 /**
  * Finds the CollectPerson model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CollectPerson the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CollectPerson::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }