feat: 新增发布额度权益与订单管理功能,优化多端交互细节
这个提交包含在:
@@ -66,6 +66,12 @@ class FcAssets
|
||||
ROOT_PATH . 'public' . DS . 'assets' . DS . 'css',
|
||||
];
|
||||
|
||||
// FastAdmin 后台公共脚本(表格操作列、工具栏按钮)不在 backend 目录,需单独纳入指纹
|
||||
$files = [
|
||||
ROOT_PATH . 'public' . DS . 'assets' . DS . 'js' . DS . 'require-table.js',
|
||||
ROOT_PATH . 'public' . DS . 'assets' . DS . 'js' . DS . 'require-backend.min.js',
|
||||
];
|
||||
|
||||
$mtime = 0;
|
||||
$count = 0;
|
||||
foreach ($dirs as $dir) {
|
||||
@@ -78,6 +84,17 @@ class FcAssets
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!is_file($file)) {
|
||||
continue;
|
||||
}
|
||||
$time = @filemtime($file);
|
||||
if ($time > $mtime) {
|
||||
$mtime = $time;
|
||||
}
|
||||
$count++;
|
||||
}
|
||||
|
||||
// 最新修改时间 + 文件数量作为种子,crc32 转成纯数字(URL 安全,且兼容版本号 +1 逻辑)
|
||||
$fingerprint = sprintf('%u', crc32($mtime . '-' . $count));
|
||||
return $fingerprint;
|
||||
|
||||
@@ -29,6 +29,23 @@ class FcConfig
|
||||
return (isset($cfg[$key]) && $cfg[$key] !== '') ? $cfg[$key] : $default;
|
||||
};
|
||||
|
||||
// 解析会员权益配置(存为 JSON 字符串的 member.benefit)
|
||||
$benefitRaw = $pick('member.benefit', '');
|
||||
$benefitCfg = [];
|
||||
if ($benefitRaw) {
|
||||
$decoded = json_decode($benefitRaw, true);
|
||||
if (is_array($decoded)) {
|
||||
$benefitCfg = $decoded;
|
||||
}
|
||||
}
|
||||
$freeView = isset($benefitCfg['freeView']) ? (int)$benefitCfg['freeView'] : 20;
|
||||
$postDiscount = isset($benefitCfg['postDiscount']) ? (string)$benefitCfg['postDiscount'] : '8 折';
|
||||
$payViewPrice = $pick('fee.payView', '1');
|
||||
$benefitsArr = isset($benefitCfg['benefits']) && is_array($benefitCfg['benefits'])
|
||||
? $benefitCfg['benefits']
|
||||
: ['每日免费查看 20 条联系方式', '发布信息 8 折', '专属会员标识', '赠送大量发布额度'];
|
||||
$benefitsText = implode("\n", $benefitsArr);
|
||||
|
||||
return [
|
||||
'fc_miniapp' => [
|
||||
'name' => 'fc_miniapp',
|
||||
@@ -70,6 +87,17 @@ class FcConfig
|
||||
self::item('fc_post_yearQuota', '年卡条数', 'number', $pick('post.yearQuota', '500'), '年卡包含的发布条数', 'required;number'),
|
||||
],
|
||||
],
|
||||
'fc_member' => [
|
||||
'name' => 'fc_member',
|
||||
'title' => '会员配置',
|
||||
'active' => false,
|
||||
'list' => [
|
||||
self::item('fc_member_freeView', '每日免费查看条数', 'number', $freeView, '会员每日可免费查看联系方式条数(默认 20 条)', 'required;number'),
|
||||
self::item('fc_member_postDiscount', '单条发布折扣', 'string', $postDiscount, '付费发布时会员专享折扣,如「8折」或「8.5折」(默认 8 折)', 'required'),
|
||||
self::item('fc_fee_payView', '非会员查看价格', 'number', $payViewPrice, '非会员单条解锁联系方式费用(元,默认 1 元)', 'required;number'),
|
||||
self::item('fc_member_benefits', '会员特权清单', 'text', $benefitsText, '小程序端展示的特权清单,每行一条(支持后台自由增删与修改)'),
|
||||
],
|
||||
],
|
||||
'fc_dist' => [
|
||||
'name' => 'fc_dist',
|
||||
'title' => '分销配置',
|
||||
@@ -113,6 +141,9 @@ class FcConfig
|
||||
if ($has('fc_post_')) {
|
||||
self::savePublish($row);
|
||||
}
|
||||
if ($has('fc_member_') || $has('fc_fee_')) {
|
||||
self::saveMember($row);
|
||||
}
|
||||
if ($has('fc_dist_')) {
|
||||
self::saveDistribution($row);
|
||||
}
|
||||
@@ -254,6 +285,58 @@ class FcConfig
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员权益与联系方式查看费用配置
|
||||
*
|
||||
* @param array $row 系统配置页提交的 row 数组
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function saveMember(array $row)
|
||||
{
|
||||
$freeView = isset($row['fc_member_freeView']) ? max(0, (int)$row['fc_member_freeView']) : 20;
|
||||
$postDiscount = isset($row['fc_member_postDiscount']) ? trim((string)$row['fc_member_postDiscount']) : '8 折';
|
||||
if ($postDiscount === '') {
|
||||
$postDiscount = '8 折';
|
||||
}
|
||||
$payView = isset($row['fc_fee_payView']) ? max(0, round((float)$row['fc_fee_payView'], 2)) : 1;
|
||||
|
||||
$benefitsRaw = isset($row['fc_member_benefits']) ? trim((string)$row['fc_member_benefits']) : '';
|
||||
$benefits = [];
|
||||
if ($benefitsRaw !== '') {
|
||||
$lines = preg_split('/[\r\n]+/', $benefitsRaw);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line !== '') {
|
||||
$benefits[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($benefits)) {
|
||||
$benefits = [
|
||||
'每日免费查看 ' . $freeView . ' 条联系方式',
|
||||
'发布信息 ' . $postDiscount . ' 专属优惠',
|
||||
'专属会员标识',
|
||||
'赠送大量发布额度',
|
||||
];
|
||||
}
|
||||
|
||||
$current = [];
|
||||
$raw = Db::name('fc_config')->where('key', 'member.benefit')->value('value');
|
||||
if ($raw) {
|
||||
$decoded = json_decode($raw, true);
|
||||
if (is_array($decoded)) {
|
||||
$current = $decoded;
|
||||
}
|
||||
}
|
||||
$current['freeView'] = $freeView;
|
||||
$current['postDiscount'] = $postDiscount;
|
||||
$current['benefits'] = $benefits;
|
||||
|
||||
self::put('member.benefit', $current, 'member', '会员权益配置');
|
||||
self::put('fee.payView', $payView, 'fee', '非会员单条查看联系方式价格');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销参数
|
||||
*
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
/**
|
||||
* 订单取消与超时关闭服务
|
||||
*
|
||||
* 统一处理主动取消与超时自动关闭:
|
||||
* 1. 状态由 pending 原子更新为 closed
|
||||
* 2. 自动释放被锁定的优惠券
|
||||
* 3. 关联业务的回收处理(如未支付的发布贴置为关闭,防止未支付生效)
|
||||
* 4. 触发站内信通知
|
||||
*/
|
||||
class OrderClose
|
||||
{
|
||||
/** 默认订单超时时间(秒):30分钟 */
|
||||
const DEFAULT_TIMEOUT_SECONDS = 1800;
|
||||
|
||||
/**
|
||||
* 获取系统待支付订单超时时长(秒)
|
||||
* 优先读取配置 trade.order_timeout 或 order.timeout_minutes(单位:分钟),默认 30 分钟
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getTimeoutSeconds()
|
||||
{
|
||||
$minutes = Db::name('fc_config')->where('key', 'order.timeout_minutes')->value('value');
|
||||
if ($minutes === null || $minutes === '') {
|
||||
$minutes = Db::name('fc_config')->where('key', 'trade.order_timeout')->value('value');
|
||||
}
|
||||
$val = (int)$minutes;
|
||||
if ($val > 0) {
|
||||
return $val * 60;
|
||||
}
|
||||
return self::DEFAULT_TIMEOUT_SECONDS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断订单是否超时
|
||||
*
|
||||
* @param array $order fc_order 行
|
||||
* @param int|null $now 当前时间戳
|
||||
* @return bool
|
||||
*/
|
||||
public static function isExpired(array $order, $now = null)
|
||||
{
|
||||
if (empty($order) || (string)$order['status'] !== 'pending') {
|
||||
return false;
|
||||
}
|
||||
$now = $now ?: time();
|
||||
$createtime = isset($order['createtime']) ? (int)$order['createtime'] : 0;
|
||||
if ($createtime <= 0) {
|
||||
return false;
|
||||
}
|
||||
$timeout = self::getTimeoutSeconds();
|
||||
return ($now - $createtime) >= $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单(原子操作,支持主动取消或超时自动关闭)
|
||||
*
|
||||
* @param array $order fc_order 行(至少含 id、order_no、user_id、type、status、related_id)
|
||||
* @param string $reason 关闭原因:user_cancel(用户主动取消)、timeout_auto(超时自动关闭)、admin_cancel(后台取消)
|
||||
* @return bool 是否成功关闭
|
||||
*/
|
||||
public static function close(array $order, $reason = 'user_cancel')
|
||||
{
|
||||
$orderId = isset($order['id']) ? (int)$order['id'] : 0;
|
||||
$orderNo = isset($order['order_no']) ? (string)$order['order_no'] : '';
|
||||
if ($orderId <= 0 || $orderNo === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$closed = false;
|
||||
|
||||
try {
|
||||
Db::transaction(function () use ($orderId, $orderNo, $order, $reason, $now, &$closed) {
|
||||
// 条件更新,保证只有 pending 状态的订单才能转为 closed,天然防并发与重复关闭
|
||||
$affected = Db::name('fc_order')
|
||||
->where('id', $orderId)
|
||||
->where('status', 'pending')
|
||||
->update([
|
||||
'status' => 'closed',
|
||||
'refund_reason' => ($reason === 'user_cancel' ? '用户主动取消' : ($reason === 'timeout_auto' ? '超时未支付自动关闭' : '管理员关闭')),
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
|
||||
if (!$affected) {
|
||||
$closed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
$closed = true;
|
||||
|
||||
// 1. 释放优惠券(若有)
|
||||
CouponService::release($orderNo);
|
||||
|
||||
// 2. 关联业务的回收处理
|
||||
$type = isset($order['type']) ? (string)$order['type'] : '';
|
||||
$relatedId = isset($order['related_id']) ? (int)$order['related_id'] : 0;
|
||||
|
||||
// 若是未付款的发布信息,将关联的草稿或帖子置为下架/关闭,避免未付款直接审核显示
|
||||
if ($type === 'post' && $relatedId > 0) {
|
||||
Db::name('fc_post')
|
||||
->where('id', $relatedId)
|
||||
->where('user_id', (int)$order['user_id'])
|
||||
->where('audit_status', 0) // 仅当尚未审核通过时
|
||||
->update([
|
||||
'status' => 0, // 设为下架/关闭
|
||||
'updatetime' => $now,
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. 发送站内消息通知
|
||||
$userId = isset($order['user_id']) ? (int)$order['user_id'] : 0;
|
||||
if ($userId > 0) {
|
||||
$title = $reason === 'user_cancel' ? '订单已取消' : '订单已超时关闭';
|
||||
$orderTitle = isset($order['title']) ? (string)$order['title'] : '同城订单';
|
||||
$content = $reason === 'user_cancel'
|
||||
? "您的订单【{$orderTitle}】(订单号:{$orderNo})已主动取消。"
|
||||
: "您的订单【{$orderTitle}】(订单号:{$orderNo})因超过支付时效已自动关闭,锁定的优惠券已退回。";
|
||||
|
||||
Db::name('fc_message')->insert([
|
||||
'user_id' => $userId,
|
||||
'type' => 'system',
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'isread' => 0,
|
||||
'readtime' => null,
|
||||
'createtime' => $now,
|
||||
]);
|
||||
}
|
||||
});
|
||||
} catch (\Throwable $e) {
|
||||
Log::record("订单关闭失败:订单 {$orderNo},原因:{$e->getMessage()}", 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
return $closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 惰性检查并在超时时代为关闭
|
||||
*
|
||||
* @param array $order fc_order 行
|
||||
* @return array 最新订单数据
|
||||
*/
|
||||
public static function checkAndCloseIfExpired(array $order)
|
||||
{
|
||||
if (empty($order) || (string)$order['status'] !== 'pending') {
|
||||
return $order;
|
||||
}
|
||||
|
||||
if (self::isExpired($order)) {
|
||||
if (self::close($order, 'timeout_auto')) {
|
||||
$order['status'] = 'closed';
|
||||
$order['updatetime'] = time();
|
||||
}
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户