diff --git a/order/src/main/java/com/order/controller/OrderController.java b/order/src/main/java/com/order/controller/OrderController.java index ce4c79f..220de97 100644 --- a/order/src/main/java/com/order/controller/OrderController.java +++ b/order/src/main/java/com/order/controller/OrderController.java @@ -15,6 +15,7 @@ import com.hfkj.model.order.OrderModel; import com.hfkj.service.order.BsOrderService; import com.hfkj.service.pay.HuiPayService; import com.hfkj.sysenum.UserStatusEnum; +import com.hfkj.sysenum.order.OrderChildProductTypeEnum; import com.hfkj.sysenum.order.OrderPayChannelEnum; import com.hfkj.sysenum.order.OrderPayTypeEnum; import com.hfkj.sysenum.order.OrderStatusEnum; @@ -45,6 +46,7 @@ public class OrderController { private UserCenter userCenter; @Resource private BsOrderService orderService; + @RequestMapping(value="/create",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "创建订单") @@ -69,6 +71,11 @@ public class OrderController { || orderChild.getProductCount() == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + + if (orderChild.getProductType().equals(OrderChildProductTypeEnum.type1.getCode()) + && orderChild.getProductSpecId() == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } } body.setUserId(userSession.getUser().getId()); diff --git a/order/src/main/java/com/order/controller/OrderPayController.java b/order/src/main/java/com/order/controller/OrderPayController.java index ce4bf09..e10bf6a 100644 --- a/order/src/main/java/com/order/controller/OrderPayController.java +++ b/order/src/main/java/com/order/controller/OrderPayController.java @@ -95,7 +95,6 @@ public class OrderPayController { // 请求支付渠道 Map preorder = HuiPayService.preorder(body.getString("userId"), order); - return ResponseMsgUtil.success(preorder); } catch (Exception e) { log.error("error!",e); @@ -104,5 +103,4 @@ public class OrderPayController { } - } diff --git a/order/src/main/java/com/order/controller/business/OrderCouponController.java b/order/src/main/java/com/order/controller/business/OrderCouponController.java new file mode 100644 index 0000000..97fd2af --- /dev/null +++ b/order/src/main/java/com/order/controller/business/OrderCouponController.java @@ -0,0 +1,83 @@ +package com.order.controller.business; + +import com.alibaba.excel.EasyExcel; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.model.ResponseData; +import com.hfkj.service.coupon.BsOrderCouponService; +import com.order.controller.OrderController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +/** + * @className: OrderCouponController + * @author: HuRui + * @date: 2024/5/11 + **/ +@Controller +@RequestMapping(value="/coupon") +@Api(value="卡券订单业务") +public class OrderCouponController { + Logger log = LoggerFactory.getLogger(OrderCouponController.class); + + @Resource + private BsOrderCouponService orderCouponService; + + @RequestMapping(value="/queryList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询交易订单列表") + public ResponseData queryList(@RequestParam(value = "orderNo" , required = false) String orderNo, + @RequestParam(value = "childOrderNo" , required = false) String childOrderNo, + @RequestParam(value = "merId" , required = false) Long merId, + @RequestParam(value = "userPhone" , required = false) String userPhone, + @RequestParam(value = "payChannel" , required = false) Integer payChannel, + @RequestParam(value = "payType" , required = false) Integer payType, + @RequestParam(value = "createTimeS" , required = false) Long createTimeS, + @RequestParam(value = "createTimeE" , required = false) Long createTimeE, + @RequestParam(value = "payTimeS" , required = false) Long payTimeS, + @RequestParam(value = "payTimeE" , required = false) Long payTimeE, + @RequestParam(value = "finishTimeS" , required = false) Long finishTimeS, + @RequestParam(value = "finishTimeE" , required = false) Long finishTimeE, + @RequestParam(value = "cancelTimeS" , required = false) Long cancelTimeS, + @RequestParam(value = "cancelTimeE" , required = false) Long cancelTimeE, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + Map param = new HashMap<>(); + param.put("orderNo", orderNo); + param.put("userPhone", userPhone); + param.put("payChannel", payChannel); + param.put("payType", payType); + param.put("createTimeS", createTimeS); + param.put("createTimeE", createTimeE); + param.put("payTimeS", payTimeS); + param.put("payTimeE", payTimeE); + param.put("finishTimeS", finishTimeS); + param.put("finishTimeE", finishTimeE); + param.put("cancelTimeS", cancelTimeS); + param.put("cancelTimeE", cancelTimeE); + + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + + +} diff --git a/service/src/main/java/com/hfkj/common/exception/ErrorCode.java b/service/src/main/java/com/hfkj/common/exception/ErrorCode.java index 1bcc6f0..8d3a267 100644 --- a/service/src/main/java/com/hfkj/common/exception/ErrorCode.java +++ b/service/src/main/java/com/hfkj/common/exception/ErrorCode.java @@ -28,7 +28,7 @@ public enum ErrorCode { ACCOUNT_LOGIN_NOT("2003","账户未登录"), CONTENT_NOT_FOUND("2004","未查询到相关内容"), ROLE_NOT_PERMISSIONS("2005","该角色没有权限"), - + REQUEST_TIMED_OUT("2006","请求超时,请稍后重试"), UNKNOW_ERROR("999999","未知异常"), EXCEL_ERROR("80000","Excel处理异常"), ;//注意:上面为逗号,此次为分号 diff --git a/service/src/main/java/com/hfkj/common/utils/AESTool.java b/service/src/main/java/com/hfkj/common/utils/AESTool.java new file mode 100644 index 0000000..0365021 --- /dev/null +++ b/service/src/main/java/com/hfkj/common/utils/AESTool.java @@ -0,0 +1,126 @@ +package com.hfkj.common.utils; + +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import java.util.Calendar; + +/** + * @className: AESTool + * @author: HuRui + * @date: 2022/9/27 + **/ +public class AESTool { + + public static String Encrypt(String sSrc, String sKey) + { + try + { + return toHex(encryptBytes(sSrc.getBytes("utf-8"), sKey)); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + } + + public static byte[] encrypt(byte[] sSrc, String sKey) { + try { + return encryptBytes(sSrc, sKey); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + } + + public static byte[] encryptBytes(byte[] sSrc, String sKey) throws Exception + { + if (sKey == null) { + throw new Exception("Key为空null"); + } + + if (sKey.length() != 16) { + throw new Exception("Key长度不是16位"); + } + byte[] raw = sKey.getBytes("utf-8"); + + SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(1, skeySpec); + byte[] encrypted = cipher.doFinal(sSrc); + return encrypted; + } + + public static String Decrypt(String sSrc, String sKey) + { + try { + return new String(decryptBytes(toBytes(sSrc), sKey), "utf-8"); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + } + + public static byte[] decrypt(byte[] sSrc, String sKey) { + try { + return decryptBytes(sSrc, sKey); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + } + + + public static byte[] decryptBytes(byte[] sSrc, String sKey) + throws Exception + { + if (sKey == null) { + throw new Exception("Key为空null"); + } + + if (sKey.length() != 16) { + throw new Exception("Key长度不是16位"); + } + byte[] raw = sKey.getBytes("utf-8"); + + SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(2, skeySpec); + byte[] original = cipher.doFinal(sSrc); + return original; + } + + + + + public static String toHex(byte[] buf) + { + if (buf == null) + return ""; + StringBuffer result = new StringBuffer(2 * buf.length); + for (int i = 0; i < buf.length; i++) { + appendHex(result, buf[i]); + } + return result.toString(); + } + + private static void appendHex(StringBuffer sb, byte b) { + sb.append("0123456789ABCDEF".charAt(b >> 4 & 0xF)).append("0123456789ABCDEF".charAt(b & 0xF)); + } + + + + public static byte[] toBytes(String hexString) + { + int len = hexString.length() / 2; + byte[] result = new byte[len]; + for (int i = 0; i < len; i++) + result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2), + 16).byteValue(); + return result; + } + + public static void main(String[] args) { + Calendar cal = Calendar.getInstance(); + cal.add(5, 10); + String str = "1,13439676580," + cal.getTimeInMillis(); + String key = "0123456789ABCDEF"; + String token = Encrypt(str, key); + System.out.println(token); + System.out.println(Decrypt(token, key)); + } +} diff --git a/service/src/main/java/com/hfkj/common/security/DesUtil.java b/service/src/main/java/com/hfkj/common/utils/DesUtil.java similarity index 99% rename from service/src/main/java/com/hfkj/common/security/DesUtil.java rename to service/src/main/java/com/hfkj/common/utils/DesUtil.java index e409578..384e7c3 100644 --- a/service/src/main/java/com/hfkj/common/security/DesUtil.java +++ b/service/src/main/java/com/hfkj/common/utils/DesUtil.java @@ -1,9 +1,7 @@ -package com.hfkj.common.security; +package com.hfkj.common.utils; -import java.nio.charset.Charset; -import java.security.Key; -import java.security.SecureRandom; -import java.security.spec.AlgorithmParameterSpec; +import com.thoughtworks.xstream.core.util.Base64Encoder; +import org.apache.commons.codec.binary.Base64; import javax.crypto.Cipher; import javax.crypto.SecretKey; @@ -11,12 +9,10 @@ import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import javax.crypto.spec.DESedeKeySpec; import javax.crypto.spec.IvParameterSpec; - -import org.apache.commons.codec.binary.Base64; -//import org.apache.commons.lang3.RandomStringUtils; - - -import com.thoughtworks.xstream.core.util.Base64Encoder; +import java.nio.charset.Charset; +import java.security.Key; +import java.security.SecureRandom; +import java.security.spec.AlgorithmParameterSpec; public class DesUtil { diff --git a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java index e8ff847..8f70b22 100644 --- a/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java +++ b/service/src/main/java/com/hfkj/common/utils/HttpsUtils.java @@ -384,6 +384,81 @@ public class HttpsUtils { return null; } + + public static JSONObject doPostForm(String apiUrl, String body, Map header) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + for (Map.Entry entry : header.entrySet()) { + httpPost.setHeader(entry.getKey(), entry.getValue().toString()); + } + StringEntity stringEntity = new StringEntity(body,"UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } + + public static JSONObject doHuiLianTongPost(String apiUrl) { + CloseableHttpClient httpClient = null; + if (apiUrl.startsWith("https")) { + httpClient = HttpClients.custom().setSSLSocketFactory(createSSLConnSocketFactory()) + .setConnectionManager(connMgr).setDefaultRequestConfig(requestConfig).build(); + } else { + httpClient = HttpClients.createDefault(); + } + String httpStr = null; + CloseableHttpResponse response = null; + try { + HttpPost httpPost = new HttpPost(apiUrl); + httpPost.setConfig(requestConfig); + StringEntity stringEntity = new StringEntity("", "UTF-8");// 解决中文乱码问题 + stringEntity.setContentEncoding("UTF-8"); + stringEntity.setContentType("application/x-www-form-urlencoded"); + httpPost.setEntity(stringEntity); + response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + httpStr = EntityUtils.toString(entity, "UTF-8"); + return JSON.parseObject(httpStr); + } catch (Exception e) { + log.error(e.getMessage(),e); + } finally { + if (response != null) { + try { + EntityUtils.consume(response.getEntity()); + } catch (IOException e) { + log.error(e.getMessage(),e); + } + } + } + return null; + } + /** * 创建SSL安全连接 * diff --git a/service/src/main/java/com/hfkj/config/CommonSysConfig.java b/service/src/main/java/com/hfkj/config/CommonSysConfig.java index a3670a0..463e848 100644 --- a/service/src/main/java/com/hfkj/config/CommonSysConfig.java +++ b/service/src/main/java/com/hfkj/config/CommonSysConfig.java @@ -33,4 +33,48 @@ public class CommonSysConfig { */ private String huiPayPreorderNotifyUrl; + /** + * 重庆中石油 请求地址 + */ + private String chongQingCnpcUrl; + /** + * 重庆中石油商户号 + */ + private String chongQingCnpcMerNo; + /** + * 重庆中石油商户秘钥 + */ + private String chongQingCnpcMerKey; + /** + * 重庆中石油电子券签名秘钥 + */ + private String chongQingCnpcCouponSignKey; + /** + * 中油优途中石油请求地址 + */ + private String pcytCnpcPostUrl; + /** + * 中油优途中石油商户 + */ + private String pcytCnpcMerchant; + /** + * 中油优途中石油密钥 + */ + private String pcytCnpcSecret; + /** + * 比领星请求地址 + */ + private String blxPostUrl; + + /** + * 汇联通卡券请求地址 + */ + private String huiliantongUrl; + private String huiliantongAppNo; + private String huiliantongAppkey; + private String huiliantongAppsecret; + private String huiliantongSinopecDistributorId; + private String huiliantongDistributorId; + private String huiliantongSinopecUrl; + } diff --git a/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java b/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java index 4e097ef..ff1695c 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderChildMapper.java @@ -40,29 +40,31 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Insert({ "insert into bs_order_child (order_no, child_order_no, ", - "product_type, product_id, ", - "product_name, product_img, ", - "product_spec_id, product_spec_name, ", - "product_price, product_count, ", - "product_total_price, total_deduction_price, ", - "coupon_discount_price, integral_discount_price, ", - "product_actual_price, surplus_refund_count, ", - "surplus_refund_price, surplus_refund_integral, ", - "`status`, create_time, ", - "update_time, finish_time, ", - "ext_1, ext_2, ext_3)", + "mer_id, product_type, ", + "product_id, product_name, ", + "product_img, product_spec_id, ", + "product_spec_name, product_price, ", + "product_count, product_total_price, ", + "total_deduction_price, coupon_discount_price, ", + "integral_discount_price, product_actual_price, ", + "surplus_refund_count, surplus_refund_price, ", + "surplus_refund_integral, `status`, ", + "create_time, update_time, ", + "finish_time, ext_1, ", + "ext_2, ext_3)", "values (#{orderNo,jdbcType=VARCHAR}, #{childOrderNo,jdbcType=VARCHAR}, ", - "#{productType,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, ", - "#{productName,jdbcType=VARCHAR}, #{productImg,jdbcType=VARCHAR}, ", - "#{productSpecId,jdbcType=BIGINT}, #{productSpecName,jdbcType=VARCHAR}, ", - "#{productPrice,jdbcType=DECIMAL}, #{productCount,jdbcType=INTEGER}, ", - "#{productTotalPrice,jdbcType=DECIMAL}, #{totalDeductionPrice,jdbcType=DECIMAL}, ", - "#{couponDiscountPrice,jdbcType=DECIMAL}, #{integralDiscountPrice,jdbcType=DECIMAL}, ", - "#{productActualPrice,jdbcType=DECIMAL}, #{surplusRefundCount,jdbcType=INTEGER}, ", - "#{surplusRefundPrice,jdbcType=DECIMAL}, #{surplusRefundIntegral,jdbcType=BIGINT}, ", - "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{updateTime,jdbcType=TIMESTAMP}, #{finishTime,jdbcType=TIMESTAMP}, ", - "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{merId,jdbcType=BIGINT}, #{productType,jdbcType=INTEGER}, ", + "#{productId,jdbcType=BIGINT}, #{productName,jdbcType=VARCHAR}, ", + "#{productImg,jdbcType=VARCHAR}, #{productSpecId,jdbcType=BIGINT}, ", + "#{productSpecName,jdbcType=VARCHAR}, #{productPrice,jdbcType=DECIMAL}, ", + "#{productCount,jdbcType=INTEGER}, #{productTotalPrice,jdbcType=DECIMAL}, ", + "#{totalDeductionPrice,jdbcType=DECIMAL}, #{couponDiscountPrice,jdbcType=DECIMAL}, ", + "#{integralDiscountPrice,jdbcType=DECIMAL}, #{productActualPrice,jdbcType=DECIMAL}, ", + "#{surplusRefundCount,jdbcType=INTEGER}, #{surplusRefundPrice,jdbcType=DECIMAL}, ", + "#{surplusRefundIntegral,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", + "#{finishTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", + "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(BsOrderChild record); @@ -76,8 +78,9 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @Result(column="child_order_no", property="childOrderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="mer_id", property="merId", jdbcType=JdbcType.BIGINT), @Result(column="product_type", property="productType", jdbcType=JdbcType.INTEGER), - @Result(column="product_id", property="productId", jdbcType=JdbcType.INTEGER), + @Result(column="product_id", property="productId", jdbcType=JdbcType.BIGINT), @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR), @Result(column="product_img", property="productImg", jdbcType=JdbcType.VARCHAR), @Result(column="product_spec_id", property="productSpecId", jdbcType=JdbcType.BIGINT), @@ -104,11 +107,11 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Select({ "select", - "id, order_no, child_order_no, product_type, product_id, product_name, product_img, ", - "product_spec_id, product_spec_name, product_price, product_count, product_total_price, ", - "total_deduction_price, coupon_discount_price, integral_discount_price, product_actual_price, ", - "surplus_refund_count, surplus_refund_price, surplus_refund_integral, `status`, ", - "create_time, update_time, finish_time, ext_1, ext_2, ext_3", + "id, order_no, child_order_no, mer_id, product_type, product_id, product_name, ", + "product_img, product_spec_id, product_spec_name, product_price, product_count, ", + "product_total_price, total_deduction_price, coupon_discount_price, integral_discount_price, ", + "product_actual_price, surplus_refund_count, surplus_refund_price, surplus_refund_integral, ", + "`status`, create_time, update_time, finish_time, ext_1, ext_2, ext_3", "from bs_order_child", "where id = #{id,jdbcType=BIGINT}" }) @@ -116,8 +119,9 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), @Result(column="child_order_no", property="childOrderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="mer_id", property="merId", jdbcType=JdbcType.BIGINT), @Result(column="product_type", property="productType", jdbcType=JdbcType.INTEGER), - @Result(column="product_id", property="productId", jdbcType=JdbcType.INTEGER), + @Result(column="product_id", property="productId", jdbcType=JdbcType.BIGINT), @Result(column="product_name", property="productName", jdbcType=JdbcType.VARCHAR), @Result(column="product_img", property="productImg", jdbcType=JdbcType.VARCHAR), @Result(column="product_spec_id", property="productSpecId", jdbcType=JdbcType.BIGINT), @@ -155,8 +159,9 @@ public interface BsOrderChildMapper extends BsOrderChildMapperExt { "update bs_order_child", "set order_no = #{orderNo,jdbcType=VARCHAR},", "child_order_no = #{childOrderNo,jdbcType=VARCHAR},", + "mer_id = #{merId,jdbcType=BIGINT},", "product_type = #{productType,jdbcType=INTEGER},", - "product_id = #{productId,jdbcType=INTEGER},", + "product_id = #{productId,jdbcType=BIGINT},", "product_name = #{productName,jdbcType=VARCHAR},", "product_img = #{productImg,jdbcType=VARCHAR},", "product_spec_id = #{productSpecId,jdbcType=BIGINT},", diff --git a/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java index e41b811..5721ada 100644 --- a/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsOrderChildSqlProvider.java @@ -36,12 +36,16 @@ public class BsOrderChildSqlProvider { sql.VALUES("child_order_no", "#{childOrderNo,jdbcType=VARCHAR}"); } + if (record.getMerId() != null) { + sql.VALUES("mer_id", "#{merId,jdbcType=BIGINT}"); + } + if (record.getProductType() != null) { sql.VALUES("product_type", "#{productType,jdbcType=INTEGER}"); } if (record.getProductId() != null) { - sql.VALUES("product_id", "#{productId,jdbcType=INTEGER}"); + sql.VALUES("product_id", "#{productId,jdbcType=BIGINT}"); } if (record.getProductName() != null) { @@ -140,6 +144,7 @@ public class BsOrderChildSqlProvider { } sql.SELECT("order_no"); sql.SELECT("child_order_no"); + sql.SELECT("mer_id"); sql.SELECT("product_type"); sql.SELECT("product_id"); sql.SELECT("product_name"); @@ -192,12 +197,16 @@ public class BsOrderChildSqlProvider { sql.SET("child_order_no = #{record.childOrderNo,jdbcType=VARCHAR}"); } + if (record.getMerId() != null) { + sql.SET("mer_id = #{record.merId,jdbcType=BIGINT}"); + } + if (record.getProductType() != null) { sql.SET("product_type = #{record.productType,jdbcType=INTEGER}"); } if (record.getProductId() != null) { - sql.SET("product_id = #{record.productId,jdbcType=INTEGER}"); + sql.SET("product_id = #{record.productId,jdbcType=BIGINT}"); } if (record.getProductName() != null) { @@ -295,8 +304,9 @@ public class BsOrderChildSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}"); sql.SET("child_order_no = #{record.childOrderNo,jdbcType=VARCHAR}"); + sql.SET("mer_id = #{record.merId,jdbcType=BIGINT}"); sql.SET("product_type = #{record.productType,jdbcType=INTEGER}"); - sql.SET("product_id = #{record.productId,jdbcType=INTEGER}"); + sql.SET("product_id = #{record.productId,jdbcType=BIGINT}"); sql.SET("product_name = #{record.productName,jdbcType=VARCHAR}"); sql.SET("product_img = #{record.productImg,jdbcType=VARCHAR}"); sql.SET("product_spec_id = #{record.productSpecId,jdbcType=BIGINT}"); @@ -336,12 +346,16 @@ public class BsOrderChildSqlProvider { sql.SET("child_order_no = #{childOrderNo,jdbcType=VARCHAR}"); } + if (record.getMerId() != null) { + sql.SET("mer_id = #{merId,jdbcType=BIGINT}"); + } + if (record.getProductType() != null) { sql.SET("product_type = #{productType,jdbcType=INTEGER}"); } if (record.getProductId() != null) { - sql.SET("product_id = #{productId,jdbcType=INTEGER}"); + sql.SET("product_id = #{productId,jdbcType=BIGINT}"); } if (record.getProductName() != null) { diff --git a/service/src/main/java/com/hfkj/entity/BsOrderChild.java b/service/src/main/java/com/hfkj/entity/BsOrderChild.java index 06c63a8..bcddd2a 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderChild.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderChild.java @@ -29,6 +29,11 @@ public class BsOrderChild implements Serializable { */ private String childOrderNo; + /** + * 商户id + */ + private Long merId; + /** * 产品类型 */ @@ -37,7 +42,7 @@ public class BsOrderChild implements Serializable { /** * 产品id */ - private Integer productId; + private Long productId; /** * 产品名称 @@ -167,6 +172,14 @@ public class BsOrderChild implements Serializable { this.childOrderNo = childOrderNo; } + public Long getMerId() { + return merId; + } + + public void setMerId(Long merId) { + this.merId = merId; + } + public Integer getProductType() { return productType; } @@ -175,11 +188,11 @@ public class BsOrderChild implements Serializable { this.productType = productType; } - public Integer getProductId() { + public Long getProductId() { return productId; } - public void setProductId(Integer productId) { + public void setProductId(Long productId) { this.productId = productId; } @@ -366,6 +379,7 @@ public class BsOrderChild implements Serializable { return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getOrderNo() == null ? other.getOrderNo() == null : this.getOrderNo().equals(other.getOrderNo())) && (this.getChildOrderNo() == null ? other.getChildOrderNo() == null : this.getChildOrderNo().equals(other.getChildOrderNo())) + && (this.getMerId() == null ? other.getMerId() == null : this.getMerId().equals(other.getMerId())) && (this.getProductType() == null ? other.getProductType() == null : this.getProductType().equals(other.getProductType())) && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId())) && (this.getProductName() == null ? other.getProductName() == null : this.getProductName().equals(other.getProductName())) @@ -398,6 +412,7 @@ public class BsOrderChild implements Serializable { result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getOrderNo() == null) ? 0 : getOrderNo().hashCode()); result = prime * result + ((getChildOrderNo() == null) ? 0 : getChildOrderNo().hashCode()); + result = prime * result + ((getMerId() == null) ? 0 : getMerId().hashCode()); result = prime * result + ((getProductType() == null) ? 0 : getProductType().hashCode()); result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode()); result = prime * result + ((getProductName() == null) ? 0 : getProductName().hashCode()); @@ -433,6 +448,7 @@ public class BsOrderChild implements Serializable { sb.append(", id=").append(id); sb.append(", orderNo=").append(orderNo); sb.append(", childOrderNo=").append(childOrderNo); + sb.append(", merId=").append(merId); sb.append(", productType=").append(productType); sb.append(", productId=").append(productId); sb.append(", productName=").append(productName); diff --git a/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java b/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java index 38329c6..a57a17b 100644 --- a/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java +++ b/service/src/main/java/com/hfkj/entity/BsOrderChildExample.java @@ -326,6 +326,66 @@ public class BsOrderChildExample { return (Criteria) this; } + public Criteria andMerIdIsNull() { + addCriterion("mer_id is null"); + return (Criteria) this; + } + + public Criteria andMerIdIsNotNull() { + addCriterion("mer_id is not null"); + return (Criteria) this; + } + + public Criteria andMerIdEqualTo(Long value) { + addCriterion("mer_id =", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdNotEqualTo(Long value) { + addCriterion("mer_id <>", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdGreaterThan(Long value) { + addCriterion("mer_id >", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdGreaterThanOrEqualTo(Long value) { + addCriterion("mer_id >=", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdLessThan(Long value) { + addCriterion("mer_id <", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdLessThanOrEqualTo(Long value) { + addCriterion("mer_id <=", value, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdIn(List values) { + addCriterion("mer_id in", values, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdNotIn(List values) { + addCriterion("mer_id not in", values, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdBetween(Long value1, Long value2) { + addCriterion("mer_id between", value1, value2, "merId"); + return (Criteria) this; + } + + public Criteria andMerIdNotBetween(Long value1, Long value2) { + addCriterion("mer_id not between", value1, value2, "merId"); + return (Criteria) this; + } + public Criteria andProductTypeIsNull() { addCriterion("product_type is null"); return (Criteria) this; @@ -396,52 +456,52 @@ public class BsOrderChildExample { return (Criteria) this; } - public Criteria andProductIdEqualTo(Integer value) { + public Criteria andProductIdEqualTo(Long value) { addCriterion("product_id =", value, "productId"); return (Criteria) this; } - public Criteria andProductIdNotEqualTo(Integer value) { + public Criteria andProductIdNotEqualTo(Long value) { addCriterion("product_id <>", value, "productId"); return (Criteria) this; } - public Criteria andProductIdGreaterThan(Integer value) { + public Criteria andProductIdGreaterThan(Long value) { addCriterion("product_id >", value, "productId"); return (Criteria) this; } - public Criteria andProductIdGreaterThanOrEqualTo(Integer value) { + public Criteria andProductIdGreaterThanOrEqualTo(Long value) { addCriterion("product_id >=", value, "productId"); return (Criteria) this; } - public Criteria andProductIdLessThan(Integer value) { + public Criteria andProductIdLessThan(Long value) { addCriterion("product_id <", value, "productId"); return (Criteria) this; } - public Criteria andProductIdLessThanOrEqualTo(Integer value) { + public Criteria andProductIdLessThanOrEqualTo(Long value) { addCriterion("product_id <=", value, "productId"); return (Criteria) this; } - public Criteria andProductIdIn(List values) { + public Criteria andProductIdIn(List values) { addCriterion("product_id in", values, "productId"); return (Criteria) this; } - public Criteria andProductIdNotIn(List values) { + public Criteria andProductIdNotIn(List values) { addCriterion("product_id not in", values, "productId"); return (Criteria) this; } - public Criteria andProductIdBetween(Integer value1, Integer value2) { + public Criteria andProductIdBetween(Long value1, Long value2) { addCriterion("product_id between", value1, value2, "productId"); return (Criteria) this; } - public Criteria andProductIdNotBetween(Integer value1, Integer value2) { + public Criteria andProductIdNotBetween(Long value1, Long value2) { addCriterion("product_id not between", value1, value2, "productId"); return (Criteria) this; } diff --git a/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponNoService.java b/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponNoService.java new file mode 100644 index 0000000..bbbeeaa --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponNoService.java @@ -0,0 +1,27 @@ +package com.hfkj.service.coupon; + +import com.hfkj.entity.BsOrderCouponNo; + +import java.util.List; + +/** + * @className: BsOrderCouponNoService + * @author: HuRui + * @date: 2024/5/11 + **/ +public interface BsOrderCouponNoService { + + /** + * 编辑数据 + * @param data + */ + void editData(BsOrderCouponNo data); + + /** + * 查询列表 + * @param couponOrderNo + * @return + */ + List getListByCouponOrderId(Long couponOrderId); + +} diff --git a/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponService.java b/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponService.java new file mode 100644 index 0000000..336c91b --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/BsOrderCouponService.java @@ -0,0 +1,28 @@ +package com.hfkj.service.coupon; + +import com.hfkj.entity.BsOrderCoupon; + +import java.util.List; + +/** + * 卡券订单业务 + * @className: BsOrderCouponService + * @author: HuRui + * @date: 2024/5/10 + **/ +public interface BsOrderCouponService { + + /** + * 编辑数据 + * @param data + */ + void editData(BsOrderCoupon data); + + /** + * 查询卡券订单 + * @param orderChildOrderNo 子订单号 + * @return + */ + List getListByChildOrderNo(String orderChildOrderNo); + +} diff --git a/service/src/main/java/com/hfkj/service/coupon/channel/BlxCouponService.java b/service/src/main/java/com/hfkj/service/coupon/channel/BlxCouponService.java new file mode 100644 index 0000000..0c0114e --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/channel/BlxCouponService.java @@ -0,0 +1,340 @@ +package com.hfkj.service.coupon.channel; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.config.CommonSysConst; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.Map; + +/** + * 比邻星业务 + */ +@Component +public class BlxCouponService { + + private static Logger log = LoggerFactory.getLogger(BlxCouponService.class); + + @Resource + private RedisUtil redisUtil; + + /** + * @Author Sum1Dream + * @Name generateJw + * @Description // 获取token + * @Date 10:42 2023/7/11 + * @Param [] + * @Return java.lang.String + */ + public String generateJw() { + + Object token = redisUtil.get("BlxToken"); + + if (token == null) { + Map map = new HashMap<>(); + map.put("organizeCode" , "dhy"); + log.info("============ 比邻星停车券业务-获取TOKEN-START ============="); + JSONObject object = HttpsUtils.doGet(CommonSysConst.getSysConfig().getBlxPostUrl() + "/admin/api/generateJwt" , map); + log.info("请求参数: " + map); + log.info("响应参数: " + object); + log.info("============ 比邻星停车券业务-获取TOKEN-END =============="); + redisUtil.set("BlxToken" , object.getString("data") , 2000); + return object.getString("data"); + } + + return token.toString(); + } + + + + /** + * @Author Sum1Dream + * @Name queryCouponPage + * @Description // 获取比邻星停车券列表 + * @Date 10:57 2023/7/11 + * @Param [] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject queryCouponPage() { + log.info("============ 比邻星停车券业务-获取比邻星停车券列表-START ============="); + Map map = new HashMap<>(); + map.put("rows" , "20"); + map.put("currPage" , "1"); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + + JSONObject object = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/admin/api/qureyCouponPage" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + object); + log.info("============ 比邻星停车券业务-获取比邻星停车券列表-END =============="); + return object; + + } + /** + * @Author Sum1Dream + * @Name sendCoupon + * @Description // 发放券 + * @Date 11:01 2023/7/11 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject sendCoupon(JSONObject object) { + + Map map = new HashMap<>(); + map.put("couponCode" , object.getString("couponCode")); + map.put("receiverPhone" , object.getString("receiverPhone")); + map.put("receiverCount" , object.getInteger("receiverCount")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-发放停车券-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/admin/api/sendCupon" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-发放停车券-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name queryCouponPage + * @Description // 获取比邻星停车券列表 + * @Date 10:57 2023/7/11 + * @Param [] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject getUserCouponPage(JSONObject object) { + log.info("============ 比邻星停车券业务-获取用户未使用卡券列表-START ============="); + Map map = new HashMap<>(); + map.put("rows" , "2000"); + map.put("currPage" , "1"); + + JSONObject jsonObject = new JSONObject(); + + jsonObject.put("userMobile" , object.getString("userMobile")); + jsonObject.put("couponStatus" , object.getInteger("couponStatus")); + map.put("data" , jsonObject); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/admin/api/getUserCouponPage" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-获取比邻星停车券列表-END =============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name getUserBindCarNo + * @Description // 获取用户绑定车辆信息 + * @Date 10:11 2023/8/25 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject getUserBindCarNo(JSONObject object) { + + Map map = new HashMap<>(); + map.put("userMobile" , object.getString("userMobile")); + map.put("organizeCode" , object.getString("organizeCode")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-获取用户绑定车辆信息-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/getUserBindCarNo" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-获取用户绑定车辆信息-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name addUserBindCarNo + * @Description // 用户绑定车辆 + * @Date 10:11 2023/8/25 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject addUserBindCarNo(JSONObject object) { + + Map map = new HashMap<>(); + map.put("userMobile" , object.getString("userMobile")); + map.put("organizeCode" , object.getString("organizeCode")); + map.put("plateNumber" , object.getString("plateNumber")); + // 车牌颜色- 0:未知,1:蓝色,2:黄色,3:黑色,4:白色,5:绿色 + map.put("plateColor" , object.getString("plateColor")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-用户绑定车辆-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/addUserBindCarNo" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-用户绑定车辆-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name delUserBindCarNo + * @Description // 删除用户绑定车辆 + * @Date 10:20 2023/8/25 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject delUserBindCarNo(JSONObject object) { + + Map map = new HashMap<>(); + map.put("userMobile" , object.getString("userMobile")); + map.put("organizeCode" , object.getString("organizeCode")); + map.put("plateNumber" , object.getString("plateNumber")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-删除用户绑定车辆-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/delUserBindCarNo" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-删除用户绑定车辆-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name queryJsParking + * @Description // 获取附近停车场-捷顺 + * @Date 10:26 2023/8/25 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject queryJsParking(JSONObject object) { + + Map map = new HashMap<>(); + map.put("gps" , object.getString("gps")); + map.put("range" , object.getString("range")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-获取附近停车场-捷顺-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/queryJsParking" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-获取附近停车场-捷顺-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name queryJsOrderList + * @Description // 查询车牌订单列表信息 + * @Date 11:42 2023/8/28 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject queryJsOrderList(JSONObject object) { + + Map map = new HashMap<>(); + map.put("carNo" , object.getString("carNo")); + map.put("orderStatus" , object.getString("orderStatus")); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-查询车牌订单列表信息--捷顺-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/queryJsOrderList" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + System.out.println(header); + System.out.println(map); + log.info("============ 比邻星停车券业务-查询车牌订单列表信息--捷顺-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name creatOrder + * @Description // 停车添加订单 + * @Date 10:12 2023/8/30 + * @Param [object] + * @Return com.alibaba.fastjson.JSONObject + */ + public JSONObject creatOrder(JSONObject object) { + + Map map = new HashMap<>(); + map.put("organizeCode" , "dhy"); + map.put("userMobile" , object.getString("userMobile")); + map.put("userCouponCode" , object.getString("userCouponCode")); + map.put("parkOrderId" , object.getString("parkOrderId")); + map.put("orderType" , object.getString("orderType")); + map.put("prePrice" , object.getString("prePrice")); + map.put("parkId" , object.getString("parkId")); + map.put("parkName" , object.getString("parkName")); + map.put("parkTime" , object.getString("parkTime")); + map.put("carSeatId" , object.getString("carSeatId")); + map.put("inTime" , object.getString("inTime")); + map.put("outTime" , object.getString("outTime")); + map.put("carNo" , object.getString("carNo")); + map.put("parkType" , 1); + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + log.info("============ 比邻星停车券业务-查询车牌订单列表信息--捷顺-START ============="); + JSONObject data = HttpsUtils.doPost(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/creatOrder" , map , header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-查询车牌订单列表信息--捷顺-END ============="); + return data; + + } + + /** + * @Author Sum1Dream + * @Name parkOrderPay + * @Description // 订单支付 + * @Date 14:49 2023/9/4 + * @Param object + * @return com.alibaba.fastjson.JSONObject + */ + public JSONObject parkOrderPay(JSONObject object) { + + Map header = new HashMap<>(); + header.put("token" , generateJw()); + Map map = new HashMap<>(); + map.put("orderCode" , object.getString("orderCode")); + log.info("============ 比邻星停车券业务-停车场订单支付--捷顺-START ============="); + JSONObject data = HttpsUtils.doGet(CommonSysConst.getSysConfig().getBlxPostUrl() + "/peration/member/parking/api/parkOrderPay" , map, header); + log.info("头部参数: " + header); + log.info("请求参数: " + map); + log.info("响应参数: " + data); + log.info("============ 比邻星停车券业务-停车场订单支付--捷顺-END ============="); + return data; + + } + + + + +} diff --git a/service/src/main/java/com/hfkj/service/coupon/channel/ChongQingCNPCCouponService.java b/service/src/main/java/com/hfkj/service/coupon/channel/ChongQingCNPCCouponService.java new file mode 100644 index 0000000..e33d585 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/channel/ChongQingCNPCCouponService.java @@ -0,0 +1,165 @@ +package com.hfkj.service.coupon.channel; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.AESTool; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.MD5Util; +import com.hfkj.config.CommonSysConst; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** + * 重庆中石油卡券 + * @className: CqPetroChina + * @author: HuRui + * @date: 2022/9/26 + **/ +public class ChongQingCNPCCouponService { + + private static Logger log = LoggerFactory.getLogger(ChongQingCNPCCouponService.class); + + /** + * 电子券预发放接口 + * @param requestCode + * @param tradeId + * @param ticketSum + * @param phone + */ + public static JSONObject preSendCoupon(String requestCode, String tradeId, Integer ticketSum, String phone) throws Exception { + Map map = new HashMap<>(); + map.put("requestCode", requestCode); + map.put("tradeId", tradeId); + map.put("ticketSum", ticketSum); + map.put("phone", phone); + return request("preSendCoupon", map); + } + + /** + * 发放电子券 + * @param requestCode + * @param tradeId + * @param ticketSum + * @param phone + */ + public static JSONObject sendCNPCTicket(String requestCode, String tradeId, Integer ticketSum, String phone) throws Exception { + Map map = new HashMap<>(); + map.put("requestCode", requestCode); + map.put("tradeId", tradeId); + map.put("ticketSum", ticketSum); + map.put("phone", phone); + return request("sendCNPCTicket", map); + } + + /** + * 电子券作废 + * @param couponNo 电子券编号 + * @param random 随机数 + */ + public static JSONObject invalidCoupon(String couponNo, String random) throws Exception { + Map map = new HashMap<>(); + map.put("couponNo", couponNo); + map.put("random", random); + return request("invalidCoupon", map); + } + + /** + * 获取中石油跨界券核销码 + * @param couponNo + * @param tradeId + * @return + */ + public static JSONObject getCNPCCheckCode(String couponNo, String tradeId) throws Exception { + Map map = new HashMap<>(); + map.put("couponNo", couponNo); + map.put("tradeId", tradeId); + return request("getCNPCCheckCode", map); + } + + /** + * 获取电子券详情 + * @param couponNo + * @return + */ + public static JSONObject queryCoupon(String couponNo) throws Exception { + Map map = new HashMap<>(); + map.put("couponNo", couponNo); + map.put("random", String.valueOf(new Random().nextInt(899999) + 100000)); + return request("queryCoupon", map); + } + + + /** + * 请求 + * @param actionType 接口类型 + * @param param 参数 + * @return + * @throws Exception + */ + public static JSONObject request(String actionType, Map param) throws Exception { + String verifyCode = AESTool.Encrypt(JSONObject.toJSONString(param), CommonSysConst.getSysConfig().getChongQingCnpcMerKey()); + + JSONObject header = new JSONObject(); + header.put("strVendorCode", CommonSysConst.getSysConfig().getChongQingCnpcMerNo()); + header.put("strActionType", actionType); + header.put("verifyCode", MD5Util.encode((verifyCode + CommonSysConst.getSysConfig().getChongQingCnpcMerKey()).getBytes()).toLowerCase()); + + JSONObject msg = new JSONObject(); + msg.put("head", header); + msg.put("body", verifyCode); + + Map reqParam = new HashMap<>(); + reqParam.put("sendMessage", msg); + + log.info("============start============"); + log.info("请求接口:" + actionType); + log.info("参数:" + JSONObject.toJSONString(param)); + log.info("请求参数:" + JSONObject.toJSONString(reqParam)); + JSONObject response = HttpsUtils.doPost(CommonSysConst.getSysConfig().getChongQingCnpcUrl(), reqParam, new HashMap<>()); + log.info("响应参数:" + response.toJSONString()); + log.info("============end============"); + + JSONObject postMessage = response.getJSONObject("postMessage"); + if (postMessage == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求失败!"); + } + // 解密body + JSONObject body = decryptBody(response.getJSONObject("postMessage").getString("body")); + if (!body.getInteger("status").equals(1)) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, body.getString("info")); + } + return body; + } + + /** + * 解密body + * @param bodyStr body加密字符串 + * @return + */ + public static JSONObject decryptBody(String bodyStr) { + // 解密body + String decryptBody = AESTool.Decrypt(bodyStr, CommonSysConst.getSysConfig().getChongQingCnpcMerKey()); + return JSONObject.parseObject(decryptBody, JSONObject.class); + } + + /** + * 解密电子券码 + * @param couponCode 券码加密字符串 + * @return 核销码 + */ + public static String decryptCouponCode(String couponCode) { + return AESTool.Decrypt(couponCode, CommonSysConst.getSysConfig().getChongQingCnpcCouponSignKey()); + } + + public static void main(String[] args) { + //System.out.println(AESTool.Decrypt("A9D356D4614F874586EAF8678C8C3E7D8CD0EEF031ADA44DDAA3B342CE4BBE44F115AABE27324A6A1F049619139A1A889FCA0FB48EB6E1EA4B1B50F041961B2D686FE8B9696C02DF95BA99B342747D67ECC7847646C87993CF924F33C1308829","n2j30jxhl3rhuoci")); + System.out.println(AESTool.Decrypt("0E14C37B5657B48857A7D3AEFB8E24BACCA40AFF00B073FC22B4116FC97BAED3CBF38FDC5196FDF595637701FDEC1CDDA0AE518707D91B16DA65A63848AF6DB117D2F6E31A09074EB0E42422C6B3B15B96D230680D9E97E4324A384AA8E60F6E","5ojd0nkdqb1ff84t")); + //System.out.println(AESTool.Decrypt("3549AD565800370205265D7518D26E5F40C90A61FDEB5DD73966126A5D25F5E9","5ojldakiz343a6yk")); + } +} diff --git a/service/src/main/java/com/hfkj/service/coupon/channel/HuiLianTongCouponService.java b/service/src/main/java/com/hfkj/service/coupon/channel/HuiLianTongCouponService.java new file mode 100644 index 0000000..dfe1c71 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/channel/HuiLianTongCouponService.java @@ -0,0 +1,356 @@ +package com.hfkj.service.coupon.channel; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.Base64Util; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.MD5Util; +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.config.CommonSysConst; +import com.hfkj.service.hlt.HuiLianTongUnionCardService; +import org.apache.commons.collections4.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.security.MessageDigest; +import java.util.*; + +/** + * 贵州中石化卡券业务 + * @author hurui + */ +@Component +public class HuiLianTongCouponService { + + private static Logger log = LoggerFactory.getLogger(HuiLianTongCouponService.class); + + @Resource + private RedisUtil redisUtil; + + /** + * 获取电子券类型列表 + * @return + * @throws Exception + */ + public static JSONObject getHltFuelCoupList() throws Exception { + Map map = new HashMap<>(); + map.put("serviceType", "01"); + map.put("distributorId", CommonSysConst.getSysConfig().getHuiliantongSinopecDistributorId() ); + return HuiLianTongUnionCardService.request(CommonSysConst.getSysConfig().getHuiliantongSinopecUrl() + "/getHltFuelCoupList", map); + } + + /** + * 下单购买加油券 + * @param orderNo + * @param distCouCount + * @param couTypeCode + * @param phone + * @return + * @throws Exception + */ + public static JSONObject recharge(String orderNo, Integer distCouCount, String couTypeCode, String phone) throws Exception { + Map map = new HashMap<>(); + map.put("orderNo", orderNo); + map.put("distCouCount", distCouCount); + map.put("couTypeCode", couTypeCode); + map.put("phone", phone); + map.put("distributorId", CommonSysConst.getSysConfig().getHuiliantongSinopecDistributorId()); + log.info("============请求任务Start============="); + log.info("下单购买加油券-请求参数: " + JSON.toJSONString(map)); + + JSONObject returnObject = HuiLianTongUnionCardService.request(CommonSysConst.getSysConfig().getHuiliantongSinopecUrl()+"/recharge", map); + + log.info("下单购买加油券-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + } + + /** + * 购买加油券充值订单 + * @param couNo 订单号 + * @return + * @throws Exception + */ + public static JSONObject getPayOrderByCouNo(String couNo) throws Exception { + Map map = new HashMap<>(); + map.put("couNo", couNo); + map.put("distributorId", CommonSysConst.getSysConfig().getHuiliantongSinopecDistributorId()); + log.info("============请求任务Start============="); + log.info("购买加油券充值订单-请求参数: " + JSON.toJSONString(map)); + + JSONObject returnObject = HuiLianTongUnionCardService.request(CommonSysConst.getSysConfig().getHuiliantongSinopecUrl()+"/getPayOrderByCouNo", map); + + log.info("购买加油券充值订单-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + } + + /** + * 购买加油券充值订单 + * @param rechargeOrderId 订单号 + * @return + * @throws Exception + */ + public static JSONObject costRechargeOrder(String rechargeOrderId) throws Exception { + Map map = new HashMap<>(); + map.put("rechargeOrderId", rechargeOrderId); + map.put("distributorId", CommonSysConst.getSysConfig().getHuiliantongSinopecDistributorId()); + + + log.info("============请求任务Start============="); + log.info("购买加油券充值订单-请求参数: " + JSON.toJSONString(map)); + + JSONObject returnObject = HuiLianTongUnionCardService.request(CommonSysConst.getSysConfig().getHuiliantongSinopecUrl()+"/costRechargeOrder", map); + + log.info("购买加油券充值订单-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + } + + /** + * 获取token + * @return + * @throws Exception + */ + public String getToken() throws Exception { + Object token = redisUtil.get(CommonSysConst.getSysConfig().getHuiliantongAppNo()); + if (token != null) { + return token.toString(); + } + + Map map = new HashMap<>(); + map.put("appNo",CommonSysConst.getSysConfig().getHuiliantongAppNo()); + map.put("appKey", MD5Util.encode(CommonSysConst.getSysConfig().getHuiliantongAppkey().getBytes())); + + // 获取token + JSONObject tokenObject = HttpsUtils.doPost(CommonSysConst.getSysConfig().getHuiliantongUrl()+"/api/api/auth/getAccessToken", JSON.toJSONString(map)); + if (tokenObject.getString("result").equals("success")) { + // 缓存到redis 有效期30分钟 + redisUtil.set(CommonSysConst.getSysConfig().getHuiliantongAppNo(),tokenObject.getString("data"),60*30); + return tokenObject.getString("data"); + } + + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "获取token失败"); + } + + /** + * 获取电子券类型列表 + * @param token + * @return + * @throws Exception + */ + public static JSONObject getCorpCouTypes(String token) { + Map param = new HashMap<>(); + Map map = new HashMap<>(); + map.put("token", token); + /* map.put("jsonData", get3DESEncryptECB(JSON.toJSONString(param), CommonSysConst.getSysConfig().getHuiliantongAppsecret())); + StringJoiner urlParamStr = new StringJoiner("&"); + urlParamStr.add(String.format("jsonData=%s", param)); + urlParamStr.add(String.format("secretKey=%s",CommonSysConst.getSysConfig().getHuiliantongAppsecret())); + map.put("sign", md5Capital(urlParamStr.toString()));*/ + return HttpsUtils.doPost(CommonSysConst.getSysConfig().getHuiliantongUrl()+"/coupon/api/coupon_corp/getCorpCouTypes", JSON.toJSONString(map)); + } + + /** + * 获取电子券类型列表 + * @param token + * @return + * @throws Exception + */ + public static JSONObject getCouState(String token,String couNo) { + Map map = new HashMap<>(); + map.put("token", token); + map.put("couNo", couNo); + return HttpsUtils.doPost(CommonSysConst.getSysConfig().getHuiliantongUrl()+"/coupon/api/coupon_corp/getCouState", JSON.toJSONString(map)); + } + + + /** + * 商户派发电子券 + * @param token + * @param couTypeCode 电子卡券类型 + * @param distCouCount 分配数量 + * @param userPhone 用户手机号 + * @param thirdUserId 用户编号 + * @return + * @throws Exception + */ + public static JSONObject couJointDist(String token,String orderNo,String couTypeCode,Integer distCouCount,String userPhone,String thirdUserId) throws Exception { + // 券列表 + List> objectList = new ArrayList<>(); + Map object = new HashMap<>(); + object.put("couTypeCode", couTypeCode); + object.put("distCouCount", distCouCount); + objectList.add(object); + // 参数 + Map param = new HashMap<>(); + param.put("coupons", objectList); + param.put("phone", userPhone); + param.put("thirdUserId", thirdUserId); + param.put("orderNo", orderNo); + param.put("distOuCode", "guizhouhltcs"); + + Map map = new HashMap<>(); + map.put("token", token); + map.put("jsonData", get3DESEncryptECB(JSON.toJSONString(param), CommonSysConst.getSysConfig().getHuiliantongAppkey())); + StringJoiner joiner = new StringJoiner("&"); + joiner.add("jsonData=" + JSON.toJSONString(param)); + joiner.add("secretKey=" + CommonSysConst.getSysConfig().getHuiliantongAppsecret()); + map.put("sign", md5Capital(joiner.toString())); + + String paramStr = "token="+MapUtils.getString(map, "token")+"&sign=" + MapUtils.getString(map, "sign")+"&jsonData=" + URLEncoder.encode(MapUtils.getString(map, "jsonData"),"UTF-8"); + JSONObject object1 = HttpsUtils.doHuiLianTongPost(CommonSysConst.getSysConfig().getHuiliantongUrl() + "/coupon/api/coupon_corp/couJointDist?" + paramStr); + return object1; + } + + + public static String get3DESEncryptECB(String src,String secretKey) { + try { + Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(build3DesKey(secretKey), "DESede")); + String base64Encode = getBase64Encode(cipher.doFinal(src.getBytes("UTF-8"))); + return filter(base64Encode); + } catch (Exception ex) { + //加密失败,打日志 +// //logger.error(ex,ex); + } + return null; + } + + public static String get3DESDecryptECB(String src,String secretKey){ + try { + Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(build3DesKey(secretKey), "DESede")); + byte[] base64DValue = getBase64Decode(src); + byte ciphertext[] = cipher.doFinal(base64DValue); + return new String(ciphertext, "UTF-8"); + } catch (Exception e) { + //解密失败,打日志 +// //logger.error(e,e); + } + return null; + } + + /* + * 根据字符串生成密钥字节数组 + * @param keyStr 密钥字符串 + * @return + * @throws UnsupportedEncodingException + */ + public static byte[] build3DesKey(String keyStr) throws UnsupportedEncodingException { + byte[] key = new byte[24]; //声明一个24位的字节数组,默认里面都是0 + byte[] temp = keyStr.getBytes("UTF-8"); //将字符串转成字节数组 + + /* + * 执行数组拷贝 + * System.arraycopy(源数组,从源数组哪里开始拷贝,目标数组,拷贝多少位) + */ + if(key.length > temp.length){ + //如果temp不够24位,则拷贝temp数组整个长度的内容到key数组中 + System.arraycopy(temp, 0, key, 0, temp.length); + }else{ + //如果temp大于24位,则拷贝temp数组24个长度的内容到key数组中 + System.arraycopy(temp, 0, key, 0, key.length); + } + return key; + } + /** + * 对字符串进行Base64编码 + * + * + * @return String 进行编码后的字符串 + */ + + public static String getBase64Encode(byte[] src) { + String requestValue = ""; + try { + //BASE64Encoder base64en = new BASE64Encoder(); + //requestValue = filter(base64en.encode(src)); + + requestValue = filter(Base64Util.encode(new String(src))); + // //logger.debug(requestValue); + } catch (Exception e) { + e.printStackTrace(); + } + + return requestValue; + } + + public static byte[] getBase64Decode(String str) { + byte[] src = null; + + try { + //BASE64Decoder base64de = new BASE64Decoder(); + //src = base64de.decodeBuffer(str); + src = filter(Base64Util.decode(new String(src))).getBytes(); + } catch (Exception var3) { + var3.printStackTrace(); + } + + return src; + } + + private static String filter(String str) { + String output = null; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < str.length(); i++) { + int asc = str.charAt(i); + if (asc != 10 && asc != 13) + sb.append(str.subSequence(i, i + 1)); + } + output = new String(sb); + return output; + } + + /** + * 大写 + * @param s + * @return + */ + public static String md5Capital(String s){ + char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + try { + byte[] strTemp = s.getBytes(); + //使用MD5创建MessageDigest对象 + MessageDigest mdTemp = MessageDigest.getInstance("MD5"); + mdTemp.update(strTemp); + byte[] md = mdTemp.digest(); + int j = md.length; + char str[] = new char[j * 2]; + int k = 0; + for (int i = 0; i < j; i++) { + byte b = md[i]; + ////logger.debug((int)b); + //将没个数(int)b进行双字节加密 + str[k++] = hexDigits[b >> 4 & 0xf]; + str[k++] = hexDigits[b & 0xf]; + } + return new String(str); + } catch (Exception e) {return null;} + } +/* + 测试实例: + String appkey = "q[*^%]#%675f"; + String param = "{\"phone\":\"18550231381\"}"; + String secretKey = "7EFD6D5D7052E29B4FBC4AD75CA737ED"; + String jsonData = Coder.get3DESEncryptECB(param, appkey); +System.out.println("jsonData:" + jsonData); + + StringJoiner joiner = new StringJoiner("&"); +joiner.add("jsonData=" + param); +joiner.add("secretKey=" + secretKey); + String sign = Coder.md5Capital(joiner.toString()); +System.out.println("sign:" + sign); + + jsonData:aOF3MZAENbJE/t+r4P0+RQGfhSEa5Hyq + sign:835A267FCA8D36C6F79E308F18AECEE8*/ +} diff --git a/service/src/main/java/com/hfkj/service/coupon/channel/PcytCNPCCouponService.java b/service/src/main/java/com/hfkj/service/coupon/channel/PcytCNPCCouponService.java new file mode 100644 index 0000000..75e20ec --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/channel/PcytCNPCCouponService.java @@ -0,0 +1,142 @@ +package com.hfkj.service.coupon.channel; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.MD5Util; +import com.hfkj.config.CommonSysConst; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * @serviceName .java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 中油优途中石油卡券 + * @createTime 18:33 2023/11/13 + **/ +@Configuration +public class PcytCNPCCouponService { + + /** + * @Author Sum1Dream + * @Name getCouponList + * @Description // 获取卡券列表 + * @Date 11:50 2024/4/7 + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject getCouponList() throws Exception { + JSONObject paramMap = new JSONObject(); + paramMap.put("method" , "api.coupon.reserve"); + paramMap.put("merchant" ,CommonSysConst.getSysConfig().getPcytCnpcMerchant()); + paramMap.put("sign", generateSign(paramMap , CommonSysConst.getSysConfig().getPcytCnpcSecret())); + return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getPcytCnpcPostUrl() , paramSort(paramMap), new HashMap<>()); + } + + /** + * @Author Sum1Dream + * @Name getCoupon + * @Description // 获取电子券 + * @Date 17:19 2024/4/7 + + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject getCoupon(String orderNo , String mobile, String reqCode) throws Exception { + JSONObject paramMap = new JSONObject(); + + paramMap.put("method" , "api.coupon.once"); + paramMap.put("batchId" , orderNo); + paramMap.put("mobile" , mobile); + paramMap.put("reqCode" , reqCode); + paramMap.put("merchant" ,CommonSysConst.getSysConfig().getPcytCnpcMerchant()); + paramMap.put("sign", generateSign(paramMap , CommonSysConst.getSysConfig().getPcytCnpcSecret())); + return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getPcytCnpcPostUrl() , paramSort(paramMap), new HashMap<>()); + } + + /** + * @Author Sum1Dream + * @Name getCouponQuery + * @Description // 查询电子券信息 + * @Date 17:25 2024/4/7 + * @Param couponCode + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject getCouponQuery(String couponCode ) throws Exception { + JSONObject paramMap = new JSONObject(); + + paramMap.put("method" , "api.coupon.query"); + paramMap.put("couponCode" , couponCode); + paramMap.put("merchant" ,CommonSysConst.getSysConfig().getPcytCnpcMerchant()); + paramMap.put("sign", generateSign(paramMap , CommonSysConst.getSysConfig().getPcytCnpcSecret())); + return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getPcytCnpcPostUrl() , paramSort(paramMap), new HashMap<>()); + } + + /** + * @Author Sum1Dream + * @Name getCouponDestroy + * @Description // 作废电子券 + * @Date 17:26 2024/4/7 + * @Param couponCode + * @return com.alibaba.fastjson.JSONObject + */ + public static JSONObject getCouponDestroy(String couponCode ) throws Exception { + JSONObject paramMap = new JSONObject(); + + paramMap.put("method" , "api.coupon.destroy"); + paramMap.put("couponCode" , couponCode); + paramMap.put("merchant" ,CommonSysConst.getSysConfig().getPcytCnpcMerchant()); + paramMap.put("sign", generateSign(paramMap , CommonSysConst.getSysConfig().getPcytCnpcSecret())); + return HttpsUtils.doPostForm(CommonSysConst.getSysConfig().getPcytCnpcPostUrl() , paramSort(paramMap), new HashMap<>()); + } + + + /** + * 排序 + * @param param + * @return + */ + private static String paramSort(final Map param) { + Set keySet = param.keySet(); + String[] keyArray = keySet.toArray(new String[keySet.size()]); + StringBuilder sb = new StringBuilder(); + for (String k : keyArray) { + if (StringUtils.isBlank(sb.toString())) { + sb.append(k).append("=").append(param.get(k)); + } else { + sb.append("&").append(k).append("=").append(param.get(k)); + } + } + return sb.toString(); + } + + /** + * 签名 + * @param map + * @param key + * @return + * @throws Exception + */ + public static String generateSign(Map map , String key) throws Exception { + Set keySet = map.keySet(); + String[] keyArray = keySet.toArray(new String[keySet.size()]); + Arrays.sort(keyArray); + StringBuilder sb = new StringBuilder(); + for (String k : keyArray) { + if (k.equals("sign") || k.equals("secret")) { + continue; + } + if (map.get(k) != null) // 参数值为空,则不参与签名 + { + sb.append(k).append("=").append(map.get(k)).append("&"); + } + } + sb.append("secret=").append(key); + return MD5Util.encode(sb.toString().getBytes()).toUpperCase(); + } + + +} diff --git a/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponNoServiceImpl.java b/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponNoServiceImpl.java new file mode 100644 index 0000000..a5e1648 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponNoServiceImpl.java @@ -0,0 +1,39 @@ +package com.hfkj.service.coupon.impl; + +import com.hfkj.dao.BsOrderCouponNoMapper; +import com.hfkj.entity.BsOrderCouponNo; +import com.hfkj.entity.BsOrderCouponNoExample; +import com.hfkj.service.coupon.BsOrderCouponNoService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @className: BsOrderCouponNoServiceImpl + * @author: HuRui + * @date: 2024/5/11 + **/ +@Service("orderCouponNoService") +public class BsOrderCouponNoServiceImpl implements BsOrderCouponNoService { + @Resource + private BsOrderCouponNoMapper orderCouponNoMapper; + @Override + public void editData(BsOrderCouponNo data) { + data.setUpdateTime(new Date()); + if (data.getId() == null) { + data.setCreateTime(new Date()); + orderCouponNoMapper.insert(data); + } else { + orderCouponNoMapper.updateByPrimaryKey(data); + } + } + + @Override + public List getListByCouponOrderId(Long couponOrderId) { + BsOrderCouponNoExample example = new BsOrderCouponNoExample(); + example.createCriteria().andCouponOrderIdEqualTo(couponOrderId); + return orderCouponNoMapper.selectByExample(example); + } +} diff --git a/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponServiceImpl.java b/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponServiceImpl.java new file mode 100644 index 0000000..3ba716c --- /dev/null +++ b/service/src/main/java/com/hfkj/service/coupon/impl/BsOrderCouponServiceImpl.java @@ -0,0 +1,43 @@ +package com.hfkj.service.coupon.impl; + +import com.hfkj.dao.BsOrderCouponMapper; +import com.hfkj.entity.BsOrderCoupon; +import com.hfkj.entity.BsOrderCouponExample; +import com.hfkj.service.coupon.BsOrderCouponService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.List; + +/** + * @className: BsOrderCouponServiceImpl + * @author: HuRui + * @date: 2024/5/10 + **/ +@Service("orderCouponService") +public class BsOrderCouponServiceImpl implements BsOrderCouponService { + + @Resource + private BsOrderCouponMapper orderCouponMapper; + + @Override + public void editData(BsOrderCoupon data) { + data.setUpdateTime(new Date()); + if (data.getId() == null) { + data.setCreateTime(new Date()); + orderCouponMapper.insert(data); + } else { + orderCouponMapper.updateByPrimaryKey(data); + } + } + + @Override + public List getListByChildOrderNo(String orderChildOrderNo) { + BsOrderCouponExample example = new BsOrderCouponExample(); + example.createCriteria().andChildOrderNoEqualTo(orderChildOrderNo); + return orderCouponMapper.selectByExample(example); + } + + +} diff --git a/service/src/main/java/com/hfkj/service/hlt/HuiLianTongUnionCardService.java b/service/src/main/java/com/hfkj/service/hlt/HuiLianTongUnionCardService.java new file mode 100644 index 0000000..2f8202f --- /dev/null +++ b/service/src/main/java/com/hfkj/service/hlt/HuiLianTongUnionCardService.java @@ -0,0 +1,256 @@ +package com.hfkj.service.hlt; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.pay.util.MD5Util; +import com.hfkj.common.utils.DateUtil; +import com.hfkj.common.utils.DesUtil; +import com.hfkj.common.utils.HttpsUtils; +import org.apache.commons.collections4.MapUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.math.BigDecimal; +import java.nio.charset.Charset; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * 汇联通会员卡业务接口【贵州高速工会卡】 + * @author hurui + */ +public class HuiLianTongUnionCardService { + private static Logger log = LoggerFactory.getLogger(HuiLianTongUnionCardService.class); + private static final String HLT_CARD_REQUEST_URL= "http://hltgz.com:4010/api/v2/execute.json"; + private static final String HLT_CARD_ACCESS_CODE= "6FCAE1470CEF465988351BB65ABAA8AE"; + private static final String HLT_CARD_SIGN_CODE = "F8E91A3C"; + + /** + * 根据手机号查询工会卡 + * @param phone + * @return + * @throws Exception + */ + public static JSONObject queryCardByMobile(String phone) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("userMobile", phone); + return request("qgk/queryCardByMobile", dataMap); + } + + /** + * 查询卡信息 + * @param cardNo 工会卡号 + * @return + * @throws Exception + */ + public static JSONObject queryCardInfo(String cardNo) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("cardNo", cardNo); + return request("qgk/queryCardInfo", dataMap); + } + + /** + * 查询余额 + * @param cardNo 工会卡号 + * @return + * @throws Exception + */ + public static JSONObject queryBalance(String cardNo) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("cardType", "ghk"); + dataMap.put("cardNo", cardNo); + return request("qtk/queryBalance", dataMap); + } + + /** + * 根据业务类型查询消费记录 + * @param businessType 业务类型 1.卖中石化加油券的,固定填sinopec_oil_code 2.其他商品或服务的,固定填hisen_consume + * @param cardNo 工会卡号 + * @param page 页数 + * @param pageSize 每页条数 + * @param sdate 起始日期 yyyy-MM-dd格式 + * @param edate 截止日期 yyyy-MM-dd格式 + * @return + * @throws Exception + */ + public static JSONObject queryConsumptionRecordByBusiness(String businessType,String cardNo,Long sdate,Long edate,Integer page,Integer pageSize) throws Exception { + try { + Map dataMap = new HashMap<>(); + dataMap.put("businessType", businessType); + dataMap.put("cardNo", cardNo); + dataMap.put("page", page); + dataMap.put("pageSize", pageSize); + if (sdate != null) { + dataMap.put("sdate", DateUtil.date2String(new Date(sdate), "yyyy-MM-dd")); + } + if (edate != null) { + dataMap.put("edate", DateUtil.date2String(new Date(edate), "yyyy-MM-dd")); + } + return request("qtk/queryConsumptionRecordByBusiness", dataMap); + } catch (Exception e) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQUEST_TIMED_OUT, ""); + } + + } + + /** + * 充值 + * @param orderNo 订单号 + * @param cardNo 卡号 + * @param tranAmount 支付金额 + * @param businessType 业务类型 1.卖中石化加油券的,固定填sinopec_oil_code 2.其他商品或服务的,固定填hisen_consume + * @param tranVoucher 银行卡充值可填银行卡号;支付宝、微信充值可填相应的扣款单号;接入方也可自定义填入交易流水跟踪号,但长度不能超过50 + * @param tranDesc 交易描述 + * @return + * @throws Exception + */ + public static JSONObject deposit(String orderNo, String cardNo, BigDecimal tranAmount, String businessType, String tranVoucher , String tranDesc) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("orderNo", orderNo); + dataMap.put("cardType", "ghk"); + dataMap.put("cardNo", cardNo); + dataMap.put("tranAmount", tranAmount); + dataMap.put("tranChannel", "HiSen"); + dataMap.put("businessType", businessType); + dataMap.put("tranVoucher", tranVoucher); + dataMap.put("tranDesc", tranDesc); + + + log.info("============请求任务Start============="); + log.info("汇联通充值-请求参数: " + JSON.toJSONString(dataMap)); + + JSONObject returnObject = request("qtk/deposit", dataMap); + + log.info("汇联通充值-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + + } + + /** + * 支付 + * @param orderNo 订单号 + * @param cardNo 卡号 + * @param tranAmount 支付金额 + * @param businessType 业务类型 1.卖中石化加油券的,固定填sinopec_oil_code 2.其他商品或服务的,固定填hisen_consume + * @param instCode 消费终端号 + * @param goodsDesc 商品描述 + * @param tranDesc 交易描述 + * @return + * @throws Exception + */ + public static JSONObject consumption(String orderNo, String cardNo, BigDecimal tranAmount, String businessType, String instCode,String goodsDesc, String tranDesc) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("orderNo", orderNo); + dataMap.put("cardType", "ghk"); + dataMap.put("cardNo", cardNo); + dataMap.put("checkPassword", "N"); + dataMap.put("tranAmount", tranAmount); + dataMap.put("tranChannel", "HiSen"); + dataMap.put("businessType", businessType); + dataMap.put("instCode", instCode); + dataMap.put("goodsDesc", goodsDesc); + dataMap.put("tranDesc", tranDesc); + return request("qtk/consumption", dataMap); + } + + /** + * 业务请求 + * @param method 接口名称 + * @param param 业务参数 + * @return + * @throws Exception + */ + public static JSONObject request(String method,Map param) throws Exception { + // 签名码 + String signCode = HLT_CARD_SIGN_CODE; + + Map map = new LinkedHashMap<>(); + map.put("accessCode", HLT_CARD_ACCESS_CODE); + map.put("requestId", System.currentTimeMillis()); + map.put("method", method); + + // DES加密 + map.put("data", DesUtil.encode(JSONObject.toJSONString(param), Charset.forName("UTF-8"),signCode).replace("\\n", "")); + + // 数据签名字符串 + String str = (MapUtils.getString(map,"accessCode")+signCode); + str +=(MapUtils.getString(map,"requestId")+signCode) ; + str += (MapUtils.getString(map,"method") + signCode); + str += (MapUtils.getString(map,"data") + signCode); + + // MD5加密 + map.put("sign", MD5Util.MD5Encode(str, "UTF-8").toUpperCase()); + + log.info("============请求任务Start============="); + log.info("请求参数: " + JSON.toJSONString(map)); + + JSONObject returnObject = HttpsUtils.doPost(HLT_CARD_REQUEST_URL, JSON.toJSONString(map)); + + log.info("响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + } + + /** + * 退款 + * @param refundOrderNo 退款订单号 + * @param origOrderNo 支付订单号 + * @return + * @throws Exception + */ + public static JSONObject refund(String refundOrderNo, String origOrderNo) throws Exception { + Map dataMap = new HashMap<>(); + dataMap.put("orderNo", refundOrderNo); + dataMap.put("origOrderNo", origOrderNo); + dataMap.put("checkPassword", "N"); + + + log.info("============请求任务Start============="); + log.info("汇联通退款-请求参数: " + JSON.toJSONString(dataMap)); + + JSONObject returnObject = request("qtk/refund", dataMap); + + log.info("汇联通退款-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + return returnObject; + } + + /** + * 解析响应的参数 + * @param param 参数 + * @return + */ + public static JSONObject resolveResponse(String param) { + String data = param.replace("\\n", ""); + String decodeData = DesUtil.decode(HLT_CARD_SIGN_CODE, data, Charset.forName("UTF-8")); + + log.info("============请求任务Start============="); + log.info("解析响应的参数-请求参数: " + data); + + JSONObject returnObject = JSONObject.parseObject(decodeData); + + log.info("解析响应的参数-响应参数: " + returnObject.toJSONString()); + log.info("============请求任务End=============="); + + return returnObject; + + } + + public static void main(String[] args) { + // {"respMessage":"ok","data":"Gbkl57c3fEBg+E3HfPuQ580JLkHaQPyf1P7My1oYOyJSIG4i8jYxovGVk4V8Rk58mjDswB8Vpy4E\nyj/wi/UNr8TDne094+yu","sign":"47186141FD8B3FB6CCB590F58321D9C6","respCode":"0000","responseId":"1669202185936"} + String data = "Gbkl57c3fEBg+E3HfPuQ55SDLVyAf2Ys3VN1cifAfXIoT1gnbFR0NaiH/z1OIZZiuqlFwDLLu6n4\n" + + "VBkM8fF5jVEekFNLY57NgRfRr4BghKXdIr8hdPJnbfOO0VtjITPrrZWwMDwfYzJulYhBsNGCubov\n" + + "9ruAA0DN0ESoH765nvlH0lI/wdIOvRE7GyTfQzzT68i5p+Qf/k7yjQk22l4KUfuUVM+jMeW95xkd\n" + + "+gVJvWctjBC0DN3zi3CwsVgQwVmj".replace("\\n", ""); + String decodeData = DesUtil.decode(HLT_CARD_SIGN_CODE, data, Charset.forName("UTF-8")); + System.out.println(JSONObject.parseObject(decodeData)); + + } + +} diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderService.java b/service/src/main/java/com/hfkj/service/order/BsOrderService.java index fd6486d..6b42d88 100644 --- a/service/src/main/java/com/hfkj/service/order/BsOrderService.java +++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java @@ -25,7 +25,7 @@ public interface BsOrderService { * @param order 订单 * @return */ - OrderModel create(OrderModel order); + OrderModel create(OrderModel order) throws Exception; /** * 取消订单 diff --git a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java index 8fae77f..1ccb0be 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java @@ -1,10 +1,25 @@ package com.hfkj.service.order; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.RandomUtils; import com.hfkj.common.utils.RedisUtil; -import com.hfkj.entity.BsOrderChild; +import com.hfkj.entity.*; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; +import com.hfkj.service.coupon.BsOrderCouponNoService; +import com.hfkj.service.coupon.BsOrderCouponService; +import com.hfkj.service.coupon.channel.HuiLianTongCouponService; +import com.hfkj.service.goods.GoodsMsgService; +import com.hfkj.service.goods.GoodsSpecsService; +import com.hfkj.service.goods.GoodsVpdService; +import com.hfkj.service.hlt.HuiLianTongUnionCardService; +import com.hfkj.sysenum.GoodsVpdSourceEnum; import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import com.hfkj.sysenum.order.OrderChildStatusEnum; +import com.hfkj.sysenum.order.OrderCouponNoStatusEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -30,15 +45,104 @@ public class OrderCreateService { @Resource private BsOrderService orderService; @Resource + private BsOrderCouponService orderCouponService; + @Resource + private BsOrderCouponNoService orderCouponNoService; + @Resource private BsOrderChildService orderChildService; + @Resource + private GoodsMsgService goodsMsgService; + @Resource + private GoodsSpecsService goodsSpecsService; + @Resource + private GoodsVpdService goodsVpdService; /** * 事务产品 * @param orderChild 子订单 * @throws Exception */ - public OrderChildModel materialProduct(OrderChildModel orderChild) { - orderChild.setProductPrice(new BigDecimal("10")); + public OrderChildModel product(OrderModel order, OrderChildModel orderChild) throws Exception { + // 查询商品 + GoodsMsg goodsMsg = goodsMsgService.queryDetail(orderChild.getProductId()); + if (goodsMsg == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品"); + } + if (goodsMsg.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, goodsMsg.getTitle()+"暂无法就进行购买"); + } + // 查询商品规格 + GoodsSpecs goodsSpecs = goodsSpecsService.queryDetail(orderChild.getProductSpecId()); + if (goodsSpecs == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品规格"); + } + orderChild.setMerId(goodsMsg.getMerId()); + orderChild.setProductName(goodsMsg.getTitle()); + orderChild.setProductImg(goodsMsg.getListImg()); + orderChild.setProductSpecName(goodsSpecs.getName()); + orderChild.setProductPrice(goodsSpecs.getSalePrice()); + + if (goodsMsg.getType() == 1) { + // TODO 实物 + + + } else if (goodsMsg.getType() == 2) { + // 虚拟 + // 查询商品虚拟信息 + GoodsVpd goodsVpd = goodsVpdService.queryDetailBySpecsId(goodsSpecs.getId()); + if (goodsVpd == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品虚拟规格"); + } + + // 创建卡券订单 + BsOrderCoupon orderCoupon = new BsOrderCoupon(); + orderCoupon.setOrderNo(orderChild.getOrderNo()); + orderCoupon.setChildOrderNo(orderChild.getChildOrderNo()); + orderCoupon.setMerId(orderChild.getMerId()); + orderCoupon.setUserId(order.getUserId()); + orderCoupon.setUserPhone(order.getUserPhone()); + orderCoupon.setGoodsId(goodsMsg.getId()); + orderCoupon.setGoodsName(goodsMsg.getTitle()); + orderCoupon.setGoodsTypeId(goodsMsg.getGoodsType()); + orderCoupon.setGoodsTypeName(goodsMsg.getGoodsTypeName()); + orderCoupon.setGoodsBrandId(goodsMsg.getGoodsBrand()); + orderCoupon.setGoodsBrandName(goodsMsg.getGoodsBrandName()); + orderCoupon.setGoodsSpecsId(goodsSpecs.getId()); + orderCoupon.setGoodsSpecsName(goodsSpecs.getName()); + orderCoupon.setGoodsSpescOriginalPrice(goodsSpecs.getOriginalPrice()); + orderCoupon.setGoodsVpdId(goodsVpd.getId()); + orderCoupon.setGoodsVpdKey(goodsVpd.getKey()); + orderCoupon.setGoodsVpdSource(goodsVpd.getSource()); + orderCoupon.setStatus(OrderChildStatusEnum.status1.getCode()); + orderCouponService.editData(orderCoupon); + + for (int i = 0; i <= orderChild.getProductCount(); i++) { + // 卡券订单卡密 + BsOrderCouponNo orderCouponNo = new BsOrderCouponNo(); + orderCouponNo.setCouponOrderId(orderCoupon.getId()); + orderCouponNo.setOrderNo(orderCoupon.getId() + RandomUtils.number(6, false)); + orderCouponNo.setExpireStatus(false); + orderCouponNo.setExceptionStatus(false); + orderCouponNo.setStatus(OrderCouponNoStatusEnum.status1.getCode()); + + if (goodsVpd.getSource().equals(GoodsVpdSourceEnum.type4.getCode())) { + // 下单请求 + JSONObject jsonObject = HuiLianTongCouponService.recharge(orderCouponNo.getOrderNo(), + 1, + orderCoupon.getGoodsVpdKey(), + orderCoupon.getUserPhone()); + if (!jsonObject.getString("respCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败"); + } + JSONObject response = HuiLianTongUnionCardService.resolveResponse(jsonObject.getString("data")); + if (!response.getString("respCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("msg")); + } + orderCouponNo.setChannelOrderNo(response.getJSONObject("data").getString("rechargeOrderId")); + } + orderCouponNoService.editData(orderCouponNo); + } + } return orderChild; } diff --git a/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java index d2b183e..9c49fa7 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderPaySuccessService.java @@ -1,21 +1,33 @@ package com.hfkj.service.order; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.DateUtil; import com.hfkj.common.utils.RedisUtil; -import com.hfkj.entity.BsOrderChild; +import com.hfkj.entity.*; import com.hfkj.model.order.OrderModel; +import com.hfkj.service.coupon.BsOrderCouponNoService; +import com.hfkj.service.coupon.BsOrderCouponService; +import com.hfkj.service.coupon.channel.ChongQingCNPCCouponService; +import com.hfkj.service.coupon.channel.HuiLianTongCouponService; +import com.hfkj.service.coupon.channel.PcytCNPCCouponService; +import com.hfkj.service.goods.GoodsMsgService; +import com.hfkj.service.goods.GoodsVpdService; +import com.hfkj.service.hlt.HuiLianTongUnionCardService; +import com.hfkj.sysenum.GoodsVpdSourceEnum; import com.hfkj.sysenum.order.OrderChildProductTypeEnum; -import com.hfkj.sysenum.order.OrderChildStatusEnum; -import com.hfkj.sysenum.order.OrderStatusEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * @className: OrderPaySuccesService @@ -31,25 +43,159 @@ public class OrderPaySuccessService { private BsOrderService orderService; @Resource private BsOrderChildService orderChildService; + @Resource + private BsOrderCouponService orderCouponService; + @Resource + private BsOrderCouponNoService orderCouponNoService; + @Resource + private GoodsMsgService goodsMsgService; + @Resource + private GoodsVpdService goodsVpdService; /** * 订单业务处理 * @param order * @throws Exception */ - @Transactional( - propagation= Propagation.REQUIRED, - isolation = Isolation.READ_COMMITTED, - timeout = 20, - rollbackFor = Exception.class) public void orderBusHandle(OrderModel order) { for (BsOrderChild childOrder : order.getOrderChildList()) { - if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + try { + if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { + product(order, childOrder); + } + } catch (Exception e) { } } + } + + /** + * 处理产品 + * @param childOrder + * @throws Exception + */ + public void product(OrderModel order,BsOrderChild childOrder) throws Exception { + // 查询产品 + GoodsMsg goods = goodsMsgService.queryDetail(childOrder.getProductId()); + if (goods.getType() == 1) { + } else if (goods.getType() == 2) { + productVpd(order, childOrder); + } } + /** + * 虚拟产品 + * @param childOrder + */ + public void productVpd(OrderModel order, BsOrderChild childOrder) throws Exception { + // 查询卡券订单 + List orderCouponList = orderCouponService.getListByChildOrderNo(childOrder.getChildOrderNo()); + for (BsOrderCoupon orderCoupon : orderCouponList) { + // 查询卡券订单的卡密 + List couponNoList = orderCouponNoService.getListByCouponOrderId(orderCoupon.getId()); + for (BsOrderCouponNo couponNo : couponNoList) { + try { + // 虚拟商品 + GoodsVpd vpd = goodsVpdService.queryDetail(childOrder.getProductSpecId()); + if (vpd.getSource() == GoodsVpdSourceEnum.type1.getCode()) { + + } else if (vpd.getSource() == GoodsVpdSourceEnum.type4.getCode()) { + // 推送给汇联通 + JSONObject returnParam = HuiLianTongCouponService.costRechargeOrder(couponNo.getChannelOrderNo()); + if (returnParam.getString("respCode").equals("0000")) { + // 解密 + JSONObject jsonObject = HuiLianTongUnionCardService.resolveResponse(returnParam.getString("data")); + JSONArray dataArray = JSONObject.parseObject(jsonObject.getString("data"), JSONArray.class); + for (Object data : dataArray) { + JSONObject dataObject = (JSONObject) data; + couponNo.setExpireTime(dataObject.getDate("validEndDate")); + couponNo.setGoodsVpdSourceCouNo(dataObject.getString("couNo")); + orderCouponNoService.editData(couponNo); + } + } + + } else if (vpd.getSource() == GoodsVpdSourceEnum.type5.getCode()) { + // 预发码 + JSONObject preSendCoupon = ChongQingCNPCCouponService.preSendCoupon(orderCoupon.getGoodsVpdKey(), orderCoupon.getOrderNo(), 1, orderCoupon.getUserPhone()); + if (preSendCoupon.getInteger("status").equals(1)) { + // 给用户发码 + JSONObject response = ChongQingCNPCCouponService.sendCNPCTicket(orderCoupon.getGoodsVpdKey(), orderCoupon.getOrderNo(), 1, orderCoupon.getUserPhone()); + JSONObject couponDetail = response.getJSONObject("ticketDetail"); + JSONArray codeList = response.getJSONArray("codeList"); + for (Object data : codeList) { + couponNo.setExpireTime(DateUtil.format(couponDetail.getString("expiredDate"), "yyyy-MM-dd")); + couponNo.setGoodsVpdSourceCouNo(ChongQingCNPCCouponService.decryptCouponCode(String.valueOf(data))); + orderCouponNoService.editData(couponNo); + } + } + + } else if (vpd.getSource() == GoodsVpdSourceEnum.type6.getCode()) { + /* // 派发停车券 + ApiBlxCoupon apiBlxCoupon = apiBlxCouponService.findBlxCoupon(coupon.getCouponKey()); + if (apiBlxCoupon == null || apiBlxCoupon.getCouponStatus() != 1) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "当前卡券不可购买"); + } + // 计算上送卡券数量 + int num = coupon.getSalesPrice().divide(new BigDecimal(apiBlxCoupon.getDenomination())).intValue(); + if (num > 0) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("couponCode" , coupon.getCouponKey()); + jsonObject.put("receiverPhone" , order.getMemPhone()); + jsonObject.put("receiverCount" , num); + + JSONObject object = blxConfig.sendCoupon(jsonObject); + + if (object.getInteger("code") == 1) { + order.setOrderStatus(OrderStatus.STATUS3.getNumber()); + order.setFinishTime(new Date()); + orderService.updateOrderData(order); + highUserCardService.getBlxCouponBalance(order.getMemPhone()); + } else { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , object.getString("msg")); + } + }*/ + + } else if (vpd.getSource() == GoodsVpdSourceEnum.type7.getCode()) { + /* // 发放卡券 + JSONObject jsonObject = petroConfig.getCoupon(orderCoupon.getGoodsVpdKey(), orderCoupon.getUserPhone()); + if (!jsonObject.getString("resultCode").equals("0000")) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , jsonObject.getString("errMsg")); + } + String data = PetroConfig.decrypt(jsonObject.getString("jsonResult")); + JSONObject object = JSONObject.parseObject(data); + orderCoupon.setExpireTime(vpd.getSalesEndTime()); + orderCoupon.setGoodsVpdSourceCouNo(object.getString("voucher")); + orderCouponService.editData(orderCoupon);*/ + + } else if (vpd.getSource() == GoodsVpdSourceEnum.type10.getCode()) { + // 发放卡券 + JSONObject jsonObject = PcytCNPCCouponService.getCoupon(orderCoupon.getOrderNo() , orderCoupon.getUserPhone() , orderCoupon.getGoodsVpdKey()); + if (!jsonObject.getString("code").equals("200")) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , jsonObject.getString("errMsg")); + } + JSONObject object = jsonObject.getJSONObject("data"); + couponNo.setExpireTime(vpd.getSalesEndTime()); + couponNo.setGoodsVpdSourceCouNo(object.getString("couponCode")); + orderCouponNoService.editData(couponNo); + } + } catch (Exception e) { + couponNo.setExceptionStatus(true); + orderCouponService.editData(orderCoupon); + } + } + + orderCoupon.setTotalPrice(childOrder.getProductTotalPrice()); + orderCoupon.setTotalDeductionPrice(childOrder.getTotalDeductionPrice()); + orderCoupon.setCouponDiscountPrice(childOrder.getCouponDiscountPrice()); + orderCoupon.setIntegralDiscountPrice(childOrder.getIntegralDiscountPrice()); + orderCoupon.setPayRealPrice(childOrder.getSurplusRefundPrice()); + orderCoupon.setPayChannel(order.getPayChannel()); + orderCoupon.setPayType(order.getPayType()); + orderCoupon.setPaySerialNo(order.getPaySerialNo()); + orderCouponService.editData(orderCoupon); + } + + } } diff --git a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java index 03760e9..d3a097f 100644 --- a/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/order/impl/BsOrderServiceImpl.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.DateUtils; @@ -81,8 +82,12 @@ public class BsOrderServiceImpl implements BsOrderService { } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW, rollbackFor= {RuntimeException.class}, timeout = 10) - public OrderModel create(OrderModel order) { + @Transactional( + propagation= Propagation.REQUIRES_NEW, + isolation = Isolation.READ_COMMITTED, + timeout = 20, + rollbackFor = Exception.class) + public OrderModel create(OrderModel order) throws Exception { // 生成交易单号,共18位,时间 + 6位随机数 order.setOrderNo(DateUtil.date2String(new Date(), "yyMMddHHmmss") + RandomUtils.number(6, false)); editData(order); @@ -117,8 +122,7 @@ public class BsOrderServiceImpl implements BsOrderService { // 提交订单前产品处理 if (child.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { - // TODO 示例 - child = orderCreateService.materialProduct(child); + child = orderCreateService.product(order, child); } child.setProductTotalPrice(child.getProductPrice().multiply(new BigDecimal(child.getProductCount().toString()))); child.setStatus(OrderChildStatusEnum.status1.getCode()); diff --git a/service/src/main/java/com/hfkj/sysenum/GoodsVpdSourceEnum.java b/service/src/main/java/com/hfkj/sysenum/GoodsVpdSourceEnum.java new file mode 100644 index 0000000..56bab82 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/GoodsVpdSourceEnum.java @@ -0,0 +1,62 @@ +package com.hfkj.sysenum; + +/** + * 产品来源 + * @className: SecMenuTypeEnum + * @author: HuRui + * @date: 2024/4/10 + **/ +public enum GoodsVpdSourceEnum { + + /** + * 内部虚拟商品 + */ + type1(1, "内部虚拟商品"), + /** + * 贵州中石化 + */ + type4(4, "贵州中石化"), + /** + * 重庆中石油 + */ + type5(5, "重庆中石油"), + /** + * 比邻星停车券 + */ + type6(6, "比邻星停车券"), + /** + * 四川中石油 + */ + type7(7, "四川中石油"), + /** + * 中油优途中石油 + */ + type10(10, "中油优途中石油"), + ; + + private int code; + + private String name; + + + GoodsVpdSourceEnum(int code, String name) { + this.code = code; + this.name = name; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java index 63200d5..a966190 100644 --- a/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java @@ -6,8 +6,10 @@ package com.hfkj.sysenum.order; * @date: 2024/4/30 **/ public enum OrderChildProductTypeEnum { - type1(1, "实物商品"), - type2(2, ""), + /** + * 产品 + */ + type1(1, "产品"), ; private int code; diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderCouponNoStatusEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderCouponNoStatusEnum.java new file mode 100644 index 0000000..9dd3cb1 --- /dev/null +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderCouponNoStatusEnum.java @@ -0,0 +1,43 @@ +package com.hfkj.sysenum.order; + +import lombok.Getter; + +/** + * 卡券编号订单状态 + * @className: OrderCouponNoStatusEnum + * @author: HuRui + * @date: 2024/5/11 + **/ +@Getter +public enum OrderCouponNoStatusEnum { + /** + * 待支付 + */ + status1(1, "未派发"), + + /** + * 已支付 + */ + status2(2, "已派发"), + + /** + * 已完成 + */ + status3(3, "已使用"), + + /** + * 已退款 + */ + status4(4, "已过期"), + ; + + private final int code; + + private final String name; + + + OrderCouponNoStatusEnum(int code, String name) { + this.code = code; + this.name = name; + } +} diff --git a/service/src/main/resources/dev/commonConfig.properties b/service/src/main/resources/dev/commonConfig.properties index e0738fd..a3e4b16 100644 --- a/service/src/main/resources/dev/commonConfig.properties +++ b/service/src/main/resources/dev/commonConfig.properties @@ -3,4 +3,26 @@ wechatMaSecret= wechatMpAppid= wechatMpSecret= -huiPayPreorderNotifyUrl= +huiPayPreorderNotifyUrl=https://phgcs.dctpay.com/order/notify/huipay + +# ChongQingCNPC configuration parameters +chongQingCnpcUrl=http://121.40.235.135:9083/d/cross/api +chongQingCnpcMerNo=toywqvi14wenrhb3d9 +chongQingCnpcMerKey=n2j30jxhl3rhuoci +chongQingCnpcCouponSignKey=5ojldakiz343a6yk + +# PetroChinaYouTu configuration parameters +pcytCnpcPostUrl=https://api.coupon.shuangpenghui.com//business/entry +pcytCnpcMerchant=355920109860 +pcytCnpcSecret=Es9cshhRoDxeFAuGItLZUDi8Qj3PWrje + +# BiLingXing +blxPostUrl=https://zhctapplet.gyzhtc.com/gateway + +huiliantongUrl=https://gzapi.deepermobile.com.cn +huiliantongAppNo=guizhouhuilt +huiliantongAppkey=e0ja2Ex%2BmQ2hIPF6x%2BHA%3D +huiliantongAppsecret=52662415DDCE55C7BA34223BCF53877A +huiliantongSinopecDistributorId=aNId4A3X +huiliantongDistributorId=1JnL8YMV +huiliantongSinopecUrl=fuelCoupons diff --git a/service/src/main/resources/prod/commonConfig.properties b/service/src/main/resources/prod/commonConfig.properties index e69de29..0720d23 100644 --- a/service/src/main/resources/prod/commonConfig.properties +++ b/service/src/main/resources/prod/commonConfig.properties @@ -0,0 +1,28 @@ +wechatMaAppid= +wechatMaSecret= +wechatMpAppid= +wechatMpSecret= + +huiPayPreorderNotifyUrl=https://phgcs.dctpay.com/order/notify/huipay + +# ChongQingCNPC configuration parameters +chongQingCnpcUrl=http://cqpingan.wisdomyt.cn/d/cross/api +chongQingCnpcMerNo=7ygt1b2b8rpl7vttm6 +chongQingCnpcMerKey=5ojd0nkdqb1ff84t +chongQingCnpcCouponSignKey=pzj69n2r8l1l3kry + +# PetroChinaYouTu configuration parameters +pcytCnpcPostUrl=https://api.coupon.shuangpenghui.com//business/entry +pcytCnpcMerchant=618809656349 +pcytCnpcSecret=xstEWAhjw74GzMkXcPr2Cf7z00aYXaSy + +# BiLingXing +blxPostUrl=https://zhctapplet.gyzhtc.com/gateway + +huiliantongUrl=https://gzapi.deepermobile.com.cn +huiliantongAppNo=guizhouhuilt +huiliantongAppkey=e0ja2Ex%2BmQ2hIPF6x%2BHA%3D +huiliantongAppsecret=52662415DDCE55C7BA34223BCF53877A +huiliantongSinopecDistributorId=aNId4A3X +huiliantongDistributorId=1JnL8YMV +huiliantongSinopecUrl=fuelCoupons diff --git a/user/src/main/java/com/user/controller/SmsController.java b/user/src/main/java/com/user/controller/SmsController.java index 96c9b87..b37d107 100644 --- a/user/src/main/java/com/user/controller/SmsController.java +++ b/user/src/main/java/com/user/controller/SmsController.java @@ -1 +1 @@ -package com.user.controller; import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.MessageConfig; import com.hfkj.model.ResponseData; import com.hfkj.service.user.BsUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.Random; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/sms") @Api(value = "短信服务") public class SmsController { private static Logger log = LoggerFactory.getLogger(SmsController.class); @Resource private RedisUtil redisUtil; @Resource private BsUserService userService; @RequestMapping(value = "/sendLoginSMSCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取登录验证码") public ResponseData sendLoginSMSCode(@RequestBody JSONObject body) { try { if (body == null || StringUtils.isBlank(body.getString("phone"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } String phone = body.getString("phone"); // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 生成随机6位验证码 String smsCode = String.valueOf(new Random().nextInt(899999) + 100000); // MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5); // 验证码缓存5分钟 redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5); return ResponseMsgUtil.success("短信发送成功"); } catch (Exception e) { log.error("SMSController --> getLoginSMSCode() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file +package com.user.controller; import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.MessageConfig; import com.hfkj.model.ResponseData; import com.hfkj.service.user.BsUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.util.Random; /** * @Auther: 胡锐 * @Description: * @Date: 2021/3/26 23:08 */ @Controller @RequestMapping(value = "/sms") @Api(value = "短信服务") public class SmsController { private static Logger log = LoggerFactory.getLogger(SmsController.class); @Resource private RedisUtil redisUtil; @Resource private BsUserService userService; @RequestMapping(value = "/sendLoginSMSCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "获取登录验证码") public ResponseData sendLoginSMSCode(@RequestBody JSONObject body) { try { if (body == null || StringUtils.isBlank(body.getString("phone"))) { log.error("LoginController --> phone() error!", "请求参数校验失败"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } String phone = body.getString("phone"); // 校验手机号格式 if (MemberValidateUtil.validatePhone(phone) == false) { log.error("LoginController --> phone() error!", "请输入正确的手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); } // 生成随机6位验证码 String smsCode = String.valueOf(new Random().nextInt(899999) + 100000); MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5); // 验证码缓存5分钟 redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5); return ResponseMsgUtil.success("短信发送成功"); } catch (Exception e) { log.error("SMSController --> getLoginSMSCode() error!", e); return ResponseMsgUtil.exception(e); } } } \ No newline at end of file