完成了基本调整调整

This commit is contained in:
2026-09-18 20:55:21 +08:00
parent 864187e105
commit 57e0854a0e
56 changed files with 3122 additions and 105 deletions
@@ -16,7 +16,9 @@ namespace app\store\controller\partners;
use app\common\service\PartnersBalance;
use app\common\service\QueueService;
use app\common\model\qyt\Enterprise as EnterpriseModel;
use app\common\service\QytInvoice;
use app\common\service\QytOil;
use app\common\service\QytRefund;
use app\store\controller\Controller;
use app\store\model\order\QrCode as QrCodeModel;
use app\store\model\partners\Order as OrderModel;
@@ -66,8 +68,12 @@ class Order extends Controller
if (!$order) {
return $this->renderError('订单不存在');
}
if ($order['use_status'] != 0) {
return $this->renderError('该单已加油核销');
// 一单可以分多次加油:没加完的单继续给加油地址
if ((int) $order['refund_status'] === 2) {
return $this->renderError('该单已退款,不能再加油');
}
if ((float) $order['used_amount'] + 0.005 >= (float) $order['total_price']) {
return $this->renderError('该单金额已全部加油');
}
if ($order['oil_status'] != 1) {
return $this->renderError('该单尚未发放成功,无法获取加油地址');
@@ -193,12 +199,120 @@ class Order extends Controller
if ($order['use_status'] != 1) {
return $this->renderError('该单未加油核销,无可回调内容');
}
(new QueueService())->push('notify_queue', json_encode([
'order_id' => $orderId,
'type' => 'sub',
'optType' => 'add_oil',
'retry_count' => 0,
], 320));
return $this->renderSuccess('已重新推送加油结果');
// 每笔加油单独通知:优先补推还没通知成功的;都通知过了就全部重推一遍(下游按 shareNo 去重)
$ids = Db::name('qyt_consume')->where('order_id', $orderId)->where('notify_status', 0)->order('id')->column('id');
$all = !$ids;
$all && $ids = Db::name('qyt_consume')->where('order_id', $orderId)->order('id')->column('id');
$queue = new QueueService();
if (!$ids) {
// 没有消费流水(改造前的历史单),按旧口径推一次
$queue->push('notify_queue', json_encode(['order_id' => $orderId, 'optType' => 'add_oil', 'retry_count' => 0], 320));
return $this->renderSuccess('已重新推送加油结果');
}
foreach ($ids as $consumeId) {
$queue->push('notify_queue', json_encode([
'order_id' => $orderId,
'optType' => 'add_oil',
'consume_id' => (int) $consumeId,
'retry_count' => 0,
], 320));
}
return $this->renderSuccess(($all ? '已重新推送全部 ' : '已补推未通知的 ') . count($ids) . ' 笔加油结果');
}
// ================================================================
// 退款(整单全额:7.17 查凭证 + 7.16 调低额度)
// ================================================================
/**
* 发起退款
*/
public function refund(): Json
{
$orderId = (int) $this->request->param('orderId');
$reason = trim((string) $this->request->param('reason', ''));
if (!Db::name('partners_order')->where('order_id', $orderId)->count()) {
return $this->renderError('订单不存在');
}
$res = QytRefund::apply($orderId, 'admin', $this->operator(), $reason);
return $res['ok'] ? $this->renderSuccess($res['data'], $res['message']) : $this->renderError($res['message']);
}
/**
* 确认「待人工确认」的退款:向企油通取证(7.13 流水 + 7.17 凭证)
*/
public function refundConfirm(): Json
{
$res = QytRefund::confirm((int) $this->request->param('orderId'));
return $this->decided($res) ? $this->renderSuccess($res['data'], $res['message']) : $this->renderError($res['message']);
}
/**
* 人工判定「待人工确认」的退款
* result = success / failed,remark 必填(判定依据)
*/
public function refundResolve(): Json
{
$result = (string) $this->request->param('result');
if (!in_array($result, ['success', 'failed'], true)) {
return $this->renderError('判定结果不合法');
}
$res = QytRefund::resolve(
(int) $this->request->param('orderId'),
$result === 'success',
$this->operator(),
(string) $this->request->param('remark', '')
);
return $this->decided($res) ? $this->renderSuccess($res['data'], $res['message']) : $this->renderError($res['message']);
}
/**
* 订单的退款流水
*/
public function refundLog(): Json
{
$list = Db::name('qyt_refund')
->where('order_id', (int) $this->request->param('orderId'))
->field('refund_id,refund_no,source,operator,reason,amount,quota_id,total_before,available_before,total_after,available_after,status,message,create_time,update_time')
->order('refund_id', 'desc')
->select()->toArray();
foreach ($list as &$row) {
$row['status_text'] = QytRefund::STATUS_TEXT[(int) $row['status']] ?? '';
$row['create_time_text'] = date('Y-m-d H:i:s', (int) $row['create_time']);
}
return $this->renderSuccess(compact('list'));
}
// ================================================================
// 发票(7.14,按「企业 + 消费月份 + 司机」关联)
// ================================================================
public function invoice(): Json
{
$order = Db::name('partners_order')->where('order_id', (int) $this->request->param('orderId'))->find();
if (!$order) {
return $this->renderError('订单不存在');
}
if ((int) $order['use_status'] !== 1) {
return $this->renderError('该订单还没有加油记录,暂无发票');
}
$res = QytInvoice::forOrder($order, (bool) $this->request->param('refresh', 0));
return $res['ok'] ? $this->renderSuccess($res, $res['message']) : $this->renderError($res['message']);
}
/**
* 取证 / 人工判定是否得出了结论:退款成功,或明确判定为「未生效」都算请求成功,
* 由返回的 refundStatus 区分;状态不符、取证失败、仍无法判定才算失败
*/
private function decided(array $res): bool
{
return $res['ok']
|| ($res['status'] === QytRefund::FAILED && $res['reason'] === QytRefund::REASON_UPSTREAM);
}
/** 当前后台操作人 */
private function operator(): string
{
return (string) ($this->store['user']['user_name'] ?? 'admin');
}
}