Ejemplo n.º 1
0
 function get_list_cid($id, $count = 10, $orderby = "post_desc")
 {
     if (!$id) {
         return false;
     }
     //读取当前分类信息
     $sql = "SELECT c.* FROM " . $this->db->prefix . "cate c ";
     $sql .= "WHERE c.id='" . $id . "'";
     $c_rs = $this->db->get_one($sql);
     if (!$c_rs || !$c_rs["status"]) {
         return false;
     }
     //取得模块信息
     $m_rs = $this->get_one_module_cate($id);
     if (!$m_rs) {
         return false;
     }
     if (!$this->thumbtype) {
         $thumbtype = $c_rs["inpic"] ? $c_rs["inpic"] : $m_rs["inpic"];
         //是否同时加载指定的缩略图
     } else {
         $thumbtype = $this->thumbtype;
     }
     $count = intval($count) < 1 ? 10 : intval($count);
     if ($orderby == "rand") {
         $cate_list = explode(",", $id);
         foreach ($cate_list as $key => $value) {
             sys_son_cateid($cate_list, $value);
             //取得子分类信息
         }
         $cate_in = implode(",", $cate_list);
         $idlist = array();
         for ($i = 0; $i < $count; $i++) {
             $tid = $this->get_rand_id($cate_in, "cate_id");
             if (!$tid) {
                 return false;
             }
             $idlist[] = $tid;
         }
         if (count($idlist) < 1) {
             return false;
         }
         $idin = implode(",", $idlist);
         if ($thumbtype) {
             $sql = "SELECT l.*,g.filename picture FROM " . $this->db->prefix . "list l LEFT JOIN " . $this->db->prefix . "upfiles_gd g ON(l.thumb_id=g.pid AND g.gdtype='" . $thumbtype . "') ";
         } else {
             $sql = "SELECT l.*,g.filename picture FROM " . $this->db->prefix . "list l LEFT JOIN " . $this->db->prefix . "upfiles g ON(l.thumb_id=g.id) ";
         }
         $sql .= " WHERE l.id IN(" . $idin . ") AND l.langid='" . $this->langid . "' ORDER BY substring_index('" . $idin . "',l.id,1)";
         $rslist = $this->db->get_all($sql);
         if (!$rslist) {
             return false;
         }
     } else {
         $order_by = $this->order_by($orderby);
         $cate_list = array($id);
         sys_son_cateid($cate_list, $id);
         //取得子分类信息
         $cate_in = implode(",", $cate_list);
         if ($thumbtype) {
             $sql = "SELECT l.*,g.filename picture FROM " . $this->db->prefix . "list l LEFT JOIN " . $this->db->prefix . "upfiles_gd g ON(l.thumb_id=g.pid AND g.gdtype='" . $thumbtype . "') ";
         } else {
             $sql = "SELECT l.*,g.filename picture FROM " . $this->db->prefix . "list l LEFT JOIN " . $this->db->prefix . "upfiles g ON(l.thumb_id=g.id) ";
         }
         $sql .= " WHERE l.status='1' AND l.langid='" . $this->langid . "' ";
         if ($this->phpok_rs["pic_required"]) {
             $sql .= " AND l.thumb_id>0 ";
         }
         if ($this->phpok_rs["attr"]) {
             $sql .= " AND l." . $this->phpok_rs["attr"] . ">0 ";
         }
         $sql .= " AND l.cate_id IN(" . $cate_in . ") ORDER BY " . $order_by;
         $sql .= " LIMIT " . $count;
         $rslist = $this->db->get_all($sql);
         if (!$rslist || !is_array($rslist) || count($rslist) < 1) {
             return false;
         }
         $idlist = array();
         foreach ($rslist as $key => $value) {
             $idlist[] = $value["id"];
         }
         $idin = implode(",", $idlist);
     }
     //判断是否有启用电子商务,如果启用,获取相关数据
     if ($m_rs["if_biz"]) {
         $sql = "SELECT * FROM " . $this->db->prefix . "list_biz WHERE id IN(" . $idin . ") ORDER BY substring_index('" . $idin . "',id,1)";
         $biz_list = $this->db->get_all($sql, "id");
         if ($biz_list && is_array($biz_list) && count($biz_list) > 0) {
             foreach ($rslist as $key => $value) {
                 $vid = $value["id"];
                 if ($biz_list[$vid]) {
                     $rslist[$key] = array_merge($value, $biz_list[$vid]);
                     //合并数据
                 }
             }
             unset($biz_list);
         }
     }
     //获取扩展数据
     $sql = "SELECT * FROM " . $this->db->prefix . "list_ext WHERE id IN(" . $idin . ")";
     $ext_list = $this->db->get_all($sql);
     if ($ext_list && is_array($ext_list) && count($ext_list) > 0) {
         $e_list = array();
         foreach ($ext_list as $key => $value) {
             $e_list[$value["id"]][$value["field"]] = $value["val"];
         }
         foreach ($rslist as $key => $value) {
             $vid = $value["id"];
             if ($e_list[$vid]) {
                 $rslist[$key] = array_merge($value, $e_list[$vid]);
             }
         }
     }
     //获取扩展内容数据
     unset($ext_list);
     $sql = "SELECT * FROM " . $this->db->prefix . "list_c WHERE id IN(" . $idin . ")";
     $ext_list = $this->db->get_all($sql);
     if ($ext_list && is_array($ext_list) && count($ext_list) > 0) {
         $e_list = array();
         foreach ($ext_list as $key => $value) {
             $e_list[$value["id"]][$value["field"]] = $value["val"];
         }
         foreach ($rslist as $key => $value) {
             $vid = $value["id"];
             if ($e_list[$vid]) {
                 $rslist[$key] = array_merge($value, $e_list[$vid]);
             }
         }
     }
     return array("me" => $c_rs, "rslist" => $rslist);
 }
Ejemplo n.º 2
0
 function sys_son_cateid(&$cate_array, $id = 0)
 {
     $sys_app = sys_init();
     $sys_app->load_model("category_model", true);
     $sys_app->category_model->langid($_SESSION["sys_lang_id"]);
     $rslist = $sys_app->category_model->get_son_cateid($id);
     if ($rslist && is_array($rslist) && count($rslist)) {
         foreach ($rslist as $key => $value) {
             $cate_array[] = $value["id"];
             sys_son_cateid($cate_array, $value["id"]);
         }
     }
 }