feat: 新增电话拨打功能及相关配置,完善农产品分类与地区数据

- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录
- 新增平台免责声明内容及协议接口,完善用户服务协议相关配置
- 新增农产品分类图标与上市角标展示,优化分类管理界面样式
- 新增全国行政区划工具类与城市选择组件,重构地区数据结构
- 新增SSH自检与部署脚本,完善项目部署流程
这个提交包含在:
2026-10-27 17:05:00 +08:00
父节点 b9fdb7cd77
当前提交 bb6418f51b
共有 86 个文件被更改,包括 5354 次插入 和 2061 次删除

查看文件

@@ -95,6 +95,9 @@ class FcInstall extends Command
$output->writeln('==> 服务区域平铺升级(省 / 市 / 区县)');
$this->upgradeArea($output);
$output->writeln('==> 农产品二级分类 / 发布扩展字段 / 拨打次数限制升级(v2.0.0)');
$this->upgradeAgriV200($output);
$output->writeln('==> 初始化后台菜单');
$this->menu($output);
@@ -612,6 +615,210 @@ class FcInstall extends Command
}
/**
* v2.0.0:农产品二级分类(蔬菜/水果 + 带实拍图二级分类)、发布页扩展字段(种植面积/采摘时间/量产范围)、拨打次数限制升级
*
* @param Output $output
* @return void
*/
private function upgradeAgriV200(Output $output)
{
$prefix = \think\Config::get('database.prefix');
$catTable = $prefix . 'fc_category';
$postTable = $prefix . 'fc_post';
$draftTable = $prefix . 'fc_draft';
$now = time();
$changed = 0;
// 1. fa_fc_category 补充 pid 与 image 字段
if (!$this->hasColumn($catTable, 'pid')) {
Db::execute("ALTER TABLE `{$catTable}` ADD COLUMN `pid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父级分类ID(0为一级分类)' AFTER `id`");
$changed++;
}
if (!$this->hasColumn($catTable, 'image')) {
Db::execute("ALTER TABLE `{$catTable}` ADD COLUMN `image` varchar(255) NOT NULL DEFAULT '' COMMENT '分类实拍图' AFTER `icon_key`");
$changed++;
}
if (!$this->hasColumn($catTable, 'kind')) {
Db::execute("ALTER TABLE `{$catTable}` ADD COLUMN `kind` varchar(20) NOT NULL DEFAULT 'general' COMMENT '分类类型:farm=农产品,general=通用信息' AFTER `image`");
$changed++;
}
if (!$this->hasIndex($catTable, 'pid')) {
Db::execute("ALTER TABLE `{$catTable}` ADD KEY `pid` (`pid`)");
}
// 分类类型回填:蔬菜/水果两大类及其二级品类标记为农产品(farm),其余分类保持通用(general)
Db::name('fc_category')->where('id', 'in', [1, 2])->update(['kind' => 'farm', 'updatetime' => $now]);
Db::name('fc_category')->where('pid', 'in', [1, 2])->update(['kind' => 'farm', 'updatetime' => $now]);
// 2. fa_fc_post 与 fa_fc_draft 补充二级分类、省/市、种植面积、采摘时间、量产范围字段
$agriCols = [
'sub_category_id' => "int(10) unsigned NOT NULL DEFAULT '0' COMMENT '二级分类ID' AFTER `category_id`",
'province' => "varchar(32) NOT NULL DEFAULT '' COMMENT '省份' AFTER `price_unit`",
'city' => "varchar(32) NOT NULL DEFAULT '' COMMENT '城市' AFTER `province`",
'plant_area' => "varchar(64) NOT NULL DEFAULT '' COMMENT '种植面积' AFTER `tags`",
'harvest_time' => "varchar(32) NOT NULL DEFAULT '' COMMENT '采摘时间' AFTER `plant_area`",
'output_range' => "varchar(64) NOT NULL DEFAULT '' COMMENT '量产范围' AFTER `harvest_time`",
];
foreach ([$postTable, $draftTable] as $tbl) {
foreach ($agriCols as $col => $def) {
if (!$this->hasColumn($tbl, $col)) {
// draft 表无 price_unit/tags 时放在 category_id 或 address 后
$afterSql = $def;
if ($tbl === $draftTable && in_array($col, ['province', 'city', 'plant_area', 'harvest_time', 'output_range'], true)) {
$afterSql = preg_replace('/\s+AFTER\s+`[^`]+`$/i', '', $def);
}
Db::execute("ALTER TABLE `{$tbl}` ADD COLUMN `{$col}` {$afterSql}");
$changed++;
}
}
}
// 3. 拨打次数限制配置项(普通用户每日免费拨打次数 & VIP会员每日免费拨打次数)
$callConfigs = [
['call.normalDailyQuota', '5', 'call', '普通用户每日可拨打电话次数上限(超出后引导开通VIP或单次解锁)'],
['call.vipDailyQuota', '30', 'call', 'VIP会员每日可拨打电话次数上限(0=不限次数)'],
];
foreach ($callConfigs as $c) {
if (!Db::name('fc_config')->where('key', $c[0])->find()) {
Db::name('fc_config')->insert([
'key' => $c[0],
'value' => $c[1],
'group_key' => $c[2],
'remark' => $c[3],
'createtime' => $now,
'updatetime' => $now,
]);
$changed++;
}
}
// 4. 初始化一级分类(蔬菜、水果)及带实拍图的二级分类
$hasSubCats = Db::name('fc_category')->where('pid', '>', 0)->count();
if (!$hasSubCats) {
// 将 ID=1 设为「蔬菜」,ID=2 设为「水果」,其余旧一级分类若为通用分类则停用或归并
$cat1 = Db::name('fc_category')->where('id', 1)->find();
if ($cat1) {
Db::name('fc_category')->where('id', 1)->update([
'pid' => 0,
'name' => '蔬菜',
'icon_key' => 'cat-veg',
'image' => '/static/categories/cat-veg.png',
'kind' => 'farm',
'color' => '#00D26A',
'sort' => 1,
'enabled' => 1,
'updatetime' => $now,
]);
} else {
Db::name('fc_category')->insert([
'id' => 1, 'pid' => 0, 'name' => '蔬菜', 'icon_key' => 'cat-veg',
'image' => '/static/categories/cat-veg.png', 'kind' => 'farm', 'color' => '#00D26A',
'sort' => 1, 'enabled' => 1, 'post_count' => 0, 'createtime' => $now, 'updatetime' => $now,
]);
}
$cat2 = Db::name('fc_category')->where('id', 2)->find();
if ($cat2) {
Db::name('fc_category')->where('id', 2)->update([
'pid' => 0,
'name' => '水果',
'icon_key' => 'cat-fruit',
'image' => '/static/categories/cat-fruit.png',
'kind' => 'farm',
'color' => '#F5A623',
'sort' => 2,
'enabled' => 1,
'updatetime' => $now,
]);
} else {
Db::name('fc_category')->insert([
'id' => 2, 'pid' => 0, 'name' => '水果', 'icon_key' => 'cat-fruit',
'image' => '/static/categories/cat-fruit.png', 'kind' => 'farm', 'color' => '#F5A623',
'sort' => 2, 'enabled' => 1, 'post_count' => 0, 'createtime' => $now, 'updatetime' => $now,
]);
}
// 停用 ID 3~8 的旧通用分类,保持平台聚焦于蔬菜和水果两大类
Db::name('fc_category')->where('id', 'in', [3, 4, 5, 6, 7, 8])->where('pid', 0)->update([
'kind' => 'general',
'enabled' => 0,
'updatetime' => $now,
]);
$subCategories = [
// 蔬菜二级分类 (pid = 1)
['pid' => 1, 'name' => '花菜', 'icon_key' => 'veg-cauliflower', 'image' => '/static/categories/veg-cauliflower.png', 'color' => '#00D26A', 'sort' => 1],
['pid' => 1, 'name' => '白菜', 'icon_key' => 'veg-cabbage', 'image' => '/static/categories/veg-cabbage.png', 'color' => '#00D26A', 'sort' => 2],
['pid' => 1, 'name' => '紫甘蓝', 'icon_key' => 'veg-purple-cabbage', 'image' => '/static/categories/veg-purple-cabbage.png', 'color' => '#9333EA', 'sort' => 3],
['pid' => 1, 'name' => '青甘蓝', 'icon_key' => 'veg-green-cabbage', 'image' => '/static/categories/veg-green-cabbage.png', 'color' => '#10B981', 'sort' => 4],
['pid' => 1, 'name' => '青菜', 'icon_key' => 'veg-greens', 'image' => '/static/categories/veg-greens.png', 'color' => '#16A34A', 'sort' => 5],
['pid' => 1, 'name' => '萝卜', 'icon_key' => 'veg-radish', 'image' => '/static/categories/veg-radish.png', 'color' => '#22C55E', 'sort' => 6],
['pid' => 1, 'name' => '辣椒', 'icon_key' => 'veg-chili', 'image' => '/static/categories/veg-chili.png', 'color' => '#EF4444', 'sort' => 7],
['pid' => 1, 'name' => '西红柿', 'icon_key' => 'veg-tomato', 'image' => '/static/categories/veg-tomato.png', 'color' => '#F97316', 'sort' => 8],
// 水果二级分类 (pid = 2)
['pid' => 2, 'name' => '苹果', 'icon_key' => 'fruit-apple', 'image' => '/static/categories/fruit-apple.png', 'color' => '#E11D48', 'sort' => 1],
['pid' => 2, 'name' => '柑橘', 'icon_key' => 'fruit-orange', 'image' => '/static/categories/fruit-orange.png', 'color' => '#F97316', 'sort' => 2],
['pid' => 2, 'name' => '猕猴桃', 'icon_key' => 'fruit-kiwi', 'image' => '/static/categories/fruit-kiwi.png', 'color' => '#65A30D', 'sort' => 3],
['pid' => 2, 'name' => '草莓', 'icon_key' => 'fruit-strawberry', 'image' => '/static/categories/fruit-strawberry.png', 'color' => '#F43F5E', 'sort' => 4],
['pid' => 2, 'name' => '西瓜', 'icon_key' => 'fruit-watermelon', 'image' => '/static/categories/fruit-watermelon.png', 'color' => '#16A34A', 'sort' => 5],
['pid' => 2, 'name' => '葡萄', 'icon_key' => 'fruit-grape', 'image' => '/static/categories/fruit-grape.png', 'color' => '#7E22CE', 'sort' => 6],
['pid' => 2, 'name' => '蜜桃', 'icon_key' => 'fruit-peach', 'image' => '/static/categories/fruit-peach.png', 'color' => '#EC4899', 'sort' => 7],
['pid' => 2, 'name' => '百香果', 'icon_key' => 'fruit-passion', 'image' => '/static/categories/fruit-passion.png', 'color' => '#9333EA', 'sort' => 8],
];
foreach ($subCategories as $sc) {
Db::name('fc_category')->insert([
'pid' => $sc['pid'],
'name' => $sc['name'],
'icon_key' => $sc['icon_key'],
'image' => $sc['image'],
'kind' => 'farm',
'color' => $sc['color'],
'sort' => $sc['sort'],
'enabled' => 1,
'post_count' => 5,
'createtime' => $now,
'updatetime' => $now,
]);
}
$changed++;
}
// 5. 为历史帖子回填省/市与农产品字段,确保首页、分类页与详情页立即呈现标准蔬菜/水果数据
$vegSubs = Db::name('fc_category')->where('pid', 1)->where('enabled', 1)->select();
$fruitSubs = Db::name('fc_category')->where('pid', 2)->where('enabled', 1)->select();
if ($vegSubs && $fruitSubs) {
$posts = Db::query("SELECT id, title, area, province, city, price FROM `{$postTable}` WHERE `plant_area` = ''");
$areaChoices = ['15亩', '30亩', '50亩', '80亩', '120亩', '200亩'];
$rangeChoices = ['1000-5000斤', '5000-1万斤', '1万-5万斤', '5万-10万斤', '10万斤以上'];
$harvestChoices = ['2026-10-28', '2026-11-05', '2026-11-15', '2026-11-20', '2026-12-01'];
foreach ($posts as $idx => $p) {
$isVeg = ($idx % 2 === 0);
$catId = $isVeg ? 1 : 2;
$subPool = $isVeg ? $vegSubs : $fruitSubs;
$sub = $subPool[$idx % count($subPool)];
$pArea = $areaChoices[$idx % count($areaChoices)];
$hTime = $harvestChoices[$idx % count($harvestChoices)];
$oRange = $rangeChoices[$idx % count($rangeChoices)];
$prov = !empty($p['province']) ? $p['province'] : '贵州省';
$city = !empty($p['city']) ? $p['city'] : ($p['area'] === '七星关区' ? '毕节市' : '贵阳市');
$price = (float)$p['price'] > 0 ? (float)$p['price'] : round(1.5 + ($idx % 8) * 0.8, 2);
$subId = (int)$sub['id'];
Db::execute(
"UPDATE `{$postTable}` SET `category_id`=?, `sub_category_id`=?, `province`=?, `city`=?, `plant_area`=?, `harvest_time`=?, `output_range`=?, `price`=?, `price_unit`=? WHERE `id`=?",
[$catId, $subId, $prov, $city, $pArea, $hTime, $oRange, $price, '元/斤', (int)$p['id']]
);
}
$changed++;
}
$output->writeln($changed
? ' - 完成(农产品二级分类、发布扩展字段与拨打次数限制升级 ' . $changed . ' 处)'
: ' - 农产品二级分类与扩展字段已是最新,无需处理');
}
/** 表是否存在某列 */
private function hasColumn($table, $column)
{
@@ -723,6 +930,19 @@ class FcInstall extends Command
UNIQUE KEY `key` (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='同城-业务配置';",
'call_log' => "CREATE TABLE IF NOT EXISTS `#P#call_log` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '拨打用户ID',
`target_type` varchar(16) NOT NULL DEFAULT 'post' COMMENT 'post=信息 merchant=商家',
`target_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '目标记录ID',
`phone` varchar(32) NOT NULL DEFAULT '' COMMENT '拨打号码',
`call_date` varchar(10) NOT NULL DEFAULT '' COMMENT '拨打日期YYYY-MM-DD',
`createtime` int(10) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_date` (`user_id`, `call_date`),
KEY `target` (`target_type`, `target_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='同城-电话拨打次数记录';",
'category' => "CREATE TABLE IF NOT EXISTS `#P#category` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL DEFAULT '' COMMENT '分类名',

查看文件

@@ -79,14 +79,16 @@ class FcMenu extends Command
// 系统设置
'general/config' => ['fc/system', '系统配置', 'fa fa-cog', 99],
'dashboard' => ['fc/system', '平台概况', 'fa fa-dashboard', 95],
'fc/area' => ['fc/system', '服务区域', 'fa fa-map-o', 90],
'general/attachment' => ['fc/system', '附件管理', 'fa fa-file-image-o', 80],
'general/profile' => ['fc/system', '个人资料', 'fa fa-user', 70],
'addon' => ['fc/system', '插件管理', 'fa fa-rocket', 60],
];
/** 已并入对应主菜单、不再单独显示的历史菜单 */
const RETIRED = ['fc/setting', 'fc/memberbenefit'];
/** 已并入对应主菜单或默认全国无需手动配置、不再单独显示的历史菜单 */
const RETIRED = ['fc/setting', 'fc/memberbenefit', 'fc/area'];
/** 已彻底废弃的菜单(控制器不存在),重建时直接从数据库删除 */
const REMOVED = ['fc/board'];
/** 权限节点:name => [上级菜单, 标题] */
const NODES = [
@@ -241,6 +243,19 @@ class FcMenu extends Command
$table->where('name', $name)->update(['status' => 'hidden', 'updatetime' => $now]);
}
// 6.2) 彻底废弃的菜单(控制器不存在),连同子节点直接删除
$removedCount = 0;
foreach (self::REMOVED as $name) {
$rows = $table->where('name', 'like', $name . '%')->select();
if (!$rows) {
continue;
}
$ids = array_column($rows, 'id');
$table->where('id', 'in', $ids)->delete();
$table->where('pid', 'in', $ids)->delete();
$removedCount += count($ids);
}
// 7) 清理已搬空的历史分组(同城业务 / 基础数据 / 常规管理 / 权限管理)
$emptyRemoved = 0;
foreach (['fc', 'fc/base', 'general', 'auth'] as $name) {

查看文件

@@ -3,9 +3,10 @@
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-分类
* 同城-分类管理(支持一级分类「蔬菜/水果」与带实拍图的二级分类)
*
* @icon fa fa-circle-o
*/
@@ -20,11 +21,188 @@ class Category extends Backend
protected $noNeedRight = ['selectpage'];
/**
* 初始化分类控制器并注入一级分类下拉选项
*
* @return void
*/
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\FcCategory;
$parentList = [0 => '顶级分类(一级大类)'];
$topRows = Db::name('fc_category')
->where('pid', 0)
->order('sort asc, id asc')
->select();
foreach ($topRows as $r) {
$parentList[(int)$r['id']] = (string)$r['name'] . ((int)$r['enabled'] ? '' : ' (已停用)');
}
$this->view->assign('parentList', $parentList);
}
/**
* 分类列表(按一级分类 + 二级分类层级分组展示,支持附带父分类名称)
*
* @return string|\think\response\Json
*/
public function index()
{
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
// 分类总量有限:全量取回后按「父在前、子随父」的树形顺序在内存中重排,
// 再切片分页,避免数据库层先 limit 导致翻页后父子分组被打散。
$rows = $this->model->where($where)
->order('pid asc, sort asc, id asc')
->select();
$total = count($rows);
$rows = collection($rows)->toArray();
$parentMap = Db::name('fc_category')->where('pid', 0)->column('name', 'id');
// 树形顺序排列(一级分类紧跟其下属二级分类)
$byParent = [];
$tops = [];
$others = [];
foreach ($rows as &$r) {
$pid = isset($r['pid']) ? (int)$r['pid'] : 0;
$r['parent_name'] = $pid > 0 && isset($parentMap[$pid]) ? (string)$parentMap[$pid] : '顶级分类';
if (empty($r['image']) && !empty($r['icon_key'])) {
$r['image'] = $this->resolveImageFromKey($r['icon_key']);
}
if ($pid === 0) {
$tops[] = $r;
} else {
$byParent[$pid][] = $r;
$others[] = $r;
}
}
unset($r);
$ordered = [];
$usedIds = [];
foreach ($tops as $top) {
$ordered[] = $top;
$usedIds[$top['id']] = true;
$tid = (int)$top['id'];
if (!empty($byParent[$tid])) {
foreach ($byParent[$tid] as $child) {
$ordered[] = $child;
$usedIds[$child['id']] = true;
}
}
}
foreach ($others as $o) {
if (!isset($usedIds[$o['id']])) {
$ordered[] = $o;
}
}
return json(['total' => $total, 'rows' => array_slice($ordered, $offset, $limit)]);
}
return $this->view->fetch();
}
/**
* 新增分类(自动同步 image 与 icon_key)
*
* @return string
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post('row/a', []);
$params = $this->normalizeCategoryParams($params);
$this->request->post(['row' => $params]);
}
return parent::add();
}
/**
* 编辑分类(自动同步 image 与 icon_key)
*
* @param mixed $ids
* @return string
*/
public function edit($ids = null)
{
if ($this->request->isPost()) {
$params = $this->request->post('row/a', []);
$params = $this->normalizeCategoryParams($params, (int)$ids);
$this->request->post(['row' => $params]);
}
return parent::edit($ids);
}
/**
* 规范化分类参数:同步实拍图 image 与 icon_key,防止将自身设为上级分类
*
* @param array $params
* @param int $currentId
* @return array
*/
protected function normalizeCategoryParams(array $params, $currentId = 0)
{
$pid = isset($params['pid']) ? max(0, (int)$params['pid']) : 0;
if ($currentId > 0 && $pid === $currentId) {
$pid = 0;
}
$params['pid'] = $pid;
// 分类类型:farm=农产品(发布页显示产地规格字段),general=通用信息(招聘求职等)
// 二级分类强制继承上级类型;编辑一级分类时级联同步其下属二级分类
$kind = isset($params['kind']) ? trim((string)$params['kind']) : '';
if (!in_array($kind, ['farm', 'general'], true)) {
$kind = 'general';
}
if ($pid > 0) {
$parentKind = Db::name('fc_category')->where('id', $pid)->value('kind');
if ($parentKind === 'farm' || $parentKind === 'general') {
$kind = $parentKind;
}
} elseif ($currentId > 0) {
Db::name('fc_category')->where('pid', $currentId)->update(['kind' => $kind, 'updatetime' => time()]);
}
$params['kind'] = $kind;
$iconKey = isset($params['icon_key']) ? trim((string)$params['icon_key']) : '';
$image = isset($params['image']) ? trim((string)$params['image']) : '';
if ($image !== '' && $iconKey === '') {
$params['icon_key'] = $image;
} elseif ($iconKey !== '' && $image === '') {
$params['image'] = $this->resolveImageFromKey($iconKey);
} elseif ($iconKey !== '' && preg_match('/^(\/uploads\/|\/static\/|https?:\/\/)/i', $iconKey)) {
$params['image'] = $iconKey;
}
return $params;
}
/**
* 根据 icon_key 推导分类图片路径
*
* @param string $iconKey
* @return string
*/
protected function resolveImageFromKey($iconKey)
{
$iconKey = trim((string)$iconKey);
if ($iconKey === '') {
return '/static/categories/cat-veg.png';
}
if (preg_match('/^(\/uploads\/|\/static\/|https?:\/\/)/i', $iconKey)) {
return $iconKey;
}
$file = strpos($iconKey, '.') !== false ? $iconKey : ($iconKey . '.png');
if (is_file(ROOT_PATH . 'public/static/categories/' . $file)) {
return '/static/categories/' . $file;
}
return '/static/icons/' . $file;
}
/**
@@ -36,14 +214,4 @@ class Category extends Backend
{
return parent::selectpage();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
}

查看文件

@@ -1,6 +1,116 @@
<style>
.fc-form-container {
padding: 15px 15px 0;
background: #f7faf9;
}
/* 分区卡片:把表单切成三个认知区块 */
.fc-section {
background: #ffffff;
border: 1px solid #eef2f6;
border-radius: 14px;
padding: 18px 18px 4px;
margin-bottom: 14px;
box-shadow: 0 1px 4px rgba(15, 23, 42, 0.03);
}
.fc-section-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 14px;
font-weight: 700;
color: #1e293b;
margin-bottom: 16px;
padding-bottom: 10px;
border-bottom: 1px dashed #eef2f6;
}
.fc-sec-icon {
width: 26px;
height: 26px;
border-radius: 8px;
background: #e6fbf1;
color: #00a854;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 13px;
flex: 0 0 auto;
}
.fc-sec-tip {
margin-left: auto;
font-size: 11px;
font-weight: 400;
color: #94a3b8;
}
/* 分类类型:分段选择器 */
.fc-kind-seg {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.fc-kind-seg label {
position: relative;
margin: 0;
cursor: pointer;
flex: 1;
min-width: 180px;
}
.fc-kind-seg input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.fc-kind-seg .fc-pill {
display: block;
padding: 10px 14px;
border-radius: 12px;
border: 1.5px solid #e2e8f0;
background: #f8fafc;
transition: all 0.15s ease;
}
.fc-kind-seg .fc-pill b {
display: block;
font-size: 13.5px;
color: #334155;
margin-bottom: 2px;
}
.fc-kind-seg .fc-pill small {
display: block;
font-size: 11px;
color: #94a3b8;
line-height: 1.5;
}
.fc-kind-seg input:checked + .fc-pill {
border-color: #00d26a;
background: #f2fef7;
box-shadow: 0 0 0 2px rgba(0, 210, 106, 0.18);
}
.fc-kind-seg input:checked + .fc-pill.farm b { color: #059669; }
.fc-kind-seg input:checked + .fc-pill.general b { color: #2563eb; }
.fc-kind-seg input:focus-visible + .fc-pill { outline: 2px solid #00d26a; outline-offset: 2px; }
/* 主题色:原生取色器 */
.fc-color-row {
display: flex;
align-items: center;
gap: 10px;
}
.fc-color-row .form-control { flex: 1; }
.fc-color-native {
width: 42px;
height: 36px;
padding: 2px 3px;
border: 1px solid #e2e8f0;
border-radius: 9px;
background: #ffffff;
cursor: pointer;
flex: 0 0 auto;
}
.fc-color-preview {
width: 42px;
height: 36px;
border-radius: 9px;
border: 1px solid #e2e8f0;
flex: 0 0 auto;
box-shadow: inset 0 0 0 2px #ffffff;
}
/* 当前选中的图标微卡片展示区 */
.fc-current-icon-box {
@@ -18,25 +128,32 @@
align-items: center;
}
.fc-current-icon-info img {
width: 40px;
height: 40px;
object-fit: contain;
width: 44px;
height: 44px;
object-fit: cover;
background: #ffffff;
border-radius: 10px;
padding: 4px;
border: 1px solid #e2e8f0;
box-shadow: 0 2px 6px rgba(0,0,0,0.04);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.fc-icon-actions {
display: flex;
gap: 8px;
}
.fc-icon-actions .btn { border-radius: 9px; font-weight: 600; }
.fc-btn-main {
background: linear-gradient(135deg, #00e070, #00c860) !important;
border: none !important;
color: #04301e !important;
font-weight: 700 !important;
box-shadow: 0 3px 8px rgba(0, 210, 106, 0.28);
}
/* 推荐调色板 */
.fc-color-presets {
display: flex;
align-items: center;
gap: 8px;
margin-top: 8px;
margin-top: 10px;
}
.fc-color-dot {
width: 24px;
@@ -47,15 +164,15 @@
box-shadow: 0 0 0 1px #d5d5d5;
transition: transform 0.15s ease;
}
.fc-color-dot:hover {
transform: scale(1.2);
}
.fc-color-dot:hover { transform: scale(1.2); }
/* 右侧迷你小程序模拟器 */
.fc-preview-box {
position: sticky;
top: 15px;
background: linear-gradient(150deg, #f2fef7 0%, #e6fbf1 100%);
border: 1px solid #c8f2de;
border-radius: 14px;
padding: 16px 14px;
border-radius: 16px;
padding: 18px 14px;
text-align: center;
box-shadow: 0 4px 14px rgba(4, 48, 30, 0.05);
}
@@ -63,31 +180,38 @@
font-size: 12px;
color: #04874a;
font-weight: 700;
margin-bottom: 12px;
margin-bottom: 14px;
}
.fc-preview-badge {
width: 60px;
height: 60px;
width: 64px;
height: 64px;
border-radius: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
margin: 0 auto 8px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(4, 48, 30, 0.08);
transition: all 0.2s ease;
}
.fc-preview-badge img {
width: 38px;
height: 38px;
object-fit: contain;
width: 100%;
height: 100%;
object-fit: cover;
}
.fc-preview-name {
font-size: 14px;
font-weight: 700;
color: #1e293b;
}
.fc-preview-note {
font-size: 11px;
color: #64748b;
margin-top: 10px;
line-height: 1.6;
}
/* 纯插画选择模态窗口(默认严格隐藏,仅在点击按钮后展示) */
/* 插画选择模态窗口 */
.fc-icon-modal-wrap {
display: none;
position: fixed;
@@ -148,7 +272,6 @@
border: none;
font-size: 16px;
}
/* 纯图标网格容器 */
.fc-modal-grid-box {
max-height: 360px;
overflow-y: auto;
@@ -165,6 +288,7 @@
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
@@ -182,9 +306,9 @@
box-shadow: 0 0 0 2px #00E070;
}
.fc-icon-chip img {
width: 44px;
height: 44px;
object-fit: contain;
width: 100%;
height: 100%;
object-fit: cover;
}
@keyframes fcModalZoom {
from { opacity: 0; transform: scale(0.95); }
@@ -194,142 +318,171 @@
<form id="add-form" class="form-horizontal fc-form-container" role="form" data-toggle="validator" method="POST" action="">
<div class="row">
<!-- 左侧核心表单区 -->
<div class="col-xs-12 col-sm-8">
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" placeholder="例如:招聘求职、房产租售、二手闲置" value="">
<!-- 区块一:归属与类型 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-sitemap"></i></span> 归属与类型
<span class="fc-sec-tip">决定发布页展示哪些字段</span>
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">上级分类:</label>
<div class="col-xs-12 col-sm-9">
{:build_select('row[pid]', $parentList, 0, ['class'=>'form-control selectpicker', 'id'=>'c-pid', 'data-rule'=>'required'])}
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">选「顶级分类」创建一级大类;选「蔬菜」「水果」则创建其下属二级品类。</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">
<div class="fc-kind-seg">
<label>
<input type="radio" name="row[kind]" value="farm" checked>
<span class="fc-pill farm"><b><i class="fa fa-leaf"></i> 农产品</b><small>发布时需填写种植面积、采摘时间、量产</small></span>
</label>
<label>
<input type="radio" name="row[kind]" value="general">
<span class="fc-pill general"><b><i class="fa fa-briefcase"></i> 通用信息</b><small>招聘求职等,无产地字段</small></span>
</label>
</div>
<span class="help-block text-muted" style="margin-top:8px;margin-bottom:0;font-size:11px;">二级分类自动跟随上级分类的类型,无需单独设置。</span>
</div>
</div>
</div>
<!-- 分类图标(纯视觉图标控件,无多余文字标签) -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">分类图标:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-current-icon-box">
<div class="fc-current-icon-info">
<img id="current-icon-img" src="/static/icons/cat-job.png?v=2" alt="当前图标">
<!-- 区块二:基本信息 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-pencil-square-o"></i></span> 基本信息
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">分类名称:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" placeholder="例如:蔬菜、水果 或 花菜、白菜、紫甘蓝" value="">
</div>
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">实拍图:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-current-icon-box">
<div class="fc-current-icon-info">
<img id="current-icon-img" src="/static/categories/cat-veg.png?v=2" alt="当前图片">
</div>
<div class="fc-icon-actions">
<button type="button" class="btn btn-success fc-btn-main" id="btn-open-icon-picker">
<i class="fa fa-th-large"></i> 挑选果蔬实拍图
</button>
<button type="button" id="faupload-icon_key" class="btn btn-default faupload" data-input-id="c-icon_key" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/svg+xml" data-multiple="false">
<i class="fa fa-upload text-primary"></i> 上传实拍图
</button>
</div>
</div>
<div class="fc-icon-actions">
<button type="button" class="btn btn-success" id="btn-open-icon-picker" style="background:#00E070;border-color:#00c860;color:#04301e;font-weight:700;">
<i class="fa fa-th-large"></i> 挑选系统插画
</button>
<button type="button" id="faupload-icon_key" class="btn btn-default faupload" data-input-id="c-icon_key" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/svg+xml" data-multiple="false">
<i class="fa fa-upload text-primary"></i> 上传图片
</button>
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">优先上传真实农产品照片,农民用户靠「看图识物」选择品类。</span>
<input type="hidden" name="row[icon_key]" id="c-icon_key" value="cat-veg">
</div>
</div>
</div>
<!-- 区块三:视觉与排序 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-paint-brush"></i></span> 视觉与排序
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">主题色:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-color-row">
<input id="c-color" data-rule="required" class="form-control" name="row[color]" type="text" value="#00E070" placeholder="例如:#00E070">
<input type="color" id="c-color-native" class="fc-color-native" value="#00E070" title="点选颜色">
<span class="fc-color-preview" id="color-preview-addon" style="background:#00E070;"></span>
</div>
<div class="fc-color-presets">
<span style="font-size:11px;color:#64748b;">推荐:</span>
<div class="fc-color-dot" style="background:#00E070;" title="春绿(品牌主色)" data-color="#00E070"></div>
<div class="fc-color-dot" style="background:#F5A623;" title="阳光金" data-color="#F5A623"></div>
<div class="fc-color-dot" style="background:#FF7A59;" title="活力橙" data-color="#FF7A59"></div>
<div class="fc-color-dot" style="background:#2ECC71;" title="翠青绿" data-color="#2ECC71"></div>
<div class="fc-color-dot" style="background:#3498DB;" title="晴空蓝" data-color="#3498DB"></div>
<div class="fc-color-dot" style="background:#9B59B6;" title="典雅紫" data-color="#9B59B6"></div>
</div>
</div>
<!-- 底层安全隐蔽传参 -->
<input type="hidden" name="row[icon_key]" id="c-icon_key" value="cat-job">
</div>
</div>
<!-- 主题色设置 + 推荐调色板 -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Color')}:</label>
<div class="col-xs-12 col-sm-9">
<div class="input-group">
<input id="c-color" data-rule="required" class="form-control" name="row[color]" type="text" value="#00E070" placeholder="例如:#00E070">
<span class="input-group-addon" id="color-preview-addon" style="width:38px;padding:0;background:#00E070;border-color:#ccc;"></span>
</div>
<div class="fc-color-presets">
<span style="font-size:11px;color:#64748b;">推荐配色:</span>
<div class="fc-color-dot" style="background:#00E070;" title="春绿(品牌主色)" data-color="#00E070"></div>
<div class="fc-color-dot" style="background:#FF7A59;" title="活力橙" data-color="#FF7A59"></div>
<div class="fc-color-dot" style="background:#F5A623;" title="阳光金" data-color="#F5A623"></div>
<div class="fc-color-dot" style="background:#2ECC71;" title="翠青绿" data-color="#2ECC71"></div>
<div class="fc-color-dot" style="background:#3498DB;" title="晴空蓝" data-color="#3498DB"></div>
<div class="fc-color-dot" style="background:#9B59B6;" title="典雅紫" data-color="#9B59B6"></div>
<div class="fc-color-dot" style="background:#E67E22;" title="收获橙" data-color="#E67E22"></div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">排序权重:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-sort" data-rule="required" class="form-control" name="row[sort]" type="number" value="10">
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">数值越小越靠前,决定小程序端的排列次序。</span>
</div>
</div>
</div>
<!-- 排序权重 -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Sort')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-sort" data-rule="required" class="form-control" name="row[sort]" type="number" value="10">
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;"><i class="fa fa-info-circle"></i> 数值越小越靠前,直接决定小程序金刚区的排列次序。</span>
</div>
</div>
<!-- 启用状态 -->
<div class="form-group" style="margin-bottom:10px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Enabled')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-enabled" name="row[enabled]" type="hidden" value="1">
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-enabled" data-yes="1" data-no="0">
<i class="fa fa-toggle-on text-success fa-2x"></i>
</a>
<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-enabled" name="row[enabled]" type="hidden" value="1">
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-enabled" data-yes="1" data-no="0">
<i class="fa fa-toggle-on text-success fa-2x"></i>
</a>
</div>
</div>
</div>
<input id="c-post_count" name="row[post_count]" type="hidden" value="0">
</div>
<!-- 右侧:小程序金刚区微缩呈现 -->
<!-- 右侧:小程序端实时预览 -->
<div class="col-xs-12 col-sm-4 hidden-xs">
<div class="fc-preview-box">
<div class="fc-preview-title">
<i class="fa fa-mobile fa-lg"></i> 小程序金刚区·实时呈现
<i class="fa fa-mobile fa-lg"></i> 小程序端 · 实时预览
</div>
<div class="fc-preview-badge" id="preview-badge" style="background: rgba(0, 224, 112, 0.15); border: 1px solid rgba(0, 224, 112, 0.35);">
<img id="preview-icon" src="/static/icons/cat-job.png?v=2" alt="分类图标">
<img id="preview-icon" src="/static/categories/cat-veg.png?v=2" alt="分类图片">
</div>
<div class="fc-preview-name" id="preview-name">未命名分类</div>
<div class="fc-preview-note">修改名称 / 实拍图 / 主题色时<br>此预览会同步更新</div>
</div>
</div>
</div>
<div class="form-group layer-footer" style="margin-top:16px;padding-top:14px;border-top:1px solid #f1f5f9;">
<div class="form-group layer-footer" style="margin-top:10px;padding-top:14px;border-top:1px solid #eef2f6;">
<label class="control-label col-xs-12 col-sm-3"></label>
<div class="col-xs-12 col-sm-9">
<button type="submit" class="btn btn-success btn-embossed disabled" style="background:#00E070;border-color:#00c860;color:#04301e;font-weight:700;"><i class="fa fa-check"></i> 确认保存分类</button>
<button type="submit" class="btn btn-success btn-embossed disabled fc-btn-main"><i class="fa fa-check"></i> 确认保存分类</button>
<button type="reset" class="btn btn-default btn-embossed" style="margin-left:10px;">重置</button>
</div>
</div>
</form>
<!-- 纯插画选择面板(默认完全隐藏,只有主动点击按钮才唤起) -->
<!-- 插画选择面板(默认完全隐藏,只有主动点击按钮才唤起) -->
<div class="fc-icon-modal-wrap" id="fc-icon-modal" style="display:none !important;">
<div class="fc-modal-overlay"></div>
<div class="fc-modal-card">
<div class="fc-modal-header">
<div class="fc-modal-title">
<i class="fa fa-th-large text-success"></i> 选择分类插画
<i class="fa fa-th-large text-success"></i> 选择分类实拍图
</div>
<button type="button" class="fc-modal-close" id="btn-close-icon-modal">&times;</button>
</div>
<!-- 纯插画网格 -->
<div class="fc-modal-grid-box">
<div class="fc-modal-grid">
<div class="fc-icon-chip" data-key="cat-job"><img src="/static/icons/cat-job.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-house"><img src="/static/icons/cat-house.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-goods"><img src="/static/icons/cat-goods.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-car"><img src="/static/icons/cat-car.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-service"><img src="/static/icons/cat-service.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-education"><img src="/static/icons/cat-education.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-clean"><img src="/static/icons/cat-clean.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-friend"><img src="/static/icons/cat-friend.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-pet"><img src="/static/icons/cat-pet.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-food"><img src="/static/icons/cat-food.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-digital"><img src="/static/icons/cat-digital.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-sport"><img src="/static/icons/cat-sport.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-baby"><img src="/static/icons/cat-baby.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-health"><img src="/static/icons/cat-health.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-entertainment"><img src="/static/icons/cat-entertainment.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-community"><img src="/static/icons/cat-community.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-move"><img src="/static/icons/cat-move.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-repair"><img src="/static/icons/cat-repair.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-furniture"><img src="/static/icons/cat-furniture.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-business"><img src="/static/icons/cat-business.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-law"><img src="/static/icons/cat-law.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-consult"><img src="/static/icons/cat-consult.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-vip"><img src="/static/icons/cat-vip.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-photo"><img src="/static/icons/cat-photo.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-veg" title="新鲜蔬菜"><img src="/static/categories/cat-veg.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-fruit" title="时令水果"><img src="/static/categories/cat-fruit.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-cauliflower" title="花菜"><img src="/static/categories/veg-cauliflower.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-cabbage" title="白菜"><img src="/static/categories/veg-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-purple-cabbage" title="紫甘蓝"><img src="/static/categories/veg-purple-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-green-cabbage" title="青甘蓝"><img src="/static/categories/veg-green-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-greens" title="青菜"><img src="/static/categories/veg-greens.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-radish" title="萝卜"><img src="/static/categories/veg-radish.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-chili" title="辣椒"><img src="/static/categories/veg-chili.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-tomato" title="西红柿"><img src="/static/categories/veg-tomato.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-apple" title="苹果"><img src="/static/categories/fruit-apple.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-orange" title="柑橘"><img src="/static/categories/fruit-orange.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-kiwi" title="猕猴桃"><img src="/static/categories/fruit-kiwi.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-strawberry" title="草莓"><img src="/static/categories/fruit-strawberry.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-watermelon" title="西瓜"><img src="/static/categories/fruit-watermelon.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-grape" title="葡萄"><img src="/static/categories/fruit-grape.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-peach" title="蜜桃"><img src="/static/categories/fruit-peach.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-passion" title="百香果"><img src="/static/categories/fruit-passion.png?v=2" alt="icon"></div>
</div>
</div>
</div>

查看文件

@@ -1,6 +1,116 @@
<style>
.fc-form-container {
padding: 15px 15px 0;
background: #f7faf9;
}
/* 分区卡片:把表单切成三个认知区块 */
.fc-section {
background: #ffffff;
border: 1px solid #eef2f6;
border-radius: 14px;
padding: 18px 18px 4px;
margin-bottom: 14px;
box-shadow: 0 1px 4px rgba(15, 23, 42, 0.03);
}
.fc-section-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 14px;
font-weight: 700;
color: #1e293b;
margin-bottom: 16px;
padding-bottom: 10px;
border-bottom: 1px dashed #eef2f6;
}
.fc-sec-icon {
width: 26px;
height: 26px;
border-radius: 8px;
background: #e6fbf1;
color: #00a854;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 13px;
flex: 0 0 auto;
}
.fc-sec-tip {
margin-left: auto;
font-size: 11px;
font-weight: 400;
color: #94a3b8;
}
/* 分类类型:分段选择器 */
.fc-kind-seg {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.fc-kind-seg label {
position: relative;
margin: 0;
cursor: pointer;
flex: 1;
min-width: 180px;
}
.fc-kind-seg input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.fc-kind-seg .fc-pill {
display: block;
padding: 10px 14px;
border-radius: 12px;
border: 1.5px solid #e2e8f0;
background: #f8fafc;
transition: all 0.15s ease;
}
.fc-kind-seg .fc-pill b {
display: block;
font-size: 13.5px;
color: #334155;
margin-bottom: 2px;
}
.fc-kind-seg .fc-pill small {
display: block;
font-size: 11px;
color: #94a3b8;
line-height: 1.5;
}
.fc-kind-seg input:checked + .fc-pill {
border-color: #00d26a;
background: #f2fef7;
box-shadow: 0 0 0 2px rgba(0, 210, 106, 0.18);
}
.fc-kind-seg input:checked + .fc-pill.farm b { color: #059669; }
.fc-kind-seg input:checked + .fc-pill.general b { color: #2563eb; }
.fc-kind-seg input:focus-visible + .fc-pill { outline: 2px solid #00d26a; outline-offset: 2px; }
/* 主题色:原生取色器 */
.fc-color-row {
display: flex;
align-items: center;
gap: 10px;
}
.fc-color-row .form-control { flex: 1; }
.fc-color-native {
width: 42px;
height: 36px;
padding: 2px 3px;
border: 1px solid #e2e8f0;
border-radius: 9px;
background: #ffffff;
cursor: pointer;
flex: 0 0 auto;
}
.fc-color-preview {
width: 42px;
height: 36px;
border-radius: 9px;
border: 1px solid #e2e8f0;
flex: 0 0 auto;
box-shadow: inset 0 0 0 2px #ffffff;
}
/* 当前选中的图标微卡片展示区 */
.fc-current-icon-box {
@@ -18,25 +128,32 @@
align-items: center;
}
.fc-current-icon-info img {
width: 40px;
height: 40px;
object-fit: contain;
width: 44px;
height: 44px;
object-fit: cover;
background: #ffffff;
border-radius: 10px;
padding: 4px;
border: 1px solid #e2e8f0;
box-shadow: 0 2px 6px rgba(0,0,0,0.04);
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.fc-icon-actions {
display: flex;
gap: 8px;
}
.fc-icon-actions .btn { border-radius: 9px; font-weight: 600; }
.fc-btn-main {
background: linear-gradient(135deg, #00e070, #00c860) !important;
border: none !important;
color: #04301e !important;
font-weight: 700 !important;
box-shadow: 0 3px 8px rgba(0, 210, 106, 0.28);
}
/* 推荐调色板 */
.fc-color-presets {
display: flex;
align-items: center;
gap: 8px;
margin-top: 8px;
margin-top: 10px;
}
.fc-color-dot {
width: 24px;
@@ -47,15 +164,15 @@
box-shadow: 0 0 0 1px #d5d5d5;
transition: transform 0.15s ease;
}
.fc-color-dot:hover {
transform: scale(1.2);
}
.fc-color-dot:hover { transform: scale(1.2); }
/* 右侧迷你小程序模拟器 */
.fc-preview-box {
position: sticky;
top: 15px;
background: linear-gradient(150deg, #f2fef7 0%, #e6fbf1 100%);
border: 1px solid #c8f2de;
border-radius: 14px;
padding: 16px 14px;
border-radius: 16px;
padding: 18px 14px;
text-align: center;
box-shadow: 0 4px 14px rgba(4, 48, 30, 0.05);
}
@@ -63,31 +180,38 @@
font-size: 12px;
color: #04874a;
font-weight: 700;
margin-bottom: 12px;
margin-bottom: 14px;
}
.fc-preview-badge {
width: 60px;
height: 60px;
width: 64px;
height: 64px;
border-radius: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
margin: 0 auto 8px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(4, 48, 30, 0.08);
transition: all 0.2s ease;
}
.fc-preview-badge img {
width: 38px;
height: 38px;
object-fit: contain;
width: 100%;
height: 100%;
object-fit: cover;
}
.fc-preview-name {
font-size: 14px;
font-weight: 700;
color: #1e293b;
}
.fc-preview-note {
font-size: 11px;
color: #64748b;
margin-top: 10px;
line-height: 1.6;
}
/* 纯插画选择模态窗口(默认严格隐藏,仅在点击按钮后展示) */
/* 插画选择模态窗口 */
.fc-icon-modal-wrap {
display: none;
position: fixed;
@@ -148,7 +272,6 @@
border: none;
font-size: 16px;
}
/* 纯图标网格容器 */
.fc-modal-grid-box {
max-height: 360px;
overflow-y: auto;
@@ -165,6 +288,7 @@
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
@@ -182,9 +306,9 @@
box-shadow: 0 0 0 2px #00E070;
}
.fc-icon-chip img {
width: 44px;
height: 44px;
object-fit: contain;
width: 100%;
height: 100%;
object-fit: cover;
}
@keyframes fcModalZoom {
from { opacity: 0; transform: scale(0.95); }
@@ -194,151 +318,178 @@
<form id="edit-form" class="form-horizontal fc-form-container" role="form" data-toggle="validator" method="POST" action="">
<div class="row">
<!-- 左侧核心表单区 -->
<div class="col-xs-12 col-sm-8">
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}" placeholder="例如:招聘求职、房产租售、二手闲置">
<!-- 区块一:归属与类型 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-sitemap"></i></span> 归属与类型
<span class="fc-sec-tip">决定发布页展示哪些字段</span>
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">上级分类:</label>
<div class="col-xs-12 col-sm-9">
{:build_select('row[pid]', $parentList, $row.pid, ['class'=>'form-control selectpicker', 'id'=>'c-pid', 'data-rule'=>'required'])}
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">选「顶级分类」创建一级大类;选「蔬菜」「水果」则创建其下属二级品类。</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">
<div class="fc-kind-seg">
<label>
<input type="radio" name="row[kind]" value="farm" {$row.kind == 'farm' ? 'checked' : ''}>
<span class="fc-pill farm"><b><i class="fa fa-leaf"></i> 农产品</b><small>发布时需填写种植面积、采摘时间、量产</small></span>
</label>
<label>
<input type="radio" name="row[kind]" value="general" {$row.kind != 'farm' ? 'checked' : ''}>
<span class="fc-pill general"><b><i class="fa fa-briefcase"></i> 通用信息</b><small>招聘求职等,无产地字段</small></span>
</label>
</div>
<span class="help-block text-muted" style="margin-top:8px;margin-bottom:0;font-size:11px;">修改一级分类类型时,下属二级分类自动同步。</span>
</div>
</div>
</div>
<!-- 分类图标(纯视觉图标控件,无多余文字标签) -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">分类图标:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-current-icon-box">
<div class="fc-current-icon-info">
<img id="current-icon-img" src="/static/icons/{$row.icon_key|htmlentities}.png?v=2" onerror="this.src='/static/icons/cat-job.png'" alt="当前图标">
<!-- 区块二:基本信息 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-pencil-square-o"></i></span> 基本信息
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">分类名称:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}" placeholder="例如:蔬菜、水果 或 花菜、白菜、紫甘蓝">
</div>
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">实拍图:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-current-icon-box">
<div class="fc-current-icon-info">
<img id="current-icon-img" src="/static/categories/{$row.icon_key|htmlentities}.png?v=2" onerror="this.src='/static/categories/cat-veg.png'" alt="当前图片">
</div>
<div class="fc-icon-actions">
<button type="button" class="btn btn-success fc-btn-main" id="btn-open-icon-picker">
<i class="fa fa-th-large"></i> 挑选果蔬实拍图
</button>
<button type="button" id="faupload-icon_key" class="btn btn-default faupload" data-input-id="c-icon_key" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/svg+xml" data-multiple="false">
<i class="fa fa-upload text-primary"></i> 上传实拍图
</button>
</div>
</div>
<div class="fc-icon-actions">
<button type="button" class="btn btn-success" id="btn-open-icon-picker" style="background:#00E070;border-color:#00c860;color:#04301e;font-weight:700;">
<i class="fa fa-th-large"></i> 挑选系统插画
</button>
<button type="button" id="faupload-icon_key" class="btn btn-default faupload" data-input-id="c-icon_key" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/svg+xml" data-multiple="false">
<i class="fa fa-upload text-primary"></i> 上传图片
</button>
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">优先上传真实农产品照片,农民用户靠「看图识物」选择品类。</span>
<input type="hidden" name="row[icon_key]" id="c-icon_key" value="{$row.icon_key|htmlentities}">
</div>
</div>
</div>
<!-- 区块三:视觉与排序 -->
<div class="fc-section">
<div class="fc-section-title">
<span class="fc-sec-icon"><i class="fa fa-paint-brush"></i></span> 视觉与排序
</div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">主题色:</label>
<div class="col-xs-12 col-sm-9">
<div class="fc-color-row">
<input id="c-color" data-rule="required" class="form-control" name="row[color]" type="text" value="{$row.color|htmlentities}" placeholder="例如:#00E070">
<input type="color" id="c-color-native" class="fc-color-native" value="{$row.color|htmlentities}" title="点选颜色">
<span class="fc-color-preview" id="color-preview-addon" style="background:{$row.color|htmlentities};"></span>
</div>
<div class="fc-color-presets">
<span style="font-size:11px;color:#64748b;">推荐:</span>
<div class="fc-color-dot" style="background:#00E070;" title="春绿(品牌主色)" data-color="#00E070"></div>
<div class="fc-color-dot" style="background:#F5A623;" title="阳光金" data-color="#F5A623"></div>
<div class="fc-color-dot" style="background:#FF7A59;" title="活力橙" data-color="#FF7A59"></div>
<div class="fc-color-dot" style="background:#2ECC71;" title="翠青绿" data-color="#2ECC71"></div>
<div class="fc-color-dot" style="background:#3498DB;" title="晴空蓝" data-color="#3498DB"></div>
<div class="fc-color-dot" style="background:#9B59B6;" title="典雅紫" data-color="#9B59B6"></div>
</div>
</div>
<!-- 底层安全隐蔽传参 -->
<input type="hidden" name="row[icon_key]" id="c-icon_key" value="{$row.icon_key|htmlentities}">
</div>
</div>
<!-- 主题色设置 + 推荐调色板 -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Color')}:</label>
<div class="col-xs-12 col-sm-9">
<div class="input-group">
<input id="c-color" data-rule="required" class="form-control" name="row[color]" type="text" value="{$row.color|htmlentities}" placeholder="例如:#00E070">
<span class="input-group-addon" id="color-preview-addon" style="width:38px;padding:0;background:{$row.color|htmlentities};border-color:#ccc;"></span>
</div>
<div class="fc-color-presets">
<span style="font-size:11px;color:#64748b;">推荐配色:</span>
<div class="fc-color-dot" style="background:#00E070;" title="春绿(品牌主色)" data-color="#00E070"></div>
<div class="fc-color-dot" style="background:#FF7A59;" title="活力橙" data-color="#FF7A59"></div>
<div class="fc-color-dot" style="background:#F5A623;" title="阳光金" data-color="#F5A623"></div>
<div class="fc-color-dot" style="background:#2ECC71;" title="翠青绿" data-color="#2ECC71"></div>
<div class="fc-color-dot" style="background:#3498DB;" title="晴空蓝" data-color="#3498DB"></div>
<div class="fc-color-dot" style="background:#9B59B6;" title="典雅紫" data-color="#9B59B6"></div>
<div class="fc-color-dot" style="background:#E67E22;" title="收获橙" data-color="#E67E22"></div>
<div class="form-group" style="margin-bottom:14px;">
<label class="control-label col-xs-12 col-sm-3">排序权重:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-sort" data-rule="required" class="form-control" name="row[sort]" type="number" value="{$row.sort|htmlentities}">
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;">数值越小越靠前,决定小程序端的排列次序。</span>
</div>
</div>
</div>
<!-- 排序权重 -->
<div class="form-group" style="margin-bottom:16px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Sort')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-sort" data-rule="required" class="form-control" name="row[sort]" type="number" value="{$row.sort|htmlentities}">
<span class="help-block text-muted" style="margin-top:4px;margin-bottom:0;font-size:11px;"><i class="fa fa-info-circle"></i> 数值越小越靠前,直接决定小程序金刚区的排列次序。</span>
<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-enabled" name="row[enabled]" type="hidden" value="{$row.enabled}">
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-enabled" data-yes="1" data-no="0">
<i class="fa fa-toggle-on text-success {eq name="$row.enabled" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i>
</a>
</div>
</div>
</div>
<!-- 启用状态 -->
<div class="form-group" style="margin-bottom:12px;">
<label class="control-label col-xs-12 col-sm-3">{:__('Enabled')}:</label>
<div class="col-xs-12 col-sm-9">
<input id="c-enabled" name="row[enabled]" type="hidden" value="{$row.enabled}">
<a href="javascript:;" data-toggle="switcher" class="btn-switcher" data-input-id="c-enabled" data-yes="1" data-no="0">
<i class="fa fa-toggle-on text-success {eq name="$row.enabled" value="0"}fa-flip-horizontal text-gray{/eq} fa-2x"></i>
</a>
</div>
</div>
<!-- 帖子统计信息(只读展示) -->
<div class="form-group" style="margin-bottom:0;">
<label class="control-label col-xs-12 col-sm-3">{:__('Post_count')}:</label>
<div class="col-xs-12 col-sm-9">
<p class="form-control-static" style="padding-top:7px;color:#64748b;font-weight:600;">
<span class="label label-success" style="background:#eaf8f1;color:#04874a;">{$row.post_count|htmlentities} 篇已审核帖子</span>
</p>
<input id="c-post_count" type="hidden" name="row[post_count]" value="{$row.post_count|htmlentities}">
<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">
<p class="form-control-static" style="padding-top:7px;">
<span class="label" style="background:#eaf8f1;color:#04874a;font-size:12px;padding:5px 10px;border-radius:8px;">{$row.post_count|htmlentities} 篇已审核帖子</span>
</p>
<input id="c-post_count" type="hidden" name="row[post_count]" value="{$row.post_count|htmlentities}">
</div>
</div>
</div>
</div>
<!-- 右侧:小程序金刚区微缩呈现 -->
<!-- 右侧:小程序端实时预览 -->
<div class="col-xs-12 col-sm-4 hidden-xs">
<div class="fc-preview-box">
<div class="fc-preview-title">
<i class="fa fa-mobile fa-lg"></i> 小程序金刚区·实时呈现
<i class="fa fa-mobile fa-lg"></i> 小程序端 · 实时预览
</div>
<div class="fc-preview-badge" id="preview-badge" style="background: rgba(0, 224, 112, 0.15); border: 1px solid rgba(0, 224, 112, 0.35);">
<img id="preview-icon" src="/static/icons/{$row.icon_key|htmlentities}.png?v=2" onerror="this.src='/static/icons/cat-job.png'" alt="分类图标">
<img id="preview-icon" src="/static/categories/{$row.icon_key|htmlentities}.png?v=2" onerror="this.src='/static/categories/cat-veg.png'" alt="分类图片">
</div>
<div class="fc-preview-name" id="preview-name">{$row.name|htmlentities}</div>
<div class="fc-preview-note">修改名称 / 实拍图 / 主题色时<br>此预览会同步更新</div>
</div>
</div>
</div>
<div class="form-group layer-footer" style="margin-top:16px;padding-top:14px;border-top:1px solid #f1f5f9;">
<div class="form-group layer-footer" style="margin-top:10px;padding-top:14px;border-top:1px solid #eef2f6;">
<label class="control-label col-xs-12 col-sm-3"></label>
<div class="col-xs-12 col-sm-9">
<button type="submit" class="btn btn-success btn-embossed disabled" style="background:#00E070;border-color:#00c860;color:#04301e;font-weight:700;"><i class="fa fa-check"></i> 确认保存修改</button>
<button type="submit" class="btn btn-success btn-embossed disabled fc-btn-main"><i class="fa fa-check"></i> 确认保存修改</button>
<button type="reset" class="btn btn-default btn-embossed" style="margin-left:10px;">重置</button>
</div>
</div>
</form>
<!-- 纯插画选择面板(默认完全隐藏,只有主动点击按钮才唤起) -->
<!-- 插画选择面板(默认完全隐藏,只有主动点击按钮才唤起) -->
<div class="fc-icon-modal-wrap" id="fc-icon-modal" style="display:none !important;">
<div class="fc-modal-overlay"></div>
<div class="fc-modal-card">
<div class="fc-modal-header">
<div class="fc-modal-title">
<i class="fa fa-th-large text-success"></i> 选择分类插画
<i class="fa fa-th-large text-success"></i> 选择分类实拍图
</div>
<button type="button" class="fc-modal-close" id="btn-close-icon-modal">&times;</button>
</div>
<!-- 纯插画网格 -->
<div class="fc-modal-grid-box">
<div class="fc-modal-grid">
<div class="fc-icon-chip" data-key="cat-job"><img src="/static/icons/cat-job.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-house"><img src="/static/icons/cat-house.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-goods"><img src="/static/icons/cat-goods.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-car"><img src="/static/icons/cat-car.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-service"><img src="/static/icons/cat-service.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-education"><img src="/static/icons/cat-education.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-clean"><img src="/static/icons/cat-clean.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-friend"><img src="/static/icons/cat-friend.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-pet"><img src="/static/icons/cat-pet.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-food"><img src="/static/icons/cat-food.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-digital"><img src="/static/icons/cat-digital.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-sport"><img src="/static/icons/cat-sport.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-baby"><img src="/static/icons/cat-baby.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-health"><img src="/static/icons/cat-health.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-entertainment"><img src="/static/icons/cat-entertainment.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-community"><img src="/static/icons/cat-community.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-move"><img src="/static/icons/cat-move.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-repair"><img src="/static/icons/cat-repair.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-furniture"><img src="/static/icons/cat-furniture.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-business"><img src="/static/icons/cat-business.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-law"><img src="/static/icons/cat-law.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-consult"><img src="/static/icons/cat-consult.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-vip"><img src="/static/icons/cat-vip.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-photo"><img src="/static/icons/cat-photo.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-veg" title="新鲜蔬菜"><img src="/static/categories/cat-veg.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="cat-fruit" title="时令水果"><img src="/static/categories/cat-fruit.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-cauliflower" title="花菜"><img src="/static/categories/veg-cauliflower.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-cabbage" title="白菜"><img src="/static/categories/veg-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-purple-cabbage" title="紫甘蓝"><img src="/static/categories/veg-purple-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-green-cabbage" title="青甘蓝"><img src="/static/categories/veg-green-cabbage.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-greens" title="青菜"><img src="/static/categories/veg-greens.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-radish" title="萝卜"><img src="/static/categories/veg-radish.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-chili" title="辣椒"><img src="/static/categories/veg-chili.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="veg-tomato" title="西红柿"><img src="/static/categories/veg-tomato.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-apple" title="苹果"><img src="/static/categories/fruit-apple.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-orange" title="柑橘"><img src="/static/categories/fruit-orange.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-kiwi" title="猕猴桃"><img src="/static/categories/fruit-kiwi.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-strawberry" title="草莓"><img src="/static/categories/fruit-strawberry.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-watermelon" title="西瓜"><img src="/static/categories/fruit-watermelon.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-grape" title="葡萄"><img src="/static/categories/fruit-grape.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-peach" title="蜜桃"><img src="/static/categories/fruit-peach.png?v=2" alt="icon"></div>
<div class="fc-icon-chip" data-key="fruit-passion" title="百香果"><img src="/static/categories/fruit-passion.png?v=2" alt="icon"></div>
</div>
</div>
</div>

查看文件

@@ -1,24 +1,115 @@
<style>
/* ===== 分类管理列表 · 轻氧薄荷主题 ===== */
.panel-intro > .panel-heading { border-bottom: none; }
/* 提示条:更轻更薄 */
.fc-cat-notice {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
padding: 10px 14px;
background: linear-gradient(90deg, #f2fef7, #ffffff);
border: 1px solid #d9f5e6;
border-left: 4px solid #00d26a;
border-radius: 10px;
color: #334155;
font-size: 12.5px;
line-height: 1.6;
}
.fc-cat-notice .fa { color: #00a854; font-size: 15px; }
.fc-cat-notice strong { color: #1e293b; }
/* 工具栏按钮:图标 + 主题化 */
.toolbar .btn { border-radius: 8px; font-weight: 600; padding: 6px 14px; }
.toolbar .btn-refresh { background: #fff; border: 1px solid #dbe6ee; color: #475569; }
.toolbar .btn-refresh:hover { border-color: #00d26a; color: #00a854; }
.toolbar .btn-success { background: linear-gradient(135deg, #00e070, #00c860); border: none; color: #04301e; box-shadow: 0 3px 8px rgba(0, 210, 106, 0.28); }
.toolbar .btn-success:hover { background: linear-gradient(135deg, #00d26a, #00b856); }
.toolbar .btn-danger { border-radius: 8px; }
/* 表格:去重边框,柔和横线 + 薄荷表头 */
.fc-cat-table { border-collapse: separate !important; border-spacing: 0 !important; }
.fc-cat-table thead th {
background: #f2fef7 !important;
color: #1e293b !important;
font-weight: 700 !important;
border-bottom: 2px solid #d9f5e6 !important;
border-top: none !important;
border-left: none !important;
border-right: none !important;
padding: 11px 12px !important;
white-space: nowrap;
}
.fc-cat-table tbody td {
border: none !important;
border-bottom: 1px solid #f1f7f3 !important;
padding: 10px 12px !important;
vertical-align: middle !important;
}
.fc-cat-table tbody tr:hover td { background: #f7fdfa !important; }
.fc-cat-table tbody tr:last-child td { border-bottom: none !important; }
/* 树形层级缩进:子分类带弧形引导线 */
.fc-tree-sub { position: relative; padding-left: 26px; }
.fc-tree-sub::before {
content: '';
position: absolute;
left: 8px;
top: 50%;
width: 12px;
height: 14px;
margin-top: -8px;
border-left: 2px solid #bcead1;
border-bottom: 2px solid #bcead1;
border-bottom-left-radius: 8px;
}
/* 实拍图悬浮放大预览 */
.fc-img-wrap { position: relative; display: inline-block; }
.fc-img-wrap .fc-img-zoom {
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%) scale(0.85);
width: 200px;
height: 200px;
border-radius: 14px;
overflow: hidden;
border: 3px solid #ffffff;
box-shadow: 0 12px 32px rgba(4, 48, 30, 0.22);
opacity: 0;
pointer-events: none;
transition: opacity 0.15s ease, transform 0.15s ease;
z-index: 500;
}
.fc-img-wrap .fc-img-zoom img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fc-img-wrap:hover .fc-img-zoom { opacity: 1; transform: translateX(-50%) scale(1); }
/* 分页与信息区 */
.fixed-table-pagination .pagination-detail, .fixed-table-pagination .page-list { color: #64748b; }
.fixed-table-pagination .pagination > li > a { border-radius: 8px !important; margin: 0 2px; border: 1px solid #e2e8f0; }
.fixed-table-pagination .pagination > li.active > a { background: #00d26a; border-color: #00d26a; color: #fff; }
</style>
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-body">
<div class="alert alert-success-light" style="margin-bottom:15px;border-radius:8px;border-left:4px solid #00E070;background:#f2fef7;color:#04301e;">
<i class="fa fa-info-circle fa-lg"></i>
<strong>分类展示与运营规则说明:</strong>
此处的分类直接联动微信小程序首页<strong>「金刚区导航」</strong>与<strong>「全部分类频道」</strong>。
列表已默认按<strong>「排序权重」从小到大</strong>升序排列(所见即所得)。点击状态开关可<strong>一键上架/下架</strong>,点击【添加】或【编辑】可在右侧<strong>实时预览小程序端呈现效果</strong>。
<div class="fc-cat-notice">
<i class="fa fa-info-circle"></i>
<div>分类直接联动小程序<strong>首页金刚区</strong>与<strong>分类频道</strong>,按排序权重升序展示。点击开关可<strong>一键上架/下架</strong>,鼠标悬停实拍图可<strong>放大预览</strong>。</div>
</div>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}">刷新</a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('fc/category/add')?'':'hide'}" title="{:__('Add')}">添加</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('fc/category/edit')?'':'hide'}" title="{:__('Edit')}">{:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('fc/category/del')?'':'hide'}" title="{:__('Delete')}">{:__('Delete')}</a>
<a href="javascript:;" class="btn btn-refresh btn-refresh"><i class="fa fa-refresh"></i> 刷新</a>
<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>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
<table id="table" class="table table-hover table-nowrap fc-cat-table"
data-operate-edit="{:$auth->check('fc/category/edit')}"
data-operate-del="{:$auth->check('fc/category/del')}"
width="100%">

查看文件

@@ -126,10 +126,38 @@
</div>
</div>
<div class="col-xs-12 col-sm-6">
<span class="help-block">普通用户解锁单条帖子联系方式的价格(同一条信息一次解锁永久有效;VIP 会员每日免费看次数在各会员套餐中设置)</span>
<span class="help-block">普通用户超额后解锁单条帖子拨打权限的价格(同一条信息一次解锁永久有效)</span>
</div>
</div>
</div>
<hr style="border-top: 1px dashed #e2e8f0; margin: 18px 0;">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">普通用户每日拨打上限:</label>
<div class="col-xs-12 col-sm-4">
<div class="input-group">
<input type="number" min="0" step="1" class="form-control" name="row[fc_call_normalDailyQuota]" value="{$row.callNormalDailyQuota|default=5|htmlentities}" data-rule="required;integer;range(0~)"/>
<span class="input-group-addon">次 / 日</span>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<span class="help-block">详情页与商家详情页统一隐藏明文手机号,仅保留拨打按钮;填 <code>0</code> 表示不限次数</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">VIP会员每日拨打上限:</label>
<div class="col-xs-12 col-sm-4">
<div class="input-group">
<input type="number" min="0" step="1" class="form-control" name="row[fc_call_vipDailyQuota]" value="{$row.callVipDailyQuota|default=30|htmlentities}" data-rule="required;integer;range(0~)"/>
<span class="input-group-addon">次 / 日</span>
</div>
</div>
<div class="col-xs-12 col-sm-6">
<span class="help-block">VIP 会员每日可拨打电话次数上限(填 <code>0</code> 表示 VIP 会员不限拨打次数)</span>
</div>
</div>
</div>
<!-- Tab 3:分销配置 -->

查看文件

@@ -3,16 +3,17 @@
namespace app\api\controller;
use think\Db;
use app\common\library\NationalArea;
/**
* 用户端 · 首页与展示(Module-HOME)
* 路由:
* GET /api/v1/home/banners H1 轮播广告位
* GET /api/v1/home/categories H2 分类导航
* GET /api/v1/home/categories H2 分类导航(含二级分类树与实拍图)
* GET /api/v1/home/search/hot H3 热门搜索
* GET /api/v1/home/feed H4 信息流(支持 lat/lng + sort=nearby 距离排序)
* GET /api/v1/home/areas H5 服务区域列表(平铺省/市/区县,区县为服务区域)
* GET /api/v1/home/locate H6 按定位坐标匹配服务区域
* GET /api/v1/home/feed H4 信息流(支持全国省/市/区县筛选 + 一二级分类筛选 + 距离排序)
* GET /api/v1/home/areas H5 全国服务区域列表(平铺省/市/区县)
* GET /api/v1/home/locate H6 按定位坐标匹配全国当前区县
*/
class Home extends V1
{
@@ -48,41 +49,82 @@ class Home extends V1
}
/**
* H2 分类导航
* GET /api/v1/home/categories → [{id,name,iconKey,icon,color,count}]
* 规则:仅 enabled=1,按 sort asc;icon 为固定 /static/icons/ 文件名(按 id 映射)
* H2 分类导航(一级分类 + 二级分类树,附带农产品实拍图)
* GET /api/v1/home/categories → [{id,pid,name,iconKey,icon,image,color,count,children:[...]}]
* 规则:仅 enabled=1,按 sort asc;一级分类下挂 children 二级分类列表
*
* @return void
*/
public function categories()
{
$rows = Db::name('fc_category')
->where('enabled', 1)
->order('sort asc')
->order('pid asc, sort asc, id asc')
->select();
$list = [];
$parents = [];
$childrenMap = [];
foreach ($rows as $row) {
$id = (int)$row['id'];
$pid = isset($row['pid']) ? (int)$row['pid'] : 0;
$iconKey = (string)$row['icon_key'];
$list[] = [
$rawImage = isset($row['image']) ? (string)$row['image'] : '';
$iconPath = $this->resolveCategoryIconPath($id, $iconKey, $rawImage);
$imagePath = $rawImage !== '' ? $rawImage : $iconPath;
$item = [
'id' => $id,
'pid' => $pid,
'name' => (string)$row['name'],
'iconKey' => $iconKey,
'icon' => $this->resolveCategoryIconPath($id, $iconKey),
'icon' => $iconPath,
'image' => $imagePath,
'color' => (string)$row['color'],
'kind' => isset($row['kind']) && $row['kind'] === 'farm' ? 'farm' : 'general',
'count' => (int)$row['post_count'],
];
if ($pid === 0) {
$item['children'] = [];
$parents[$id] = $item;
} else {
if (!isset($childrenMap[$pid])) {
$childrenMap[$pid] = [];
}
$childrenMap[$pid][] = $item;
}
}
$list = [];
foreach ($parents as $pid => $parent) {
$parent['children'] = isset($childrenMap[$pid]) ? $childrenMap[$pid] : [];
$list[] = $parent;
}
// 兜底:若数据库中仅有未挂载父级的孤立分类,直接返回
if (empty($list) && !empty($childrenMap)) {
foreach ($childrenMap as $group) {
foreach ($group as $c) {
$c['children'] = [];
$list[] = $c;
}
}
}
$this->ok($list);
}
/**
* H3 热门搜索
* GET /api/v1/home/search/hot → [string]
* 规则:读配置 home.hotKeywords,未配置则返回默认
* 规则:读配置 home.hotKeywords,未配置则返回农产品热门搜索词
*
* @return void
*/
public function hotKeywords()
{
$default = ['租房 一室一厅', '二手电动车', '急招快递员', '钢琴家教', '空调维修'];
$default = ['有机花菜', '高山大白菜', '红富士苹果', '大棚草莓', '修文猕猴桃'];
$keywords = $this->cfg('home.hotKeywords', $default);
if (!is_array($keywords) || !$keywords) {
$keywords = $default;
@@ -91,37 +133,24 @@ class Home extends V1
}
/**
* H5 服务区域列表(平铺:每条记录自带省 / 市 / 区县)
* H5 全国服务区域列表(平铺:每条记录自带省 / 市 / 区县)
* GET /api/v1/home/areas → [{id,province,city,district,lat,lng}]
* 规则:仅 enabled=1;按省、市、sort、id 排序。
* 区县为最终服务区域;省 / 市由前端按 distinct 值生成级联列。
* 规则:默认开放全国所有省市区县,供小程序端省/市/区三级联动选择。
*
* @return void
*/
public function areas()
{
$rows = Db::name('fc_area')
->where('enabled', 1)
->order('province asc, city asc, sort asc, id asc')
->select();
$list = [];
foreach ($rows as $row) {
$list[] = [
'id' => (int)$row['id'],
'province' => (string)$row['province'],
'city' => (string)$row['city'],
'district' => (string)$row['district'],
'lat' => $row['lat'] !== null ? (float)$row['lat'] : null,
'lng' => $row['lng'] !== null ? (float)$row['lng'] : null,
];
}
$list = NationalArea::all();
$this->ok($list);
}
/**
* H6 按定位坐标匹配服务区域(区县)
* H6 按定位坐标匹配全国当前服务区域(省/市/区县)
* GET /api/v1/home/locate?lat=&lng= → {areaId,province,city,district,distance}
* 规则:在启用的服务区域中心点中取最近的一个(Haversine),超出 300km 视为不在服务范围,返回 null。
* 规则:在全国区县字典中匹配距离当前坐标最近的区县。
*
* @return void
*/
public function locate()
{
@@ -136,107 +165,132 @@ class Home extends V1
$this->ok(null);
}
$rows = Db::name('fc_area')
->where('enabled', 1)
->whereNotNull('lat')
->whereNotNull('lng')
->select();
$best = null;
foreach ($rows as $row) {
$distance = $this->haversine($lat, $lng, (float)$row['lat'], (float)$row['lng']);
if ($best === null || $distance < $best['distance']) {
$best = ['row' => $row, 'distance' => $distance];
}
}
if (!$best || $best['distance'] > 300) {
$this->ok(null);
}
$area = $best['row'];
$this->ok([
'areaId' => (int)$area['id'],
'province' => (string)$area['province'],
'city' => (string)$area['city'],
'district' => (string)$area['district'],
'distance' => $best['distance'],
]);
$matched = NationalArea::locate($lat, $lng);
$this->ok($matched);
}
/**
* H4 信息流
* GET /api/v1/home/feed {categoryId?,keyword?,areaId?,area?,sort?,lat?,lng?,page,size}
* GET /api/v1/home/feed {categoryId?,subCategoryId?,keyword?,province?,city?,areaId?,area?,sort?,lat?,lng?,page,size}
* → {list,page,size,total,hasMore}
* 规则:仅 audit_status=1 AND status=1 AND deletetime IS NULL
* - sort=nearby 时按距离升序(无坐标的信息排最后;请求未带 lat/lng 则回落发布时间倒序);
* - 列表项 distance 为 km(一位小数),请求未带坐标 / 信息未定位时为 null。
*
* @return void
*/
public function feed()
{
list($page, $size) = $this->pager();
$categoryId = (int)$this->input('categoryId', 0);
$subCategoryId = (int)$this->input('subCategoryId', 0);
$keyword = trim((string)$this->input('keyword', ''));
$province = trim((string)$this->input('province', ''));
$city = trim((string)$this->input('city', ''));
$area = trim((string)$this->input('area', ''));
// 服务区域 ID(兼容上一版的 districtId 参数)
$areaId = (int)$this->input('areaId', 0);
if (!$areaId) {
$areaId = (int)$this->input('districtId', 0);
}
$sort = (string)$this->input('sort', '');
// 容错处理:过滤前端小程序可能序列化出的 undefined 与 null 字符串
if ($area === 'undefined' || $area === 'null') {
foreach (['province', 'city', 'area', 'keyword', 'sort'] as $strVar) {
if ($$strVar === 'undefined' || $$strVar === 'null') {
$$strVar = '';
}
}
if (in_array($province, ['全部', '全国', '不限'], true)) {
$province = '';
}
if (in_array($city, ['全部', '全市', '全州', '不限'], true)) {
$city = '';
}
if (in_array($area, ['全部', '全区', '全城', '全国', '不限'], true)) {
$area = '';
}
if ($keyword === 'undefined' || $keyword === 'null') {
$keyword = '';
}
if ($sort === 'undefined' || $sort === 'null') {
$sort = '';
}
$query = Db::name('fc_post')
->where('audit_status', 1)
->where('status', 1)
->whereNull('deletetime');
if ($categoryId > 0) {
$query->where('category_id', $categoryId);
}
if ($keyword !== '') {
$query->where('title', 'like', '%' . $keyword . '%');
}
$applyArea = function ($q) use ($area, $areaId) {
// 服务区域 = 区县:areaId 优先,兼容旧的 area=区县名称
if ($areaId > 0) {
$row = Db::name('fc_area')->where('id', $areaId)->find();
if ($row) {
$q->where(function ($w) use ($row) {
$w->where('district_id', (int)$row['id'])->whereOr('area', (string)$row['district']);
// 若传入的 categoryId 本身是二级分类(pid > 0),自动作为二级分类匹配
$catRow = $categoryId > 0 ? Db::name('fc_category')->where('id', $categoryId)->find() : null;
$isSubCatId = $catRow && !empty($catRow['pid']) && (int)$catRow['pid'] > 0;
$applyCategory = function ($q) use ($categoryId, $subCategoryId, $isSubCatId) {
if ($subCategoryId > 0) {
$q->where(function ($w) use ($subCategoryId) {
$w->where('sub_category_id', $subCategoryId)->whereOr('category_id', $subCategoryId);
});
return;
}
if ($categoryId > 0) {
if ($isSubCatId) {
$q->where(function ($w) use ($categoryId) {
$w->where('sub_category_id', $categoryId)->whereOr('category_id', $categoryId);
});
} else {
$q->where('category_id', $categoryId);
}
}
};
$applyArea = function ($q) use ($province, $city, $area, $areaId) {
if ($areaId > 0) {
$natRow = NationalArea::findById($areaId);
if (!$natRow) {
$natRow = Db::name('fc_area')->where('id', $areaId)->find();
}
if ($natRow) {
$q->where(function ($w) use ($natRow) {
$w->where('district_id', (int)$natRow['id'])->whereOr('area', (string)$natRow['district']);
});
} else {
$q->where('district_id', $areaId);
}
return;
}
if ($area !== '') {
$q->where('area', $area);
return;
}
if ($city !== '') {
$cityDistricts = [];
foreach (NationalArea::all() as $item) {
if ($item['city'] === $city || rtrim($item['city'], '市') === rtrim($city, '市')) {
$cityDistricts[] = $item['district'];
}
}
$q->where(function ($w) use ($city, $cityDistricts) {
$w->where('city', $city);
if (!empty($cityDistricts)) {
$w->whereOr('area', 'in', array_slice(array_unique($cityDistricts), 0, 100));
}
});
return;
}
if ($province !== '') {
$q->where('province', $province);
}
};
$applyArea($query);
// 付费发帖拦截:未付清款项的帖子(微信支付待付款)严禁向外展示
$applyPaid = function ($q) {
$q->where(function ($w) {
$w->where('amount', 'null')->whereOr('amount', '<=', 0)->whereOr('is_paid', 1);
});
};
$query = Db::name('fc_post')
->where('audit_status', 1)
->where('status', 1)
->whereNull('deletetime');
$applyCategory($query);
if ($keyword !== '') {
$query->where('title', 'like', '%' . $keyword . '%');
}
$applyArea($query);
$applyPaid($query);
$counter = Db::name('fc_post')
->where('audit_status', 1)
->where('status', 1)
->whereNull('deletetime');
if ($categoryId > 0) {
$counter->where('category_id', $categoryId);
}
$applyCategory($counter);
if ($keyword !== '') {
$counter->where('title', 'like', '%' . $keyword . '%');
}
@@ -244,8 +298,6 @@ class Home extends V1
$applyPaid($counter);
$total = $counter->count();
// 「附近」:距离在 PHP 内用 Haversine 计算后排序(不用 SQL 距离函数,避免 MySQL 兼容问题);
// 因排序依赖计算结果,这里取全量匹配行排序后再做**内存分页**,保证 page/size/total 一致。
if ($sort === 'nearby') {
$rows = $query->order('createtime desc')->select();
$items = [];
@@ -260,12 +312,12 @@ class Home extends V1
$na = $a['distance'] === null;
$nb = $b['distance'] === null;
if ($na !== $nb) {
return $na ? 1 : -1; // 无坐标的排最后
return $na ? 1 : -1;
}
if (!$na && $a['distance'] != $b['distance']) {
return $a['distance'] < $b['distance'] ? -1 : 1;
}
return $b['ct'] - $a['ct']; // 距离相同(或都无坐标):新的在前
return $b['ct'] - $a['ct'];
});
$list = [];
foreach ($items as $it) {
@@ -274,12 +326,13 @@ class Home extends V1
$this->ok($this->paginateArray($list, $page, $size));
}
if ($sort === 'price') {
if ($sort === 'price_desc') {
$query->order('is_top desc, price desc');
} elseif ($sort === 'price' || $sort === 'price_asc') {
$query->order('is_top desc, price asc');
} elseif ($sort === 'hot') {
$query->order('is_top desc, views desc');
} else {
// 后台「置顶」优先展示,其余按发布时间倒序
$query->order('is_top desc, createtime desc');
}
@@ -294,7 +347,7 @@ class Home extends V1
}
/**
* Haversine 距离(km,一位小数)—— 与 Post 控制器同一算法
* Haversine 距离(km,一位小数)
* @return float
*/
protected function haversine($lat1, $lng1, $lat2, $lng2)
@@ -335,7 +388,7 @@ class Home extends V1
}
/**
* 组装 Post 结构(与前端 mock 数据字段严格对齐)
* 组装 Post 结构(含二级分类与农产品属性)
* @param array $row fc_post 行
* @return array
*/
@@ -349,6 +402,15 @@ class Home extends V1
}
}
$subCategoryId = isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0;
$subCategoryName = '';
if ($subCategoryId > 0) {
$subCat = Db::name('fc_category')->where('id', $subCategoryId)->find();
if ($subCat) {
$subCategoryName = (string)$subCat['name'];
}
}
$publisher = ['id' => 0, 'name' => '', 'avatar' => '', 'isMerchant' => false, 'verified' => false];
if (!empty($row['user_id'])) {
$pub = Db::name('user')->where('id', $row['user_id'])->find();
@@ -376,82 +438,76 @@ class Home extends V1
}
return [
'id' => (int)$row['id'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $categoryName,
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'cover' => (string)$row['cover'],
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'contact' => $this->maskPhone($row['phone']),
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'isPaid' => (int)$row['is_paid'] === 1,
'isTop' => (int)$row['is_top'] === 1,
'auditStatus' => (int)$row['audit_status'],
'createdAt' => $this->iso($row['createtime']),
'tags' => $tags,
'publisher' => $publisher,
'commentCount' => (int)$row['comment_count'],
'distance' => $this->postDistance($row),
'id' => (int)$row['id'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $categoryName,
'subCategoryId' => $subCategoryId,
'subCategoryName' => $subCategoryName,
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'cover' => (string)$row['cover'],
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'province' => isset($row['province']) ? (string)$row['province'] : '',
'city' => isset($row['city']) ? (string)$row['city'] : '',
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
'contact' => $this->maskPhone($row['phone']),
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'isPaid' => (int)$row['is_paid'] === 1,
'isTop' => (int)$row['is_top'] === 1,
'auditStatus' => (int)$row['audit_status'],
'createdAt' => $this->iso($row['createtime']),
'tags' => $tags,
'publisher' => $publisher,
'commentCount' => (int)$row['comment_count'],
'distance' => $this->postDistance($row),
];
}
/**
* 全兼容分类图标路径解析
* 规则:网络URL或相对路径直接透传;支持根据 iconKey 或 分类 ID 智能映射内置图标;默认回落 cat-job.png 兜底
* @param int $id 分类ID
* 全兼容分类图标/实拍图路径解析
* @param int $id 分类ID
* @param string $iconKey 分类图标键名或图片路径
* @param string $image 分类实拍图路径
* @return string
*/
protected function resolveCategoryIconPath($id, $iconKey = '')
protected function resolveCategoryIconPath($id, $iconKey = '', $image = '')
{
if ($image !== '' && preg_match('/^https?:\/\/|^\/uploads\/|^\/static\//i', $image)) {
return $image;
}
if ($iconKey !== '') {
if (preg_match('/^https?:\/\/|^\/uploads\/|^\/static\//i', $iconKey)) {
return $iconKey;
}
$iconFileName = (strpos($iconKey, '.') !== false) ? $iconKey : $iconKey . '.png';
if (file_exists(ROOT_PATH . 'public/static/categories/' . $iconFileName)) {
return '/static/categories/' . $iconFileName;
}
if (file_exists(ROOT_PATH . 'public/static/icons/' . $iconFileName)) {
return '/static/icons/' . $iconFileName;
}
$keyMap = [
'cat-job' => 'cat-job.png',
'cat-house' => 'cat-house.png',
'cat-goods' => 'cat-goods.png',
'cat-car' => 'cat-car.png',
'cat-service' => 'cat-service.png',
'cat-education' => 'cat-education.png',
'cat-clean' => 'cat-clean.png',
'cat-friend' => 'cat-friend.png',
];
if (isset($keyMap[$iconKey])) {
return '/static/icons/' . $keyMap[$iconKey];
}
}
return '/static/icons/' . $this->iconFile($id);
return '/static/categories/' . $this->iconFile($id);
}
/**
* 分类 id → 固定图标文件名(向下兼容)
* 分类 id → 默认图标文件名
* @param int $id
* @return string
*/
protected function iconFile($id)
{
$map = [
1 => 'cat-job.png',
2 => 'cat-house.png',
3 => 'cat-goods.png',
4 => 'cat-car.png',
5 => 'cat-service.png',
6 => 'cat-education.png',
7 => 'cat-clean.png',
8 => 'cat-friend.png',
1 => 'cat-veg.png',
2 => 'cat-fruit.png',
];
return isset($map[$id]) ? $map[$id] : 'cat-job.png';
return isset($map[$id]) ? $map[$id] : 'cat-veg.png';
}
}

查看文件

@@ -7,15 +7,16 @@ use think\Db;
/**
* 用户端 · 商家门店与主页(Module-MERCHANT)
* 路由:
* GET /api/v1/merchant/:id M1 商家公开主页/门店详情
* GET /api/v1/merchant/:id/posts M2 商家名下发布的信息流(分页)
* GET /api/v1/merchant/:id M1 商家公开主页/门店详情(手机号隐藏脱敏)
* POST /api/v1/merchant/:id/dial M1-B 商家门店申请拨打电话(校验每日拨打次数上限)
* GET /api/v1/merchant/:id/posts M2 商家名下发布的信息流(分页)
*/
class Merchant extends V1
{
/**
* M1 获取商家门店详情及公开档案
* GET /api/v1/merchant/:id
* 规则:允许游客;支持通过 merchant.id 或 user_id 查询;若提供客户端坐标则计算到店距离
* 规则:允许游客;支持通过 merchant.id 或 user_id 查询;界面隐藏明文手机号,仅保留拨打按钮与免责弹窗
*
* @return void
*/
@@ -62,9 +63,10 @@ class Merchant extends V1
// 首屏拉取前 6 条该商家的有效发帖
$posts = $this->fetchMerchantPosts($m['user_id'], 1, 6);
// 严格保护商家联系电话:未付费解锁或非会员状态下脱敏,杜绝从信息详情页跳转商家主页白嫖绕过
$rawContact = (string)(isset($m['contact']) ? $m['contact'] : '');
$unlocked = false;
// 商家详情页统一隐藏明文手机号(仅返回脱敏号码),通过 POST /merchant/:id/dial 校验每日拨打次数上限
$rawContact = trim((string)(isset($m['contact']) ? $m['contact'] : ''));
$isMember = false;
$isOwner = false;
$me = $this->user();
if ($me) {
$now = time();
@@ -72,24 +74,11 @@ class Merchant extends V1
$isMember = (int)$ext['is_member'] === 1
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
$isOwner = (int)$m['user_id'] === (int)$me['id'];
if ($isOwner || $isMember) {
$unlocked = true;
} else {
// 检查是否从已解锁的关联信息跳转而来
$postId = (int)$this->input('postId', 0);
if ($postId > 0) {
$paidView = Db::name('fc_pay_view')
->where('user_id', $me['id'])
->where('post_id', $postId)
->find();
if ($paidView) {
$unlocked = true;
}
}
}
}
$displayContact = $unlocked ? $rawContact : $this->maskPhone($rawContact);
$callState = $this->callQuotaState($me ? (int)$me['id'] : 0, $isMember);
$maskedContact = $this->maskPhone($rawContact);
$dialDisplay = $this->buildDialDisplay($userNickname ?: (string)$m['name'], $rawContact);
$data = [
'id' => (int)$m['id'],
@@ -100,8 +89,14 @@ class Merchant extends V1
'address' => (string)(isset($m['address']) ? $m['address'] : ''),
'lat' => (isset($m['lat']) && $m['lat'] !== null && $m['lat'] !== '') ? (float)$m['lat'] : null,
'lng' => (isset($m['lng']) && $m['lng'] !== null && $m['lng'] !== '') ? (float)$m['lng'] : null,
'contact' => $displayContact,
'unlocked' => $unlocked,
'contact' => $maskedContact,
'hasPhone' => $rawContact !== '',
'dialDisplay' => $dialDisplay,
'callQuotaTotal' => $callState['total'],
'callQuotaUsed' => $callState['used'],
'callQuotaLeft' => $callState['left'],
'canDial' => $isOwner || $callState['unlimited'] || $callState['left'] > 0,
'unlocked' => false,
'category' => (string)(isset($m['category']) ? $m['category'] : ''),
'notice' => (string)(isset($m['notice']) ? $m['notice'] : ''),
'auditStatus' => (int)$m['audit_status'],
@@ -119,6 +114,125 @@ class Merchant extends V1
$this->ok($data);
}
/**
* M1-B 商家详情页申请拨打电话(校验每日拨打次数上限并记录拨打日志)
* POST /api/v1/merchant/:id/dial
* → {phoneNumber, dialDisplay, callQuotaTotal, callQuotaUsed, callQuotaLeft}
*
* @return void
*/
public function dial()
{
$user = $this->auth();
$id = (int)$this->routeId();
if ($id <= 0) {
$id = (int)$this->input('id', 0) ?: (int)$this->input('userId', 0);
}
if ($id <= 0) {
$this->fail('缺少商家参数', 400);
}
$m = Db::name('fc_merchant')->where('id', $id)->find();
if (!$m) {
$m = Db::name('fc_merchant')->where('user_id', $id)->find();
}
if (!$m) {
$this->fail('商家门店不存在', 404);
}
$phone = trim((string)(isset($m['contact']) ? $m['contact'] : ''));
if ($phone === '') {
$this->fail('该商家暂未预留联系电话');
}
$now = time();
$ext = $this->ext($user['id']);
$isMember = (int)$ext['is_member'] === 1
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
$isOwner = (int)$m['user_id'] === (int)$user['id'];
$state = $this->callQuotaState((int)$user['id'], $isMember);
if (!$isOwner && !$state['unlimited'] && $state['left'] <= 0) {
$msg = $isMember
? ('您今日的 VIP 拨打次数已达上限(' . $state['total'] . '次/日)')
: ('您今日的免费拨打次数已达上限(' . $state['total'] . '次/日),开通 VIP 会员可享每日更多拨打次数');
$this->fail($msg, 403);
}
$today = date('Y-m-d');
Db::name('fc_call_log')->insert([
'user_id' => (int)$user['id'],
'target_type' => 'merchant',
'target_id' => (int)$m['id'],
'phone' => $phone,
'call_date' => $today,
'createtime' => $now,
]);
$newUsed = $state['used'] + 1;
$newLeft = $state['unlimited'] ? 999 : max(0, $state['total'] - $newUsed);
$pubUser = Db::name('user')->where('id', $m['user_id'])->find();
$contactLabel = $pubUser && !empty($pubUser['nickname']) ? (string)$pubUser['nickname'] : (string)$m['name'];
$this->ok([
'phoneNumber' => $phone,
'dialDisplay' => $this->buildDialDisplay($contactLabel, $phone),
'callQuotaTotal' => $state['total'],
'callQuotaUsed' => $newUsed,
'callQuotaLeft' => $newLeft,
]);
}
/**
* 构造免责声明拨打弹窗展示文案(如:王138****8000)
*
* @param string $name 联系人或门店名称
* @param string $phone 手机号
* @return string
*/
protected function buildDialDisplay($name, $phone)
{
$masked = $this->maskPhone($phone);
$clean = trim((string)$name);
if ($clean === '') {
return $masked;
}
$surname = mb_substr($clean, 0, 1, 'UTF-8');
return $surname . $masked;
}
/**
* 计算指定用户今日的电话拨打额度状态
*
* @param int $userId 用户ID(0表示游客)
* @param bool $isMember 是否为有效期内VIP会员
* @return array{total:int,used:int,left:int,unlimited:bool}
*/
protected function callQuotaState($userId, $isMember)
{
$normalQuota = max(0, (int)$this->cfg('call.normalDailyQuota', 5));
$vipQuota = max(0, (int)$this->cfg('call.vipDailyQuota', 30));
$total = $isMember ? $vipQuota : $normalQuota;
$unlimited = ($total === 0);
$used = 0;
if ($userId > 0) {
$today = date('Y-m-d');
$used = (int)Db::name('fc_call_log')
->where('user_id', $userId)
->where('call_date', $today)
->count();
}
return [
'total' => $total,
'used' => $used,
'left' => $unlimited ? 999 : max(0, $total - $used),
'unlimited' => $unlimited,
];
}
/**
* M2 获取商家名下的信息列表(支持分页)
* GET /api/v1/merchant/:id/posts
@@ -179,6 +293,12 @@ class Merchant extends V1
$cat = Db::name('fc_category')->where('id', $r['category_id'])->value('name');
$catName = $cat ? (string)$cat : '';
}
$subCatId = isset($r['sub_category_id']) ? (int)$r['sub_category_id'] : 0;
$subCatName = '';
if ($subCatId > 0) {
$subCat = Db::name('fc_category')->where('id', $subCatId)->value('name');
$subCatName = $subCat ? (string)$subCat : '';
}
$cover = (string)$r['cover'];
$mediaArr = $this->jsonArr($r['media']);
@@ -197,22 +317,29 @@ class Merchant extends V1
}
$list[] = [
'id' => (int)$r['id'],
'title' => (string)$r['title'],
'content' => (string)$r['content'],
'price' => (float)$r['price'],
'priceUnit' => (string)$r['price_unit'],
'cover' => $cover,
'media' => $mediaArr,
'area' => (string)$r['area'],
'address' => (string)$r['address'],
'categoryId' => (int)$r['category_id'],
'categoryName' => $catName,
'isTop' => (int)$r['is_top'] === 1,
'views' => (int)$r['views'],
'commentCount' => (int)$r['comment_count'],
'createdAt' => $this->iso($r['createtime']),
'tags' => $tags,
'id' => (int)$r['id'],
'title' => (string)$r['title'],
'content' => (string)$r['content'],
'price' => (float)$r['price'],
'priceUnit' => (string)$r['price_unit'],
'cover' => $cover,
'media' => $mediaArr,
'province' => isset($r['province']) ? (string)$r['province'] : '',
'city' => isset($r['city']) ? (string)$r['city'] : '',
'area' => (string)$r['area'],
'address' => (string)$r['address'],
'plantArea' => isset($r['plant_area']) ? (string)$r['plant_area'] : '',
'harvestTime' => isset($r['harvest_time']) ? (string)$r['harvest_time'] : '',
'outputRange' => isset($r['output_range']) ? (string)$r['output_range'] : '',
'categoryId' => (int)$r['category_id'],
'categoryName' => $catName,
'subCategoryId' => $subCatId,
'subCategoryName' => $subCatName,
'isTop' => (int)$r['is_top'] === 1,
'views' => (int)$r['views'],
'commentCount' => (int)$r['comment_count'],
'createdAt' => $this->iso($r['createtime']),
'tags' => $tags,
];
}

查看文件

@@ -5,6 +5,7 @@ namespace app\api\controller;
use think\Db;
use app\common\library\DistributionService;
use app\common\library\CouponService;
use app\common\library\NationalArea;
/**
* 用户端 · 信息发布与详情(Module-POST)
@@ -57,12 +58,13 @@ class Post extends V1
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
// 扩展名白名单:[媒体类型, 体积上限(字节), 允许的真实 MIME]
// 图片限制 ≤ 5MB,保障顶部轮播加载速度与清晰度
$allow = [
'jpg' => ['image', 10 * 1024 * 1024, ['image/jpeg']],
'jpeg' => ['image', 10 * 1024 * 1024, ['image/jpeg']],
'png' => ['image', 10 * 1024 * 1024, ['image/png']],
'gif' => ['image', 10 * 1024 * 1024, ['image/gif']],
'webp' => ['image', 10 * 1024 * 1024, ['image/webp']],
'jpg' => ['image', 5 * 1024 * 1024, ['image/jpeg']],
'jpeg' => ['image', 5 * 1024 * 1024, ['image/jpeg']],
'png' => ['image', 5 * 1024 * 1024, ['image/png']],
'gif' => ['image', 5 * 1024 * 1024, ['image/gif']],
'webp' => ['image', 5 * 1024 * 1024, ['image/webp']],
'mp4' => ['video', 50 * 1024 * 1024, ['video/mp4']],
'mov' => ['video', 50 * 1024 * 1024, ['video/quicktime']],
];
@@ -80,7 +82,7 @@ class Post extends V1
$this->fail('文件大小超出限制');
}
if ($size > $maxSize) {
$this->fail('文件大小超出限制');
$this->fail($type === 'image' ? '单张图片大小不能超过 5MB' : '文件大小超出限制');
}
// 真实 MIME 双重校验(读临时文件头,图片/视频都必须命中白名单);
@@ -96,6 +98,23 @@ class Post extends V1
}
}
// 轮播图片宽高比校验(0.75 ~ 2.2,即 3:4 至 16:9 之间,避免极端长条图破坏详情页轮播展示)
$imgWidth = 0;
$imgHeight = 0;
if ($type === 'image' && function_exists('getimagesize')) {
$imgInfo = @getimagesize($file->getPathname());
if (is_array($imgInfo) && !empty($imgInfo[0]) && !empty($imgInfo[1])) {
$imgWidth = (int)$imgInfo[0];
$imgHeight = (int)$imgInfo[1];
if ($imgWidth >= 50 && $imgHeight >= 50) {
$ratio = $imgWidth / $imgHeight;
if ($ratio < 0.75 || $ratio > 2.2) {
$this->fail('为保障轮播展示效果,请上传宽高比在 3:4 ~ 16:9 之间的横图或方图');
}
}
}
}
$dirName = date('Ymd');
$saveName = $file->hash('md5') . '.' . $ext; // md5 命名:同内容文件天然去重
$destDir = ROOT_PATH . 'public' . DS . 'uploads' . DS . $dirName . DS;
@@ -105,10 +124,12 @@ class Post extends V1
}
$this->ok([
'url' => '/uploads/' . $dirName . '/' . $saveName,
'type' => $type,
'size' => $size,
'name' => $name,
'url' => '/uploads/' . $dirName . '/' . $saveName,
'type' => $type,
'size' => $size,
'name' => $name,
'width' => $imgWidth,
'height' => $imgHeight,
]);
}
@@ -131,12 +152,27 @@ class Post extends V1
$user = $this->auth();
$categoryId = (int)$this->input('categoryId', 0);
$subCategoryId = (int)$this->input('subCategoryId', 0);
$title = trim((string)$this->input('title', ''));
$content = trim((string)$this->input('content', ''));
if ($categoryId <= 0 && $subCategoryId > 0) {
$categoryId = $subCategoryId;
}
if ($categoryId <= 0) {
$this->fail('分类不能为空');
}
// 若传入的 categoryId 是二级分类(pid > 0),自动归属其一级大类与二级分类
$catRow = Db::name('fc_category')->where('id', $categoryId)->find();
if ($catRow && !empty($catRow['pid']) && (int)$catRow['pid'] > 0) {
$subCategoryId = (int)$catRow['id'];
$categoryId = (int)$catRow['pid'];
} elseif ($subCategoryId > 0) {
$subRow = Db::name('fc_category')->where('id', $subCategoryId)->find();
if ($subRow && !empty($subRow['pid']) && (int)$subRow['pid'] > 0) {
$categoryId = (int)$subRow['pid'];
}
}
if ($title === '') {
$this->fail('标题不能为空');
}
@@ -262,15 +298,33 @@ class Post extends V1
}
$price = max(0, round((float)$this->input('price', 0), 2));
$priceUnit = mb_substr(trim((string)$this->input('priceUnit', '')), 0, 16);
$wechat = mb_substr(trim((string)$this->input('wechat', '')), 0, 64);
if ($price > 0 && $priceUnit === '') {
$priceUnit = '元/斤';
}
$wechat = ''; // 微信字段已移除
$address = mb_substr(trim((string)$this->input('address', '')), 0, 128);
$plantArea = mb_substr(trim((string)$this->input('plantArea', '')), 0, 64);
$harvestTime = mb_substr(trim((string)$this->input('harvestTime', '')), 0, 64);
$outputRange = mb_substr(trim((string)$this->input('outputRange', '')), 0, 64);
// 农产品分类(kind=farm)必须完善产地规格与价格;通用分类(招聘求职等)自动跳过这些校验
$topCatRow = Db::name('fc_category')->where('id', $categoryId)->find();
$isFarmCategory = $topCatRow && isset($topCatRow['kind']) && $topCatRow['kind'] === 'farm';
if ($isFarmCategory) {
if ($plantArea === '' || $harvestTime === '' || $outputRange === '') {
$this->fail('请完善种植面积、采摘时间与预计量产');
}
if ($price <= 0) {
$this->fail('请填写销售价格');
}
}
try {
// 发布落库 + 扣款 + 订单 + 额度扣减 同一事务:任一步失败整体回滚
Db::transaction(function () use (
&$postId, &$order, &$balanceAfter, &$quotaLeft,
$paid, $user, $amount, $originAmount, $couponAmount, $userCouponId, $payType,
$now, $categoryId, $identityType, $title, $content, $phone, $wechat, $price, $priceUnit, $address, $useQuota, $region, $cover
$now, $categoryId, $subCategoryId, $identityType, $title, $content, $phone, $wechat, $price, $priceUnit, $address, $plantArea, $harvestTime, $outputRange, $useQuota, $region, $cover
) {
$paidNow = $paid && $payType === 'balance';
// 订单号提前生成:优惠券锁定需要绑定订单号
@@ -293,21 +347,27 @@ class Post extends V1
}
$postId = Db::name('fc_post')->insertGetId([
'user_id' => $user['id'],
'category_id' => $categoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'cover' => $cover,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => $price,
'price_unit' => $priceUnit,
'area' => $region['area'],
'district_id' => $region['district_id'],
'address' => $address,
'contact' => (string)$this->input('contact', ''),
'phone' => $phone,
'wechat' => $wechat,
'user_id' => $user['id'],
'category_id' => $categoryId,
'sub_category_id' => $subCategoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'cover' => $cover,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => $price,
'price_unit' => $priceUnit,
'province' => $region['province'],
'city' => $region['city'],
'area' => $region['area'],
'district_id' => $region['district_id'],
'address' => $address,
'plant_area' => $plantArea,
'harvest_time' => $harvestTime,
'output_range' => $outputRange,
'contact' => (string)$this->input('contact', ''),
'phone' => $phone,
'wechat' => $wechat,
'tags' => $this->tagsString(),
// LBS 坐标(gcj02;未定位/为 0 时存 NULL,首页「附近」不参与距离排序)
'lat' => $this->coord('lat', 90),
@@ -434,28 +494,37 @@ class Post extends V1
$list = [];
foreach ($rows as $row) {
$cat = Db::name('fc_category')->where('id', $row['category_id'])->find();
$subCatId = isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0;
$subCat = $subCatId > 0 ? Db::name('fc_category')->where('id', $subCatId)->find() : null;
$list[] = [
'id' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $cat ? (string)$cat['name'] : '',
'cover' => (string)$row['cover'],
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'auditStatus' => (int)$row['audit_status'],
'auditReason' => (string)$row['audit_reason'],
'status' => (int)$row['status'],
'isTop' => (int)$row['is_top'] === 1,
'isPaid' => (int)$row['is_paid'] === 1,
'amount' => (float)$row['amount'],
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'commentCount' => (int)$row['comment_count'],
'createdAt' => $this->iso($row['createtime']),
'id' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $cat ? (string)$cat['name'] : '',
'subCategoryId' => $subCatId,
'subCategoryName' => $subCat ? (string)$subCat['name'] : '',
'cover' => (string)$row['cover'],
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'province' => isset($row['province']) ? (string)$row['province'] : '',
'city' => isset($row['city']) ? (string)$row['city'] : '',
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
'auditStatus' => (int)$row['audit_status'],
'auditReason' => (string)$row['audit_reason'],
'status' => (int)$row['status'],
'isTop' => (int)$row['is_top'] === 1,
'isPaid' => (int)$row['is_paid'] === 1,
'amount' => (float)$row['amount'],
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'commentCount' => (int)$row['comment_count'],
'createdAt' => $this->iso($row['createtime']),
];
}
@@ -680,24 +749,30 @@ class Post extends V1
$tags = array_values(array_filter(array_map('trim', explode(',', (string)$row['tags']))));
}
$list[] = [
'draftId' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'media' => is_array($media) ? $media : [],
'price' => (float)(isset($row['price']) ? $row['price'] : 0),
'priceUnit' => (string)(isset($row['price_unit']) ? $row['price_unit'] : ''),
'contact' => (string)$row['contact'],
'phone' => (string)$row['phone'],
'wechat' => (string)(isset($row['wechat']) ? $row['wechat'] : ''),
'tags' => $tags,
'address' => (string)$row['address'],
'lat' => isset($row['lat']) && $row['lat'] !== null ? (float)$row['lat'] : null,
'lng' => isset($row['lng']) && $row['lng'] !== null ? (float)$row['lng'] : null,
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'savedAt' => $this->iso($row['savedat']),
'draftId' => (int)$row['id'],
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'categoryId' => (int)$row['category_id'],
'subCategoryId' => isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0,
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'media' => is_array($media) ? $media : [],
'price' => (float)(isset($row['price']) ? $row['price'] : 0),
'priceUnit' => (string)(isset($row['price_unit']) ? $row['price_unit'] : ''),
'contact' => (string)$row['contact'],
'phone' => (string)$row['phone'],
'wechat' => '',
'tags' => $tags,
'address' => (string)$row['address'],
'lat' => isset($row['lat']) && $row['lat'] !== null ? (float)$row['lat'] : null,
'lng' => isset($row['lng']) && $row['lng'] !== null ? (float)$row['lng'] : null,
'province' => isset($row['province']) ? (string)$row['province'] : '',
'city' => isset($row['city']) ? (string)$row['city'] : '',
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
'savedAt' => $this->iso($row['savedat']),
];
}
$this->ok($list);
@@ -733,6 +808,7 @@ class Post extends V1
$draftId = (int)$this->input('draftId', 0);
$categoryId = (int)$this->input('categoryId', 0);
$subCategoryId = (int)$this->input('subCategoryId', 0);
$title = (string)$this->input('title', '');
$content = (string)$this->input('content', '');
$now = time();
@@ -741,25 +817,31 @@ class Post extends V1
$identityType = ($identityTypeInput === 'merchant' || $identityTypeInput === '2') ? 2 : 1;
$data = [
'user_id' => $user['id'],
'category_id' => $categoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => max(0, round((float)$this->input('price', 0), 2)),
'price_unit' => mb_substr(trim((string)$this->input('priceUnit', '')), 0, 16),
'contact' => (string)$this->input('contact', ''),
'phone' => (string)$this->input('phone', ''),
'wechat' => mb_substr(trim((string)$this->input('wechat', '')), 0, 64),
'tags' => $this->tagsString(),
'address' => mb_substr(trim((string)$this->input('address', '')), 0, 128),
'lat' => $this->coord('lat', 90),
'lng' => $this->coord('lng', 180),
'area' => (string)$this->input('area', ''),
'district_id' => (int)$this->input('areaId', (int)$this->input('districtId', 0)),
'savedat' => $now,
'updatetime' => $now,
'user_id' => $user['id'],
'category_id' => $categoryId,
'sub_category_id' => $subCategoryId,
'identity_type' => $identityType,
'title' => $title,
'content' => $content,
'media' => json_encode($this->mediaArray(), JSON_UNESCAPED_UNICODE),
'price' => max(0, round((float)$this->input('price', 0), 2)),
'price_unit' => mb_substr(trim((string)$this->input('priceUnit', '')), 0, 16),
'contact' => (string)$this->input('contact', ''),
'phone' => (string)$this->input('phone', ''),
'wechat' => '',
'tags' => $this->tagsString(),
'address' => mb_substr(trim((string)$this->input('address', '')), 0, 128),
'lat' => $this->coord('lat', 90),
'lng' => $this->coord('lng', 180),
'province' => mb_substr(trim((string)$this->input('province', '')), 0, 32),
'city' => mb_substr(trim((string)$this->input('city', '')), 0, 32),
'area' => (string)$this->input('area', ''),
'district_id' => (int)$this->input('areaId', (int)$this->input('districtId', 0)),
'plant_area' => mb_substr(trim((string)$this->input('plantArea', '')), 0, 64),
'harvest_time' => mb_substr(trim((string)$this->input('harvestTime', '')), 0, 64),
'output_range' => mb_substr(trim((string)$this->input('outputRange', '')), 0, 64),
'savedat' => $now,
'updatetime' => $now,
];
if ($draftId > 0) {
@@ -926,33 +1008,150 @@ class Post extends V1
$data['freeViewLeft'] = $freeViewLeft;
$data['payViewPrice'] = $isFreeView ? 0 : $payViewPrice;
// 真实解锁态判定:全站免费公开模式、本人发布、或已生成有效解锁记录
if ($isFreeView || $isOwner || $paid) {
$data['unlocked'] = true;
$data['phone'] = (string)$post['phone'];
$data['contact'] = (string)$post['phone'];
$data['contactName'] = (string)(isset($post['contact']) ? $post['contact'] : '');
$data['wechat'] = $post['wechat'] !== '' ? (string)$post['wechat'] : ('tongcheng_' . $post['id']);
// 若发帖人有关联商家门店,在解锁态下一并展现真实门店电话
if (!empty($data['merchant']) && is_array($data['merchant']) && !empty($data['merchant']['id'])) {
$rawShopContact = Db::name('fc_merchant')->where('id', $data['merchant']['id'])->value('contact');
if ($rawShopContact) {
$data['merchant']['contact'] = (string)$rawShopContact;
}
}
} else {
// 未解锁态:标题与详细描述中的任何手机号执行动态安全遮蔽,杜绝正文绕过
if (!empty($data['content'])) {
$data['content'] = $this->maskTextPhones($data['content']);
}
if (!empty($data['title'])) {
$data['title'] = $this->maskTextPhones($data['title']);
}
// 每日电话拨打次数上限与剩余额度(详情预览页隐藏明文手机号,仅保留免责声明弹窗拨打)
$callState = $this->callQuotaState($me ? (int)$me['id'] : 0, $isMember);
$rawPhone = (string)$post['phone'];
$contactName = (string)(isset($post['contact']) ? $post['contact'] : '');
$maskedPhone = $this->maskPhone($rawPhone);
$data['hasPhone'] = $rawPhone !== '';
$data['dialDisplay'] = $this->buildDialDisplay($contactName, $rawPhone);
$data['callQuotaTotal'] = $callState['total'];
$data['callQuotaUsed'] = $callState['used'];
$data['callQuotaLeft'] = $callState['left'];
$data['canDial'] = $isOwner || $paid || $callState['unlimited'] || $callState['left'] > 0;
// 界面上始终隐藏明文手机号(仅返回脱敏号码),通过 POST /post/:id/dial 校验额度并调起系统拨号
$data['unlocked'] = ($isFreeView || $isOwner || $paid);
$data['phone'] = $maskedPhone;
$data['contact'] = $maskedPhone;
$data['contactName'] = $contactName;
$data['wechat'] = '';
// 标题与详细描述中的任何手机号执行动态安全遮蔽,防止正文直接贴电话
if (!empty($data['content'])) {
$data['content'] = $this->maskTextPhones($data['content']);
}
if (!empty($data['title'])) {
$data['title'] = $this->maskTextPhones($data['title']);
}
return $data;
}
/**
* 构造免责声明拨打弹窗展示文案(如:夏178****8426)
*
* @param string $contactName 联系人姓名
* @param string $phone 手机号
* @return string
*/
protected function buildDialDisplay($contactName, $phone)
{
$masked = $this->maskPhone($phone);
$name = trim((string)$contactName);
if ($name === '') {
return $masked;
}
$surname = mb_substr($name, 0, 1, 'UTF-8');
return $surname . $masked;
}
/**
* 计算指定用户今日的电话拨打额度状态
*
* @param int $userId 用户ID(0表示游客)
* @param bool $isMember 是否为有效期内VIP会员
* @return array{total:int,used:int,left:int,unlimited:bool}
*/
protected function callQuotaState($userId, $isMember)
{
$normalQuota = max(0, (int)$this->cfg('call.normalDailyQuota', 5));
$vipQuota = max(0, (int)$this->cfg('call.vipDailyQuota', 30));
$total = $isMember ? $vipQuota : $normalQuota;
$unlimited = ($total === 0);
$used = 0;
if ($userId > 0) {
$today = date('Y-m-d');
$used = (int)Db::name('fc_call_log')
->where('user_id', $userId)
->where('call_date', $today)
->count();
}
return [
'total' => $total,
'used' => $used,
'left' => $unlimited ? 999 : max(0, $total - $used),
'unlimited' => $unlimited,
];
}
/**
* P6-B 信息详情页申请拨打电话(校验每日拨打次数上限并记录拨打日志)
* POST /api/v1/post/:id/dial
* → {phoneNumber, dialDisplay, callQuotaTotal, callQuotaUsed, callQuotaLeft}
*
* @return void
*/
public function dial()
{
$user = $this->auth();
$id = $this->routeId();
$post = Db::name('fc_post')->where('id', $id)->whereNull('deletetime')->find();
if (!$post) {
$this->fail('信息不存在', 404);
}
$phone = trim((string)$post['phone']);
if ($phone === '') {
$this->fail('发布者未预留联系电话');
}
$now = time();
$ext = $this->ext($user['id']);
$isMember = (int)$ext['is_member'] === 1
&& !empty($ext['member_expiretime']) && (int)$ext['member_expiretime'] > $now;
$isOwner = (int)$post['user_id'] === (int)$user['id'];
$paid = (bool)Db::name('fc_pay_view')
->where('user_id', $user['id'])
->where('post_id', $id)
->find();
$state = $this->callQuotaState((int)$user['id'], $isMember);
// 非本人且未单条付费解锁时,校验每日拨打次数上限
if (!$isOwner && !$paid && !$state['unlimited'] && $state['left'] <= 0) {
$msg = $isMember
? ('您今日的 VIP 拨打次数已达上限(' . $state['total'] . '次/日)')
: ('您今日的免费拨打次数已达上限(' . $state['total'] . '次/日),开通 VIP 会员可享每日更多拨打次数');
$this->fail($msg, 403);
}
$today = date('Y-m-d');
Db::name('fc_call_log')->insert([
'user_id' => (int)$user['id'],
'target_type' => 'post',
'target_id' => (int)$id,
'phone' => $phone,
'call_date' => $today,
'createtime' => $now,
]);
$newUsed = $state['used'] + 1;
$newLeft = $state['unlimited'] ? 999 : max(0, $state['total'] - $newUsed);
$this->ok([
'phoneNumber' => $phone,
'dialDisplay' => $this->buildDialDisplay(isset($post['contact']) ? $post['contact'] : '', $phone),
'callQuotaTotal' => $state['total'],
'callQuotaUsed' => $newUsed,
'callQuotaLeft' => $newLeft,
]);
}
/**
* 会员每日免费查看条数(从用户所属 fc_plan 套餐或默认套餐读取;0 代表会员无限次免费看)
*
@@ -1409,10 +1608,9 @@ class Post extends V1
}
/**
* 解析发布信息的服务区域(区县)
* 优先级:areaId(兼容 districtId)> area 名称 > 经纬度最近区域(300km 内)。
* 未提供任何区域时返回空区域,保持与旧客户端兼容。
* @return array{area:string,district_id:int}
* 解析发布信息的全国服务区域(省/市/区县)
* 优先级:areaId(兼容 districtId)> area 名称 > 经纬度最近区域。
* @return array{province:string,city:string,area:string,district_id:int}
*/
protected function resolveRegion()
{
@@ -1420,49 +1618,58 @@ class Post extends V1
if (!$areaId) {
$areaId = (int)$this->input('districtId', 0);
}
$provinceInput = trim((string)$this->input('province', ''));
$cityInput = trim((string)$this->input('city', ''));
$areaName = trim((string)$this->input('area', ''));
$area = null;
if ($areaId > 0) {
$area = Db::name('fc_area')
->where('id', $areaId)
->where('enabled', 1)
->find();
$area = NationalArea::findById($areaId);
if (!$area) {
$area = Db::name('fc_area')
->where('id', $areaId)
->where('enabled', 1)
->find();
}
if (!$area) {
$this->fail('所选服务区域不可用,请重新选择');
}
} elseif ($areaName !== '') {
$area = Db::name('fc_area')
->where('district', $areaName)
->where('enabled', 1)
->find();
$area = NationalArea::findByDistrict($areaName, $provinceInput, $cityInput);
if (!$area) {
$area = Db::name('fc_area')
->where('district', $areaName)
->where('enabled', 1)
->find();
}
} else {
$lat = $this->coord('lat', 90);
$lng = $this->coord('lng', 180);
if ($lat !== null && $lng !== null) {
$rows = Db::name('fc_area')
->where('enabled', 1)
->whereNotNull('lat')
->whereNotNull('lng')
->select();
$best = null;
foreach ($rows as $row) {
$distance = $this->haversine($lat, $lng, (float)$row['lat'], (float)$row['lng']);
if ($best === null || $distance < $best['distance']) {
$best = ['row' => $row, 'distance' => $distance];
}
}
if ($best && $best['distance'] <= 300) {
$area = $best['row'];
$located = NationalArea::locate($lat, $lng);
if ($located) {
$area = [
'id' => $located['areaId'],
'province' => $located['province'],
'city' => $located['city'],
'district' => $located['district'],
];
}
}
}
if (!$area) {
return ['area' => $areaName, 'district_id' => 0];
return [
'province' => $provinceInput,
'city' => $cityInput,
'area' => $areaName,
'district_id' => 0,
];
}
return [
'province' => isset($area['province']) ? (string)$area['province'] : $provinceInput,
'city' => isset($area['city']) ? (string)$area['city'] : $cityInput,
'area' => (string)$area['district'],
'district_id' => (int)$area['id'],
];
@@ -1584,6 +1791,15 @@ class Post extends V1
}
}
$subCategoryId = isset($row['sub_category_id']) ? (int)$row['sub_category_id'] : 0;
$subCategoryName = '';
if ($subCategoryId > 0) {
$subCat = Db::name('fc_category')->where('id', $subCategoryId)->find();
if ($subCat) {
$subCategoryName = (string)$subCat['name'];
}
}
$publisher = ['id' => 0, 'name' => '', 'avatar' => '', 'isMerchant' => false, 'verified' => false, 'isMember' => false, 'memberLevel' => ''];
$merchant = null;
if (!empty($row['user_id'])) {
@@ -1666,39 +1882,46 @@ class Post extends V1
}
return [
'id' => $postId,
'userId' => (int)$row['user_id'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $categoryName,
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'cover' => (string)$row['cover'],
'media' => $this->jsonArr(isset($row['media']) ? $row['media'] : ''),
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'contact' => $this->maskPhone($row['phone']),
'phone' => $this->maskPhone($row['phone']),
'contactName' => (string)(isset($row['contact']) ? $row['contact'] : ''),
'isTop' => isset($row['is_top']) && (int)$row['is_top'] === 1,
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'isPaid' => (int)$row['is_paid'] === 1,
'auditStatus' => (int)$row['audit_status'],
'createdAt' => $this->iso($row['createtime']),
'tags' => $tags,
'publisher' => $publisher,
'merchant' => $merchant,
'commentCount' => (int)$row['comment_count'],
'lat' => $lat,
'lng' => $lng,
'distance' => $this->postDistance($row),
'faved' => $faved,
'followed' => $followed,
'favoriteCount' => $favoriteCount,
'id' => $postId,
'userId' => (int)$row['user_id'],
'categoryId' => (int)$row['category_id'],
'categoryName' => $categoryName,
'subCategoryId' => $subCategoryId,
'subCategoryName' => $subCategoryName,
'identityType' => (isset($row['identity_type']) && (int)$row['identity_type'] === 2) ? 'merchant' : 'person',
'title' => (string)$row['title'],
'content' => (string)$row['content'],
'cover' => (string)$row['cover'],
'media' => $this->jsonArr(isset($row['media']) ? $row['media'] : ''),
'price' => (float)$row['price'],
'priceUnit' => (string)$row['price_unit'],
'province' => isset($row['province']) ? (string)$row['province'] : '',
'city' => isset($row['city']) ? (string)$row['city'] : '',
'area' => (string)$row['area'],
'areaId' => (int)$row['district_id'],
'address' => (string)$row['address'],
'plantArea' => isset($row['plant_area']) ? (string)$row['plant_area'] : '',
'harvestTime' => isset($row['harvest_time']) ? (string)$row['harvest_time'] : '',
'outputRange' => isset($row['output_range']) ? (string)$row['output_range'] : '',
'contact' => $this->maskPhone($row['phone']),
'phone' => $this->maskPhone($row['phone']),
'contactName' => (string)(isset($row['contact']) ? $row['contact'] : ''),
'isTop' => isset($row['is_top']) && (int)$row['is_top'] === 1,
'views' => (int)$row['views'],
'likes' => (int)$row['likes'],
'isPaid' => (int)$row['is_paid'] === 1,
'auditStatus' => (int)$row['audit_status'],
'createdAt' => $this->iso($row['createtime']),
'tags' => $tags,
'publisher' => $publisher,
'merchant' => $merchant,
'commentCount' => (int)$row['comment_count'],
'lat' => $lat,
'lng' => $lng,
'distance' => $this->postDistance($row),
'faved' => $faved,
'followed' => $followed,
'favoriteCount' => $favoriteCount,
];
}
}

查看文件

@@ -53,7 +53,7 @@ class Setting extends V1
/**
* 获取协议与隐私政策内容(游客可用)
* GET /api/v1/setting/agreement?type=service|privacy
* GET /api/v1/setting/agreement?type=service|privacy|disclaimer
* 出参:{ title, content, updateTime }
*/
public function agreement()
@@ -63,6 +63,10 @@ class Setting extends V1
$title = '隐私政策';
$defaultContent = "【隐私政策】\n\n同城分类信息便民平台重视用户的隐私与个人信息保护。我们承诺将按照法律法规要求,采取相应的安全保护措施保护您的个人信息。\n\n1. 信息收集与使用:我们仅收集为您提供服务所必需的信息,如登录手机号、发布信息时提供的联系方式与内容。\n2. 信息安全保障:我们采用业界标准的安全防护措施,保护用户个人信息不被未经授权的访问、泄露、篡改或损毁。\n3. 权限说明:仅在您主动上传图片、定位实体门店时,请求相册及地理位置权限。\n4. 未成年人保护:如您为未成年人,建议在父母或监护人指导下使用本服务。";
$content = (string)$this->cfg('site.privacyPolicy', $defaultContent);
} elseif ($type === 'disclaimer') {
$title = '平台免责声明';
$defaultContent = "【平台免责声明】\n\n1. 信息媒介属性:本平台仅为农产品及本地生活信息展示与联络媒介,不参与任何线下交易,不对信息真实性、合法性作出担保。\n2. 交易风险自担:请自行鉴别信息真伪,在未核实清楚前不要提前给对方转账,谨防诈骗。因私下交易产生的纠纷与损失,由交易双方依法依规自行处理。\n3. 联系方式保护:为保护用户隐私,平台对联系电话进行脱敏展示,拨打记录仅用于限制每日恶意拨打行为。\n4. 举报与处置:如发现虚假、违法违规信息,请及时通过页面「举报」入口反馈,平台将核实后采取下架、封禁等措施。";
$content = (string)$this->cfg('site.disclaimer', $defaultContent);
} else {
$title = '用户服务协议';
$defaultContent = "【用户服务协议】\n\n欢迎使用同城分类信息生活便民平台。在使用本平台服务前,请仔细阅读本协议。\n\n1. 服务条款确认与接纳:用户在注册或使用本平台服务即视为完全理解并同意本协议全部条款。\n2. 用户发布行为规范:用户承诺发布的信息真实、合法、有效,严禁发布违法、虚假、侵权或违背公序良俗的商业与便民信息。\n3. 平台免责声明:平台作为同城信息展示与撮合媒介,用户应自主辨识交易风险,因私下线下交易产生的纠纷由当事人依法依规处理。\n4. 违规处罚机制:对发布违法违规、虚假诈骗内容的用户,平台有权采取警告、下架信息、限制发布乃至封禁账号的处置措施。";

查看文件

@@ -78,12 +78,14 @@ class FcConfig
}
return [
'postMode' => $postMode,
'freeQuota' => max(0, (int)$pick('post.freeQuota', 0)),
'freeQuotaCycle' => in_array($pick('post.freeQuotaCycle', 'day'), ['day', 'month', 'total'], true) ? $pick('post.freeQuotaCycle', 'day') : 'day',
'singlePrice' => max(0, round((float)$pick('post.singlePrice', 5), 2)),
'viewMode' => $viewMode,
'payViewPrice' => max(0, $payViewPrice),
'postMode' => $postMode,
'freeQuota' => max(0, (int)$pick('post.freeQuota', 0)),
'freeQuotaCycle' => in_array($pick('post.freeQuotaCycle', 'day'), ['day', 'month', 'total'], true) ? $pick('post.freeQuotaCycle', 'day') : 'day',
'singlePrice' => max(0, round((float)$pick('post.singlePrice', 5), 2)),
'viewMode' => $viewMode,
'payViewPrice' => max(0, $payViewPrice),
'callNormalDailyQuota' => max(0, (int)$pick('call.normalDailyQuota', 5)),
'callVipDailyQuota' => max(0, (int)$pick('call.vipDailyQuota', 30)),
];
}
@@ -480,6 +482,16 @@ class FcConfig
self::put('fee.viewMode', $viewMode, 'fee', '联系方式浏览模式:free免费公开 / paid付费或会员解锁');
self::put('fee.payView', $viewMode === 'free' ? 0 : $payView, 'fee', '非会员单条查看联系方式价格');
}
// 每日电话拨打次数限制(详情页与商家主页共用额度池)
if (isset($row['fc_call_normalDailyQuota'])) {
$normalQuota = max(0, $int('fc_call_normalDailyQuota', 5));
self::put('call.normalDailyQuota', $normalQuota, 'call', '普通用户每日免费拨打次数上限(0表示不限制)');
}
if (isset($row['fc_call_vipDailyQuota'])) {
$vipQuota = max(0, $int('fc_call_vipDailyQuota', 30));
self::put('call.vipDailyQuota', $vipQuota, 'call', 'VIP会员每日拨打次数上限(0表示不限制)');
}
}
/**

查看文件

@@ -0,0 +1,188 @@
<?php
namespace app\common\library;
use think\Db;
/**
* 全国标准省/市/区县服务区域工具类
*
* 规则:
* - 默认全国所有省、市、区县全部开通,无需后台手动维护;
* - 数据源取自 application/extra/national_areas.json(由全国行政区划字典构建,涵盖全国 34 个省级行政区、全部地级市及区县);
* - 同时合并 fa_fc_area 表中历史自定义记录,确保旧 ID 与历史数据 100% 兼容。
*/
class NationalArea
{
/** @var array|null 内存级缓存 */
protected static $allCache = null;
/**
* 获取全国全部省/市/区县平铺列表
*
* @return array<int, array{id:int,province:string,city:string,district:string,lat:float|null,lng:float|null}>
*/
public static function all()
{
if (self::$allCache !== null) {
return self::$allCache;
}
$jsonFile = APP_PATH . 'extra' . DS . 'national_areas.json';
$list = [];
if (is_file($jsonFile)) {
$decoded = json_decode((string)file_get_contents($jsonFile), true);
if (is_array($decoded)) {
$list = $decoded;
}
}
// 合并数据库中已有的自定义启用区域(避免重复)
try {
$dbRows = Db::name('fc_area')
->where('enabled', 1)
->order('sort asc, id asc')
->select();
$seenKey = [];
$seenId = [];
foreach ($list as $idx => $item) {
$k = $item['province'] . '|' . $item['city'] . '|' . $item['district'];
$seenKey[$k] = $idx;
$seenId[(int)$item['id']] = $idx;
}
foreach ($dbRows as $row) {
$p = (string)$row['province'];
$c = (string)$row['city'];
$d = (string)$row['district'];
$k = $p . '|' . $c . '|' . $d;
$id = (int)$row['id'];
if (isset($seenKey[$k])) {
$targetIdx = $seenKey[$k];
if ($row['lat'] !== null && $row['lng'] !== null) {
$list[$targetIdx]['lat'] = (float)$row['lat'];
$list[$targetIdx]['lng'] = (float)$row['lng'];
}
continue;
}
if (!isset($seenId[$id])) {
$list[] = [
'id' => $id,
'province' => $p,
'city' => $c,
'district' => $d,
'lat' => $row['lat'] !== null ? (float)$row['lat'] : null,
'lng' => $row['lng'] !== null ? (float)$row['lng'] : null,
];
}
}
} catch (\Throwable $e) {
// 忽略数据库读取异常,以全国静态字典兜底
}
self::$allCache = $list;
return self::$allCache;
}
/**
* 按区域 ID 查找单条省/市/区县记录
*
* @param int $areaId 区县ID
* @return array|null
*/
public static function findById($areaId)
{
$areaId = (int)$areaId;
if ($areaId <= 0) {
return null;
}
foreach (self::all() as $row) {
if ((int)$row['id'] === $areaId) {
return $row;
}
}
return null;
}
/**
* 按区县名称(及可选省/市)查找匹配记录
*
* @param string $district 区县名称
* @param string $city 可选城市名称
* @param string $province 可选省份名称
* @return array|null
*/
public static function findByName($district, $city = '', $province = '')
{
$district = trim((string)$district);
$city = trim((string)$city);
$province = trim((string)$province);
if ($district === '') {
return null;
}
foreach (self::all() as $row) {
if ($row['district'] === $district) {
if ($city !== '' && $row['city'] !== $city) {
continue;
}
if ($province !== '' && $row['province'] !== $province) {
continue;
}
return $row;
}
}
return null;
}
/**
* 按经纬度坐标(gcj02)匹配最近的全国区县
*
* @param float $lat 纬度
* @param float $lng 经度
* @return array|null {areaId, province, city, district, distance}
*/
public static function locate($lat, $lng)
{
$best = null;
foreach (self::all() as $row) {
if ($row['lat'] === null || $row['lng'] === null) {
continue;
}
$dist = self::haversine($lat, $lng, (float)$row['lat'], (float)$row['lng']);
if ($best === null || $dist < $best['distance']) {
$best = ['row' => $row, 'distance' => $dist];
}
}
if (!$best || $best['distance'] > 1000) {
return null;
}
$area = $best['row'];
return [
'areaId' => (int)$area['id'],
'province' => (string)$area['province'],
'city' => (string)$area['city'],
'district' => (string)$area['district'],
'distance' => $best['distance'],
];
}
/**
* 计算两点间 Haversine 球面距离(km,保留 1 位小数)
*
* @param float $lat1
* @param float $lng1
* @param float $lat2
* @param float $lng2
* @return float
*/
public static function haversine($lat1, $lng1, $lat2, $lng2)
{
$earth = 6371.0;
$rad = M_PI / 180;
$dLat = ($lat2 - $lat1) * $rad;
$dLng = ($lng2 - $lng1) * $rad;
$a = sin($dLat / 2) * sin($dLat / 2)
+ cos($lat1 * $rad) * cos($lat2 * $rad) * sin($dLng / 2) * sin($dLng / 2);
$c = 2 * asin(min(1.0, sqrt($a)));
return round($earth * $c, 1);
}
}

文件差异因一行或多行过长而隐藏

查看文件

@@ -51,6 +51,7 @@ return [
'api/v1/home/locate' => 'api/Home/locate',
/* =============== 三、用户端 · 信息发布与详情(长路径优先) =============== */
'api/v1/post/:id/dial' => 'api/Post/dial',
'api/v1/post/:id/pay-view' => 'api/Post/payView',
'api/v1/post/comment/:id/reply' => 'api/Post/replyComment',
'api/v1/post/:id/comment' => 'api/Post/comment',
@@ -66,6 +67,7 @@ return [
'api/v1/post/:id' => 'api/Post/detail',
/* =============== 三·A、用户端 · 商家主页与门店详情 =============== */
'api/v1/merchant/:id/dial' => 'api/Merchant/dial',
'api/v1/merchant/:id/posts' => 'api/Merchant/posts',
'api/v1/merchant/:id' => 'api/Merchant/detail',