123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace addons\unishop\controller;
- use app\common\controller\Api;
- use think\Db;
- class Category extends Api
- {
- protected $frequently = ['all','menu','inlist'];
- protected $noNeedLogin = ['all','menu','inlist'];
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \addons\unishop\model\Category();
- }
-
- public function all(){
- $all = $this->model
- ->where('type','product')
- ->where('status','normal')
- ->field('id,name,nickname,pid,image,type,flag,weigh')
- ->order('weigh ASC')
- ->cache(20)
- ->select();
- if ($all) {
- $all = collection($all)->toArray();
- }
- $this->success('',$all);
- }
- public function inlist(){
- $list = Db::name('unishop_category')
- ->where('status','normal')
- ->field('id,name,nickname,keywords')
- ->order('weigh ASC')
- ->cache(20)
- ->select();
- $this->success('',$list);
- }
- public function inlist_old(){
- $list = Db::name('unishop_category')
- ->where('status','normal')
- ->field('id,name,nickname,pid')
- ->order('weigh ASC')
- ->cache(20)
- ->select();
-
- $list_1 = [];
- $list_2 = [];
- foreach($list as $key => $value){
- if($value['pid'] == 0){
- $list_1[] = $value;
- }else{
- $list_2[] = $value;
- }
- }
-
- foreach($list_1 as $k1 => $v1){
- foreach($list_2 as $k2 => $v2){
- if($v1['id'] == $v2['pid']){
- $list_1[$k1]['child'][] = $v2;
- }
- }
- }
- $this->success('',$list_1);
- }
-
- public function menu()
- {
- $list = $this->model
- ->where('flag','index')
- ->where('status','normal')
- ->cache(20)
- ->select();
- if ($list) {
- $list = collection($list)->toArray();
- }
- $this->success('菜单',$list);
- }
- }
|