/**
  * Creates a new Usertoapp model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Usertoapp();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $data['Usertoapp']['userid']]);
         $appinfo = app::findOne(['name' => $data['Usertoapp']['appid']]);
         $model->appid = (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]);
     }
 }
 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!'));
 }