Ejemplo n.º 1
0
 /**
  * 函数get_module_infos方法,获取分类文章列表数据.
  *
  * @param  查询参数集合
  *
  * @return $category_article 根据param,返回分类文章列表数组
  */
 public function get_module_infos($params)
 {
     $conditions = '';
     $limit = 10;
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $page = 1;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     $c_locale = 'chi';
     if (isset($params['locale'])) {
         $c_locale = $params['locale'];
     }
     $order = 'created';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     if (isset($params['id'])) {
         $conditions['Article.category_id'] = $params['id'];
     }
     if ($params['type'] == 'module_help_information') {
         $conditions['Article.type'] = 'H';
     }
     $conditions['Article.status'] = 1;
     $Article = ClassRegistry::init('Article');
     //分页start
     $total = $Article->find('count', array('conditions' => $conditions));
     App::import('Component', 'Paginationmodel');
     $pagination = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $parameters['route'] = array('controller' => 'articles', 'action' => 'category/' . $params['id'], 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => 'Article', 'total' => $total);
     //pr($conditions);die;
     $pages = $pagination->init($conditions, $parameters, $options);
     // Added
     //pr($pages);
     //分页end
     $category_article_infos = $Article->find('all', array('conditions' => $conditions, 'page' => $page, 'limit' => $limit, 'order' => 'Article.' . $order, 'fields' => 'Article.id,Article.category_id,Article.file,Article.created,ArticleI18n.img01,ArticleI18n.title,ArticleI18n.subtitle,ArticleI18n.content,ArticleI18n.meta_description'));
     //pr($category_article_infos);die;
     if (!empty($category_article_infos)) {
         //$reg = "/<[^>]+>(.*)<\/[^>]+>/";
         foreach ($article_infos as $k => $v) {
             $category_article_infos[$k]['ArticleI18n']['des_content'] = $this->cutstr($v['ArticleI18n']['meta_description'], 80);
         }
     }
     $CategoryArticle = ClassRegistry::init('CategoryArticle');
     $category_article['category_name'] = $CategoryArticle->get_articlecategory_name_by_id($params['id'], $c_locale);
     $category_article['category_detail'] = $CategoryArticle->get_articlecategory_detail_by_id($params['id'], $c_locale);
     $category_article['category_article'] = $category_article_infos;
     $category_article['paging'] = $pages;
     return $category_article;
 }
Ejemplo n.º 2
0
 /**
  * 函数get_module_infos 获取品牌列表信息.
  *
  * @param  参数集合
  *
  * @return $brand_infos 返回品牌列表信息
  */
 public function get_module_infos($params)
 {
     $conditions = '';
     $limit = 10;
     //pr($params);die;
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $page = 1;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     $order = 'created';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     $conditions['Brand.status'] = 1;
     //分页start
     $total = $this->find('count', array('conditions' => $conditions));
     App::import('Component', 'Paginationmodel');
     $pagination = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $parameters['route'] = array('controller' => 'brands', 'action' => 'index', 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => $this->name, 'total' => $total);
     //pr($conditions);die;
     $pages = $pagination->init($conditions, $parameters, $options);
     // Added
     //pr($pages);
     //分页end
     $brand_infos = $this->find('all', array('conditions' => $conditions, 'limit' => $limit, 'order' => 'Brand.' . $order, 'fields' => array('Brand.id', 'BrandI18n.name', 'BrandI18n.img01'), 'page' => $page));
     $brand_infos['brand'] = $brand_infos;
     $brand_infos['paging'] = $pages;
     return $brand_infos;
 }
Ejemplo n.º 3
0
 public function get_products_lists($params)
 {
     $products_list = array();
     $page = 1;
     $limit = 10;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $order = 'Product.online_time';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     $order .= ' desc';
     $conditions = '';
     if (isset($params['category_id'])) {
         $conditions['Product.category_id'] = $params['category_id'];
     }
     $conditions['Product.status'] = '1';
     $conditions['Product.forsale'] = '1';
     //分页start
     $total = $this->find('count', array('conditions' => $conditions));
     App::import('Component', 'Paginationmodel');
     $pagM = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $parameters['route'] = array('controller' => 'products', 'action' => 'index', 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => $this->name, 'total' => $total);
     //pr($conditions);die;
     $pages = $pagM->init($conditions, $parameters, $options);
     // Added
     //pr($pages);
     //分页end
     $products_list = $this->find('all', array('conditions' => $conditions, 'order' => $order, 'page' => $page, 'limit' => $limit));
     $product['products_list'] = $products_list;
     $product['paging'] = $pages;
     return $product;
 }
Ejemplo n.º 4
0
 public function get_module_category_product($params)
 {
     $conditions = '';
     $limit = 10;
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $order = 'orderby';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     $id = 0;
     if (isset($params['id'])) {
         $id = $params['id'];
     }
     $page = 1;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     //查询当前分类设置的显示产品(新品,推荐,销量),判断赋值给sale和price
     $cond = $this->find('first', array('conditions' => array('CategoryProduct.id' => $id), 'fields' => 'CategoryProduct.show_info'));
     $sale = false;
     $new_arrival = false;
     $recommend = false;
     $price = false;
     $sub_category_goods = false;
     //子分类商品
     if (sizeof($cond) > 0) {
         $show_arr = explode(';', $cond['CategoryProduct']['show_info']);
         //字符串分割成数组
         foreach ($show_arr as $sk => $sv) {
             if ($sv == 'new_arrival') {
                 $new_arrival = true;
             } elseif ($sv == 'recommend') {
                 $recommend = true;
             } elseif ($sv == 'selling') {
                 $sale = true;
             } elseif ($sv == 'sub_categories_product') {
                 $sub_category_goods = true;
             }
         }
     }
     $ProductsCategory = ClassRegistry::init('ProductsCategory');
     //echo "1.".$sale."2.".$recommend."3.".$new_arrival;die;
     //分类筛选
     $pro_tab_cond['category_id'] = $this->allinfo['P']['subids'][$id];
     if (isset($params['min_price']) && $params['min_price'] != -1) {
         $pro_tab_cond['shop_price >='] = $params['min_price'];
     }
     if (isset($params['max_price']) && $params['max_price'] != -1) {
         $pro_tab_cond['shop_price <='] = $params['max_price'];
     }
     if (isset($params['ControllerObj'])) {
         $pro_tab_cond['ControllerObj'] = $params['ControllerObj'];
     }
     $Brand = ClassRegistry::init('Brand');
     $brand_info = $Brand->find('all', array('fields' => array('Brand.id', 'BrandI18n.name'), 'conditions' => array("Brand.status" => '1')));
     $branddata = array();
     foreach ($brand_info as $v) {
         $branddata[$v['Brand']['id']] = $v['BrandI18n']['name'];
     }
     $Product = ClassRegistry::init('Product');
     $category_product['product'] = $Product->products_tab($pro_tab_cond, $sale, $price, $recommend, $new_arrival);
     //查找子分类
     $category_product['sub_categories_product'] = array();
     if ($sub_category_goods) {
         $cate_limt = 15;
         if (isset($params['ControllerObj'])) {
             if (isset($params['ControllerObj']->configs['products_category_page_size'])) {
                 $cate_limit = $params['ControllerObj']->configs['products_category_page_size'];
             }
         }
         $sub_cate_ids = $this->find('all', array('conditions' => array('CategoryProduct.parent_id' => $id), 'fields' => 'CategoryProduct.id,CategoryProductI18n.name'));
         //循环查找每个子分类的商品
         $p_fields = array('Product.id', 'Product.brand_id', 'Product.recommand_flag', 'Product.status', 'Product.img_thumb', 'Product.img_detail', 'Product.img_original', 'Product.product_image1', 'Product.product_image2', 'Product.market_price', 'Product.shop_price', 'Product.category_id', 'Product.promotion_price', 'Product.promotion_start', 'Product.promotion_end', 'Product.promotion_status', 'Product.code', 'Product.product_rank_id', 'Product.quantity', 'Product.freeshopping', 'ProductI18n.name', 'ProductI18n.description', 'ProductI18n.description02', 'Product.unit');
         foreach ($sub_cate_ids as $sid_k => $sid_v) {
             $ProductsCategory_pro_ids = $ProductsCategory->find('list', array('fields' => 'ProductsCategory.product_id', 'conditions' => array('ProductsCategory.category_id' => $sid_v['CategoryProduct']['id'])));
             $p_cond['OR']['Product.category_id'] = $sid_v['CategoryProduct']['id'];
             $p_cond['OR']['Product.id'] = $ProductsCategory_pro_ids;
             $p_cond['Product.status'] = 1;
             $p_cond['Product.forsale'] = 1;
             $p_cond['Product.alone'] = 1;
             if (isset($params['min_price']) && $params['min_price'] != -1) {
                 $p_cond['Product.shop_price >='] = $params['min_price'];
             }
             if (isset($params['max_price']) && $params['max_price'] != -1) {
                 $p_cond['Product.shop_price <='] = $params['max_price'];
             }
             $Product->hasMany = array();
             $p_arr = $Product->find('all', array('conditions' => $p_cond, 'fields' => $p_fields, 'limit' => $cate_limit));
             if (!empty($p_arr)) {
                 foreach ($p_arr as $k => $v) {
                     $p_arr[$k]['Brand'] = isset($branddata[$v['Product']['brand_id']]) ? $branddata[$v['Product']['brand_id']] : '';
                 }
                 $sub_category_goods_list[$sid_v['CategoryProductI18n']['name']] = $p_arr;
             }
         }
         $category_product['sub_categories_product'] = $sub_category_goods_list;
     }
     $cate_grade = 'bottom';
     if (!empty($this->allinfo['P']['direct_subids'][$id])) {
         if (!empty($this->allinfo['P']['assoc'][$id]['CategoryProduct']['parent_id'])) {
             //中间层分类
             $cate_grade = 'middle';
         } else {
             //最顶层分类
             $cate_grade = 'top';
         }
     } else {
         //最底层分类
         $cate_grade = 'bottom';
     }
     if (isset($params['ControllerObj']) && $cate_grade == 'top') {
         if (isset($params['ControllerObj']->configs['show_brand_by_category']) && $params['ControllerObj']->configs['show_brand_by_category'] == '1') {
             $brand_data = $Brand->get_brand_by_category($id);
             $category_product['brand'] = $brand_data;
         }
     }
     $category_ids = array();
     $category_ids[] = $id;
     $category_child_ids = $this->find('list', array('conditions' => array('CategoryProduct.parent_id' => $id), 'fields' => "CategoryProduct.id"));
     if (!empty($category_child_ids)) {
         $category_ids = array_merge($category_ids, $category_child_ids);
         $category_sub_ids = $this->find('list', array('conditions' => array('CategoryProduct.parent_id' => $category_child_ids), 'fields' => "CategoryProduct.id"));
         if (!empty($category_sub_ids)) {
             $category_ids = array_merge($category_ids, $category_sub_ids);
         }
     }
     $bottom_pro_cond = array();
     $bottom_pro_ids = $ProductsCategory->find('list', array('fields' => 'ProductsCategory.product_id', 'conditions' => array('ProductsCategory.category_id' => $category_ids)));
     $bottom_pro_cond['and']['or']['Product.category_id'] = $category_ids;
     $bottom_pro_cond['and']['or']['Product.id'] = $bottom_pro_ids;
     $bottom_pro_cond['and']['Product.status'] = 1;
     $bottom_pro_cond['and']['Product.forsale'] = 1;
     $bottom_pro_cond['and']['Product.alone'] = 1;
     if (isset($params['min_price']) && $params['min_price'] != -1) {
         $bottom_pro_cond['Product.shop_price >='] = $params['min_price'];
     }
     if (isset($params['max_price']) && $params['max_price'] != -1) {
         $bottom_pro_cond['Product.shop_price <='] = $params['max_price'];
     }
     //三级分类的产品
     //分页start
     $total = $Product->find('count', array('conditions' => $bottom_pro_cond));
     App::import('Component', 'Paginationmodel');
     $pagination = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $page_action = isset($params['ControllerObj']->action) ? $params['ControllerObj']->action : "";
     $parameters['route'] = array('controller' => 'categories', 'action' => $page_action . "/" . $id, 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => 'Product', 'total' => $total);
     $pages = $pagination->init($conditions, $parameters, $options);
     // Added
     //分页end
     $category_product['bottom'] = $Product->find('all', array('conditions' => $bottom_pro_cond, 'fields' => 'Product.id,Product.category_id,Product.brand_id,Product.shop_price,Product.img_thumb,Product.img_detail,Product.img_original,Product.product_image1,Product.product_image2,Product.code,ProductI18n.name,Product.like_stat, ProductI18n.description,ProductI18n.description02,Product.unit', 'limit' => $limit, 'page' => $page));
     if (!empty($category_product['bottom']) && sizeof($category_product['bottom']) > 0) {
         $product_ids = $Product->getproduct_ids($category_product['bottom']);
         $product_codes = $Product->getproduct_codes($category_product['bottom']);
         $comment = ClassRegistry::init('Comment');
         $user_like = ClassRegistry::init('UserLike');
         $user_favorite = ClassRegistry::init('UserFavorite');
         $SkuProduct = ClassRegistry::init('SkuProduct');
         $price_range = $SkuProduct->sku_price_range($product_codes);
         $comment_num = $comment->find('all', array('conditions' => array('Comment.type_id' => $product_ids, 'Comment.type' => 'P'), 'fields' => array('Comment.type_id', 'count(Comment.type_id) as Commentnum'), 'group' => 'Comment.type_id'));
         $like_num = $user_like->find('all', array('conditions' => array('UserLike.type' => 'P', 'UserLike.type_id' => $product_ids), 'fields' => array('UserLike.type', 'count(UserLike.type_id) as num'), 'group' => 'UserLike.type_id'));
         $UserLike_data = array();
         $UserFavorite_data = array();
         if (isset($_SESSION['User']) && !empty($product_ids)) {
             $user_id = $_SESSION['User']['User']['id'];
             $UserLike_data = $user_like->find('list', array('fields' => 'type_id,id', 'conditions' => array('UserLike.user_id' => $user_id, 'UserLike.action' => 'like', 'UserLike.type' => 'P', 'UserLike.type_id' => $product_ids)));
             $UserFavorite_data = $user_favorite->find('list', array('fields' => 'type_id,id', 'conditions' => array('UserFavorite.user_id' => $user_id, 'UserFavorite.status' => '1', 'UserFavorite.type' => 'P', 'UserFavorite.type_id' => $product_ids)));
         }
         foreach ($category_product['bottom'] as $k => $v) {
             foreach ($like_num as $like_k => $like_v) {
                 if ($v['Product']['id'] == $like_v['UserLike']['type']) {
                     $category_product['bottom'][$k]['Product']['like_num'] = $like_v[0]['num'];
                 }
             }
             foreach ($comment_num as $com_k => $com_v) {
                 if ($v['Product']['id'] == $com_v['Comment']['type_id']) {
                     $category_product['bottom'][$k]['Product']['Commentnum'] = $com_v[0]['Commentnum'];
                 }
             }
             if (isset($price_range[$v['Product']['code']])) {
                 $category_product['bottom'][$k]['price_range'] = $price_range[$v['Product']['code']];
             }
             $category_product['bottom'][$k]['UserLike'] = isset($UserLike_data[$v['Product']['id']]) ? '1' : '0';
             $category_product['bottom'][$k]['UserFavorite'] = isset($UserFavorite_data[$v['Product']['id']]) ? '1' : '0';
             $category_product['bottom'][$k]['Brand'] = isset($branddata[$v['Product']['brand_id']]) ? $branddata[$v['Product']['brand_id']] : '';
         }
     }
     $category_product['paging'] = $pages;
     $category_product['cate_grade'] = $cate_grade;
     return $category_product;
 }
Ejemplo n.º 5
0
 public function get_module_infos($params)
 {
     $conditions['Topic.status'] = 1;
     $limit = 10;
     $page = 1;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $order = 'orderby,Topic.created';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     if (isset($params['type_id'])) {
         $conditions['Topic.category_id'] = $params['type_id'];
     }
     if (isset($params['start_time'])) {
         $conditions['Topic.start_time <='] = $params['start_time'];
     }
     if (isset($params['end_time'])) {
         $conditions['Topic.end_time >='] = $params['end_time'];
     }
     //分页start
     $total = $this->find('count', array('conditions' => $conditions));
     App::import('Component', 'Paginationmodel');
     $pagM = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $parameters['route'] = array('controller' => 'topics', 'action' => 'index', 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => $this->name, 'total' => $total);
     //pr($conditions);die;
     $pages = $pagM->init($conditions, $parameters, $options);
     // Added
     //pr($pages);
     //分页end
     $module_topic_infos = $this->find('all', array('conditions' => $conditions, 'limit' => $limit, 'order' => 'Topic.' . $order, 'page' => $page));
     $module_topic['topic'] = $module_topic_infos;
     $module_topic['paging'] = $pages;
     return $module_topic;
 }
Ejemplo n.º 6
0
 public function get_article_lists($params)
 {
     $conditions = '';
     $limit = 10;
     if (isset($params['limit'])) {
         $limit = $params['limit'];
     }
     $order = 'created desc';
     if (isset($params['order'])) {
         $order = $params['order'];
     }
     $page = 1;
     if (isset($params['page'])) {
         $page = $params['page'];
     }
     if (isset($params['id'])) {
         $conditions['Article.category_id'] = $params['id'];
     }
     $conditions['Article.status'] = '1';
     //分页start
     $total = $this->find('count', array('conditions' => $conditions));
     App::import('Component', 'Paginationmodel');
     $pagM = new PaginationModelComponent();
     //get参数
     $parameters['get'] = array();
     //地址路由参数(和control,action的参数对应)
     $parameters['route'] = array('controller' => 'articles', 'action' => 'category', 'page' => $page, 'limit' => $limit);
     //分页参数
     $options = array('page' => $page, 'show' => $limit, 'modelClass' => $this->name, 'total' => $total);
     //pr($conditions);die;
     $pages = $pagM->init($conditions, $parameters, $options);
     // Added
     //pr($pages);
     //分页end
     $article_lists = $this->find('all', array('fields' => array('Article.id', 'Article.created', 'ArticleI18n.title', 'ArticleI18n.subtitle', 'ArticleI18n.content', 'ArticleI18n.author', 'ArticleI18n.img01', 'ArticleI18n.meta_description'), 'conditions' => $conditions, 'order' => $order, 'page' => $page, 'limit' => $limit));
     $article_infos['article_list'] = $article_lists;
     $article_infos['paging'] = $pages;
     return $article_infos;
 }