public function articleAdd() { $org_imgs = array(); $del_imgs = array(); $id = Input::get('id'); if ($id) { //修改操作 $article = Articles::find($id); $data = MoreImg::where('a_id', $id)->get()->toArray(); foreach ((array) $data as $v) { $org_imgs[] = $v["img"]; } $org_imgs[] = $article->img; } else { //新增操作 $article = new Articles(); } $cus_id = Auth::id(); $article->title = trim(Input::get('title')); $article->c_id = Input::get('c_id'); $article->viewcount = Input::get('viewcount') ? Input::get('viewcount') : 0; $article->title_bold = Input::get('title_bold'); $article->title_color = Input::get('title_color'); $article->keywords = Input::get('keywords'); $article->introduction = Input::get('introduction'); $article->content = trim(Input::get('content')); $article->url = trim(Input::get('url')); $article->use_url = trim(Input::get('use_url')); if ($article->title == "") { return Response::json(array('err' => 3001, 'msg' => '标题不能为空')); } $img_arr = explode(',', Input::get('src')); foreach ((array) $org_imgs as $v) { if (!in_array($v, (array) $img_arr)) { $del_imgs[] = $v; } } if (count($img_arr)) { $article->img = $img_arr[0]; unset($img_arr[0]); } $is_show = empty(Input::get('is_show')) ? array() : explode(',', Input::get('is_show')); $article->pc_show = 0; $article->mobile_show = 0; $article->wechat_show = 0; if (count($is_show)) { foreach ($is_show as $val) { $article->{$val} = 1; } } $pubdate = Input::get('pubdate'); if ($pubdate) { $article->created_at = date('Y-m-d H:i:s', strtotime($pubdate)); } $article->cus_id = $cus_id; $article->pushed = 1; //===ueditor文件统计容量=== $Capacity = new CapacityController(); $Capacity->compare_filename($article->content, $article->file_array); $article->file_array = $Capacity->reg_ueditor_content($article->content); //===end=== $result = $article->save(); if ($result) { if ($id) { MoreImg::where('a_id', $id)->delete(); foreach ((array) $del_imgs as $v) { $imgdel = new ImgDel(); $imgdel->mysave($v, 'articles'); } } if (count($img_arr)) { foreach ($img_arr as $img) { $moreimg = new Moreimg(); $moreimg->title = ''; $moreimg->img = $img; $moreimg->url = ''; $moreimg->sort = ''; $moreimg->a_id = $article->id; $moreimg->save(); } } $return_msg = array('err' => 0, 'msg' => '', 'data' => array($article->id)); } else { $return_msg = array('err' => 3001, 'msg' => '文章添加失败'); } return Response::json($return_msg); }
/** * ===栏目批量添加=== */ public function classifyBatch() { $cus_id = Auth::id(); $c_imgs = ''; $is_forced = Input::get('force'); $is_passed = true; $id = Input::get('id'); $classify = new stdClass(); $batch_column_name = Input::get('batch_column_name') ? Input::get('batch_column_name') : ''; $batch_array = explode(',', $batch_column_name); $batch_flag = true; $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 (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)) { $result = ['err' => 1001, 'msg' => '存在文章的栏目不允许批量添加栏目', 'data' => []]; $is_passed = false; } } } } else { $result = ['err' => 1001, 'msg' => '添加失败,超过最大限制层级', 'data' => []]; $is_passed = false; } } if ($is_passed) { $classify->en_name = trim(Input::get('en_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; $classify_arr = (array) $classify; // $ids = ''; foreach ($batch_array as $key => $value) { $classify_obj[$key] = $classify_arr; $classify_obj[$key]["name"] = trim($value); $temp_flag = Classify::insertGetId($classify_obj[$key]); // $ids[] = $temp_flag; $batch_flag = $batch_flag && $temp_flag; } if ($batch_flag) { // $data['ids'] = $ids; // 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' => '']; } else { $result = ['err' => 1001, 'msg' => '批量创建栏目失败', 'data' => []]; } } return Response::json($result); }