- 新增上传分类归一化处理,统一白名单校验规则 - 新增COS存储记录同步逻辑 - 新增分享功能支持,配置多页面分享参数 - 新增订单案例分享按钮 - 新增订单自动校验和回收命令 - 新增测试脚本和图片同步脚本 - 优化后台上传分类配置,统一分类映射
124 行
4.9 KiB
PHP
124 行
4.9 KiB
PHP
<?php
|
||
|
||
namespace app\admin\command;
|
||
|
||
use app\common\library\OrderStatus;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\Db;
|
||
|
||
/**
|
||
* 自动核销完工超过48小时未确认的工单守护任务
|
||
* 运行方式:php think order:autoverify
|
||
*/
|
||
class OrderAutoverify extends Command
|
||
{
|
||
protected function configure()
|
||
{
|
||
$this->setName('order:autoverify')
|
||
->setDescription('自动核销完工超过48小时未确认的工单');
|
||
}
|
||
|
||
protected function execute(Input $input, Output $output)
|
||
{
|
||
$threshold = time() - (48 * 3600);
|
||
$orders = Db::name('order')
|
||
->where('status', OrderStatus::PENDING_VERIFY)
|
||
->where('finish_time', '>', 0)
|
||
->where('finish_time', '<=', $threshold)
|
||
->select();
|
||
|
||
$count = count($orders);
|
||
$output->writeln("[OrderAutoverify] 扫描到 {$count} 笔超48小时待核销工单");
|
||
|
||
$success = 0;
|
||
foreach ($orders as $order) {
|
||
$orderId = (int)$order['id'];
|
||
$masterId = (int)$order['master_id'];
|
||
$payAmount = (float)$order['pay_amount'];
|
||
$rate = 10.00;
|
||
$commission = round($payAmount * $rate / 100, 2);
|
||
$settleAmount = round($payAmount - $commission, 2);
|
||
|
||
Db::startTrans();
|
||
try {
|
||
// 1. 更新订单为已完成
|
||
Db::name('order')->where('id', $orderId)->update([
|
||
'status' => OrderStatus::COMPLETED,
|
||
'verify_time' => time(),
|
||
'settle_status' => 1,
|
||
'settle_amount' => $settleAmount,
|
||
'updatetime' => time(),
|
||
]);
|
||
|
||
// 2. 插入订单日志
|
||
Db::name('order_log')->insert([
|
||
'order_id' => $orderId,
|
||
'from_status'=> OrderStatus::PENDING_VERIFY,
|
||
'to_status' => OrderStatus::COMPLETED,
|
||
'remark' => '完工满48小时客户未确认,系统自动验收结算',
|
||
'operator' => 'system',
|
||
'op_id' => 0,
|
||
'createtime' => time(),
|
||
]);
|
||
|
||
// 3. 写入结算表
|
||
Db::name('settle')->insert([
|
||
'order_id' => $orderId,
|
||
'master_id' => $masterId,
|
||
'order_amount' => $payAmount,
|
||
'commission_rate' => $rate,
|
||
'commission' => $commission,
|
||
'settle_amount' => $settleAmount,
|
||
'status' => 'settled',
|
||
'settle_time' => time(),
|
||
'createtime' => time(),
|
||
]);
|
||
|
||
// 4. 师傅钱包入账(行级悲观锁)
|
||
if ($masterId > 0) {
|
||
$master = Db::name('master')->where('id', $masterId)->lock(true)->find();
|
||
$newMoney = round((float)$master['money'] + $settleAmount, 2);
|
||
Db::name('master')->where('id', $masterId)->update([
|
||
'money' => $newMoney,
|
||
'order_count' => (int)$master['order_count'] + 1,
|
||
'updatetime' => time(),
|
||
]);
|
||
Db::name('wallet_log')->insert([
|
||
'user_type' => 'master',
|
||
'user_id' => $masterId,
|
||
'type' => 'settle',
|
||
'amount' => $settleAmount,
|
||
'balance' => $newMoney,
|
||
'order_id' => $orderId,
|
||
'remark' => '订单超时自动核销结算入账',
|
||
'createtime' => time(),
|
||
]);
|
||
|
||
// 通知师傅
|
||
Db::name('message')->insert([
|
||
'user_type' => 'master',
|
||
'user_id' => (int)$master['user_id'],
|
||
'title' => '订单自动核销结算入账',
|
||
'content' => "订单 {$order['order_no']} 完工满48小时已自动验收,收入 ¥{$settleAmount}",
|
||
'type' => 'order',
|
||
'target_id' => $orderId,
|
||
'is_read' => 0,
|
||
'createtime' => time(),
|
||
]);
|
||
}
|
||
|
||
Db::commit();
|
||
$success++;
|
||
$output->writeln(" [OK] 订单 #{$orderId} ({$order['order_no']}) 自动核销完成,结算 ¥{$settleAmount}");
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
$output->writeln(" [FAIL] 订单 #{$orderId} 自动核销异常: " . $e->getMessage());
|
||
}
|
||
}
|
||
|
||
$output->writeln("[OrderAutoverify] 执行结束,成功自动核销 {$success} 笔");
|
||
}
|
||
}
|