From 1b0cf0db5c82ea8308d2f338973a91555787c34d Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期二, 18 三月 2025 11:17:23 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java | 91 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 84 insertions(+), 7 deletions(-) diff --git a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java index 295eb7e..fa41272 100644 --- a/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java +++ b/server/services/src/main/java/com/doumee/core/wx/WxMiniUtilService.java @@ -1,28 +1,41 @@ package com.doumee.core.wx; +import com.alibaba.fastjson.JSONObject; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.core.constants.Constants; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; +import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.ID; import com.doumee.dao.business.RefundMapper; import com.doumee.dao.business.TransactionsMapper; +import com.doumee.dao.business.model.Locks; import com.doumee.dao.business.model.Refund; import com.doumee.dao.business.model.Transactions; import com.doumee.dao.business.web.request.RefundDTO; +import com.doumee.dao.system.model.SystemDictData; import com.doumee.service.business.RefundService; import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest; import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; import com.github.binarywang.wxpay.exception.WxPayException; +import io.netty.handler.codec.base64.Base64Decoder; +import io.netty.handler.codec.base64.Base64Encoder; import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sun.misc.BASE64Decoder; +import java.io.*; import java.math.BigDecimal; -import java.util.Date; +import java.util.*; /** * 寰俊灏忕▼搴�-鍏叡鏂规硶 @@ -37,8 +50,11 @@ @Autowired private TransactionsMapper transactionsMapper; + @Autowired + private SystemDictDataBiz systemDictDataBiz; - @Transactional(rollbackFor = Exception.class) + + @Transactional(rollbackFor = {BusinessException.class,Exception.class}) public Refund wxRefund(RefundDTO refundDTO) { try { // 鍙戦�侀��娆捐姹� @@ -46,35 +62,57 @@ WxPayRefundRequest request = new WxPayRefundRequest(); request.setOutTradeNo(refundDTO.getOrderId()); request.setOutRefundNo(refNum); - request.setTotalFee(BaseWxPayRequest.yuanToFen(refundDTO.getTotalAmount().toString())); - request.setRefundFee(BaseWxPayRequest.yuanToFen(refundDTO.getRefundAmount().toString())); + request.setTotalFee(refundDTO.getTotalAmount().intValue()); + request.setRefundFee(refundDTO.getRefundAmount().intValue()); + System.out.println("瀹為檯鎬婚噾棰�" + refundDTO.getTotalAmount()); + System.out.println("瀹為檯閫�娆鹃噾棰�" + refundDTO.getRefundAmount()); +// request.setTotalFee(1); +// request.setRefundFee(1); WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request); if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) { //瀛樺偍閫�娆捐褰� 涓� 娴佹按璁板綍 Refund refund = new Refund(); + refund.setId(Constants.getUUID()); refund.setCreateDate(new Date()); refund.setMemberId(refundDTO.getMemberId()); refund.setMoney(refundDTO.getRefundAmount()); refund.setOnlineOrderid(refNum); refund.setPayWay(Constants.ZERO); + refund.setStatus(Constants.TWO); refund.setDoneDate(new Date()); + refund.setCreator(refundDTO.getCreator()); refund.setType(refundDTO.getType()); refund.setObjId(refundDTO.getOrderId()); refund.setReason(refundDTO.getReason()); + refund.setCanBalance(refundDTO.getCanBalance()); refundMapper.insert(refund); //瀛樺偍浜ゆ槗娴佹按琛� Transactions transactions = new Transactions(); + transactions.setId(Constants.getUUID()); transactions.setMemberId(refundDTO.getMemberId()); transactions.setCreateDate(new Date()); transactions.setIsdeleted(Constants.ZERO); transactions.setOrderId(refundDTO.getOrderId()); transactions.setMoney(refundDTO.getRefundAmount()); - transactions.setType(refundDTO.getType()==Constants.transactionsType.refund?Constants.transactionsType.platformRefund:Constants.transactionsType.refund); transactions.setPreOrderid(refundDTO.getOrderId()); transactions.setOnlineOrderid(refNum); transactions.setDoneDate(new Date()); - transactions.setTitle("閫�娆�"); - transactions.setContent(refundDTO.getType()==Constants.transactionsType.refund?"骞冲彴閫�娆�":"缁撶畻閫�娆�"); + if(refund.getType().equals(Constants.REFUND_TYPE.PLAT_AUTO.getKey())||refund.getType().equals(Constants.REFUND_TYPE.PLAT_FORCE.getKey())){ + //骞冲彴鑷姩閫�娆� 鎴� 寮哄埗閫�娆� + transactions.setType(Constants.TRANSACTIONS_TYPE.REFUND.getKey()); + transactions.setTitle(Constants.REFUND_TYPE.PLAT_AUTO.getInfo()); + transactions.setContent(Constants.REFUND_TYPE.PLAT_AUTO.getInfo()); + }else if(refund.getType().equals(Constants.REFUND_TYPE.NORMAL.getKey())){ + //鐢ㄦ埛涓诲姩閫�娆� + transactions.setType(Constants.TRANSACTIONS_TYPE.REFUND.getKey()); + transactions.setTitle(Constants.REFUND_TYPE.NORMAL.getInfo()); + transactions.setContent(Constants.REFUND_TYPE.NORMAL.getInfo()); + }else if(refund.getType().equals(Constants.REFUND_TYPE.BACK.getKey())){ + //缁撶畻鍚庨��娆� + transactions.setType(Constants.TRANSACTIONS_TYPE.REFUND.getKey()); + transactions.setTitle(Constants.REFUND_TYPE.BACK.getInfo()); + transactions.setContent(Constants.REFUND_TYPE.BACK.getInfo()); + } transactions.setBalance(BigDecimal.ZERO); transactions.setObjId(refund.getId()); transactions.setObjType(Constants.ONE); @@ -89,4 +127,43 @@ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"閫�娆惧彂鐢熷紓甯歌鑱旂郴绠$悊鍛�"); } + + /** + * 鐢熸垚灏忕▼搴忕爜 + * https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html + * @return + */ + public void generateWXMiniCode(Locks locks,SystemDictData systemDictData,String prePath,String path){ + + if(Objects.isNull(systemDictData)){ + return; + } + //鐢熸垚鍥剧墖涓婁紶OSS + Map<String,Object> body = new HashMap<>(); + // 鍦烘櫙鐮侊紝涓庡墠绔害瀹氾紝鏈�缁堟槸闇�瑕佸墠绔В鏋� + body.put("scene", locks.getSiteId() + "/" +locks.getCode() ); + // 姝e紡鐗堜负 "release"锛屼綋楠岀増涓� "trial"锛屽紑鍙戠増涓� "develop"銆傞粯璁ゆ槸姝e紡鐗堛�� + body.put("env_version", "release"); + // 閫忔槑锛屾牴鎹綘鐨勫満鏅嚜琛岃缃産ody鍙傛暟 + body.put("is_hyaline", false); + body.put("check_path", false); + body.put("page","pages/index/index"); + OkHttpClient client = new OkHttpClient().newBuilder().build(); + okhttp3.MediaType mediaType = okhttp3.MediaType.parse("application/json"); + okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(mediaType, JSONObject.toJSONString(body)); + Request request = new Request.Builder().url("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+systemDictData.getCode()).method("POST", requestBody).build(); + try { + Response response = client.newCall(request).execute(); + if (response.isSuccessful()) { + InputStream inputStream = new ByteArrayInputStream(response.body().bytes()); + String nowDate = DateUtil.getNowShortDate(); + File file = new File(prePath+path,locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); + FileUtils.copyInputStreamToFile(inputStream,file); + locks.setInfo(locks.getSiteId()+"-"+locks.getCode()+"-"+nowDate+".png"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } -- Gitblit v1.9.3