Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Usertoapp::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if ($params != false && !empty($params['UsertoappSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['UsertoappSearch'] as $name => $value1) {
             if ($name === 'appid' && $value1 != null) {
                 $appinfo = app::findOne(['name' => $params['UsertoappSearch']['appid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
             if ($name === 'userid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['UsertoappSearch']['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, 'appid' => $this->value, 'created_at' => $this->created_at]);
     return $dataProvider;
 }
 /**
  * Finds the Usertoapp model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Usertoapp the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Usertoapp::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUsertoapps()
 {
     return $this->hasMany(Usertoapp::className(), ['userid' => 'id']);
 }
Exemplo n.º 4
0
 public function actionUpload()
 {
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     foreach ($data['apps'] as $app) {
         $a = Appl::findOne(['package' => $app[1]]);
         if ($a) {
             $model = new Usertoapp();
             $model->userid = $phone->id;
             $model->appid = $a->id;
             $model->created_at = time();
             if (!$model->save()) {
                 echo json_encode(array('flag' => 0, 'msg' => 'Upload your app failed!'));
                 return;
             }
         } else {
             $model1 = new Appl();
             $model1->name = $app[0];
             $model1->package = $app[1];
             $model1->updated_at = time();
             if (!$model1->save()) {
                 echo json_encode(array('flag' => 0, 'msg' => 'Upload your app failed!'));
                 return;
             }
             $a1 = Appl::findOne(['package' => $app[1]]);
             $model2 = new Usertoapp();
             $model2->userid = $phone->id;
             $model2->appid = $a1->id;
             $model2->created_at = time();
             if (!$model2->save()) {
                 echo json_encode(array('flag' => 0, 'msg' => 'Upload your app failed!'));
                 return;
             }
         }
     }
     echo json_encode(array('flag' => 1, 'msg' => 'Upload your app success!'));
 }