/**
  * Creates a new Recommendations model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Recommendations();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Applyjobs model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Recommendations();
     $data = Yii::$app->request->post();
     if (empty($data['phone']) || empty($data['title']) || empty($data['location']) || empty($data['kindid']) || empty($data['reason'])) {
         return array('flag' => 0, 'msg' => 'no enough arg!');
     }
     $user = Users::findOne(['phone' => $data['phone']]);
     if (!$user) {
         return array('flag' => 0, 'msg' => 'create recommendation fail!');
     }
     unset($data['phone']);
     $model->title = isset($data['title']) ? $data['title'] : '';
     $model->kindid = $data['kindid'];
     $model->location = $data['location'];
     $model->sellerphone = isset($data['sellerphone']) ? $data['sellerphone'] : '';
     $model->reason = $data['reason'];
     $model->pictures = isset($data['pictures']) ? $data['pictures'] : '';
     $model->longitude = isset($data['longitude']) ? $data['longitude'] : 0;
     $model->latitude = isset($data['latitude']) ? $data['latitude'] : 0;
     //         $i=0;
     //         for($i=1;$i<=9;$i++){
     //         	$model->setAttribute('picture'. $i, isset($data['picture' . $i])?$data['picture' . $i]:'');
     //         }
     //         if(is_array($data['picture'])){
     //         	foreach ($data['picture'] as $i=>$picture){
     //         		$model->setAttribute('picture'. ($i+1), $picture);
     //         	}
     //         }
     //         for($i++;$i<9;$i++){
     //         	$model->setAttribute('picture'. ($i+1), '');
     //         }
     //$model->load($data);
     $model->userid = $user->id;
     $model->created_at = time();
     //var_dump();
     if ($model->save()) {
         return array('flag' => 1, 'msg' => 'create recommendation success!');
     } else {
         //var_dump($model->errors);
         return array('flag' => 0, 'msg' => 'create recommendation fail!');
     }
 }