数据商品修改为无限级

This commit is contained in:
邹景立 2021-05-20 13:56:07 +08:00
parent bca386201c
commit 1baab32868
8 changed files with 21 additions and 56 deletions

View File

@ -2,7 +2,6 @@
namespace app\data\controller\shop;
use app\data\service\GoodsService;
use think\admin\Controller;
use think\admin\extend\DataExtend;
@ -19,20 +18,6 @@ class Cate extends Controller
*/
private $table = 'ShopGoodsCate';
/**
* 最大分类等级
* @var integer
*/
protected $cateLevel;
/**
* 控制器初始化
*/
protected function initialize()
{
$this->cateLevel = GoodsService::instance()->getCateMax();
}
/**
* 商品分类管理
* @auth true
@ -43,7 +28,7 @@ class Cate extends Controller
*/
public function index()
{
$this->title = "商品分类管理(最大{$this->cateLevel}级)";
$this->title = "商品分类管理";
$query = $this->_query($this->table)->like('name')->dateBetween('create_at');
$query->equal('status')->where(['deleted' => 0])->order('sort desc,id desc')->page(false);
}
@ -97,8 +82,8 @@ class Cate extends Controller
$data['pid'] = intval($data['pid'] ?? input('pid', '0'));
$cates = $this->app->db->name($this->table)->where(['deleted' => 0])->order('sort desc,id desc')->select()->toArray();
$this->cates = DataExtend::arr2table(array_merge($cates, [['id' => '0', 'pid' => '-1', 'name' => '顶部分类']]));
if (isset($data['id'])) foreach ($this->cates as $key => $cate) if ($cate['id'] === $data['id']) $data = $cate;
foreach ($this->cates as $key => $cate) if ($cate['spt'] >= $this->cateLevel || (isset($data['spt']) && $data['spt'] <= $cate['spt'])) {
if (isset($data['id'])) foreach ($this->cates as $cate) if ($cate['id'] === $data['id']) $data = $cate;
foreach ($this->cates as $key => $cate) if ((isset($data['spt']) && $data['spt'] <= $cate['spt'])) {
unset($this->cates[$key]);
}
}

View File

@ -27,14 +27,6 @@ class Goods extends Controller
*/
protected $cateLevel;
/**
* 控制器初始化
*/
protected function initialize()
{
$this->cateLevel = GoodsService::instance()->getCateMax();
}
/**
* 商品数据管理
* @auth true

View File

@ -59,22 +59,14 @@ class GoodsService extends Service
}
$cates[$id]['ids'] = array_reverse($cates[$id]['ids']);
$cates[$id]['names'] = array_reverse($cates[$id]['names']);
if ($simple && count($cates[$id]['names']) !== $this->getCateMax()) {
unset($cates[$key]);
if (isset($pky) && $simple && in_array($cates[$pky]['name'], $cates[$id]['names'])) {
unset($cates[$pky]);
}
$pky = $key;
}
return $cates;
}
/**
* 最大分类等级
* @return integer
*/
public function getCateMax(): int
{
return 3;
}
/**
* 更新商品库存数据
* @param string $code

View File

@ -40,13 +40,9 @@
<td class='text-center nowrap'>{eq name='vo.status' value='0'}<span class="color-red">已禁用</span>{else}<span class="color-green">已激活</span>{/eq}</td>
<td class='text-center nowrap notselect'>
{if auth("add")}
<!--{if $vo.spt < $cateLevel-1}-->
<!--{if auth("add")}-->
<a class="layui-btn layui-btn-xs layui-btn-primary" data-modal='{:url("add")}?pid={$vo.id}' data-title="添加子分类"> </a>
<!--{else}-->
<a class="layui-btn layui-btn-xs layui-btn-disabled"> </a>
<!--{/if}-->
{/if}
<!--{if auth("edit")}-->
<a class="layui-btn layui-btn-xs" data-dbclick data-modal='{:url("edit")}?id={$vo.id}' data-title="编辑分类"> </a>

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03::getLoader();
return ComposerAutoloaderInitb2f66138aea76ab30d756f683b9213f0::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03
class ComposerAutoloaderInitb2f66138aea76ab30d756f683b9213f0
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitb2f66138aea76ab30d756f683b9213f0', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitb2f66138aea76ab30d756f683b9213f0', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit0ec6378467f464339c264d61cf644c03::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -51,19 +51,19 @@ class ComposerAutoloaderInit0ec6378467f464339c264d61cf644c03
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit0ec6378467f464339c264d61cf644c03::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire0ec6378467f464339c264d61cf644c03($fileIdentifier, $file);
composerRequireb2f66138aea76ab30d756f683b9213f0($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire0ec6378467f464339c264d61cf644c03($fileIdentifier, $file)
function composerRequireb2f66138aea76ab30d756f683b9213f0($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit0ec6378467f464339c264d61cf644c03
class ComposerStaticInitb2f66138aea76ab30d756f683b9213f0
{
public static $files = array (
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
@ -687,10 +687,10 @@ class ComposerStaticInit0ec6378467f464339c264d61cf644c03
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit0ec6378467f464339c264d61cf644c03::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit0ec6378467f464339c264d61cf644c03::$prefixDirsPsr4;
$loader->fallbackDirsPsr0 = ComposerStaticInit0ec6378467f464339c264d61cf644c03::$fallbackDirsPsr0;
$loader->classMap = ComposerStaticInit0ec6378467f464339c264d61cf644c03::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::$prefixDirsPsr4;
$loader->fallbackDirsPsr0 = ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::$fallbackDirsPsr0;
$loader->classMap = ComposerStaticInitb2f66138aea76ab30d756f683b9213f0::$classMap;
}, null, ClassLoader::class);
}

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2021-05-19 19:06:53
// This file is automatically generated at:2021-05-20 13:55:29
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',