文件
fenleixinxi/application/admin/controller/fc/Setting.php
MiAn cb12bf5fc8 feat: 新增地址选择插件及订阅消息等多项功能优化
- 新增地址选择插件,支持地图位置选择并返回地址和经纬度
- 新增微信订阅消息发送功能,支持审核结果、提现通知等场景
- 新增订单支付状态查询、提现收款人姓名保存等接口
- 新增服务区域管理,支持按省市区划分并同步到信息发布
- 新增资金流水和营收报表导出功能
- 新增可用优惠券查询、订单退款拆分处理等功能
- 优化后台角标显示、首页数据统计、UI配置下发等
- 修复订单支付并发问题、地区管理逻辑等
2026-10-22 17:14:56 +08:00

122 行
4.4 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-小程序设置
*
* 页面职责(路由 fc/setting/index):
* 维护小程序端基础信息配置:小程序名称、LOGO、客服电话、关于我们、分享标题。
* 保存后写入 fa_fc_config 表的 base.* 键,供小程序端接口统一读取。
*
* @icon fa fa-cogs
*/
class Setting extends Backend
{
/**
* 小程序基础设置首页(GET 显示表单 / POST 保存基础配置)
*
* @return string|null 渲染页面或响应重定向
*/
public function index()
{
if ($this->request->isPost()) {
return $this->save();
}
$this->view->assign('row', $this->current());
return $this->view->fetch();
}
/**
* 保存小程序基础配置
*
* @return void
*/
protected function save()
{
$params = $this->request->post('row/a');
if (!is_array($params)) {
$params = $this->request->post();
}
$appName = isset($params['appName']) ? trim((string)$params['appName']) : '';
if ($appName === '') {
$this->error('小程序名称不能为空');
}
$logo = isset($params['logo']) ? trim((string)$params['logo']) : '';
$values = [
'base.appName' => ['value' => $appName, 'group_key' => 'base', 'remark' => '小程序名称'],
'base.logo' => ['value' => $logo, 'group_key' => 'base', 'remark' => 'LOGO地址'],
'base.servicePhone' => ['value' => isset($params['servicePhone']) ? trim((string)$params['servicePhone']) : '', 'group_key' => 'base', 'remark' => '客服电话'],
'base.aboutUs' => ['value' => isset($params['aboutUs']) ? trim((string)$params['aboutUs']) : '', 'group_key' => 'base', 'remark' => '关于我们'],
'base.shareTitle' => ['value' => isset($params['shareTitle']) ? trim((string)$params['shareTitle']) : '', 'group_key' => 'base', 'remark' => '分享标题'],
// 兼容旧 ui.* 键(用户端已优先读 base.*)
'ui.siteName' => ['value' => $appName, 'group_key' => 'ui', 'remark' => '站点名称'],
'ui.logo' => ['value' => $logo, 'group_key' => 'ui', 'remark' => '自定义LOGO'],
];
$this->setConfig($values);
$this->success('小程序设置已保存');
}
/**
* 批量写入 fc_config(存在则更新,不存在则新增)
*
* @param array $values 结构:键名 => ['value' => 值, 'group_key' => 分组, 'remark' => 备注]
* @return void
*/
protected function setConfig(array $values)
{
$now = time();
foreach ($values as $key => $item) {
$exist = Db::name('fc_config')->where('key', $key)->find();
if ($exist) {
Db::name('fc_config')->where('key', $key)->update([
'value' => (string)$item['value'],
'group_key' => $item['group_key'],
'updatetime' => $now,
]);
} else {
Db::name('fc_config')->insert([
'key' => $key,
'value' => (string)$item['value'],
'group_key' => $item['group_key'],
'remark' => $item['remark'],
'createtime' => $now,
'updatetime' => $now,
]);
}
}
}
/**
* 获取当前小程序基础配置(若数据库未设置则回退内置默认值)
*
* @return array 包含 appName, logo, servicePhone, aboutUs, shareTitle 的配置数组
*/
protected function current()
{
$cfg = [];
foreach (Db::name('fc_config')->select() as $row) {
$cfg[$row['key']] = $row['value'];
}
$pick = function ($key, $default) use ($cfg) {
return (isset($cfg[$key]) && $cfg[$key] !== '') ? $cfg[$key] : $default;
};
return [
'appName' => $pick('base.appName', '同城分类信息'),
'logo' => $pick('base.logo', ''),
'servicePhone' => $pick('base.servicePhone', '400-000-0000'),
'aboutUs' => $pick('base.aboutUs', ''),
'shareTitle' => $pick('base.shareTitle', ''),
];
}
}