|
@@ -200,7 +200,21 @@ public class OrderInvoiceService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 商家出餐自动开票(010 Phase 11):读 pos_order 发票意图 → 组装 dto(个人 BuyerName=手机号、
|
|
|
|
|
|
|
+ * 下单捕获发票意图(010 Phase 11):把下单选的发票类型/载具/统编/捐赠码落成 pos_order_invoice
|
|
|
|
|
+ * 意图行(issueTriggered=0 未触发开票、invoiceStatus=0 未开);出餐 {@link #autoIssue} 在该行
|
|
|
|
|
+ * 上更新开票结果并置 issueTriggered=1。仅在门店可开票时由 createOrder 调用。
|
|
|
|
|
+ */
|
|
|
|
|
+ public void captureInvoiceIntent(PosOrderInvoice intent) {
|
|
|
|
|
+ intent.setInvoiceStatus(STATUS_NOT_ISSUED);
|
|
|
|
|
+ intent.setIssueTriggered(0);
|
|
|
|
|
+ if (intent.getApplyTime() == null) {
|
|
|
|
|
+ intent.setApplyTime(new Date());
|
|
|
|
|
+ }
|
|
|
|
|
+ saveOrUpdate(intent);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商家出餐自动开票(010 Phase 11):读 pos_order_invoice 发票意图行 → 组装 dto(个人 BuyerName=手机号、
|
|
|
* 捐赠=机构名)→ 复用开票核心 {@link #reIssueAndSave}。系统触发,不校验客户归属;货到付款未付款也开
|
|
* 捐赠=机构名)→ 复用开票核心 {@link #reIssueAndSave}。系统触发,不校验客户归属;货到付款未付款也开
|
|
|
* (送达失败/取消时作废兜底)。门店不可开票 / 订单无发票意图 / 已开 → 静默跳过,不影响出餐。
|
|
* (送达失败/取消时作废兜底)。门店不可开票 / 订单无发票意图 / 已开 → 静默跳过,不影响出餐。
|
|
|
*
|
|
*
|
|
@@ -209,8 +223,14 @@ public class OrderInvoiceService {
|
|
|
*/
|
|
*/
|
|
|
public int autoIssue(Long orderId) {
|
|
public int autoIssue(Long orderId) {
|
|
|
PosOrder order = posOrderMapper.selectPosOrderById(orderId);
|
|
PosOrder order = posOrderMapper.selectPosOrderById(orderId);
|
|
|
- if (order == null || StrUtil.isBlank(order.getInvoiceChoice())) {
|
|
|
|
|
- return 0; // 订单不存在或无发票意图(门店不可开票时 createOrder 未写意图)
|
|
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ return 0; // 订单不存在
|
|
|
|
|
+ }
|
|
|
|
|
+ // 发票意图自 Phase 11 起落 pos_order_invoice(下单捕获的意图行),不再读 pos_order
|
|
|
|
|
+ PosOrderInvoice row = posOrderInvoiceMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<PosOrderInvoice>().eq(PosOrderInvoice::getOrderId, orderId));
|
|
|
|
|
+ if (row == null || StrUtil.isBlank(row.getInvoiceChoice())) {
|
|
|
|
|
+ return 0; // 无发票意图(门店不可开票时 createOrder 未插意图行)
|
|
|
}
|
|
}
|
|
|
Long storeId = order.getMdId();
|
|
Long storeId = order.getMdId();
|
|
|
if (!canInvoice(storeId)) {
|
|
if (!canInvoice(storeId)) {
|
|
@@ -222,60 +242,50 @@ public class OrderInvoiceService {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
// 防重复:已开则跳过
|
|
// 防重复:已开则跳过
|
|
|
- PosOrderInvoice row = posOrderInvoiceMapper.selectOne(
|
|
|
|
|
- new LambdaQueryWrapper<PosOrderInvoice>().eq(PosOrderInvoice::getOrderId, orderId));
|
|
|
|
|
- if (row != null && Integer.valueOf(STATUS_ISSUED).equals(row.getInvoiceStatus())) {
|
|
|
|
|
|
|
+ if (Integer.valueOf(STATUS_ISSUED).equals(row.getInvoiceStatus())) {
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
|
- ApplyInvoiceDto dto = buildAutoIssueDto(order);
|
|
|
|
|
|
|
+ ApplyInvoiceDto dto = buildAutoIssueDto(row);
|
|
|
EzPayConfig cfg = new EzPayConfig(ez.getMerchantId(), ez.getHashKey(), ez.getHashIv());
|
|
EzPayConfig cfg = new EzPayConfig(ez.getMerchantId(), ez.getHashKey(), ez.getHashIv());
|
|
|
// 捐赠=机构名;个人=手机号
|
|
// 捐赠=机构名;个人=手机号
|
|
|
String loveOrgName = null;
|
|
String loveOrgName = null;
|
|
|
- if ("LOVE_CODE".equals(order.getInvoiceChoice())) {
|
|
|
|
|
|
|
+ if ("LOVE_CODE".equals(row.getInvoiceChoice())) {
|
|
|
loveOrgName = resolveLoveOrg(dto.getLoveCode(), cfg);
|
|
loveOrgName = resolveLoveOrg(dto.getLoveCode(), cfg);
|
|
|
dto.setBuyerName(loveOrgName);
|
|
dto.setBuyerName(loveOrgName);
|
|
|
- } else if (isPersonalChoice(order.getInvoiceChoice())) {
|
|
|
|
|
|
|
+ } else if (isPersonalChoice(row.getInvoiceChoice())) {
|
|
|
InfoUser u = infoUserService.getOne(
|
|
InfoUser u = infoUserService.getOne(
|
|
|
new LambdaQueryWrapper<InfoUser>().eq(InfoUser::getUserId, order.getUserId()));
|
|
new LambdaQueryWrapper<InfoUser>().eq(InfoUser::getUserId, order.getUserId()));
|
|
|
dto.setBuyerName(u != null && StrUtil.isNotBlank(u.getPhone()) ? u.getPhone() : "會員");
|
|
dto.setBuyerName(u != null && StrUtil.isNotBlank(u.getPhone()) ? u.getPhone() : "會員");
|
|
|
}
|
|
}
|
|
|
- PosOrderInvoice saveRow = row == null ? new PosOrderInvoice() : row;
|
|
|
|
|
- saveRow.setOrderId(orderId);
|
|
|
|
|
- saveRow.setOrderNo(order.getDdId());
|
|
|
|
|
- saveRow.setStoreId(storeId);
|
|
|
|
|
- saveRow.setInvoiceCategory(dto.getCategory());
|
|
|
|
|
- saveRow.setBuyerName(dto.getBuyerName());
|
|
|
|
|
- saveRow.setBuyerUbn(dto.getBuyerUbn());
|
|
|
|
|
- saveRow.setBuyerEmail(dto.getBuyerEmail());
|
|
|
|
|
- saveRow.setCarrierType(dto.getCarrierType());
|
|
|
|
|
- saveRow.setCarrierNum(dto.getCarrierNum());
|
|
|
|
|
- saveRow.setLoveCode(dto.getLoveCode());
|
|
|
|
|
- saveRow.setLoveOrgName(loveOrgName);
|
|
|
|
|
- saveRow.setApplyTime(new Date());
|
|
|
|
|
- return reIssueAndSave(order, saveRow, dto, ez);
|
|
|
|
|
|
|
+ // 出餐触发开票:在意图行上落结果,并标记已触发(与 invoiceStatus 独立)
|
|
|
|
|
+ row.setInvoiceCategory(dto.getCategory());
|
|
|
|
|
+ row.setBuyerName(dto.getBuyerName());
|
|
|
|
|
+ row.setLoveOrgName(loveOrgName);
|
|
|
|
|
+ row.setIssueTriggered(1);
|
|
|
|
|
+ return reIssueAndSave(order, row, dto, ez);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 出餐自动开票:pos_order 发票意图 → ApplyInvoiceDto(捐赠走 DONATION 复用既有分支)。 */
|
|
|
|
|
- private ApplyInvoiceDto buildAutoIssueDto(PosOrder order) {
|
|
|
|
|
|
|
+ /** 出餐自动开票:pos_order_invoice 发票意图行 → ApplyInvoiceDto(捐赠走 DONATION 复用既有分支)。 */
|
|
|
|
|
+ private ApplyInvoiceDto buildAutoIssueDto(PosOrderInvoice intent) {
|
|
|
ApplyInvoiceDto dto = new ApplyInvoiceDto();
|
|
ApplyInvoiceDto dto = new ApplyInvoiceDto();
|
|
|
- dto.setOrderId(order.getId());
|
|
|
|
|
- String choice = order.getInvoiceChoice();
|
|
|
|
|
|
|
+ dto.setOrderId(intent.getOrderId());
|
|
|
|
|
+ String choice = intent.getInvoiceChoice();
|
|
|
switch (choice) {
|
|
switch (choice) {
|
|
|
case "PAPER":
|
|
case "PAPER":
|
|
|
case "PHONE_BARCODE":
|
|
case "PHONE_BARCODE":
|
|
|
case "CITIZEN":
|
|
case "CITIZEN":
|
|
|
dto.setCategory("B2C");
|
|
dto.setCategory("B2C");
|
|
|
- dto.setCarrierType(order.getCarrierType()); // PAPER 时为 null → 个人纸本分支
|
|
|
|
|
- dto.setCarrierNum(order.getCarrierNum());
|
|
|
|
|
|
|
+ dto.setCarrierType(intent.getCarrierType()); // PAPER 时为 null → 个人纸本分支
|
|
|
|
|
+ dto.setCarrierNum(intent.getCarrierNum());
|
|
|
break;
|
|
break;
|
|
|
case "LOVE_CODE":
|
|
case "LOVE_CODE":
|
|
|
dto.setCategory("DONATION");
|
|
dto.setCategory("DONATION");
|
|
|
- dto.setLoveCode(order.getLoveCode());
|
|
|
|
|
|
|
+ dto.setLoveCode(intent.getLoveCode());
|
|
|
break;
|
|
break;
|
|
|
case "COMPANY":
|
|
case "COMPANY":
|
|
|
dto.setCategory("B2B");
|
|
dto.setCategory("B2B");
|
|
|
- dto.setBuyerUbn(order.getBuyerUbn());
|
|
|
|
|
- dto.setBuyerName(order.getInvoiceBuyerName());
|
|
|
|
|
|
|
+ dto.setBuyerUbn(intent.getBuyerUbn());
|
|
|
|
|
+ dto.setBuyerName(intent.getBuyerName());
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|