10 Commits

5 changed files with 31 additions and 22 deletions

View File

@@ -99,6 +99,7 @@ class ReceiveProductSync
} }
$category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find(); $category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find();
if (!empty($category)) {
$tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find();
if (!empty($tco_parent)) { if (!empty($tco_parent)) {
$parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find();
@@ -109,10 +110,11 @@ class ReceiveProductSync
$category['path'] = $parent['path'] . $parent['pid']; $category['path'] = $parent['path'] . $parent['pid'];
$category['level'] = $parent['level'] + 1; $category['level'] = $parent['level'] + 1;
} }
if (!$category->save($category)) { if (!$category->save()) {
throw new \Exception('产品分类更新失败'); throw new \Exception('产品分类更新失败');
} }
} }
}
Db::commit(); Db::commit();
} catch (\Throwable $th) { } catch (\Throwable $th) {

View File

@@ -16,8 +16,9 @@ class ProductTcoCategory
$param = request()->param(['name']); $param = request()->param(['name']);
$categorys = ProductTcoCategoryModel::field([ $categorys = ProductTcoCategoryModel::field([
'tco_id' => 'id', 'id',
'tco_pid' => 'pid', 'tco_id',
'tco_pid',
'name', 'name',
]) ])
->withSearch(['name'], [ ->withSearch(['name'], [
@@ -25,10 +26,10 @@ class ProductTcoCategory
]) ])
->language(request()->lang_id) ->language(request()->lang_id)
->enabled() ->enabled()
->order(['id' => 'asc']) ->order(['tco_id' => 'asc'])
->select() ->select()
->toArray(); ->toArray();
return success('获取成功', array_to_tree($categorys, 0, 'pid', false)); return success('获取成功', array_to_tree($categorys, 0, 'tco_pid', false, true, 'tco_id'));
} }
} }

View File

@@ -80,7 +80,7 @@ if (!function_exists('array_to_tree')) {
* @param bool $keep_pid 是否保留pid * @param bool $keep_pid 是否保留pid
* @return array * @return array
*/ */
function array_to_tree(array $data, int $pid, string $with = 'pid', int|bool $level = 1, bool $keep_pid = true) function array_to_tree(array $data, int $pid, string $with = 'pid', int|bool $level = 1, bool $keep_pid = true, $with_ref = 'id')
{ {
$ret = []; $ret = [];
foreach ($data as $item) { foreach ($data as $item) {
@@ -93,7 +93,7 @@ if (!function_exists('array_to_tree')) {
if ($keep_pid === false) { if ($keep_pid === false) {
unset($item[$with]); unset($item[$with]);
} }
$children = array_to_tree($data, $item['id'], $with, $lv, $keep_pid); $children = array_to_tree($data, $item[$with_ref], $with, $lv, $keep_pid, $with_ref);
if ($children) { if ($children) {
$item['children'] = $children; $item['children'] = $children;
} }
@@ -153,8 +153,12 @@ if (!function_exists('get_filesystem_url')) {
* @param string $disk 磁盘配置 key * @param string $disk 磁盘配置 key
* @return string * @return string
*/ */
function get_filesystem_url(string $url, string $disk): string function get_filesystem_url(string|null $url, string $disk): string
{ {
if (is_null($url)) {
return '';
}
if (\think\helper\Str::startsWith($url, ['http://', 'https://', '//'])) { if (\think\helper\Str::startsWith($url, ['http://', 'https://', '//'])) {
return $url; return $url;
} }
@@ -171,8 +175,12 @@ if (!function_exists('url_filesystem_detect')) {
* @param string $url 文件地址 * @param string $url 文件地址
* @return string * @return string
*/ */
function url_filesystem_detect(string $url): string function url_filesystem_detect(string|null $url): string
{ {
if (is_null($url)) {
return '';
}
$idx = strrpos($url, '.'); $idx = strrpos($url, '.');
if ($idx === false) { if ($idx === false) {
return $url; return $url;

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1278,7 +1278,7 @@ video img {
margin-left: 1rem; margin-left: 1rem;
} }
.foot-cate li { .foot-cate li {
width: 50%; min-width: 50%;
display: inline-block; display: inline-block;
float: left; float: left;
color: #fff; color: #fff;