goods_class.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * 商品分类
  4. *
  5. *
  6. *
  7. */
  8. //use Shopnc\Tpl;
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class goods_classControl extends mobileHomeControl
  11. {
  12. public function __construct() {
  13. parent::__construct();
  14. }
  15. public function indexOp() {
  16. if(!empty($_GET['gc_id']) && intval($_GET['gc_id']) > 0) {
  17. $this->_get_class_list($_GET['gc_id']);
  18. } else {
  19. $this->_get_root_class();
  20. }
  21. }
  22. /**
  23. * 返回一级分类列表
  24. */
  25. private function _get_root_class() {
  26. $model_goods_class = Model('goods_class');
  27. $model_mb_category = Model('mb_category');
  28. $goods_class_array = Model('goods_class')->getGoodsClassForCacheModel();
  29. $class_list = $model_goods_class->getGoodsClassListByParentId(0);
  30. $mb_categroy = $model_mb_category->getLinkList(array());
  31. $mb_categroy = array_under_reset($mb_categroy, 'gc_id');
  32. foreach ($class_list as $key => $value) {
  33. if(!empty($mb_categroy[$value['gc_id']])) {
  34. $class_list[$key]['image'] = UPLOAD_SITE_URL.DS.ATTACH_MOBILE.DS.'category'.DS.$mb_categroy[$value['gc_id']]['gc_thumb'];
  35. } else {
  36. $class_list[$key]['image'] = '';
  37. }
  38. $class_list[$key]['text'] = '';
  39. $child_class_string = $goods_class_array[$value['gc_id']]['child'];
  40. $child_class_array = explode(',', $child_class_string);
  41. foreach ($child_class_array as $child_class) {
  42. $class_list[$key]['text'] .= $goods_class_array[$child_class]['gc_name'] . '/';
  43. }
  44. $class_list[$key]['text'] = rtrim($class_list[$key]['text'], '/');
  45. }
  46. output_data(array('class_list' => $class_list));
  47. }
  48. /**
  49. * 根据分类编号返回下级分类列表
  50. */
  51. private function _get_class_list($gc_id) {
  52. $goods_class_array = Model('goods_class')->getGoodsClassForCacheModel();
  53. $goods_class = $goods_class_array[$gc_id];
  54. if(empty($goods_class['child'])) {
  55. //无下级分类返回0
  56. output_data(array('class_list' => '0'));
  57. } else {
  58. //返回下级分类列表
  59. $class_list = array();
  60. $child_class_string = $goods_class_array[$gc_id]['child'];
  61. $child_class_array = explode(',', $child_class_string);
  62. foreach ($child_class_array as $child_class) {
  63. $class_item = array();
  64. $class_item['gc_id'] .= $goods_class_array[$child_class]['gc_id'];
  65. $class_item['gc_name'] .= $goods_class_array[$child_class]['gc_name'];
  66. $class_list[] = $class_item;
  67. }
  68. output_data(array('class_list' => $class_list));
  69. }
  70. }
  71. }