14 Commits

6 changed files with 32 additions and 25 deletions

View File

@@ -99,18 +99,20 @@ class ReceiveProductSync
} }
$category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find(); $category = ProductCategoryModel::language($lang_id)->tcoId($tco_category['id'])->find();
$tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find(); if (!empty($category)) {
if (!empty($tco_parent)) { $tco_parent = ProductTcoCategoryModel::language($lang_id)->tcoId($tco_category['tco_pid'])->find();
$parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find(); if (!empty($tco_parent)) {
if ($parent->isEmpty()) { $parent = ProductCategoryModel::language($lang_id)->tcoId($tco_parent['id'])->find();
throw new \Exception('产品分类父级不存在'); if ($parent->isEmpty()) {
throw new \Exception('产品分类父级不存在');
}
$category['pid'] = $parent['id'];
$category['path'] = $parent['path'] . $parent['pid'];
$category['level'] = $parent['level'] + 1;
}
if (!$category->save()) {
throw new \Exception('产品分类更新失败');
} }
$category['pid'] = $parent['id'];
$category['path'] = $parent['path'] . $parent['pid'];
$category['level'] = $parent['level'] + 1;
}
if (!$category->save($category)) {
throw new \Exception('产品分类更新失败');
} }
} }

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

@@ -31,9 +31,7 @@
<h3>{:lang_i18n('联系方式')}</h3> <h3>{:lang_i18n('联系方式')}</h3>
{if condition="!empty($contact_config)"} {if condition="!empty($contact_config)"}
{volist name="contact_config" id="vo"} {volist name="contact_config" id="vo"}
{if condition="$vo.type == 'image'"} {if condition="$vo.type != 'image'"}
<img src="{$vo.value}" {if condition="!empty($vo.extra)" }style="{$vo.extra}" {/if} />
{else/}
<p>{$vo.value}</p> <p>{$vo.value}</p>
{/if} {/if}
{/volist} {/volist}

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;