| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 | <?php/** * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved. * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0). * @author      pillar<ltmn@qq.com> * 商品分类管理 */namespace app\allwin\model;use think\Model;use category\Tree;class AllwinShopCate extends Model{    protected $pk     = 'id';        //添加或编辑    public static function edit($param){        $data['title']       = $param['title'];        $data['content']     = $param['content'];        $data['picture']     = $param['picture'];        $data['types']       = $param['types'];        $data['update_time'] = time();        if(isset($param['id'])){            return self::update($data,['id'=>(int)$param['id']]);        }else{            $data['create_time']       = time();            $data['member_miniapp_id'] = $param['member_miniapp_id'];            return self::insert($data);        }    }     /**     * 获取访问路径     * @param int $parent_id     */    public static function selectPath(int $miniapp_id,$parent_id) {        $pathMaps[] = ['name'=>'根目录','url'=>url('allwin/shopCate/index')];        $getPath = self::getPath($miniapp_id,$parent_id);        foreach ($getPath as $value) {            $pathMaps[] = ['name' => $value['title'],'url' => url('allwin/shopCate/index',['parent_id'=>$value['id']])];        }        return $pathMaps;    }    /**     * 获取当前路径     * @param type $parent_id     * @return type     */    public static function getPath($miniapp_id,$parent_id){        $result = self::field('id,title,parent_id')->where(['member_miniapp_id' => $miniapp_id])->select();        $tree =  new Tree(array('id','parent_id','title','name'));        return $tree->getPath($result,$parent_id);    }}
 |