| | |
| | | Map<String, Object> coupon = usableCoupon(principal.merchantId(), number(source.get("talentId")), string(source.get("cardLevel")), request.couponId(), discountedAmount(rule, request.amount())); |
| | | Map<String, Object> amounts = quote(rule, coupon, request.amount()); |
| | | Long dynamicCodeId = number(source.get("dynamicCodeId")); |
| | | int codeUpdated = jdbc.update(""" |
| | | update talent_dynamic_code set status = 1, merchant_id = ?, used_at = now() |
| | | where id = ? and status = 0 |
| | | """, principal.merchantId(), dynamicCodeId); |
| | | int codeUpdated = consumeScannedTalentCode(principal, dynamicCodeId); |
| | | if (codeUpdated == 0) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "人才码已被使用或已失效"); |
| | | } |
| | |
| | | return sources.get(0); |
| | | } |
| | | |
| | | int consumeScannedTalentCode(MerchantPrincipal principal, Long dynamicCodeId) { |
| | | return jdbc.update(""" |
| | | update talent_dynamic_code set status = 1, merchant_id = ?, used_at = now() |
| | | where id = ? and status in (0, 2) |
| | | """, principal.merchantId(), dynamicCodeId); |
| | | } |
| | | |
| | | private void ensurePending(Map<String, Object> source) { |
| | | if (number(source.get("attemptStatus")) != ATTEMPT_PENDING) { |
| | | throw new BusinessException(ErrorCode.CONFLICT, "该人才码已处理,请重新扫码"); |