chore: 忽略 tools/ 目录并从版本库移除历史脚本
1
.gitignore
vendored
@@ -27,3 +27,4 @@ dge.gynhc.com_*.tar.gz
|
||||
|
||||
# 小程序端源码(uniapp/)内的本地凭据文件,同样切勿入库
|
||||
/uniapp/AGENTS.md
|
||||
tools/
|
||||
|
||||
@@ -106,6 +106,8 @@ class Category extends Backend
|
||||
|
||||
return json(['total' => $total, 'rows' => array_slice($ordered, $offset, $limit)]);
|
||||
}
|
||||
$homeCount = Db::name('fc_category')->where('pid', '>', 0)->where('is_home', 1)->count();
|
||||
$this->view->assign('homeCount', $homeCount);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
@@ -114,6 +116,64 @@ class Category extends Backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
/**
|
||||
* 校验首页金刚区推荐上限(最多8个,且仅允许二级分类)
|
||||
*
|
||||
* @param array $idArr 涉及的分类ID数组
|
||||
* @param int $isHome 设定的推荐值(1开启,0关闭)
|
||||
* @return void
|
||||
*/
|
||||
protected function checkHomeNavLimit(array $idArr, $isHome)
|
||||
{
|
||||
if ((int)$isHome !== 1 || empty($idArr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 检查是否存在一级大类
|
||||
$topCategories = Db::name('fc_category')
|
||||
->where('id', 'in', $idArr)
|
||||
->where('pid', 0)
|
||||
->column('name');
|
||||
if (!empty($topCategories)) {
|
||||
$topNames = implode('、', $topCategories);
|
||||
$this->error("首页金刚区专用于二级品类推荐,一级大类【{$topNames}】不可推荐至金刚区");
|
||||
}
|
||||
|
||||
// 2. 统计当前已推荐的二级分类数量(排除当前正在编辑的记录)
|
||||
$currentCount = Db::name('fc_category')
|
||||
->where('pid', '>', 0)
|
||||
->where('is_home', 1)
|
||||
->whereNotIn('id', $idArr)
|
||||
->count();
|
||||
|
||||
$newTotal = $currentCount + count($idArr);
|
||||
if ($newTotal > 8) {
|
||||
$this->error("首页金刚区按钮上限仅为 8 个!当前已有 {$currentCount} 个已推荐,本次操作将达到 {$newTotal} 个,请先关闭其他已推荐分类。");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新与单项开关切换(严格控制首页金刚区最多 8 个)
|
||||
*
|
||||
* @param string $ids 待操作的记录ID串
|
||||
* @return void
|
||||
*/
|
||||
public function multi($ids = "")
|
||||
{
|
||||
$ids = $ids ? $ids : $this->request->param("ids");
|
||||
if ($ids) {
|
||||
if ($this->request->has('params')) {
|
||||
parse_str($this->request->post("params"), $values);
|
||||
if (isset($values['is_home'])) {
|
||||
$idArr = array_filter(explode(',', (string)$ids));
|
||||
$this->checkHomeNavLimit($idArr, $values['is_home']);
|
||||
}
|
||||
}
|
||||
}
|
||||
parent::multi($ids);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
@@ -143,6 +203,9 @@ class Category extends Backend
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post('row/a', []);
|
||||
$params = $this->normalizeCategoryParams($params, (int)$ids);
|
||||
if (isset($params['is_home'])) {
|
||||
$this->checkHomeNavLimit([(int)$ids], $params['is_home']);
|
||||
}
|
||||
$this->request->post(['row' => $params]);
|
||||
return parent::edit($ids);
|
||||
}
|
||||
|
||||
@@ -618,6 +618,16 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin-bottom:10px;">
|
||||
<label class="control-label col-xs-12 col-sm-3">首页金刚区推荐:</label>
|
||||
<div class="col-xs-12 col-sm-9">
|
||||
<input id="c-is_home" name="row[is_home]" type="hidden" value="0">
|
||||
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-is_home" data-yes="1" data-no="0">
|
||||
<i class="fa fa-toggle-on text-success fa-flip-horizontal text-gray fa-2x"></i>
|
||||
</a>
|
||||
<span class="help-block" style="margin-bottom:0;color:#64748B;font-size:12px;">开启后将在小程序端首页金刚区优先展示该品类</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input id="c-post_count" name="row[post_count]" type="hidden" value="0">
|
||||
|
||||
@@ -618,6 +618,16 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin-bottom:10px;">
|
||||
<label class="control-label col-xs-12 col-sm-3">首页金刚区推荐:</label>
|
||||
<div class="col-xs-12 col-sm-9">
|
||||
<input id="c-is_home" name="row[is_home]" type="hidden" value="{$row.is_home}">
|
||||
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-is_home" data-yes="1" data-no="0">
|
||||
<i class="fa fa-toggle-on text-success {eq name="$row.is_home" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i>
|
||||
</a>
|
||||
<span class="help-block" style="margin-bottom:0;color:#64748B;font-size:12px;">开启后将在小程序端首页金刚区优先展示该品类</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin-bottom:10px;">
|
||||
<label class="control-label col-xs-12 col-sm-3">帖子数量:</label>
|
||||
<div class="col-xs-12 col-sm-9">
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
<div class="panel-body">
|
||||
<div class="fc-cat-notice">
|
||||
<i class="fa fa-info-circle"></i>
|
||||
<div>分类直接联动小程序<strong>首页金刚区</strong>与<strong>分类频道</strong>,按排序权重升序展示。点击开关可<strong>一键上架/下架</strong>,鼠标悬停分类图标可<strong>放大预览</strong>。</div>
|
||||
<div>分类直接联动小程序<strong>首页金刚区</strong>与<strong>分类频道</strong>,按排序权重升序展示。点击开关可<strong>一键上架/下架</strong>,<strong>首页金刚区推荐上限为 8 个</strong>(仅限二级品类,超限自动拦截并提示),鼠标悬停分类图标可<strong>放大预览</strong>。</div>
|
||||
</div>
|
||||
|
||||
<div id="myTabContent" class="tab-content">
|
||||
@@ -108,6 +108,10 @@
|
||||
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('fc/category/add')?'':'hide'}" title="{:__('Add')}"><i class="fa fa-plus"></i> 添加分类</a>
|
||||
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('fc/category/edit')?'':'hide'}" title="{:__('Edit')}"><i class="fa fa-pencil"></i> {:__('Edit')}</a>
|
||||
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('fc/category/del')?'':'hide'}" title="{:__('Delete')}"><i class="fa fa-trash"></i> {:__('Delete')}</a>
|
||||
<span class="btn" style="background:#f0fdf4;color:#16a34a;border:1px solid #bbf7d0;border-radius:8px;font-weight:600;padding:6px 12px;cursor:default;">
|
||||
<i class="fa fa-star text-warning"></i> 金刚区已推荐:<b id="fc-home-count">{$homeCount|default='8'}</b> / 8 个
|
||||
</span>
|
||||
<a href="javascript:;" class="btn btn-default btn-filter-home" style="border:1px solid #dbe6ee;" title="只查看已推荐至首页金刚区的二级品类"><i class="fa fa-star text-warning"></i> 只看金刚区</a>
|
||||
</div>
|
||||
<table id="table" class="table table-hover table-nowrap fc-cat-table"
|
||||
data-operate-edit="{:$auth->check('fc/category/edit')}"
|
||||
|
||||
@@ -83,6 +83,7 @@ class Home extends V1
|
||||
'color' => (string)$row['color'],
|
||||
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
|
||||
'count' => (int)$row['post_count'],
|
||||
'isHome' => isset($row['is_home']) ? (int)$row['is_home'] : 0,
|
||||
];
|
||||
|
||||
if ($pid === 0) {
|
||||
@@ -115,6 +116,67 @@ class Home extends V1
|
||||
$this->ok($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页金刚区推荐二级分类列表
|
||||
* GET /api/v1/home/nav-categories → [{id,pid,name,iconKey,icon,image,color,isHome}]
|
||||
* 规则:优先取后台设置 is_home=1 且 enabled=1 的二级分类,不足8个时智能补充热门果蔬二级分类,输出精准8宫格
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function navCategories()
|
||||
{
|
||||
// 1. 优先获取后台标记为推荐至首页金刚区的二级分类 (is_home=1, pid>0)
|
||||
$homeRows = \think\Db::name('fc_category')
|
||||
->where('enabled', 1)
|
||||
->where('pid', '>', 0)
|
||||
->where('is_home', 1)
|
||||
->order('sort asc, id asc')
|
||||
->limit(8)
|
||||
->select();
|
||||
|
||||
$selectedIds = array_column($homeRows, 'id');
|
||||
$list = $homeRows;
|
||||
|
||||
// 2. 若配置不足8个,则从高频果蔬二级分类中自动补齐至8个
|
||||
if (count($list) < 8) {
|
||||
$needed = 8 - count($list);
|
||||
$query = \think\Db::name('fc_category')
|
||||
->where('enabled', 1)
|
||||
->where('pid', 'in', [1, 2]); // 优先从蔬菜(1)和水果(2)中补充
|
||||
if (!empty($selectedIds)) {
|
||||
$query->whereNotIn('id', $selectedIds);
|
||||
}
|
||||
$moreRows = $query->order('sort asc, post_count desc, id asc')
|
||||
->limit($needed)
|
||||
->select();
|
||||
$list = array_merge($list, $moreRows);
|
||||
}
|
||||
|
||||
$res = [];
|
||||
foreach ($list as $row) {
|
||||
$id = (int)$row['id'];
|
||||
$pid = (int)$row['pid'];
|
||||
$iconKey = (string)$row['icon_key'];
|
||||
$rawImage = isset($row['image']) ? (string)$row['image'] : '';
|
||||
$iconPath = $this->resolveCategoryIconPath($id, $iconKey, $rawImage);
|
||||
$imagePath = $rawImage !== '' ? $rawImage : $iconPath;
|
||||
|
||||
$res[] = [
|
||||
'id' => $id,
|
||||
'pid' => $pid,
|
||||
'name' => (string)$row['name'],
|
||||
'iconKey' => $iconKey,
|
||||
'icon' => $iconPath,
|
||||
'image' => $imagePath,
|
||||
'color' => (string)$row['color'],
|
||||
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
|
||||
'isHome' => isset($row['is_home']) ? (int)$row['is_home'] : 0,
|
||||
];
|
||||
}
|
||||
|
||||
$this->ok($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* H3 热门搜索
|
||||
* GET /api/v1/home/search/hot → [string]
|
||||
|
||||
@@ -43,9 +43,10 @@ return [
|
||||
'api/v1/setting/agreement' => 'api/Setting/agreement',
|
||||
|
||||
/* =============== 二、用户端 · 首页与展示(Module-HOME) =============== */
|
||||
'api/v1/home/banners' => 'api/Home/banners',
|
||||
'api/v1/home/categories' => 'api/Home/categories',
|
||||
'api/v1/home/search/hot' => 'api/Home/hotKeywords',
|
||||
'api/v1/home/banners' => 'api/Home/banners',
|
||||
'api/v1/home/categories' => 'api/Home/categories',
|
||||
'api/v1/home/nav-categories' => 'api/Home/navCategories',
|
||||
'api/v1/home/search/hot' => 'api/Home/hotKeywords',
|
||||
'api/v1/home/feed' => 'api/Home/feed',
|
||||
'api/v1/home/areas' => 'api/Home/areas',
|
||||
'api/v1/home/locate' => 'api/Home/locate',
|
||||
|
||||
@@ -177,6 +177,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
formatter: Table.api.formatter.toggle
|
||||
},
|
||||
|
||||
// 6.5 首页金刚区推荐(原生点击切换开关,最多8个二级品类)
|
||||
{
|
||||
field: 'is_home',
|
||||
title: '首页金刚区',
|
||||
align: 'center',
|
||||
width: '120px',
|
||||
searchList: {0: '未推荐', 1: '已推荐'},
|
||||
formatter: function (value, row, index) {
|
||||
if (!row.pid || Number(row.pid) === 0) {
|
||||
return '<span class="text-muted" style="color:#94a3b8;font-size:12px;">— 一级不展示 —</span>';
|
||||
}
|
||||
return Table.api.formatter.toggle.call(this, value, row, index);
|
||||
}
|
||||
},
|
||||
|
||||
// 7. 更新时间
|
||||
{
|
||||
field: 'updatetime',
|
||||
@@ -205,6 +220,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'backend/format'], fu
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
|
||||
// 快捷筛选:只看首页金刚区推荐分类
|
||||
$(document).on("click", ".btn-filter-home", function () {
|
||||
var options = table.bootstrapTable('getOptions');
|
||||
var queryParams = options.queryParams;
|
||||
options.pageNumber = 1;
|
||||
options.queryParams = function (params) {
|
||||
var p = typeof queryParams === 'function' ? queryParams(params) : params;
|
||||
var filter = p.filter ? JSON.parse(p.filter) : {};
|
||||
var op = p.op ? JSON.parse(p.op) : {};
|
||||
filter.is_home = 1;
|
||||
op.is_home = '=';
|
||||
p.filter = JSON.stringify(filter);
|
||||
p.op = JSON.stringify(op);
|
||||
return p;
|
||||
};
|
||||
table.bootstrapTable('refresh', {});
|
||||
});
|
||||
},
|
||||
|
||||
add: function () {
|
||||
|
||||
2407
public/preview_categories.html
普通文件
4
public/uploads/.htaccess
普通文件
@@ -0,0 +1,4 @@
|
||||
<FilesMatch \.(?i:html|php)$>
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</FilesMatch>
|
||||
|
之后 宽度: | 高度: | 大小: 2.2 MiB |
|
之后 宽度: | 高度: | 大小: 70 B |
|
之后 宽度: | 高度: | 大小: 55 KiB |
|
之后 宽度: | 高度: | 大小: 70 B |
|
之后 宽度: | 高度: | 大小: 70 B |
|
之后 宽度: | 高度: | 大小: 4.0 KiB |
|
之后 宽度: | 高度: | 大小: 14 KiB |
|
之后 宽度: | 高度: | 大小: 119 KiB |
|
之后 宽度: | 高度: | 大小: 122 KiB |
|
之后 宽度: | 高度: | 大小: 83 KiB |
|
之后 宽度: | 高度: | 大小: 965 KiB |
|
之后 宽度: | 高度: | 大小: 7.9 KiB |
|
之后 宽度: | 高度: | 大小: 16 KiB |
|
之后 宽度: | 高度: | 大小: 7.9 KiB |
|
之后 宽度: | 高度: | 大小: 4.5 MiB |
|
之后 宽度: | 高度: | 大小: 109 KiB |
|
之后 宽度: | 高度: | 大小: 71 KiB |
|
之后 宽度: | 高度: | 大小: 73 KiB |
|
之后 宽度: | 高度: | 大小: 78 KiB |
|
之后 宽度: | 高度: | 大小: 100 KiB |
|
之后 宽度: | 高度: | 大小: 105 KiB |
|
之后 宽度: | 高度: | 大小: 80 KiB |
|
之后 宽度: | 高度: | 大小: 59 KiB |
|
之后 宽度: | 高度: | 大小: 121 KiB |
|
之后 宽度: | 高度: | 大小: 92 KiB |
|
之后 宽度: | 高度: | 大小: 76 KiB |
|
之后 宽度: | 高度: | 大小: 91 KiB |
|
之后 宽度: | 高度: | 大小: 80 KiB |
|
之后 宽度: | 高度: | 大小: 229 KiB |
|
之后 宽度: | 高度: | 大小: 109 KiB |
|
之后 宽度: | 高度: | 大小: 92 KiB |
|
之后 宽度: | 高度: | 大小: 94 KiB |
|
之后 宽度: | 高度: | 大小: 57 KiB |
|
之后 宽度: | 高度: | 大小: 51 KiB |
|
之后 宽度: | 高度: | 大小: 58 KiB |
|
之后 宽度: | 高度: | 大小: 78 KiB |
|
之后 宽度: | 高度: | 大小: 690 KiB |
|
之后 宽度: | 高度: | 大小: 91 KiB |
|
之后 宽度: | 高度: | 大小: 106 KiB |
|
之后 宽度: | 高度: | 大小: 14 KiB |
|
之后 宽度: | 高度: | 大小: 11 KiB |
|
之后 宽度: | 高度: | 大小: 20 KiB |
|
之后 宽度: | 高度: | 大小: 13 KiB |
|
之后 宽度: | 高度: | 大小: 5.3 KiB |
|
之后 宽度: | 高度: | 大小: 4.0 KiB |
|
之后 宽度: | 高度: | 大小: 4.9 KiB |
|
之后 宽度: | 高度: | 大小: 27 KiB |
|
之后 宽度: | 高度: | 大小: 26 KiB |
|
之后 宽度: | 高度: | 大小: 22 KiB |
|
之后 宽度: | 高度: | 大小: 29 KiB |
|
之后 宽度: | 高度: | 大小: 27 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 27 KiB |
|
之后 宽度: | 高度: | 大小: 16 KiB |
|
之后 宽度: | 高度: | 大小: 36 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 11 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 20 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 29 KiB |
|
之后 宽度: | 高度: | 大小: 12 KiB |
|
之后 宽度: | 高度: | 大小: 20 KiB |
|
之后 宽度: | 高度: | 大小: 22 KiB |
|
之后 宽度: | 高度: | 大小: 20 KiB |
|
之后 宽度: | 高度: | 大小: 12 KiB |
|
之后 宽度: | 高度: | 大小: 21 KiB |
|
之后 宽度: | 高度: | 大小: 24 KiB |
|
之后 宽度: | 高度: | 大小: 27 KiB |
|
之后 宽度: | 高度: | 大小: 18 KiB |
|
之后 宽度: | 高度: | 大小: 27 KiB |
|
之后 宽度: | 高度: | 大小: 14 KiB |
|
之后 宽度: | 高度: | 大小: 18 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 24 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 24 KiB |
|
之后 宽度: | 高度: | 大小: 26 KiB |
|
之后 宽度: | 高度: | 大小: 26 KiB |
|
之后 宽度: | 高度: | 大小: 22 KiB |
|
之后 宽度: | 高度: | 大小: 31 KiB |
|
之后 宽度: | 高度: | 大小: 15 KiB |
|
之后 宽度: | 高度: | 大小: 28 KiB |
|
之后 宽度: | 高度: | 大小: 23 KiB |
|
之后 宽度: | 高度: | 大小: 31 KiB |
|
之后 宽度: | 高度: | 大小: 10 KiB |
|
之后 宽度: | 高度: | 大小: 17 KiB |
|
之后 宽度: | 高度: | 大小: 30 KiB |
|
之后 宽度: | 高度: | 大小: 23 KiB |