123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 品牌控制器
- */
- class Brand extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/brand.lang.php');
- }
- /**
- * @api {POST} api/Brand/get_list 品牌列表
- * @apiVersion 1.0.0
- * @apiGroup Brand
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object} result.brand_class 品牌分类列表,键为品牌分类ID
- * @apiSuccess {Object} result.brand_class.brand_class 品牌分类名称
- * @apiSuccess {Object[]} result.brand_r 推荐品牌列表
- * @apiSuccess {Int} result.brand_r.brand_apply 品牌申请,0为申请中,1为通过
- * @apiSuccess {String} result.brand_r.brand_class 品牌分类名称
- * @apiSuccess {Int} result.brand_r.brand_id 品牌ID
- * @apiSuccess {String} result.brand_r.brand_initial 品牌首字母
- * @apiSuccess {String} result.brand_r.brand_name 品牌名称
- * @apiSuccess {String} result.brand_r.brand_pic 品牌图标
- * @apiSuccess {Int} result.brand_r.brand_recommend 品牌推荐,0为否,1为是
- * @apiSuccess {Int} result.brand_r.brand_showtype 品牌展示类型 0表示图片 1表示文字
- * @apiSuccess {Int} result.brand_r.brand_sort 品牌排序
- * @apiSuccess {Int} result.brand_r.gc_id 品牌分类ID
- * @apiSuccess {Int} result.brand_r.store_id 品牌申请店铺ID
- * @apiSuccess {Object} result.brand_c 品牌列表,按品牌分类ID分组,键为品牌分类ID
- * @apiSuccess {Int} result.brand_c.brand_apply 品牌申请,0为申请中,1为通过
- * @apiSuccess {String} result.brand_c.brand_class 品牌分类名称
- * @apiSuccess {Int} result.brand_c.brand_id 品牌ID
- * @apiSuccess {String} result.brand_c.brand_initial 品牌首字母
- * @apiSuccess {String} result.brand_c.brand_name 品牌名称
- * @apiSuccess {String} result.brand_c.brand_pic 品牌图标
- * @apiSuccess {Int} result.brand_c.brand_recommend 品牌推荐,0为否,1为是
- * @apiSuccess {Int} result.brand_c.brand_showtype 品牌展示类型 0表示图片 1表示文字
- * @apiSuccess {Int} result.brand_c.brand_sort 品牌排序
- * @apiSuccess {Int} result.brand_c.gc_id 品牌分类ID
- * @apiSuccess {Int} result.brand_c.store_id 品牌申请店铺ID
- */
- public function get_list()
- {
- $brand_mod = model('brand');
- $brand_c_list = $brand_mod->getBrandList(array('brand_apply' => '1'));
- $brands = $this->_tidyBrand($brand_c_list);
- extract($brands);
- ds_json_encode(10000, '', array('brand_l' => $brand_listchar, 'brand_c' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r' => $brand_r_list));
- }
- /**
- * 所有品牌全部显示在一级类目下,不显示二三级类目
- * @param type $brand_c_list
- * @return type
- */
- private function _tidyBrand($brand_c_list)
- {
- $brand_listnew = array(); #品牌分类下对应的品牌
- $brand_listchar = array(); #品牌首字母下对应的品牌
- $brand_class = array(); #品牌分类
- $brand_r_list = array(); #推荐品牌
- if (!empty($brand_c_list) && is_array($brand_c_list)) {
- $goods_class = model('goodsclass')->getGoodsclassForCacheModel();
- foreach ($brand_c_list as $key => $brand_c) {
- $brand_c['brand_pic'] = brand_image($brand_c['brand_pic']);
- $gc_array = $this->_getTopClass($goods_class, $brand_c['gc_id']);
- if (empty($gc_array)) {
- $brand_listnew[0][] = $brand_c;
- $brand_class[0]['brand_class'] = lang('brand_index_other');
- } else {
- $brand_listnew[$gc_array['gc_id']][] = $brand_c;
- $brand_class[$gc_array['gc_id']]['brand_class'] = $gc_array['gc_name'];
- }
- $brand_listchar[$brand_c['brand_initial']][] = $brand_c;
- //推荐品牌
- if ($brand_c['brand_recommend'] == 1) {
- $brand_r_list[] = $brand_c;
- }
- }
- }
- krsort($brand_class);
- krsort($brand_listnew);
- ksort($brand_listchar);
- return array('brand_listchar' => $brand_listchar, 'brand_listnew' => $brand_listnew, 'brand_class' => $brand_class, 'brand_r_list' => $brand_r_list);
- }
- /**
- * 获取顶级商品分类\递归调用
- * @param type $goods_class
- * @param type $gc_id
- * @return type
- */
- private function _getTopClass($goods_class, $gc_id)
- {
- if (!isset($goods_class[$gc_id])) {
- return null;
- }
- if ($goods_class[$gc_id]['gc_parent_id'] == $gc_id) { //自身ID等于父ID
- return null;
- }
- if (isset($goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id']) && $goods_class[$goods_class[$gc_id]['gc_parent_id']]['gc_parent_id'] == $gc_id) { //父分类的父ID等于自身ID
- return null;
- }
- return $goods_class[$gc_id]['gc_parent_id'] == 0 ? $goods_class[$gc_id] : $this->_getTopClass($goods_class, $goods_class[$gc_id]['gc_parent_id']);
- }
- }
|