mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 21:40:50 +00:00
feat(发票): 下单勾选发票同步创建开票申请
下单创建订单后写入 eb_order_invoice 申请记录(同订单幂等跳过),供后台发票列表与支付回写 is_pay;中台 invoice 仅作抬头快照
This commit is contained in:
parent
de8fe8d87f
commit
ae85b4a375
@ -1539,15 +1539,25 @@ class CenterOrderController
|
||||
throw new \RuntimeException('订单创建失败');
|
||||
}
|
||||
|
||||
// 中台主键:开票申请与活动回调共用
|
||||
$centerOrderId = 0;
|
||||
try {
|
||||
$centerOrderId = (int)app()->make(OrderCenterDao::class)->value(['order_no' => $orderNo], 'id');
|
||||
} catch (\Throwable $e) {
|
||||
// 查询失败不影响主流程(活动回调另有兜底)
|
||||
}
|
||||
|
||||
// 下单勾选发票:同步创建开票申请记录,供后台发票列表与支付回写 is_pay 使用
|
||||
if (!empty($invoiceInfo) && $centerOrderId > 0) {
|
||||
try {
|
||||
app()->make(OrderInvoiceServices::class)->createFromOrder((int)$uid, $centerOrderId, $invoiceInfo, 0);
|
||||
} catch (\Throwable $e) {
|
||||
\think\facade\Log::warning('下单创建开票申请失败: ' . $orderNo . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 6.1 活动订单创建后回调
|
||||
if ($isActivityOrder) {
|
||||
// 查询中台订单记录主键,供扩展回调使用(如拼团 order_id_key 记录、pink_id 回写中台订单)
|
||||
$centerOrderId = 0;
|
||||
try {
|
||||
$centerOrderId = (int)app()->make(OrderCenterDao::class)->value(['order_no' => $orderNo], 'id');
|
||||
} catch (\Throwable $e) {
|
||||
// 查询失败不影响主流程
|
||||
}
|
||||
$tradeModeHandler->afterOrderCreate($orderNo, $activityId, [
|
||||
'order_no' => $orderNo,
|
||||
'id' => $centerOrderId,
|
||||
|
||||
@ -248,6 +248,47 @@ class OrderInvoiceServices extends BaseService
|
||||
return ['id' => $re->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* 下单勾选发票时创建开票申请记录
|
||||
* 列表/支付回写以 eb_order_invoice 为准;中台 order_center.invoice 只作快照展示
|
||||
* @param int $uid 用户uid
|
||||
* @param int $orderCenterId 订单中台主键
|
||||
* @param array $invoice 用户发票抬头(eb_user_invoice)
|
||||
* @param int $isPay 是否已支付 0/1
|
||||
* @return int|null 开票记录id
|
||||
*/
|
||||
public function createFromOrder(int $uid, int $orderCenterId, array $invoice, int $isPay = 0): ?int
|
||||
{
|
||||
if (!$orderCenterId || empty($invoice)) {
|
||||
return null;
|
||||
}
|
||||
// 同一订单已有申请则跳过,避免拆单/重试重复写入
|
||||
if ($this->dao->getOne(['order_id' => $orderCenterId, 'is_del' => 0])) {
|
||||
return null;
|
||||
}
|
||||
$data = [];
|
||||
$data['uid'] = $uid;
|
||||
$data['category'] = 'order';
|
||||
$data['order_id'] = $orderCenterId;
|
||||
$data['invoice_id'] = (int)($invoice['id'] ?? 0);
|
||||
$data['header_type'] = $invoice['header_type'] ?? 1;
|
||||
$data['type'] = $invoice['type'] ?? 1;
|
||||
$data['name'] = $invoice['name'] ?? '';
|
||||
$data['duty_number'] = $invoice['duty_number'] ?? '';
|
||||
$data['drawer_phone'] = $invoice['drawer_phone'] ?? '';
|
||||
$data['email'] = $invoice['email'] ?? '';
|
||||
$data['tell'] = $invoice['tell'] ?? '';
|
||||
$data['address'] = $invoice['address'] ?? '';
|
||||
$data['bank'] = $invoice['bank'] ?? '';
|
||||
$data['card_number'] = $invoice['card_number'] ?? '';
|
||||
$data['is_pay'] = $isPay;
|
||||
$data['add_time'] = time();
|
||||
if (!$re = $this->dao->save($data)) {
|
||||
return null;
|
||||
}
|
||||
return (int)$re->id;
|
||||
}
|
||||
|
||||
public function setInvoice(int $id, array $data)
|
||||
{
|
||||
$orderInvoice = $this->dao->get($id);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user