Esempio n. 1
0
 /**
  * 
  * @param type $c_id
  * @param type $is_star
  * @param type $per_page
  * @param type $search_word ===搜索关键字===
  * @return type
  */
 public function articleListData($c_id = 0, $is_star = 0, $per_page = 15, $search_word = '')
 {
     $cus_id = Auth::id();
     if (!empty($search_word)) {
         if ($c_id) {
             $cus_data = new PrintController();
             $c_ids = explode(',', $cus_data->getChirldenCid($c_id));
             if ($is_star) {
                 $article_list = Articles::whereIn('c_id', $c_ids)->where('title', 'like', '%' . $search_word . '%')->where('is_star', '=', $is_star)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             } else {
                 $article_list = Articles::whereIn('c_id', $c_ids)->where('title', 'like', '%' . $search_word . '%')->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             }
         } else {
             if ($is_star) {
                 $article_list = Articles::where('cus_id', '=', $cus_id)->where('title', 'like', '%' . $search_word . '%')->where('is_star', '=', $is_star)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             } else {
                 $article_list = Articles::where('cus_id', '=', $cus_id)->where('title', 'like', '%' . $search_word . '%')->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             }
         }
     } else {
         if ($c_id) {
             $cus_data = new PrintController();
             $c_ids = explode(',', $cus_data->getChirldenCid($c_id));
             if ($is_star) {
                 $article_list = Articles::whereIn('c_id', $c_ids)->where('is_star', '=', $is_star)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             } else {
                 $article_list = Articles::whereIn('c_id', $c_ids)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             }
         } else {
             if ($is_star) {
                 $article_list = Articles::where('cus_id', '=', $cus_id)->where('is_star', '=', $is_star)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             } else {
                 $article_list = Articles::where('cus_id', '=', $cus_id)->orderBy('is_top', 'DESC')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->paginate($per_page);
             }
         }
     }
     $article_arr = $article_list->toArray();
     if (count($article_arr['data'])) {
         foreach ($article_arr['data'] as $k => $v) {
             $moring = [];
             $article_arr['data'][$k]['c_name'] = Classify::where('id', $v['c_id'])->pluck('name');
             $moring = Moreimg::where('a_id', $v['id'])->orderBy('sort')->lists('img');
             array_unshift($moring, $v['img']);
             $article_arr['data'][$k]['img'] = $moring;
             unset($moring);
         }
         return $article_arr;
     }
 }
Esempio n. 2
0
 /**
  * 根据从数据库查询的栏目数据数组,转为树形结构的数组
  * 
  * @param array $arr 栏目数据数组
  * @param int $pid  起始栏目id
  * @param bool $isNav 是否是顶级导航(顶级导航会显示下面的几篇文章)
  * @return array 树形结构的数组
  */
 private function toTree($arr, $pid = 0, $isNav = FALSE)
 {
     $tree = array();
     foreach ((array) $arr as $k => $v) {
         if ($v['p_id'] == $pid) {
             $v['image'] = $v['img'] ? $this->source_dir . 'l/category/' . $v['img'] : '';
             $v['icon'] = '<i class="iconfont">' . $v['icon'] . '</i>';
             unset($v['img']);
             $tree[] = $v;
         }
     }
     if (empty($tree)) {
         return null;
     }
     foreach ((array) $tree as $k => $v) {
         $data = [];
         if ($v['type'] != 6) {
             if (empty($v['view_name'])) {
                 $tree[$k]['link'] = $this->showtype == 'preview' ? $this->domain . '/category/' . $v['id'] : $this->domain . '/category/' . $v['id'] . '.html';
             } else {
                 $tree[$k]['link'] = $this->showtype == 'preview' ? $this->domain . '/category/v/' . $v['view_name'] : $this->domain . '/category/v/' . $v['view_name'] . '.html';
             }
             if ($isNav == TRUE) {
                 $cids = explode(',', $this->getChirldenCid($v['id'], 1));
                 //取得所有栏目id
                 if ($this->type == 'mobile') {
                     $articles = Articles::whereIn('c_id', $cids)->where('mobile_show', '1')->where('cus_id', $this->cus_id)->select('id', 'c_id', 'title', 'img', 'introduction', 'created_at')->take(20)->get();
                 } else {
                     $articles = Articles::whereIn('c_id', $cids)->where('pc_show', '1')->where('cus_id', $this->cus_id)->select('id', 'c_id', 'title', 'img', 'introduction', 'created_at')->take(20)->get();
                 }
                 if (!empty($articles)) {
                     $abc = [];
                     foreach ((array) $articles as $key => $d) {
                         $data[$key]['title'] = $d->title;
                         $classify = Classify::where('id', $d->c_id)->first();
                         if (empty($classify->view_name)) {
                             $data[$key]['category']['link'] = $this->showtype == 'preview' ? $this->domain . '/category/' . $d->c_id : $this->domain . '/category/' . $d->c_id . '.html';
                         } else {
                             $data[$key]['category']['link'] = $this->showtype == 'preview' ? $this->domain . '/category/v/' . $classify->view_name : $this->domain . '/category/v/' . $classify->view_name . '.html';
                         }
                         $data[$key]['image'] = $d->img ? $this->source_dir . 's/articles/' . $d->img : '';
                         $data[$key]['link'] = $this->showtype == 'preview' ? $this->domain . '/detail/' . $d->id : $this->domain . '/detail/' . $d->id . '.html';
                         $data[$key]['category']['name'] = $classify->name;
                         $data[$key]['category']['en_name'] = $classify->en_name;
                         $data[$key]['category']['icon'] = '<i class="iconfont">' . $classify->icon . '</i>';
                         $data[$key]['description'] = $d->introduction;
                         $data[$key]['pubdate'] = (string) $d->created_at;
                         $data[$key]['pubtimestamp'] = strtotime($d->created_at);
                         unset($v['value']);
                     }
                     $tree[$k]['data'] = $data;
                 } else {
                     $tree[$k]['data'] = [];
                 }
             }
         } else {
             if ($v['open_page'] == 1) {
                 $tree[$k]['link'] = strpos($v['url'], 'http') === false ? 'http://' . $v['url'] : $v['url'];
             } else {
                 $tree[$k]['link'] = strpos($v['url'], 'http') === false ? 'http://' . $v['url'] . '"target="_blank' : $v['url'] . '"target="_blank';
             }
         }
         $tree[$k]['current'] = 0;
         $tree[$k]['selected'] = 0;
         $tree[$k]['childmenu'] = $this->toTree($arr, $v['id']);
     }
     return $tree;
 }
Esempio n. 3
0
 /**
  * 计算生成html文件的数量
  * 
  * @param array $pc_classify_ids  pc栏目id
  * @param array $mobile_classify_ids 手机栏目id
  * @param array $pc_article_ids  pc文章id
  * @param array $mobile_article_ids 手机文章id
  * @return int
  */
 private function htmlPagecount($pc_classify_ids = [], $mobile_classify_ids = [], $pc_article_ids = [], $mobile_article_ids = [])
 {
     $template = new PrintController();
     $page_count = 2;
     $pc_per_page = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_count');
     foreach ($pc_classify_ids as $id) {
         $c_ids = explode(',', $template->getChirldenCid($id));
         $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('pc_show', '1')->count();
         if ($total) {
             $page_count += ceil($total / $pc_per_page);
         } else {
             $page_count++;
         }
     }
     $mobileper_page = CustomerInfo::where('cus_id', $this->cus_id)->pluck('mobile_page_count');
     foreach ($pc_classify_ids as $id) {
         $c_ids = explode(',', $template->getChirldenCid($id));
         $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('mobile_show', '1')->count();
         if ($total) {
             $page_count += ceil($total / $mobileper_page);
         } else {
             $page_count++;
         }
     }
     $page_count += count($pc_article_ids);
     $page_count += count($mobile_article_ids);
     return $page_count;
 }
Esempio n. 4
0
 /**
  * 计算生成html文件的数量
  * 
  * @param array $pc_classify_ids  pc栏目id
  * @param array $mobile_classify_ids 手机栏目id
  * @param array $pc_article_ids  pc文章id
  * @param array $mobile_article_ids 手机文章id
  * @return int
  */
 private function htmlPagecount($pc_classify_ids = [], $mobile_classify_ids = [], $pc_article_ids = [], $mobile_article_ids = [])
 {
     $template = new PrintController();
     $page_count = 2;
     $pc_per_page = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_count');
     foreach ((array) $pc_classify_ids as $id) {
         $c_ids = explode(',', ltrim($template->getChirldenCid($id, 1)));
         $a_c_type = Classify::where('id', $id)->pluck('type');
         //取得栏目的type
         $pc_page_count_switch = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_count_switch');
         //页面图文列表图文显示个数是否分开控制开关
         if (isset($pc_page_count_switch) && $pc_page_count_switch == 1 && $a_c_type <= 3) {
             if ($a_c_type == 1) {
                 $page_number = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_txt_count');
                 //每页文字显示个数
                 $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('pc_show', '1')->count();
                 if ($total) {
                     $page_count += ceil($total / $page_number) + 1;
                 } else {
                     $page_count += 2;
                 }
             }
             if ($a_c_type == 3) {
                 $page_number = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_imgtxt_count');
                 //每页图文显示个数
                 $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('pc_show', '1')->count();
                 if ($total) {
                     $page_count += ceil($total / $page_number) + 1;
                 } else {
                     $page_count += 2;
                 }
             }
             if ($a_c_type == 2) {
                 $page_number = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_page_img_count');
                 //每页图片显示个数
                 $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('pc_show', '1')->count();
                 if ($total) {
                     $page_count += ceil($total / $page_number) + 1;
                 } else {
                     $page_count += 2;
                 }
             }
         } else {
             $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('pc_show', '1')->count();
             if ($total) {
                 $page_count += ceil($total / $pc_per_page) + 1;
             } else {
                 $page_count += 2;
             }
         }
     }
     $mobileper_page = CustomerInfo::where('cus_id', $this->cus_id)->pluck('mobile_page_count');
     if (!empty($mobile_classify_ids)) {
         foreach ((array) $mobile_classify_ids as $id) {
             $c_ids = explode(',', $template->getChirldenCid($id, 1));
             $total = Articles::whereIn('c_id', $c_ids)->where('cus_id', $this->cus_id)->where('mobile_show', '1')->count();
             if ($total) {
                 $page_count += ceil($total / $mobileper_page);
             } else {
                 $page_count++;
             }
         }
     }
     $page_count += count($pc_article_ids);
     $page_count += count($mobile_article_ids);
     return $page_count;
 }