Example #1
0
 public function actionCreate()
 {
     $menuList = array();
     $type = Yii::app()->request->getParam('type');
     $type = $type ? $type : Globals::TYPE_KEYWORDS;
     if ($type == Globals::TYPE_MENU) {
         //取menu的下拉列表
         $menuList = MenuModel::model()->getMenuDropDownList($this->wechatInfo->id, Globals::TYPE_GIFT);
     }
     $model = new WheelModel();
     if (isset($_POST['WheelModel'])) {
         $model->type = $type;
         $model->attributes = $_POST['WheelModel'];
         $model->wechatId = $this->wechatInfo->id;
         if ($_FILES) {
             $file = array('name' => $_FILES['WheelModel']['name']['backgroundPic'], 'type' => $_FILES['WheelModel']['type']['backgroundPic'], 'tmp_name' => $_FILES['WheelModel']['tmp_name']['backgroundPic'], 'error' => $_FILES['WheelModel']['error']['backgroundPic'], 'size' => $_FILES['WheelModel']['size']['backgroundPic']);
             $uploadPath = Yii::app()->params['scratchPath'] . "/" . $this->wechatInfo->id . '/';
             $fileUpload = new FileUpload($uploadPath, $file);
             $fileUpload->move();
             $result = $fileUpload->getMessages();
             if (isset($result['name'])) {
                 $backgroundPic = $result['name'];
             } else {
                 ShowMessage::Error(current($result));
             }
             $file = array('name' => $_FILES['WheelModel']['name']['button'], 'type' => $_FILES['WheelModel']['type']['button'], 'tmp_name' => $_FILES['WheelModel']['tmp_name']['button'], 'error' => $_FILES['WheelModel']['error']['button'], 'size' => $_FILES['WheelModel']['size']['button']);
             $uploadPath = Yii::app()->params['scratchPath'] . "/" . $this->wechatInfo->id . '/';
             $fileUpload = new FileUpload($uploadPath, $file);
             $fileUpload->move();
             $result = $fileUpload->getMessages();
             if (isset($result['name'])) {
                 $button = $result['name'];
             } else {
                 ShowMessage::Error(current($result));
             }
         }
         //奖项处理
         for ($i = 1; $i <= 4; $i++) {
             ${'award' . $i} = $_POST['award' . $i];
             ${'isentity' . $i} = $_POST['isentity' . $i] ? $_POST['isentity' . $i] : 0;
             $awards[$i] = array('name' => ${'award' . $i}, 'isentity' => ${'isentity' . $i});
         }
         $model->awards = serialize($awards);
         $model->backgroundPic = $backgroundPic;
         $model->button = $button;
         $model->created_at = date('Y-m-d H:i:s');
         //$model->ispaward = '';//$_POST['WheelModel']['ispaward'];
         if ($model->validate()) {
             $model->save();
             switch ($type) {
                 case Globals::TYPE_KEYWORDS:
                     $keywords = $_POST['WheelModel']['keywords'];
                     $isAccurate = $_POST['WheelModel']['isAccurate'];
                     $keywordsArray = explode(',', $keywords);
                     foreach ($keywordsArray as $k) {
                         $keywordsModel = new KeywordsModel();
                         $keywordsModel->responseId = $model->id;
                         $keywordsModel->type = Globals::TYPE_SCRATCH;
                         $keywordsModel->isAccurate = $isAccurate;
                         $keywordsModel->name = $k;
                         $keywordsModel->wechatId = $this->wechatInfo->id;
                         $keywordsModel->save();
                     }
                     break;
                 case Globals::TYPE_MENU:
                     $menuId = $_POST['WheelModel']['action'];
                     $menuActionModel = MenuactionModel::model()->find('menuId=:menuId', array(':menuId' => $menuId));
                     $menuActionModel->responseId = $model->id;
                     $menuActionModel->save();
                     break;
             }
             ShowMessage::success('添加成功', Yii::app()->createUrl('scratch', array('type' => $type)));
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     $this->render('create', array('model' => $model, 'type' => $type ? $type : GiftModel::TYPE_KEYWORDS, 'wechatId' => $this->wechatInfo->id, 'responseId' => 0, 'menuList' => $menuList));
 }