| | |
| | | import com.talentcard.server.business.BusinessIdGenerator; |
| | | import com.talentcard.server.business.DatabaseRows; |
| | | import com.talentcard.server.business.MoneyUtils; |
| | | import com.talentcard.server.business.merchant.MerchantPaymentReadinessService; |
| | | import com.talentcard.server.business.payment.HuifuRefundService; |
| | | import com.talentcard.server.business.PageResult; |
| | | import com.talentcard.server.common.BusinessException; |
| | |
| | | |
| | | private final JdbcTemplate jdbcTemplate; |
| | | private final HuifuRefundService refundService; |
| | | private final MerchantPaymentReadinessService merchantPaymentReadinessService; |
| | | |
| | | public OrderService(JdbcTemplate jdbcTemplate, HuifuRefundService refundService) { |
| | | public OrderService(JdbcTemplate jdbcTemplate, HuifuRefundService refundService, MerchantPaymentReadinessService merchantPaymentReadinessService) { |
| | | this.jdbcTemplate = jdbcTemplate; |
| | | this.refundService = refundService; |
| | | this.merchantPaymentReadinessService = merchantPaymentReadinessService; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | long subsidyAmount = MoneyUtils.yuanToCent(request.subsidyAmount()); |
| | | long payAmount = MoneyUtils.yuanToCent(request.payAmount()); |
| | | LocalDateTime expiresAt = payAmount == 0 ? null : LocalDateTime.now().plusMinutes(15); |
| | | // 需要支付的订单同样在创建时固定收款子商户,支付请求不再推断收款方。 |
| | | MerchantPaymentReadinessService.CollectingMerchant collectingMerchant = payAmount > 0 |
| | | ? merchantPaymentReadinessService.requireCollectingMerchant(request.merchantId(), request.storeId()) |
| | | : null; |
| | | String cardLevel = jdbcTemplate.query("select card_level from talent_card where id = ? and deleted = 0", rs -> rs.next() ? rs.getString(1) : null, request.cardId()); |
| | | jdbcTemplate.update(""" |
| | | insert into benefit_order(order_no, talent_id, card_id, card_level_snapshot, benefit_id, merchant_id, store_id, |
| | | order_type, order_amount, subsidy_amount, base_pay_amount, pay_amount, expires_at, order_status, verify_status) |
| | | values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0) |
| | | order_type, order_amount, subsidy_amount, base_pay_amount, pay_amount, expires_at, |
| | | collect_onboarding_id, collect_store_id, collect_huifu_id, order_status, verify_status) |
| | | values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0) |
| | | """, |
| | | orderNo, |
| | | request.talentId(), |
| | |
| | | payAmount, |
| | | payAmount, |
| | | expiresAt, |
| | | MerchantPaymentReadinessService.CollectingMerchant.applicationIdOf(collectingMerchant), |
| | | MerchantPaymentReadinessService.CollectingMerchant.storeIdOf(collectingMerchant), |
| | | MerchantPaymentReadinessService.CollectingMerchant.huifuIdOf(collectingMerchant), |
| | | payAmount == 0 ? 1 : 0); |
| | | return detail(orderNo); |
| | | } |