feat: 新增电话拨打功能及相关配置,完善农产品分类与地区数据
- 新增商家/信息详情页电话拨打接口,支持每日额度限制与拨打日志记录 - 新增平台免责声明内容及协议接口,完善用户服务协议相关配置 - 新增农产品分类图标与上市角标展示,优化分类管理界面样式 - 新增全国行政区划工具类与城市选择组件,重构地区数据结构 - 新增SSH自检与部署脚本,完善项目部署流程
这个提交包含在:
@@ -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 '分类名',
|
||||
|
||||
在新工单中引用
屏蔽一个用户