Exemplo n.º 1
0
 public function classifyModify()
 {
     $cus_id = Auth::id();
     $is_forced = Input::get('force');
     $is_passed = true;
     $id = Input::get('id');
     if ($id != NULL) {
         $classify = Classify::find($id);
         $page_id = Classify::where('cus_id', $cus_id)->where('id', $id)->pluck('page_id');
     } else {
         $classify = new Classify();
         $maxsort = Classify::where('cus_id', $cus_id)->max('sort');
         $classify->sort = $maxsort === NULL ? 0 : $maxsort + 1;
         $classify->cus_id = $cus_id;
         $page_id = false;
     }
     $classify->p_id = Input::get('p_id') == "undefined" ? 0 : Input::get('p_id');
     $classify->type = Input::get('type');
     if ($classify->p_id > 0) {
         if ($this->checkClassifyLevel($classify->p_id, 1, $cus_id)) {
             $p_c_info = Classify::find($classify->p_id);
             if (in_array($p_c_info->type, array(5, 6, 7, 8))) {
                 $result = ['err' => 1001, 'msg' => '该类型不允许添加子栏目', 'data' => []];
                 $is_passed = false;
             } else {
                 $c_c_ids = Classify::where('p_id', $p_c_info->id)->lists('id');
                 if (!count($c_c_ids)) {
                     $a_ids = Articles::where('c_id', $p_c_info->id)->lists('id');
                     if (count($a_ids)) {
                         if (in_array($classify->type, array(4, 5, 6, 7, 8))) {
                             $result = ['err' => 1001, 'msg' => '存在文章的栏目不允许添加该类型子栏目', 'data' => []];
                             $is_passed = false;
                         } else {
                             if (!$is_forced) {
                                 $result = ['err' => 1002, 'msg' => '该栏目存在文章,需转移才能创建子栏目', 'data' => []];
                                 $is_passed = false;
                             }
                         }
                     }
                 }
             }
         } else {
             $result = ['err' => 1001, 'msg' => '添加失败,超过最大限制层级', 'data' => []];
             $is_passed = false;
         }
     }
     if ($is_passed) {
         $classify->name = trim(Input::get('name'));
         $classify->en_name = trim(Input::get('en_name'));
         $images = Input::get('img');
         if (!empty($images) && $images != 'undefined') {
             $classify->img = $images;
         } else {
             $classify->img = '';
             //需要删除图片
         }
         $icon = Input::get('icon');
         if (!empty($icon) && $icon != 'undefined') {
             $classify->icon = $icon;
         } else {
             $classify->icon = '';
         }
         $classify->article_type = Input::get('article_type') != "undefined" ? Input::get('article_type') : 1;
         $classify->meta_keywords = trim(Input::get('keywords'));
         $classify->meta_description = trim(Input::get('description'));
         $classify->url = trim(Input::get('url'));
         $classify->pushed = 1;
         $is_show = Input::get('is_show');
         $shows = explode(',', $is_show);
         if (count($shows)) {
             $classify->pc_show = 0;
             $classify->mobile_show = 0;
             $classify->wechat_show = 0;
             foreach ($shows as $show) {
                 if ($show != '') {
                     $classify->{$show} = 1;
                 }
             }
         }
         /*
             if (Input::has('module_key') && Input::get('module_key')!=""){
                 if(Input::has('module_key') && Input::get('module_value')!=""){
                     $classify->url = Input::get('module_value').'@'.Input::get('module_key');
                 }
                 else{
                     $classify->url = Input::get('module_key');
                 }
             }
         */
         if (Input::has('page_content') && Input::get('page_content') != 'undefined') {
             $page_content = Input::get('page_content');
             if ($page_id) {
                 Page::where('id', $page_id)->update(array('content' => $page_content));
             } else {
                 $page = new Page();
                 $page->c_id = 0;
                 $page->content = $page_content;
                 if ($page->save()) {
                     $classify->page_id = $page->id;
                 } else {
                     return Response::json(['err' => 10001, 'msg' => '页面内容无法保存']);
                 }
             }
         }
         if ($classify->save()) {
             $data['id'] = $classify->id;
             if ($is_forced) {
                 Articles::where('cus_id', $cus_id)->whereIn('id', $a_ids)->update(array('c_id' => $classify->id));
             }
             if ($id != NULL) {
                 $result = ['err' => 0, 'msg' => '栏目修改成功', 'data' => $data];
             } else {
                 if (in_array($classify->type, array(1, 2, 3, 4)) && $classify->p_id == 0) {
                     $mhomepage_config = new MobileHomepage();
                     $mhomepage_config->c_id = $data['id'];
                     $mhomepage_config->index_show = 1;
                     $mhomepage_config->show_num = 0;
                     $mhomepage_config->star_only = 0;
                     $mhomepage_config->s_sort = 0;
                     $mhomepage_config->cus_id = $cus_id;
                     $mhomepage_config->save();
                 }
                 $result = ['err' => 0, 'msg' => '创建栏目成功', 'data' => $data];
             }
         } else {
             if ($id != NULL) {
                 $result = ['err' => 1001, 'msg' => '修改栏目失败', 'data' => []];
             } else {
                 $result = ['err' => 1001, 'msg' => '创建栏目失败', 'data' => []];
             }
         }
     }
     return Response::json($result);
 }
Exemplo n.º 2
0
 public function homepageBatchModify()
 {
     $ids = Input::get('id');
     $index_show = Input::get('show');
     $show_num = Input::get('total');
     $show_type = Input::get('showtype');
     $star_only = Input::get('star_only');
     $cus_id = Auth::id();
     if (is_array($ids)) {
         $err = false;
         $data = array();
         foreach ($ids as $id) {
             $m_i_config = MobileHomepage::where('c_id', '=', $id)->first();
             if (!$m_i_config) {
                 $m_i_config = new MobileHomepage();
                 $m_i_config->c_id = $ids;
                 $m_i_config->cus_id = $cus_id;
             }
             if ($index_show != NULL) {
                 $m_i_config->index_show = $index_show;
             }
             if ($show_num != NULL) {
                 $m_i_config->show_num = $show_num;
             }
             if ($star_only != NULL) {
                 $m_i_config->star_only = $star_only;
             }
             if ($show_type != NULL) {
                 $m_i_config->m_index_showtype = $show_type;
             }
             $result = $m_i_config->save();
             if ($result) {
                 $data[] = $id;
             } else {
                 $err = true;
             }
         }
         if ($err) {
             $return_msg = array('err' => 3001, 'msg' => '操作失败', 'data' => $data);
         } else {
             $return_msg = array('err' => 0, 'msg' => '操作成功');
         }
     } else {
         $m_i_config = MobileHomepage::where('c_id', '=', $ids)->first();
         if (!$m_i_config) {
             $m_i_config = new MobileHomepage();
             $m_i_config->c_id = $ids;
             $m_i_config->cus_id = $cus_id;
         }
         if ($index_show != NULL) {
             $m_i_config->index_show = $index_show;
         }
         if ($show_num != NULL && is_numeric($show_num)) {
             $m_i_config->show_num = $show_num;
         }
         if ($show_type != NULL && is_numeric($show_type)) {
             $m_i_config->m_index_showtype = $show_type;
         }
         if ($star_only != NULL) {
             $m_i_config->star_only = $star_only;
         }
         $result = $m_i_config->save();
         if ($result) {
             $return_msg = array('err' => 0, 'msg' => '操作成功');
         } else {
             $return_msg = array('err' => 3001, 'msg' => '操作失败', 'data' => array());
         }
     }
     return Response::json($return_msg);
 }
Exemplo n.º 3
0
 /**
  * 栏目添加、修改/===批量添加栏目===
  * @return type
  */
 public function classifyModify()
 {
     $cus_id = Auth::id();
     $c_imgs = '';
     $is_forced = Input::get('force');
     $is_passed = true;
     $id = Input::get('id');
     //        $box_flag = Input::get('box_flag') ? Input::get('box_flag') : 'single';
     if ($id != NULL) {
         //===修改===
         $classify = Classify::find($id);
         $c_imgs = $classify->img;
         $page_id = Classify::where('cus_id', $cus_id)->where('id', $id)->pluck('page_id');
     } else {
         //===添加===
         $classify = new Classify();
         $maxsort = Classify::where('cus_id', $cus_id)->max('sort');
         $classify->sort = $maxsort === NULL ? 0 : $maxsort + 1;
         $classify->cus_id = $cus_id;
         $page_id = false;
     }
     $classify->p_id = Input::get('p_id') == "undefined" ? 0 : Input::get('p_id');
     //===要改变的父类===
     $classify->type = Input::get('type');
     $classify->form_id = Input::get('form_id');
     if ($classify->p_id > 0) {
         if ($this->checkClassifyLevel($classify->p_id, 1, $cus_id)) {
             $p_c_info = Classify::find($classify->p_id);
             //===父类信息===
             if ($id != null) {
                 //===修改===
                 if ($p_c_info->p_id == $classify->id) {
                     //===子类不能作为父类的父类===
                     $result = ['err' => 1001, 'msg' => '不合法的父级分类', 'data' => []];
                     $is_passed = false;
                 }
             }
             if ($is_passed) {
                 if (in_array($p_c_info->type, array(5, 6, 7, 8, 9))) {
                     $result = ['err' => 1001, 'msg' => '该类型不允许添加子栏目', 'data' => []];
                     $is_passed = false;
                 } else {
                     $c_c_ids = Classify::where('p_id', $p_c_info->id)->lists('id');
                     if (!count($c_c_ids)) {
                         $a_ids = Articles::where('c_id', $p_c_info->id)->lists('id');
                         if (count($a_ids)) {
                             if (in_array($classify->type, array(4, 5, 6, 7, 8, 9))) {
                                 $result = ['err' => 1001, 'msg' => '存在文章的栏目不允许添加该类型子栏目', 'data' => []];
                                 $is_passed = false;
                             } else {
                                 if (!$is_forced) {
                                     $result = ['err' => 1002, 'msg' => '该栏目存在文章,需转移才能创建子栏目', 'data' => []];
                                     $is_passed = false;
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $result = ['err' => 1001, 'msg' => '添加失败,超过最大限制层级', 'data' => []];
             $is_passed = false;
         }
     }
     if ($is_passed) {
         $classify->name = trim(Input::get('name'));
         $classify->en_name = trim(Input::get('en_name'));
         $classify->view_name = trim(Input::get('view_name'));
         //===页面别名===
         $images = Input::get('img');
         //===新图片
         $classify->img = $images;
         if (!empty($c_imgs) && $c_imgs != 'undefined') {
             if ($c_imgs != $images) {
                 $del_img = $c_imgs;
             }
         }
         $icon = Input::get('icon');
         if (!empty($icon) && $icon != 'undefined') {
             $classify->icon = $icon;
         } else {
             $classify->icon = '';
         }
         $classify->article_type = Input::get('article_type') != "undefined" ? Input::get('article_type') : 1;
         $classify->meta_keywords = trim(Input::get('keywords'));
         $classify->meta_description = trim(Input::get('description'));
         $classify->url = trim(Input::get('url'));
         $classify->open_page = trim(Input::get('open_page')) ? trim(Input::get('open_page')) : 1;
         $classify->pushed = 1;
         $is_show = Input::get('is_show');
         $shows = explode(',', $is_show);
         if (count($shows)) {
             $classify->pc_show = 0;
             $classify->mobile_show = 0;
             $classify->wechat_show = 0;
             $classify->footer_show = 0;
             foreach ($shows as $show) {
                 if ($show != '') {
                     $classify->{$show} = 1;
                 }
             }
         }
         if (Input::has('page_content') && Input::get('page_content') != 'undefined') {
             $page_content = Input::get('page_content');
             //===ueditor保存===
             $page = Page::find($page_id);
             $Capacity = new CapacityController();
             if (empty($page)) {
                 $page_file_array = '';
             } else {
                 $page_file_array = $page->file_array;
             }
             $Capacity->compare_filename($page_content, $page_file_array);
             $file_array = $Capacity->reg_ueditor_content($page_content);
             //===end===
             if ($page_id) {
                 Page::where('id', $page_id)->update(array('content' => $page_content, 'file_array' => $file_array));
             } else {
                 $page = new Page();
                 $page->c_id = 0;
                 $page->content = $page_content;
                 $page->file_array = $file_array;
                 if ($page->save()) {
                     $classify->page_id = $page->id;
                 } else {
                     return Response::json(['err' => 10001, 'msg' => '页面内容无法保存']);
                 }
             }
         }
         $size = 0;
         if ($classify->save()) {
             if (isset($del_img)) {
                 $imgdel = new ImgDel();
                 $size = $imgdel->mysave($del_img, 'category');
             }
             $data['id'] = $classify->id;
             if ($is_forced) {
                 Articles::where('cus_id', $cus_id)->whereIn('id', $a_ids)->update(array('c_id' => $classify->id));
             }
             if ($id != NULL) {
                 $result = ['err' => 0, 'msg' => 'Success栏目修改成功' . $size, 'data' => $data];
             } else {
                 if (in_array($classify->type, array(1, 2, 3, 4, 9)) && $classify->p_id == 0) {
                     //===添加type:9万用表单===
                     $mhomepage_config = new MobileHomepage();
                     $mhomepage_config->c_id = $data['id'];
                     $mhomepage_config->index_show = 1;
                     $mhomepage_config->show_num = 0;
                     $mhomepage_config->star_only = 0;
                     $mhomepage_config->s_sort = 0;
                     $mhomepage_config->cus_id = $cus_id;
                     $mhomepage_config->save();
                 }
                 $result = ['err' => 0, 'msg' => '创建栏目成功', 'data' => $data];
             }
         } else {
             if ($id != NULL) {
                 $result = ['err' => 1001, 'msg' => '修改栏目失败', 'data' => []];
             } else {
                 $result = ['err' => 1001, 'msg' => '创建栏目失败', 'data' => []];
             }
         }
     }
     return Response::json($result);
 }