From 1a2b07f01ba4616fd9e894dddf474b56d020158c Mon Sep 17 00:00:00 2001 From: zhubaomin <zhubaomin> Date: 星期一, 07 四月 2025 15:18:51 +0800 Subject: [PATCH] 整理版本 --- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java | 520 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 520 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java new file mode 100644 index 0000000..af8e887 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java @@ -0,0 +1,520 @@ +package com.dy.pipIrrSell.wechatpay; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.dy.common.aop.SsoAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.cert.WxCertUtil; +import com.dy.pipIrrGlobal.pojoSe.*; +import com.dy.pipIrrGlobal.voSe.VoClient; +import com.dy.pipIrrSell.client.ClientSv; +import com.dy.pipIrrSell.result.SellResultCode; +import com.dy.pipIrrSell.util.AesUtil; +import com.dy.pipIrrSell.util.PayHelper; +import com.dy.pipIrrSell.util.RestTemplateUtil; +import com.dy.pipIrrSell.virtualCard.VirtualCardSv; +import com.dy.pipIrrSell.virtualCard.dto.DtoVirtualCard; +import com.dy.pipIrrSell.virtualCard.enums.LastOperateENUM; +import com.dy.pipIrrSell.virtualCard.enums.RefundItemStateENUM; +import com.dy.pipIrrSell.wallet.enums.RefundStatusENUM; +import com.dy.pipIrrSell.wechatpay.dto.*; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ResourceLoader; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import javax.crypto.NoSuchPaddingException; +import java.io.BufferedReader; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.security.SignatureException; +import java.security.spec.InvalidKeySpecException; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * @author ZhuBaoMin + * @date 2024-03-06 13:49 + * @LastEditTime 2024-03-06 13:49 + * @Description + */ + +@Slf4j +@Tag(name = "寰俊鏀粯绠$悊", description = "寰俊鏀粯鍚勭鎿嶄綔") +@RestController +@RequestMapping(path="payment") +@RequiredArgsConstructor +public class PaymentCtrl { + private final ResourceLoader resourceLoader; + + private final PaymentSv paymentSv; + private final RestTemplateUtil restTemplateUtil; + private final PayHelper payHelper; + private final VirtualCardSv virtualCardSv; + private final ClientSv clientSv; + + //private final String privateCertFileName = PayInfo.privateCertFileName; + private final String appid = PayInfo.appid; + private final String secret = PayInfo.secret; + private final String mchid = PayInfo.mchid; + private final String schema = PayInfo.schema; + private final String signType = PayInfo.signType; + private final String description = PayInfo.description; + private final String loginUrl = PayInfo.loginUrl; + private final String notifyUrl = PayInfo.notifyUrl; + private final String grantType = PayInfo.grantType; + + // 骞冲彴璇佷功鍏挜 + private final Map CERTIFICATE_MAP = new HashMap(); + + /** + * 鐧诲綍鍑瘉鏍¢獙锛屽啘鎴风粦瀹氳处鍙烽�昏緫鍖呭惈鐧诲綍鍑瘉鏍¢獙锛屾鎺ュ彛浣滃簾 + * @param code2Session 鐧诲綍鍑瘉鏍¢獙浼犲叆瀵硅薄 + * @param bindingResult + * @return + * @throws Exception + */ + @Operation(summary = "鐧诲綍鍑瘉鏍¢獙", description = "鐧诲綍鍑瘉鏍¢獙") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "getSessionId") + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> getSessionId(@RequestBody @Valid Code2Session code2Session, BindingResult bindingResult) throws Exception { + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + + String phoneNumber = code2Session.getPhoneNumber(); + String jsCode = code2Session.getJs_code(); + + Map<String, Object> queryParams = new HashMap<>(); + queryParams.put("appid", appid); + queryParams.put("secret", secret); + queryParams.put("js_code", jsCode); + queryParams.put("grant_type", grantType); + Map<String, String> headerParams = new HashMap<>(); + JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams); + + if(job.getLong("errcode") != null && job.getLong("errcode") >= -1) { + return BaseResponseUtils.buildFail("鐧诲綍鍑瘉鏍¢獙澶辫触"); + } + + String openid = job.getString("openid"); + String sessionKey = job.getString("session_key"); + + Long clientId = clientSv.getClientIdByPhone(phoneNumber); + String SessionId = ""; + if(clientId != null) { + // 娣诲姞寰俊鐢ㄦ埛璐︽埛璁板綍 + SeOpenId seOpenId = new SeOpenId(); + seOpenId.setClientId(clientId); + seOpenId.setOpenId(openid); + seOpenId.setSessionKey(sessionKey); + seOpenId.setCreateTime(new Date()); + Long rec = clientSv.addOpenId(seOpenId); + if(rec != null) { + SessionId = String.valueOf(rec); + } + return BaseResponseUtils.buildSuccess(SessionId); + + } else { + return BaseResponseUtils.buildError(SellResultCode.PHONE_NUMBER_IS_ERROR.getMessage()); + } + } + + /** + * 涓嬭浇寰俊鏀粯骞冲彴璇佷功 娴嬭瘯瀹屽簾闄� + * @return + * @throws Exception + */ + @Operation(summary = "涓嬭浇骞冲彴璇佷功", description = "涓嬭浇骞冲彴璇佷功") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @GetMapping(path = "certificates") + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> certificates() throws Exception { + String method = "GET"; + String httpUrl = "/v3/certificates"; + String nonceStr = payHelper.generateRandomString(); + Long timestamp = System.currentTimeMillis() / 1000; + + byte[] keyPemBs = WxCertUtil.getKey_pemBytes(resourceLoader) ; + String header = schema + " " + payHelper.getToken(method, httpUrl, "", nonceStr, timestamp, keyPemBs); + + Map<String, String> headers = new HashMap<>(); + headers.put("Authorization", header); + headers.put("Accept", "application/json"); + JSONObject job_result = restTemplateUtil.getHeaders(PayInfo.certificates,null, headers); + JSONObject job_headers = job_result.getJSONObject("headers"); + String wechatpayNonce = job_headers.getJSONArray("Wechatpay-Nonce").getString(0); + String wechatpaySerial = job_headers.getJSONArray("Wechatpay-Serial").getString(0); + String wechatpaySignature = job_headers.getJSONArray("Wechatpay-Signature").getString(0); + String wechatpaySignatureType = job_headers.getJSONArray("Wechatpay-Signature-Type").getString(0); + String wechatpayTimestamp = job_headers.getJSONArray("Wechatpay-Timestamp").getString(0); + + JSONObject job_body = job_result.getJSONObject("body"); + + // 鏋勯�犻獙绛惧悕涓� + String signatureStr = payHelper.responseSign(wechatpayTimestamp, wechatpayNonce, job_body.toJSONString()); + // 楠岃瘉绛惧悕 + Boolean valid = payHelper.responseSignVerify(wechatpaySerial, signatureStr, wechatpaySignature, keyPemBs); + + return BaseResponseUtils.buildSuccess(); + } + + /** + * JSAPI涓嬪崟 + * @param order 涓嬪崟璇锋眰瀵硅薄锛屽寘鍚渶瑕佷紶鍏ョ殑鍙傛暟 + * @param bindingResult + * @return 棰勬敮浠樹氦鏄撲細璇濇爣璇嗭紙鏈夋晥鏈�2灏忔椂锛� + */ + @Operation(summary = "JSAPI涓嬪崟", description = "JSAPI涓嬪崟") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "placeOrder") + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> placeOrder(@RequestBody @Valid DtoOrder order, BindingResult bindingResult) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, IOException, SignatureException, InvalidKeyException, Exception { + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + // 鎺ユ敹鍙傛暟锛氱櫥褰曟�両D銆佽櫄鎷熷崱ID銆佸厖鍊奸噾棰濓紙鍒嗭級 + Long sessionId = order.getSessionId(); + Long virtualId = order.getVcId(); + //Integer rechargeAmount = order.getRechargeAmount(); + + String prepayId = ""; + + SeOpenId po = paymentSv.selectOne(sessionId); + String openid = po.getOpenId(); + + SeVirtualCard seVirtualCard = virtualCardSv.selectVirtuCardById(virtualId); + Long clientId = seVirtualCard.getClientId(); + + VoClient voClient = clientSv.getOneClient(clientId); + String clientNum = voClient.getClientNum(); + + // 鐢熸垚璁㈠崟鍙峰苟娣诲姞鍏呭�艰褰� + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS"); + String orderNumber = clientNum + dateFormat.format(new Date()); + + // 鐢熸垚铏氭嫙鍗″厖鍊艰褰曪紙閮ㄥ垎瀛楁锛� + DtoVirtualCard virtualCard = new DtoVirtualCard(); + virtualCard.setOrderNumber(orderNumber); + virtualCard.setClientId(clientId); + virtualCard.setVirtualId(virtualId); + virtualCard.setRechargeAmount(order.getRechargeAmount()); + BaseResponse result = virtualCardSv.insertVCRecharge(virtualCard); + if(!result.getCode().equals("0001")) { + return BaseResponseUtils.buildFail(SellResultCode.RECHARGE_ADD_FAIL.getMessage()); + } + + JSONObject job_body = new JSONObject(); + job_body.put("appid", appid); + job_body.put("mchid", mchid); + job_body.put("description", description); + job_body.put("out_trade_no", orderNumber); + job_body.put("notify_url", notifyUrl); + + //璁㈠崟閲戦 + JSONObject job_amount = new JSONObject(); + job_amount.put("total", (int)(order.getRechargeAmount()*100)); + job_amount.put("currency", "CNY"); + job_body.put("amount", job_amount); + + //鏀粯鑰� + JSONObject job_payer = new JSONObject(); + job_payer.put("openid", openid); + job_body.put("payer", job_payer); + + // 鑾峰彇闅忔満涓插拰鏃堕棿鎴筹紝鏀惧湪姝ゅ浠ヤ繚璇� + String nonceStr = payHelper.generateRandomString(); + Long timestamp = System.currentTimeMillis() / 1000; + + String method = "POST"; + String httpUrl = "/v3/pay/transactions/jsapi"; + + String body = job_body.toJSONString(); + String header = schema + " " + payHelper.getToken(method, httpUrl, body, nonceStr, timestamp, WxCertUtil.getKey_pemBytes(resourceLoader)); + + Map<String, String> headers = new HashMap<>(); + headers.put("Authorization", header); + headers.put("Accept", "application/json"); + headers.put("Content-Type", "application/json"); + + // 鏆傛椂娉ㄩ噴鎺夛紝璁よ瘉閫氳繃鍚庡啀鏀惧紑 + JSONObject job_result = restTemplateUtil.post(PayInfo.orderUrl, body, headers); + if(job_result == null) { + return BaseResponseUtils.buildFail(SellResultCode.RECHARGE_ADD_FAIL.getMessage()); + } + + return BaseResponseUtils.buildSuccess(job_result) ; + } + + /** + * 鍐嶆绛惧悕 + * @param prepayId 棰勬敮浠樹氦鏄撲細璇濇爣璇� + * @return 灏忕▼搴忚皟璧锋敮浠樺弬鏁� + * @throws Exception + */ + @Operation(summary = "鍐嶆绛惧悕", description = "鍐嶆绛惧悕") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @GetMapping(path = "/signAgain") + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<JSONObject> signAgain(@RequestParam("prepayId") String prepayId) throws Exception { + + // 鑾峰彇闅忔満涓插拰鏃堕棿鎴筹紝鏀惧湪姝ゅ浠ヤ繚璇� + String appid = PayInfo.appid; + String timeStamp = String.valueOf(System.currentTimeMillis() / 1000); + String nonceStr = payHelper.generateRandomString(); + String pkg = "prepay_id=" + prepayId; + String message = payHelper.buildMessage_signAgain(appid, timeStamp, nonceStr, pkg); + String paySign = payHelper.sign(message.getBytes("utf-8"), WxCertUtil.getKey_pemBytes(resourceLoader)); + + JSONObject job_result = new JSONObject(); + job_result.put("timeStamp", timeStamp); + job_result.put("nonceStr", nonceStr); + job_result.put("package", pkg); + job_result.put("signType", signType); + job_result.put("paySign", paySign); + + return BaseResponseUtils.buildSuccess(job_result) ; + } + + /** + * 鏀粯閫氱煡/閫�娆剧粨鏋滈�氱煡 + * @param headers + * @param request + * @param response + * @return + * @throws IOException + * @throws GeneralSecurityException + */ + @Operation(summary = "鏀粯閫氱煡", description = "鏀粯閫氱煡") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "orderNotify", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public JSONObject orderNotify(@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse response) throws IOException, GeneralSecurityException, Exception { + JSONObject result = new JSONObject(); + + /** + * 1.楠岀澶勭悊 + * 浠巋eader涓彇鍑�4涓瓙鍙傛暟 + * 楠屾椂闂村樊锛岃秴杩�5鍒嗛挓鐨勪笉澶勭悊 + * 楠岃瘉绛惧悕 + * 楠岃瘉涔﹀簭鍒楀彿锛屽繀椤讳笌鏌愪竴涓瘉涔︾殑搴忓垪鍙蜂竴鑷� + */ + String wechatpayNonce = String.valueOf(headers.get("Wechatpay-Nonce").get(0)); + String wechatpaySerial = String.valueOf(headers.get("Wechatpay-Serial").get(0)); + String wechatpaySignature = String.valueOf(headers.get("Wechatpay-Signature").get(0)); + String wechatpayTimestamp = String.valueOf(headers.get("Wechatpay-Timestamp").get(0)); + + // 鑾峰彇body鍐呭 + BufferedReader reader = request.getReader(); + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + } + String bodyStr = stringBuilder.toString(); + + // body杞璞� + OrderNotify orderNotify = JSON.parseObject(bodyStr, OrderNotify.class); + + // 楠屾椂闂存埑锛屾椂闂村樊澶т簬5鍒嗛挓鐨勬嫆缁� + Long timeDiff = (System.currentTimeMillis() / 1000 - Long.parseLong(wechatpayTimestamp))/60; + if(timeDiff > 5) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + + // 鏋勯�犻獙绛惧悕涓� + String signatureStr = payHelper.responseSign(wechatpayTimestamp, wechatpayNonce, bodyStr); + byte[] keyPemBs = WxCertUtil.getKey_pemBytes(resourceLoader) ; + // 楠岃瘉绛惧悕 + Boolean valid = payHelper.responseSignVerify(wechatpaySerial, signatureStr, wechatpaySignature, keyPemBs); + if(!valid) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + + // 搴忓垪鍙烽獙璇佽鏀惧湪楠岀鍚庯紝鍥犱负楠岀鏃跺彲鑳戒細涓嬭浇鏂扮殑璇佷功 + boolean SerialIsValid = false; + for (String key : payHelper.CERTIFICATE_MAP.keySet()) { + if(key.equals(wechatpaySerial)) { + SerialIsValid = true; + } + } + if(!SerialIsValid) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + + // 瑙e瘑澶勭悊 + String eventType = orderNotify.getEvent_type(); + + if(eventType != null && eventType.equals("TRANSACTION.SUCCESS")) { + // 鏀粯鎴愬姛鍥炶皟 + /** + * 鏀粯鎴愬姛鐨勫洖璋� + * 鍙栧嚭閫氱煡鏁版嵁瀵硅薄锛岀户鑰屽彇鍑鸿В瀵嗘墍闇�鐨刟ssociatedData鍜宯once锛屼互鍙婂瘑鏂嘽iphertext + * 瑙e瘑ciphertext寰楀埌 + */ + NotifyResource notifyResource = orderNotify.getResource(); + String associatedData = notifyResource.getAssociated_data(); + String nonce = notifyResource.getNonce(); + String ciphertext = notifyResource.getCiphertext(); + + String resource = AesUtil.decryptToString(PayInfo.key.getBytes("utf-8"), associatedData.getBytes("utf-8"), nonce.getBytes("utf-8"), ciphertext); + JSONObject job_resource = JSONObject.parseObject(resource); + + // 瑙e瘑鍚庡彇鍑猴細鍟嗘埛璁㈠崟鍙枫�佸井淇℃敮浠樿鍗曞彿銆佷氦鏄撶姸鎬併�佹敮浠樺畬鎴愭椂闂� + String out_trade_no = job_resource.getString("out_trade_no"); + String transaction_id = job_resource.getString("transaction_id"); + String trade_state = job_resource.getString("trade_state"); + Date success_time = job_resource.getDate("success_time"); + + // 濡傛灉褰撳墠璁㈠崟鐘舵�佷负鏈敮浠樼姸鎬侊紝鍒欐洿鏂拌櫄鎷熷崱琛ㄥ強鍏呭�艰〃鍝嶅簲瀛楁 + SeVcRecharge seVcRecharge = virtualCardSv.getVCRechargeByorderNumber(out_trade_no); + if(seVcRecharge != null && seVcRecharge.getOrderState() == 1) { + BaseResponse result_ = virtualCardSv.updateVCRecharge(out_trade_no, success_time); + if(!result_.getCode().equals("0001")) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + } + } else if(eventType != null && eventType.equals("REFUND.SUCCESS")) { + // 閫�娆炬垚鍔熷悗鍥炶皟 + /** + * 閫�娆炬垚鍔熺殑鍥炶皟 + * 鍙栧嚭閫氱煡鏁版嵁瀵硅薄锛岀户鑰屽彇鍑鸿В瀵嗘墍闇�鐨刟ssociatedData鍜宯once锛屼互鍙婂瘑鏂嘽iphertext + * 瑙e瘑ciphertext寰楀埌 + */ + NotifyResource notifyResource = orderNotify.getResource(); + String associatedData = notifyResource.getAssociated_data(); + String nonce = notifyResource.getNonce(); + String ciphertext = notifyResource.getCiphertext(); + + String resource = AesUtil.decryptToString(PayInfo.key.getBytes("utf-8"), associatedData.getBytes("utf-8"), nonce.getBytes("utf-8"), ciphertext); + JSONObject job_resource = JSONObject.parseObject(resource); + + // 瑙e瘑鍚庡彇鍑猴細鍟嗘埛璁㈠崟鍛樸�佸井淇℃敮浠樿鍗曞彿銆佷氦鏄撶姸鎬併�佹敮浠樺畬鎴愭椂闂� + String out_trade_no = job_resource.getString("out_trade_no"); + String transaction_id = job_resource.getString("transaction_id"); + String out_refund_no = job_resource.getString("out_refund_no"); + String refund_status = job_resource.getString("refund_status"); + Date success_time = job_resource.getDate("success_time"); + if(!refund_status.equals("SUCCESS")) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + + // 鏇存柊铏氭嫙鍗¤〃鍙婂厖鍊艰〃鍝嶅簲瀛楁 + SeVcRefundItem seVcRefundItem = new SeVcRefundItem(); + seVcRefundItem.setRefundTime(success_time); + seVcRefundItem.setRefundStatus(RefundItemStateENUM.REFUNDED.getCode()); + Integer rec = virtualCardSv.updateRefundItem(seVcRefundItem); + if(rec == null && rec <= 0) { + response.setStatus(500); + result.put("code", "FAIL"); + result.put("message", "澶辫触"); + return result; + } + + // 鏍规嵁閫�娆惧崟鍙峰弽鏌ラ��娆綢D锛屾牴鎹��娆綢D鑾峰彇閫�娆剧姸鎬佹槸鏈��娆剧殑璁板綍鏁伴噺锛屽鏋滄槸0鍒欒鏄庡叏閮ㄩ��娆惧畬鎴愶紝鏇存柊閫�娆捐〃鐘舵�佷负宸查��娆撅紝灏嗛��娆惧悗閲戦鏇存柊鍒拌櫄鎷熷崱琛� + /** + * 鏍规嵁閫�娆鹃�氱煡鎺ュ彛杩斿洖鐨勯��娆惧崟鍙峰弽鏌ラ��娆綢D锛屾煡璇㈣閫�娆綢D涓嬫湭閫�娆捐褰曟暟閲� + * 濡傛灉缁撴灉涓�0锛屽垯璇ラ��娆惧凡缁忓畬鎴� + * 1. 鏇存柊閫�娆捐〃鐘舵�佷负宸查��娆� + * 2. 灏嗛��娆惧悗浣欓鏇存柊鍒拌櫄鎷熷崱琛ㄤ腑 + */ + Integer noRefundedCount = virtualCardSv.getNoRefundedCount(out_refund_no); + if(noRefundedCount != null && noRefundedCount == 0) { + // 鑾峰彇閫�娆惧璞″苟淇敼閫�娆剧姸鎬� + Long refundId = virtualCardSv.getRefundIdByRefundNumber(out_refund_no); + SeVcRefund seVcRefund = virtualCardSv.selectRefundByRefundId(refundId); + seVcRefund.setRefundStatus(RefundStatusENUM.REFUNDED.getCode()); + virtualCardSv.updateRefund(seVcRefund); + + // 鑾峰彇铏氭嫙鍗″璞″苟淇敼浣欓銆佹渶鍚庢搷浣溿�佹渶鍚庢搷浣滄椂闂� + Long vcId = seVcRefund.getVcId(); + Double afterRefund = seVcRefund.getAfterRefund(); + SeVirtualCard seVirtualCard = virtualCardSv.selectVirtuCardById(vcId); + seVirtualCard.setMoney(afterRefund); + seVirtualCard.setLastOperate(LastOperateENUM.REFUND.getCode()); + seVirtualCard.setLastOperateTime(new Date()); + virtualCardSv.updateVirtualCard(seVirtualCard); + } + } + + // 閫氱煡搴旂瓟 + response.setStatus(200); + result.put("code", "SUCCESS"); + result.put("message", "鎴愬姛"); + return result; + } + +} -- Gitblit v1.8.0