- 新增订单列表页面UI,支持状态筛选和搜索功能 - 新增订单删除API接口,支持用户软删除已完成/已取消订单 - 新增订单详情接口返回商品列表和联系信息 - 新增多个图标资源和API接口 - 修改上传配置和订单相关逻辑
197 行
8.7 KiB
PHP
197 行
8.7 KiB
PHP
<?php
|
||
|
||
// 1. 读取 Order.php
|
||
$orderFile = __DIR__ . '/../server/application/api/controller/Order.php';
|
||
$content = file_get_contents($orderFile);
|
||
|
||
// 替换 chooseQuote 中的差额补付逻辑
|
||
$oldChooseQuote = ' $quoteAmount = round((float)$quote[\'amount\'], 2);
|
||
$payAmount = max(0, round($quoteAmount - (float)$order[\'discount_amount\'], 2));
|
||
$remark = \'客户已选择 \' . $master[\'realname\'] . \' 的报价 ¥\' . $quoteAmount . \',等待师傅联系\';
|
||
|
||
Db::startTrans();
|
||
try {
|
||
$this->transit($order, OrderStatus::ACCEPTED, $remark, [
|
||
\'master_id\' => (int)$quote[\'master_id\'],
|
||
\'accept_time\' => time(),
|
||
\'base_amount\' => $quoteAmount,
|
||
\'floor_amount\' => 0,
|
||
\'urgent_amount\' => 0,
|
||
\'total_amount\' => $quoteAmount,
|
||
\'pay_amount\' => $payAmount,
|
||
], \'user\', $this->uid());
|
||
|
||
Db::name(\'order_quote\')->where(\'id\', $quoteId)->update([\'status\' => \'accept\']);
|
||
Db::name(\'order_quote\')->where(\'order_id\', $orderId)->where(\'id\', \'<>\', $quoteId)
|
||
->where(\'status\', \'wait\')->update([\'status\' => \'reject\']);
|
||
|
||
$this->notify(\'user\', (int)$order[\'user_id\'], \'已选定服务师傅\', $remark, \'order\', $orderId);
|
||
$this->notify(\'master\', (int)$master[\'user_id\'], \'您的报价已被选中\', \'订单 \' . $order[\'order_no\'] . \' 客户已选择您的报价 ¥\' . $quoteAmount . \',请尽快联系客户\', \'order\', $orderId);
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
$this->error(\'选择报价失败:\' . $e->getMessage());
|
||
}
|
||
|
||
$this->success(\'已选定师傅,请等待师傅联系\');';
|
||
|
||
$newChooseQuote = ' $quoteAmount = round((float)$quote[\'amount\'], 2);
|
||
$payAmount = max(0, round($quoteAmount - (float)$order[\'discount_amount\'], 2));
|
||
$alreadyPaid = (int)$order[\'pay_status\'] === 1 ? (float)$order[\'pay_amount\'] : 0.0;
|
||
$needDiff = max(0, round($payAmount - $alreadyPaid, 2));
|
||
|
||
$payType = $this->request->post(\'pay_type\', \'wechat\');
|
||
$remark = \'客户已选择 \' . $master[\'realname\'] . \' 的报价 ¥\' . $quoteAmount;
|
||
if ($needDiff > 0) {
|
||
$remark .= \'(补付差额 ¥\' . $needDiff . \')\';
|
||
}
|
||
$remark .= \',等待师傅联系\';
|
||
|
||
Db::startTrans();
|
||
try {
|
||
$updateData = [
|
||
\'master_id\' => (int)$quote[\'master_id\'],
|
||
\'accept_time\' => time(),
|
||
\'base_amount\' => $quoteAmount,
|
||
\'floor_amount\' => 0,
|
||
\'urgent_amount\' => 0,
|
||
\'total_amount\' => $quoteAmount,
|
||
\'pay_amount\' => $payAmount,
|
||
\'pay_status\' => 1,
|
||
];
|
||
if ($needDiff > 0) {
|
||
$updateData[\'pay_type\'] = $payType;
|
||
$updateData[\'pay_time\'] = time();
|
||
}
|
||
$this->transit($order, OrderStatus::ACCEPTED, $remark, $updateData, \'user\', $this->uid());
|
||
|
||
Db::name(\'order_quote\')->where(\'id\', $quoteId)->update([\'status\' => \'accept\']);
|
||
Db::name(\'order_quote\')->where(\'order_id\', $orderId)->where(\'id\', \'<>\', $quoteId)
|
||
->where(\'status\', \'wait\')->update([\'status\' => \'reject\']);
|
||
|
||
$this->notify(\'user\', (int)$order[\'user_id\'], \'已选定服务师傅\', $remark, \'order\', $orderId);
|
||
$this->notify(\'master\', (int)$master[\'user_id\'], \'您的报价已被选中\', \'订单 \' . $order[\'order_no\'] . \' 客户已选择您的报价 ¥\' . $quoteAmount . \',请尽快联系客户\', \'order\', $orderId);
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
$this->error(\'选择报价失败:\' . $e->getMessage());
|
||
}
|
||
|
||
$this->success(\'已选定师傅并完成支付托管,请等待师傅联系\', [
|
||
\'pay_amount\' => $payAmount,
|
||
\'need_diff\' => $needDiff,
|
||
\'already_pay\' => $alreadyPaid,
|
||
]);';
|
||
|
||
// 标准化 CRLF / LF
|
||
$content = str_replace(["\r\n", "\r"], "\n", $content);
|
||
$oldChooseQuoteNorm = str_replace(["\r\n", "\r"], "\n", $oldChooseQuote);
|
||
$newChooseQuoteNorm = str_replace(["\r\n", "\r"], "\n", $newChooseQuote);
|
||
|
||
if (strpos($content, $oldChooseQuoteNorm) !== false) {
|
||
$content = str_replace($oldChooseQuoteNorm, $newChooseQuoteNorm, $content);
|
||
echo "chooseQuote patched successfully.\n";
|
||
} else {
|
||
echo "chooseQuote block not found or already patched.\n";
|
||
}
|
||
|
||
// 增加超时自动核销方法 autoVerifyExpired
|
||
if (strpos($content, 'function autoVerifyExpired') === false) {
|
||
$autoVerifyCode = '
|
||
/**
|
||
* 超时未验收订单自动核销(默认48小时无争议自动验收结算,保障师傅权益)
|
||
*/
|
||
public static function autoVerifyExpired($timeoutSeconds = 172800)
|
||
{
|
||
$expiredTime = time() - (int)$timeoutSeconds;
|
||
$rows = Db::name(\'order\')
|
||
->where(\'status\', OrderStatus::PENDING_VERIFY)
|
||
->where(\'settle_status\', 0)
|
||
->where(\'finish_time\', \'<\', $expiredTime)
|
||
->limit(20)
|
||
->select();
|
||
|
||
$count = 0;
|
||
foreach ($rows 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 {
|
||
Db::name(\'order\')->where(\'id\', $orderId)->update([
|
||
\'status\' => OrderStatus::COMPLETED,
|
||
\'verify_time\' => time(),
|
||
\'settle_status\' => 1,
|
||
\'settle_amount\' => $settleAmount,
|
||
\'updatetime\' => time(),
|
||
]);
|
||
|
||
Db::name(\'order_log\')->insert([
|
||
\'order_id\' => $orderId,
|
||
\'status\' => OrderStatus::COMPLETED,
|
||
\'remark\' => \'完工超48小时未验收,系统自动确认完成并结算\',
|
||
\'actor_type\' => \'system\',
|
||
\'actor_id\' => 0,
|
||
\'createtime\' => time(),
|
||
]);
|
||
|
||
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(),
|
||
]);
|
||
|
||
if ($masterId > 0) {
|
||
$master = Db::name(\'master\')->where(\'id\', $masterId)->lock(true)->find();
|
||
if ($master) {
|
||
$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::commit();
|
||
$count++;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
}
|
||
}
|
||
return $count;
|
||
}
|
||
';
|
||
// 插入在类的最后一个闭合花括号前
|
||
$pos = strrpos($content, '}');
|
||
if ($pos !== false) {
|
||
$content = substr($content, 0, $pos) . $autoVerifyCode . "\n}\n";
|
||
echo "autoVerifyExpired appended to Order.php.\n";
|
||
}
|
||
}
|
||
|
||
// 统一写回文件
|
||
file_put_contents($orderFile, str_replace("\n", "\r\n", $content));
|
||
echo "Order.php updated.\n";
|