feat: 新增地址选择插件及订阅消息等多项功能优化

- 新增地址选择插件,支持地图位置选择并返回地址和经纬度
- 新增微信订阅消息发送功能,支持审核结果、提现通知等场景
- 新增订单支付状态查询、提现收款人姓名保存等接口
- 新增服务区域管理,支持按省市区划分并同步到信息发布
- 新增资金流水和营收报表导出功能
- 新增可用优惠券查询、订单退款拆分处理等功能
- 优化后台角标显示、首页数据统计、UI配置下发等
- 修复订单支付并发问题、地区管理逻辑等
这个提交包含在:
2026-10-22 17:14:56 +08:00
父节点 088a08d43a
当前提交 cb12bf5fc8
共有 180 个文件被更改,包括 9695 次插入 和 1680 次删除

查看文件

@@ -5,6 +5,7 @@ namespace app\admin\controller;
use app\admin\model\AdminLog;
use app\common\controller\Backend;
use think\Config;
use think\Db;
use think\Hook;
use think\Session;
use think\Validate;
@@ -40,11 +41,29 @@ class Index extends Backend
}
}
//左侧菜单
list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
'dashboard' => 'hot',
'addon' => ['new', 'red', 'badge'],
'auth/rule' => __('Menu'),
], $this->view->site['fixedpage']);
// 角标只展示需要处理的业务,不再使用 hot/new 这类装饰性角标
$badges = [];
try {
$pendingReport = (int)Db::name('fc_report')->where('status', 'pending')->count();
$pendingWithdraw = (int)Db::name('fc_withdraw')->where('status', 'auditing')->count();
$pendingMerchant = (int)Db::name('fc_merchant')->where('audit_status', 0)->count();
if ($pendingReport > 0) {
$badges['fc/report'] = [$pendingReport, 'orange'];
$badges['fc/content'] = [$pendingReport, 'orange'];
}
if ($pendingWithdraw > 0) {
$badges['fc/withdraw'] = [$pendingWithdraw, 'red'];
$badges['fc/trade'] = [$pendingWithdraw, 'red'];
}
if ($pendingMerchant > 0) {
$badges['fc/merchant'] = [$pendingMerchant, 'yellow'];
$badges['fc/user'] = [$pendingMerchant, 'yellow'];
}
} catch (\Exception $e) {
// 业务表缺失时不影响后台首页
}
list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar($badges, $this->view->site['fixedpage']);
$action = $this->request->request('action');
if ($this->request->isPost()) {
if ($action == 'refreshmenu') {

查看文件

@@ -11,7 +11,7 @@ use think\Cache;
* 规则管理
*
* @icon fa fa-list
* @remark 规则通常对应一个控制器的方法,同时左侧的菜单栏数据也从规则中体现,通常建议通过控制台进行生成规则节点
* @remark 左侧菜单与权限节点都在这里维护;修改后左侧导航自动刷新,删除菜单会连同其子级一起删除
*/
class Rule extends Backend
{
@@ -57,8 +57,8 @@ class Rule extends Backend
public function index()
{
if ($this->request->isAjax()) {
$list = $this->rulelist;
$total = count($this->rulelist);
$list = $this->assignSeq($this->filterRuleList($this->rulelist));
$total = count($list);
$result = array("total" => $total, "rows" => $list);
return json($result);
@@ -66,6 +66,116 @@ class Rule extends Backend
return $this->view->fetch();
}
/**
* 按筛选条件过滤规则树
*
* 支持:仅菜单 / 仅权限节点 / 全部、状态、关键词(标题或规则名)。
* 命中节点的父级会一并保留,避免树形层级断裂。
*
* @param array $list
* @return array
*/
protected function filterRuleList(array $list)
{
$type = (string)$this->request->request('rule_filter', 'menu');
$status = (string)$this->request->request('rule_status', '');
$keyword = trim((string)$this->request->request('rule_keyword', ''));
$type = in_array($type, ['menu', 'node', 'all'], true) ? $type : 'all';
$status = in_array($status, ['normal', 'hidden'], true) ? $status : '';
if ($type === 'all' && $status === '' && $keyword === '') {
return $list;
}
$byId = [];
foreach ($list as $row) {
$byId[(int)$row['id']] = $row;
}
$keep = [];
foreach ($list as $row) {
$match = true;
if ($type === 'menu' && !$row['ismenu']) {
$match = false;
}
if ($type === 'node' && $row['ismenu']) {
$match = false;
}
if ($status !== '' && $row['status'] !== $status) {
$match = false;
}
if ($keyword !== '' && stripos($row['title'], $keyword) === false && stripos($row['name'], $keyword) === false) {
$match = false;
}
if (!$match) {
continue;
}
// 保留命中节点的所有父级
$id = (int)$row['id'];
$guard = 0;
while ($id && isset($byId[$id]) && $guard++ < 20) {
$keep[$id] = true;
$id = (int)$byId[$id]['pid'];
}
}
$result = [];
foreach ($list as $row) {
if (isset($keep[(int)$row['id']])) {
$result[] = $row;
}
}
return $result;
}
/**
* 生成层级序号:1、1.1、1.2、2、2.1……
*
* 树形列表默认会隐藏子行,若按行号显示序号会出现 1/7/28 这类跳号;
* 这里按父子层级编号,展开/收起都稳定可读。
*
* @param array $list
* @return array
*/
protected function assignSeq(array $list)
{
$byId = [];
foreach ($list as $row) {
$byId[(int)$row['id']] = $row;
}
$seqById = [];
$counters = [];
foreach ($list as &$row) {
$depth = 0;
$pid = (int)$row['pid'];
$guard = 0;
while ($pid && isset($byId[$pid]) && $guard++ < 20) {
$depth++;
$pid = (int)$byId[$pid]['pid'];
}
$counters[$depth] = isset($counters[$depth]) ? $counters[$depth] + 1 : 1;
if ($depth === 0) {
$seq = (string)$counters[$depth];
} else {
$parentSeq = isset($seqById[(int)$row['pid']]) ? $seqById[(int)$row['pid']] : '';
$seq = ($parentSeq !== '' ? $parentSeq . '.' : '') . $counters[$depth];
}
// 进入新分支后,重置更深的层级计数
for ($i = $depth + 1; $i <= 10; $i++) {
unset($counters[$i]);
}
$row['seq'] = $seq;
$seqById[(int)$row['id']] = $seq;
}
unset($row);
return $list;
}
/**
* 添加
*/

查看文件

@@ -3,11 +3,12 @@
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-服务区域
* 同城-服务区域(省 / 市 / 区县平铺,区县为最终服务区域)
*
* @icon fa fa-circle-o
* @icon fa fa-map-o
*/
class Area extends Backend
{
@@ -22,16 +23,81 @@ class Area extends Backend
{
parent::_initialize();
$this->model = new \app\admin\model\FcArea;
}
/**
* 新增:保存前校验
*/
public function add()
{
$this->assignAreaOptions();
if ($this->request->isPost()) {
$this->validateArea($this->request->post('row/a'), 0);
}
return parent::add();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
* 编辑:保存前校验
* @param string $ids
*/
public function edit($ids = null)
{
$this->assignAreaOptions();
if ($this->request->isPost()) {
$this->validateArea($this->request->post('row/a'), (int)$this->request->param('ids'));
}
return parent::edit($ids);
}
/** 省 / 市 / 区县候选值,供表单级联下拉使用 */
protected function assignAreaOptions()
{
$rows = Db::name('fc_area')
->field('province,city,district')
->order('province asc, city asc, district asc')
->select();
$this->view->assign('areaOptionsJson', json_encode($rows, JSON_UNESCAPED_UNICODE));
}
/**
* 保存前校验:省 / 市 / 区县均必填,同一组合不可重复
* @param array $params 表单数据
* @param int $id 编辑时的区域ID
*/
protected function validateArea($params, $id = 0)
{
$province = isset($params['province']) ? trim((string)$params['province']) : '';
$city = isset($params['city']) ? trim((string)$params['city']) : '';
$district = isset($params['district']) ? trim((string)$params['district']) : '';
$values = ['省份' => $province, '城市' => $city, '区县' => $district];
foreach ($values as $label => $value) {
if ($value === '') {
$this->error($label . '不能为空');
}
if (mb_strlen($value) > 32) {
$this->error($label . '不能超过 32 个字符');
}
}
$duplicate = Db::name('fc_area')
->where('province', $province)
->where('city', $city)
->where('district', $district)
->where('id', '<>', $id)
->find();
if ($duplicate) {
$this->error('该省市区组合已存在');
}
foreach (['lat' => 90, 'lng' => 180] as $field => $limit) {
if (!isset($params[$field]) || $params[$field] === '' || $params[$field] === null) {
continue;
}
if (!is_numeric($params[$field]) || (float)$params[$field] < -$limit || (float)$params[$field] > $limit) {
$this->error($field === 'lat' ? '纬度格式不正确' : '经度格式不正确');
}
}
}
}

查看文件

@@ -89,6 +89,13 @@ class Dashboard extends Backend
$membersMap[$row['day']] = (int)$row['num'];
}
/* ---------- 今日较昨日的变化(用于首页涨跌标识) ---------- */
$yesterday = date('Y-m-d', $todayStart - 86400);
$metrics['yesterdayPost'] = isset($postsMap[$yesterday]) ? $postsMap[$yesterday] : 0;
$metrics['yesterdayOrder'] = isset($ordersMap[$yesterday]) ? $ordersMap[$yesterday] : 0;
$metrics['postDelta'] = $metrics['todayPost'] - $metrics['yesterdayPost'];
$metrics['orderDelta'] = round($metrics['todayOrderAmount'] - $metrics['yesterdayOrder'], 2);
$trend = [
'dates' => $days,
'posts' => [],
@@ -115,6 +122,7 @@ class Dashboard extends Backend
$this->view->assign('metrics', $metrics);
$this->view->assign('trendRows', $trendRows);
$this->view->assign('updatedAt', date('Y-m-d H:i'));
$this->assignconfig('trend', $trend);
return $this->view->fetch();

查看文件

@@ -3,6 +3,7 @@
namespace app\admin\controller\fc;
use app\common\controller\Backend;
use think\Db;
/**
* 同城-资金流水
@@ -34,4 +35,132 @@ class Financeflow extends Backend
*/
/**
* 导出资金流水(Excel)
* GET fc/financeflow/export?type=income|expense
*/
public function export()
{
$type = trim((string)$this->request->get('type', ''));
$q = Db::name('fc_finance_flow');
if ($type !== '') {
$q->where('type', $type);
}
$rows = $q->order('createtime desc')->limit(50000)->select();
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('资金流水');
$sheet->fromArray(['流水号', '类型', '场景', '金额(元)', '账户余额(元)', '关联ID', '备注', '时间'], null, 'A1');
$r = 2;
foreach ($rows as $row) {
$sheet->fromArray([
(string)$row['flow_no'],
$row['type'] === 'income' ? '收入' : '支出',
(string)$row['scene'],
(float)$row['amount'],
(float)$row['balance'],
(int)$row['related_id'],
(string)$row['remark'],
date('Y-m-d H:i:s', (int)$row['createtime']),
], null, 'A' . $r);
$r++;
}
$this->downloadXlsx($spreadsheet, '资金流水_' . date('YmdHis'));
}
/**
* 导出营收报表(Excel)
* GET fc/financeflow/exportReport?period=day|month|year
*/
public function exportReport()
{
$period = trim((string)$this->request->get('period', 'month'));
if (!in_array($period, ['day', 'month', 'year'], true)) {
$period = 'month';
}
$fmtMap = ['day' => '%Y-%m-%d', 'month' => '%Y-%m', 'year' => '%Y'];
$fmt = $fmtMap[$period];
$post = $this->periodSum('post', $fmt);
$member = $this->periodSum('member', $fmt);
$recharge = $this->periodSum('recharge', $fmt);
$withdraw = $this->periodWithdraw($fmt);
$keys = array_unique(array_merge(array_keys($post), array_keys($member), array_keys($recharge), array_keys($withdraw)));
sort($keys);
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('营收报表');
$sheet->fromArray(['周期', '发布收入', '会员收入', '充值收入', '提现支出', '净收入'], null, 'A1');
$r = 2;
foreach ($keys as $k) {
$p = isset($post[$k]) ? (float)$post[$k] : 0;
$m = isset($member[$k]) ? (float)$member[$k] : 0;
$rc = isset($recharge[$k]) ? (float)$recharge[$k] : 0;
$w = isset($withdraw[$k]) ? (float)$withdraw[$k] : 0;
$sheet->fromArray([
(string)$k,
round($p, 2),
round($m, 2),
round($rc, 2),
round($w, 2),
round($p + $m + $rc - $w, 2),
], null, 'A' . $r);
$r++;
}
$label = ['day' => '日', 'month' => '月', 'year' => '年'][$period];
$this->downloadXlsx($spreadsheet, '营收报表_按' . $label . '_' . date('YmdHis'));
}
/** 按周期聚合某类已支付订单 */
protected function periodSum($type, $fmt)
{
$rows = Db::name('fc_order')
->where('status', 'paid')
->where('type', $type)
->field("FROM_UNIXTIME(createtime, '{$fmt}') AS period, SUM(amount) AS total")
->group('period')
->select();
$map = [];
foreach ($rows as $row) {
$map[$row['period']] = (float)$row['total'];
}
return $map;
}
/** 按周期聚合已到账提现 */
protected function periodWithdraw($fmt)
{
$rows = Db::name('fc_withdraw')
->where('status', 'paid')
->whereNotNull('paytime')
->field("FROM_UNIXTIME(paytime, '{$fmt}') AS period, SUM(amount) AS total")
->group('period')
->select();
$map = [];
foreach ($rows as $row) {
$map[$row['period']] = (float)$row['total'];
}
return $map;
}
/** 输出 xlsx 下载 */
protected function downloadXlsx($spreadsheet, $filename)
{
$filename = preg_replace('/[^\w\x{4e00}-\x{9fa5}\-]/u', '', $filename) . '.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save('php://output');
exit;
}
}

查看文件

@@ -40,37 +40,43 @@ class Order extends Backend
public function refund()
{
$ids = $this->request->post('ids');
$amount = (float)$this->request->post('amount');
$amount = $this->request->post('amount');
$reason = $this->request->post('reason', '');
if ($amount <= 0) {
$this->error('退款金额需大于 0');
}
$ids = is_array($ids) ? $ids : explode(',', (string)$ids);
$ids = array_filter($ids);
if (!$ids) {
$this->error('请选择要退款的订单');
}
$orders = Db::name('fc_order')->where('id', 'in', $ids)->select();
if (!$orders) {
$this->error('订单不存在');
}
// 金额留空 = 按每笔订单实付金额全额退款
$amount = ($amount === '' || $amount === null || (float)$amount <= 0) ? null : (float)$amount;
$ok = 0;
$errors = [];
foreach ($orders as $order) {
Db::name('fc_order')->where('id', $order['id'])->update([
'status' => 'refunded',
'refund_amount' => $amount,
'refund_reason' => $reason,
'updatetime' => time(),
]);
Db::name('fc_message')->insert([
'user_id' => $order['user_id'],
'type' => 'system',
'title' => '订单退款',
'content' => '您的订单「' . $order['order_no'] . '」已退款' . $amount . '元' . ($reason ? ',原因:' . $reason : ''),
'isread' => 0,
'createtime' => time(),
]);
try {
\app\common\library\OrderRefund::refund((int)$order['id'], $amount, (string)$reason);
$ok++;
} catch (\Throwable $e) {
$errors[] = $order['order_no'] . ':' . $e->getMessage();
}
}
$this->success('退款成功');
if ($ok === 0) {
$this->error('退款失败:' . implode(';', $errors));
}
$msg = '退款成功 ' . $ok . ' 笔';
if ($errors) {
$msg .= ',失败 ' . count($errors) . ' 笔:' . implode(';', $errors);
}
$this->success($msg);
}
/**

查看文件

@@ -47,14 +47,20 @@ class Setting extends Backend
if ($appName === '') {
$this->error('小程序名称不能为空');
}
$logo = isset($params['logo']) ? trim((string)$params['logo']) : '';
$this->setConfig([
$values = [
'base.appName' => ['value' => $appName, 'group_key' => 'base', 'remark' => '小程序名称'],
'base.logo' => ['value' => isset($params['logo']) ? trim((string)$params['logo']) : '', 'group_key' => 'base', 'remark' => 'LOGO地址'],
'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('小程序设置已保存');
}

查看文件

@@ -67,6 +67,8 @@ class Userext extends Backend
* 说明:
* 余额存放在核心表 fa_user.money,本表(fc_user_ext)仅作业务扩展,
* 因此这里按 user_id 关联 fa_user 进行加减。
* 【注意】ids 必须是 fa_user.id(即本表的 user_id 字段),
* 不能传 fc_user_ext.id,否则会充错人(或报「未找到对应用户」)。
* 为可追溯,每次充值同时写入 fa_fc_finance_flow(资金流水)与
* fa_fc_message(站内通知),后台操作留痕由 Backend 自动记录。
*/
@@ -89,52 +91,66 @@ class Userext extends Backend
$remark = trim((string)$this->request->post('remark', ''));
$now = time();
$done = 0;
$missing = [];
foreach ($userIds as $uid) {
$user = Db::name('user')->where('id', $uid)->find();
if (!$user) {
continue;
Db::startTrans();
try {
foreach ($userIds as $uid) {
// 加行锁,避免并发充值互相覆盖余额
$user = Db::name('user')->where('id', $uid)->lock(true)->find();
if (!$user) {
$missing[] = $uid;
continue;
}
$balance = round((float)$user['money'] + $amount, 2);
Db::name('user')->where('id', $uid)->update([
'money' => $balance,
'updatetime' => $now,
]);
// 资金流水(平台口径:余额充值属于收入)
Db::name('fc_finance_flow')->insert([
'flow_no' => 'R' . date('YmdHis') . mt_rand(100, 999) . $uid,
'type' => 'income',
'scene' => '余额充值',
'amount' => $amount,
'balance' => $balance,
'related_id' => $uid,
'remark' => $remark !== '' ? $remark : ('后台充值给用户 #' . $uid),
'createtime' => $now,
]);
// 站内通知
Db::name('fc_message')->insert([
'user_id' => $uid,
'type' => 'system',
'title' => '余额充值到账',
'content' => '您的账户已充值 ¥' . number_format($amount, 2, '.', '')
. ',当前余额 ¥' . number_format($balance, 2, '.', '')
. '。' . ($remark !== '' ? '备注:' . $remark : ''),
'isread' => 0,
'readtime' => null,
'createtime' => $now,
]);
$done++;
}
$balance = round((float)$user['money'] + $amount, 2);
Db::name('user')->where('id', $uid)->update([
'money' => $balance,
'updatetime' => $now,
]);
// 资金流水(平台口径:余额充值属于收入)
Db::name('fc_finance_flow')->insert([
'flow_no' => 'R' . date('YmdHis') . mt_rand(100, 999) . $uid,
'type' => 'income',
'scene' => '余额充值',
'amount' => $amount,
'balance' => $balance,
'related_id' => $uid,
'remark' => $remark !== '' ? $remark : ('后台充值给用户 #' . $uid),
'createtime' => $now,
]);
// 站内通知
Db::name('fc_message')->insert([
'user_id' => $uid,
'type' => 'system',
'title' => '余额充值到账',
'content' => '您的账户已充值 ¥' . number_format($amount, 2, '.', '')
. ',当前余额 ¥' . number_format($balance, 2, '.', '')
. '。' . ($remark !== '' ? '备注:' . $remark : ''),
'isread' => 0,
'readtime' => null,
'createtime' => $now,
]);
$done++;
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('充值失败:' . $e->getMessage());
}
if (!$done) {
$this->error('未找到对应用户');
$this->error('未找到对应用户:' . implode(',', $missing) . '(请确认传的是用户ID)');
}
$this->success('充值成功:' . $done . ' 个用户,每人 ¥' . number_format($amount, 2, '.', ''));
$msg = '充值成功:' . $done . ' 个用户,每人 ¥' . number_format($amount, 2, '.', '');
if ($missing) {
$msg .= ';已跳过不存在的用户:' . implode(',', $missing);
}
$this->success($msg);
}
/**

查看文件

@@ -57,42 +57,81 @@ class Withdraw extends Backend
if (!$withdraws) {
$this->error('提现记录不存在');
}
foreach ($withdraws as $withdraw) {
if ($op === 'pay') {
Db::name('fc_withdraw')->where('id', $withdraw['id'])->update([
'status' => 'paid',
'paytime' => time(),
'updatetime' => time(),
]);
Db::name('fc_finance_flow')->insert([
'flow_no' => 'WD' . date('YmdHis') . $withdraw['id'],
'type' => 'expense',
'scene' => '佣金提现',
'amount' => $withdraw['amount'],
'balance' => 0,
'related_id' => $withdraw['id'],
'remark' => '提现打款',
'createtime' => time(),
]);
} else {
Db::name('fc_withdraw')->where('id', $withdraw['id'])->update([
'status' => 'rejected',
'reason' => $reason,
'updatetime' => time(),
]);
$done = 0;
$pending = 0;
$failed = 0;
$errors = [];
if ($op === 'reject') {
try {
Db::transaction(function () use ($withdraws, $reason, &$done) {
foreach ($withdraws as $withdraw) {
// 行锁 + 状态校验:已处理的记录不会被二次驳回
$locked = Db::name('fc_withdraw')->where('id', $withdraw['id'])->lock(true)->find();
if (!$locked || (string)$locked['status'] !== 'auditing') {
continue;
}
$done++;
Db::name('fc_withdraw')->where('id', $locked['id'])->update([
'status' => 'rejected',
'reason' => $reason,
'updatetime' => time(),
]);
Db::name('fc_message')->insert([
'user_id' => $locked['user_id'],
'type' => 'system',
'title' => '提现驳回',
'content' => '您的提现申请「' . $locked['withdraw_no'] . '」被驳回' . ($reason ? ',原因:' . $reason : ''),
'isread' => 0,
'createtime' => time(),
]);
}
});
} catch (\Throwable $e) {
$this->error('操作失败:' . $e->getMessage());
}
Db::name('fc_message')->insert([
'user_id' => $withdraw['user_id'],
'type' => 'system',
'title' => $op === 'pay' ? '提现成功' : '提现驳回',
'content' => $op === 'pay'
? '您的提现申请「' . $withdraw['withdraw_no'] . '」已打款,金额:' . $withdraw['amount'] . '元'
: '您的提现申请「' . $withdraw['withdraw_no'] . '」被驳回' . ($reason ? ',原因:' . $reason : ''),
'isread' => 0,
'createtime' => time(),
]);
if ($done === 0) {
$this->error('选中的提现记录均已处理,请刷新后重试');
}
$this->success('驳回成功(' . $done . ' 条)');
}
$this->success($op === 'pay' ? '打款成功' : '驳回成功');
// 通过 → 逐笔发起微信商家转账(外部调用不能放在事务里)
foreach ($withdraws as $withdraw) {
if ((string)$withdraw['status'] !== 'auditing') {
continue;
}
try {
$res = \app\common\library\WxTransfer::approve((int)$withdraw['id']);
$done++;
if ($res['withdrawState'] === 'paying') {
$pending++;
} elseif ($res['withdrawState'] === 'failed') {
$failed++;
}
} catch (\Throwable $e) {
$errors[] = $withdraw['withdraw_no'] . ':' . $e->getMessage();
}
}
if ($done === 0) {
$this->error('转账失败:' . implode(';', $errors));
}
$msg = '已发起转账 ' . $done . ' 笔';
if ($pending > 0) {
$msg .= '(其中 ' . $pending . ' 笔等待用户在微信确认收款)';
}
if ($failed > 0) {
$msg .= ',' . $failed . ' 笔转账失败';
}
if ($errors) {
$msg .= ';失败 ' . count($errors) . ' 笔:' . implode(';', $errors);
}
$this->success($msg);
}

查看文件

@@ -4,6 +4,7 @@ namespace app\admin\controller\general;
use app\common\controller\Backend;
use app\common\library\Email;
use app\common\library\FcConfig;
use app\common\model\Config as ConfigModel;
use think\Cache;
use think\Db;
@@ -75,11 +76,30 @@ class Config extends Backend
}
$siteList[$v['group']]['list'][] = $value;
}
// 把小程序 / 发布 / 分销三组业务配置并入系统配置页(值真源仍是 fa_fc_config)
$fcGroups = FcConfig::groups();
$merged = [];
foreach ($siteList as $k => $v) {
$merged[$k] = $v;
if ($k === 'basic') {
foreach ($fcGroups as $gk => $gv) {
$merged[$gk] = $gv;
}
}
}
if (!isset($merged['fc_miniapp'])) {
foreach ($fcGroups as $gk => $gv) {
$merged[$gk] = $gv;
}
}
$siteList = $merged;
$index = 0;
foreach ($siteList as $k => &$v) {
$v['active'] = !$index ? true : false;
$index++;
}
unset($v);
$this->view->assign('siteList', $siteList);
$this->view->assign('typeList', ConfigModel::getTypeList());
$this->view->assign('ruleList', ConfigModel::getRegexList());
@@ -138,6 +158,13 @@ class Config extends Backend
$this->token();
$row = $this->request->post("row/a", [], 'trim');
if ($row) {
// 小程序 / 发布 / 分销:写入 fc_config(系统配置页的业务分组)
try {
FcConfig::save($row);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$configList = [];
foreach ($this->model->all() as $v) {
if (isset($row[$v['name']])) {
@@ -152,14 +179,18 @@ class Config extends Backend
}
}
try {
$this->model->allowField(true)->saveAll($configList);
if ($configList) {
$this->model->allowField(true)->saveAll($configList);
}
} catch (Exception $e) {
$this->error($e->getMessage());
}
try {
ConfigModel::refreshFile();
} catch (Exception $e) {
$this->error($e->getMessage());
if ($configList) {
try {
ConfigModel::refreshFile();
} catch (Exception $e) {
$this->error($e->getMessage());
}
}
$this->success();
}