/**
  * 修改文章
  * @author 罗江涛
  * @DateTime 2016-01-13T10:26:45+0800
  */
 public function editArticle()
 {
     $articleId = I('articleId');
     $article['articleId'] = $articleId;
     // 如果是POST,接收参数
     $article = array('articleId' => $articleId, 'title' => I('title'), 'summary' => I('summary'), 'creatorName' => session("adminName"), 'content' => I('content'), 'logo' => I('logo'), 'time' => date('Y-m-d H:i:s'), 'categoryId' => I('categoryId'), 'publishTime' => I('publishTime'), 'weixin' => I('weixin'), 'author' => I('author'), 'status' => I('status', 3, 'intval'));
     // 尝试保存logo
     $file = \Admin\Service\UploadService::upload("logo");
     if ($file) {
         $article['logo'] = date("Y_m") . "/" . $file['logo']['savename'];
         // 获取以前的logo地址
         $logo = M("article")->where(array("articleId" => $articleId))->getField("logo");
         if ($logo) {
             // 补全以前的logo地址
             $logo = "./Uploads/logo/" . $logo;
             // 删除以前的logo地址
             @unlink($logo);
         }
     }
     //修改为草稿
     $db = M('article');
     if ($db->save($article)) {
         //标签处理
         //先删除之前所有标签
         M('article_tags')->where(array('articleId' => $articleId))->delete();
         $tag = trim(I('tag'));
         //不区分中英文逗号
         $tag = str_replace(",", ",", $tag);
         // 按逗号拆分成数组
         $tag = explode(",", $tag);
         // 循环插入添加关系
         foreach ($tag as $key => $value) {
             // 查找标签是否存在
             $tempTag = M('tag')->where(array('tagName' => $value))->find();
             if ($tempTag) {
                 //如果标签存在,直接关联
                 $article_tags = array('articleId' => $articleId, 'tagId' => $tempTag['tagId']);
                 M('article_tags')->add($article_tags);
             } else {
                 //如果标签不存在则添加后在关联
                 $data = array('tagName' => $value);
                 $tagId = M('tag')->add($data);
                 $article_tags = array('articleId' => $articleId, 'tagId' => $tagId);
                 // 添加标签和文章关联关系
                 M('article_tags')->add($article_tags);
             }
         }
         // 添加日志
         $content = "修改:" . I('title');
         \Admin\Service\LogService::addAdminLog(I('articleId'), 'article', $content);
         $this->redirect('Article/articleForm', array("articleId" => $articleId, "cleanLocalStorageArticle" => 1));
     } else {
         $this->error('修改失败' . $db->getDbError());
     }
 }
 /**
  * 修改管理员
  * @author 罗江涛
  * @DateTime 2016-01-13T10:26:45+0800
  */
 public function editReport()
 {
     // 如果不是POST提交
     if (!IS_POST) {
         $this->error('不是POST提交');
     }
     $reportId = I('reportId');
     // 如果是POST,接收参数
     $report = array('reportId' => $reportId, 'title' => I('title'), 'summary' => I('summary'), 'reportCategoryId' => I('reportCategoryId'), 'pageNumber' => I('pageNumber'), 'imageNumber' => I('imageNumber'), 'price' => I('price'), 'list' => I('list'), 'description' => I('description'), 'time' => date('Y-m-d H:i:s'));
     if (I("isVipFree")) {
         $report['isVipFree'] = 1;
     } else {
         $report['isVipFree'] = 0;
     }
     // 尝试保存logo
     $logo = \Admin\Service\UploadService::uploadOneFile("logo", "report_logo");
     if ($logo) {
         $report['logo'] = date("Y_m") . "/" . $logo['savename'];
         // 获取以前的logo地址
         $oldLogo = M("report")->where(array("reportId" => $reportId))->getField("logo");
         if ($oldLogo) {
             // 补全以前的logo地址
             $oldLogo = "./Uploads/report_logo/" . $oldLogo;
             // 删除以前的logo地址
             @unlink($oldLogo);
         }
     }
     // 尝试保存报告文件
     $file = \Admin\Service\UploadService::uploadOneFile("file", "report_file");
     if ($file) {
         $report['file'] = date("Y_m") . "/" . $file['savename'];
         // 获取以前的文件地址
         $oldFile = M("report")->where(array("reportId" => $reportId))->getField("file");
         if ($oldFile) {
             // 补全以前的报告文件地址
             $oldFile = "./Uploads/report_file/" . $oldFile;
             // 删除以前的报告文件地址
             @unlink($oldFile);
         }
     }
     //添加
     M('report')->save($report);
     $this->redirect('Report/reportList');
 }
 /**
  * 修改活动
  * @author 罗江涛
  * @DateTime 2016-01-13T10:55:00+0800
  */
 public function editCampaign()
 {
     //接收传值
     $campaignId = I('campaignId');
     $campaign = array('campaignId' => $campaignId, 'title' => I('title'), 'endTime' => I('endTime'), 'startTime' => I('startTime'), 'content' => I('content'), 'address' => I('address'), 'link' => I('link'), 'price' => I('price'), 'number' => I('number'), 'status' => 1);
     // 尝试保存logo
     $file = \Admin\Service\UploadService::upload("logo");
     if ($file) {
         $campaign['logo'] = date("Y_m") . "/" . $file['logo']['savename'];
         // 获取以前的logo地址
         $logo = M("campaign")->where(array("campaignId" => $campaignId))->getField("logo");
         if ($logo) {
             // 补全以前的logo地址
             $logo = "./Uploads/logo/" . $logo;
             // 删除以前的logo地址
             @unlink($logo);
         }
     }
     $db = M('campaign');
     // 开始修改
     if ($db->save($campaign)) {
         //标签处理
         //先删除之前所有标签
         M('campaign_tags')->where(array('campaignId' => $campaignId))->delete();
         $tag = trim(I('tag'));
         //不区分中英文逗号
         $tag = str_replace(",", ",", $tag);
         // 按逗号拆分成数组
         $tag = explode(",", $tag);
         // 循环插入添加关系
         foreach ($tag as $key => $value) {
             // 查找
             $tempTag = M('tag')->where(array('tagName' => $value))->find();
             if ($tempTag) {
                 //如果标签存在,直接关联
                 $campaign_tags = array('campaignId' => $campaignId, 'tagId' => $tempTag['tagId']);
                 M('campaign_tags')->add($campaign_tags);
             } else {
                 //如果标签不存在则添加后在关联
                 $data = array('tagName' => $value);
                 $tagId = M('tag')->add($data);
                 $campaign_tags = array('campaignId' => $campaignId, 'tagId' => $tagId);
                 M('campaign_tags')->add($campaign_tags);
             }
         }
         // 添加管理员日志
         $content = "修改:" . I('title');
         \Admin\Service\LogService::addAdminLog($campaignId, 'campaign', $content);
         $this->redirect('Campaign/campaignList');
     } else {
         $this->error('修改失败' . $db->getDbError());
     }
 }