コード例 #1
0
 /**
  * 添加美粒宝典
  * @date: 2016年1月4日 
  * @author: chenxiaolin
  */
 public function addAction()
 {
     $this->setLeftNav('add');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('openCity', SysOpenCity::find('city_state = 1'));
         $this->view->setVar("action", '/beautycanon/add');
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     //保存封面图片
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面大小超过了1M!');
         } else {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面必须上传!');
         }
         return;
     }
     $title = $req->getPost("title");
     $content = $req->getPost("content");
     $fit = $req->getPost("fit");
     $assist = $req->getPost("assist");
     $city = $req->getPost("city");
     $summary = $req->getPost('summary');
     $url = $cover[0];
     $state = 1;
     //循环添加数据
     foreach ($city as $k => $v) {
         $beautyCanon = new CosBeautyCanon();
         $beautyCanon->content = $content;
         $beautyCanon->img_url = $url;
         $beautyCanon->title = $title;
         $beautyCanon->state = $state;
         $beautyCanon->fit = $fit;
         $beautyCanon->assist = $assist;
         $beautyCanon->settime = date("Y-m-d H:i:s");
         $beautyCanon->summary = $summary;
         $beautyCanon->city_id = $v;
         $status = $beautyCanon->save();
         //添加数据失败
         if ($status == false) {
             $this->databaseErrorLog($status);
             $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
         }
     }
     $response->sendResult('ok');
     return $response;
 }
コード例 #2
0
 public function addAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar("action", '/beautycanon/add');
         $this->view->pick("beautycanon/ListEditBase");
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面大小超过了2M!');
         } else {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面必须上传!');
         }
         return;
     }
     $title = $req->getPost("title");
     $content = $req->getPost("content");
     $url = $cover[0];
     $state = 1;
     $BeautyCanon = new CosBeautyCanon();
     $BeautyCanon->content = $content;
     $BeautyCanon->img_url = $url;
     $BeautyCanon->title = $title;
     $BeautyCanon->state = $state;
     $status = $BeautyCanon->save();
     $response->sendResult('ok');
     return $response;
 }