123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace app\api\controller;
- class Goodsclass extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- }
-
- public function index()
- {
- $goodsclass_model = model('goodsclass');
- $goods_class = $goodsclass_model->get_all_category();
- $goods_class = array_merge($goods_class);
- foreach ($goods_class as $key => $value) {
- $goods_class[$key]['id'] = $value['gc_id'];
- $goods_class[$key]['value'] = $value['gc_name'];
- if (isset($goods_class[$key]['class2'])) {
- $goods_class[$key]['children'] = array_merge($goods_class[$key]['class2']);
- } else {
- $goods_class[$key]['children'] = [];
- }
- foreach ($goods_class[$key]['children'] as $kk => $vv) {
- $goods_class[$key]['children'][$kk]['id'] = $vv['gc_id'];
- $goods_class[$key]['children'][$kk]['value'] = $vv['gc_name'];
- if (isset($goods_class[$key]['children'][$kk]['class3'])) {
- $goods_class[$key]['children'][$kk]['children'] = array_merge($goods_class[$key]['children'][$kk]['class3']);
- } else {
- $goods_class[$key]['children'][$kk]['children'] = [];
- }
- foreach ($goods_class[$key]['children'][$kk]['children'] as $k => $v) {
- $goods_class[$key]['children'][$kk]['children'][$k]['id'] = $v['gc_id'];
- $goods_class[$key]['children'][$kk]['children'][$k]['value'] = $v['gc_name'];
- $goods_class[$key]['children'][$kk]['children'][$k]['image'] = goodsclass_image($v['gc_image']);
- }
- }
- }
- $result['class_list'] = $goods_class;
- ds_json_encode(10000, '', $result);
- }
-
- private function _get_root_class()
- {
- $goodsclass_model = model('goodsclass');
- $goods_class_array = model('goodsclass')->getGoodsclassForCacheModel();
- $class_list = $goodsclass_model->getGoodsclassListByParentId(0);
- foreach ($class_list as $key => $value) {
- $class_list[$key]['text'] = '';
- if (isset($goods_class_array[$value['gc_id']]['child'])) {
- $child_class_string = $goods_class_array[$value['gc_id']]['child'];
- $child_class_array = explode(',', $child_class_string);
- foreach ($child_class_array as $child_class) {
- $class_list[$key]['text'] .= $goods_class_array[$child_class]['gc_name'] . '/';
- }
- }
- $class_list[$key]['text'] = rtrim($class_list[$key]['text'], '/');
- }
- ds_json_encode(10000, '', array('class_list' => $class_list));
- }
-
- private function _get_class_list($gc_id)
- {
- $goods_class_array = model('goodsclass')->getGoodsclassForCacheModel();
- $goods_class = $goods_class_array[$gc_id];
- if (empty($goods_class['child'])) {
-
- return array('class_list' => array());
- } else {
-
- $class_list = array();
- $child_class_string = $goods_class_array[$gc_id]['child'];
- $child_class_array = explode(',', $child_class_string);
- foreach ($child_class_array as $child_class) {
- $class_item = array();
- $class_item['gc_id'] = '';
- $class_item['gc_name'] = '';
- $class_item['gc_id'] .= $goods_class_array[$child_class]['gc_id'];
- $class_item['gc_name'] .= $goods_class_array[$child_class]['gc_name'];
- $class_item['image'] = ds_get_pic(ATTACH_COMMON, $goods_class_array[$child_class]['gc_image']);
- $class_list[] = $class_item;
- }
- return array('class_list' => $class_list);
- }
- }
-
- public function get_child_all()
- {
- $gc_id = intval(input('param.gc_id'));
- $data = array();
- if ($gc_id > 0) {
- $prefix = 'api-goodsclass-all-';
- $data = rcache($gc_id, $prefix);
- if (empty($data)) {
- $data = $this->_get_class_list($gc_id);
- if (!empty($data['class_list'])) {
- foreach ($data['class_list'] as $key => $val) {
- $d = $this->_get_class_list($val['gc_id']);
- $data['class_list'][$key]['child'] = $d['class_list'];
- }
- }
- wcache($gc_id, $data, $prefix, 3600);
- }
- }
- ds_json_encode(10000, '', $data);
- }
- }
|