From fcfa0ab93fd493310880f78aa2bbb0fd66a6fa8f Mon Sep 17 00:00:00 2001 From: 199901012 Date: Sat, 27 Mar 2021 12:24:43 +0800 Subject: [PATCH] =?UTF-8?q?'=E5=AE=8C=E6=88=90=E6=94=AF=E4=BB=98'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/cweb/config/SysConfig.java | 9 + .../cweb/controller/HighOrderController.java | 43 ++- .../cweb/controller/pay/OrderController.java | 72 ++++- .../src/main/resources/dev/config.properties | 1 + hai-service/pom.xml | 7 +- .../java/com/hai/common/QRCodeGenerator.java | 41 +++ .../com/hai/dao/HighUserCouponMapper.java | 35 ++- .../hai/dao/HighUserCouponSqlProvider.java | 72 ++++- .../java/com/hai/entity/HighUserCoupon.java | 79 ++++- .../com/hai/entity/HighUserCouponExample.java | 297 +++++++++++++++--- .../com/hai/service/HighGoldRecService.java | 29 ++ .../com/hai/service/HighOrderService.java | 9 +- .../java/com/hai/service/HighUserService.java | 7 + .../service/impl/HighOrderServiceImpl.java | 105 ++++++- .../hai/service/impl/HighUserServiceImpl.java | 44 +++ .../pay/impl/GoodsOrderServiceImpl.java | 38 ++- .../pay/impl/HighGoldRecServiceImpl.java | 35 +++ 17 files changed, 837 insertions(+), 86 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/common/QRCodeGenerator.java create mode 100644 hai-service/src/main/java/com/hai/service/HighGoldRecService.java create mode 100644 hai-service/src/main/java/com/hai/service/pay/impl/HighGoldRecServiceImpl.java diff --git a/hai-cweb/src/main/java/com/cweb/config/SysConfig.java b/hai-cweb/src/main/java/com/cweb/config/SysConfig.java index fce8ea72..7195d84a 100644 --- a/hai-cweb/src/main/java/com/cweb/config/SysConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/SysConfig.java @@ -16,6 +16,7 @@ public class SysConfig { private String wxApiKey; private String wxMchId; private String wxUnifiedOrderUrl; + private String couponCodePath; private String notifyUrl; public String getFileUrl() { @@ -73,4 +74,12 @@ public class SysConfig { public void setNotifyUrl(String notifyUrl) { this.notifyUrl = notifyUrl; } + + public String getCouponCodePath() { + return couponCodePath; + } + + public void setCouponCodePath(String couponCodePath) { + this.couponCodePath = couponCodePath; + } } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index d93c6d86..0bd61200 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -10,20 +10,16 @@ import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; import com.hai.common.utils.IDGenerator; import com.hai.common.utils.ResponseMsgUtil; -import com.hai.entity.HighChildOrder; -import com.hai.entity.HighCoupon; -import com.hai.entity.HighCouponCode; -import com.hai.entity.HighOrder; +import com.hai.entity.*; import com.hai.model.HighCouponModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; -import com.hai.model.UserInfoModel; import com.hai.service.HighCouponCodeService; import com.hai.service.HighCouponService; import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; 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.beans.factory.annotation.Autowired; @@ -61,6 +57,9 @@ public class HighOrderController { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private HighUserService highUserService; + @RequestMapping(value="/addOrder",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "增加订单") @@ -85,9 +84,12 @@ public class HighOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 商品类型 1:卡卷 + // 商品类型 1:卡卷 2:金币充值 if (childOrder.getGoodsType() == 1) { - + if (childOrder.getSaleCount() != 1) { + log.error("HighOrderController --> addOrder() error!", "卡卷只能购买一张"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡卷只能购买一张"); + } // 查询卡卷信息 HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); if (coupon == null) { @@ -105,11 +107,30 @@ public class HighOrderController { childOrder.setGoodsSpecName("默认"); childOrder.setGoodsPrice(coupon.getDiscountPrice()); childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); - childOrder.setGiveawayType(false); // 是否是赠品 0:否 1:是 - childOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - childOrder.setPraiseStatus(0); } + if (childOrder.getGoodsType() == 2) { + if (childOrder.getGoodsPrice() == null) { + log.error("HighOrderController --> addOrder() error!", "请设置充值金额"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请设置充值金额"); + } + // 查询用户信息 + HighUser user = highUserService.findByUserId(childOrder.getGoodsId()); + if (user == null) { + log.error("HighOrderController --> addOrder() error!", "未找到用户"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, ""); + } + + childOrder.setGoodsName(user.getName()); + childOrder.setGoodsImg(user.getHeaderImg()); + childOrder.setGoodsSpecName("默认"); + childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); + } + + childOrder.setGiveawayType(false); // 是否是赠品 0:否 1:是 + childOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + childOrder.setPraiseStatus(0); + // 累计订单价格 totalPrice.add(childOrder.getTotalPrice()); } diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java index 33b89a90..3bea8460 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java @@ -13,9 +13,13 @@ import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.MathUtils; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighCoupon; import com.hai.entity.HighOrder; +import com.hai.model.HighCouponModel; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; +import com.hai.service.HighCouponService; import com.hai.service.HighOrderService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -62,6 +66,9 @@ public class OrderController { @Resource private HighOrderService highOrderService; + @Resource + private HighCouponService highCouponService; + /** * * @Title: orderToPay @@ -74,8 +81,7 @@ public class OrderController { @RequestMapping(value="/orderToPay",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "订单支付发起支付") - public ResponseData orderToPay(@RequestBody String reqBodyStr, - HttpServletRequest request) { + public ResponseData orderToPay(@RequestBody String reqBodyStr) { try { if (StringUtils.isBlank(reqBodyStr)) { log.error("orderToPay error!", "参数错误"); @@ -100,6 +106,18 @@ public class OrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, ""); } + // 商品类型 1:卡卷 2:金币充值 + for (HighChildOrder childOrder : order.getHighChildOrderList()) { + if (childOrder.getGoodsType() == 2) { + HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); + // 支付类型:1.微信支付 2.金币支付 + if (coupon.getPayType() != 1) { + log.error("OrderController --> orderToPay() ERROR", "只支持微信支持"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",只支持微信支付"); + } + } + } + Map map = new HashMap<>(); map.put("orderNo", order.getOrderNo()); map.put("payPrice", order.getPayPrice()); @@ -133,4 +151,54 @@ public class OrderController { return ResponseMsgUtil.exception(e); } } + + + @RequestMapping(value="/orderToGoldPay",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "订单支付发起金币支付") + public ResponseData orderToGoldPay(@RequestBody String reqBodyStr) { + try { + if (StringUtils.isBlank(reqBodyStr)) { + log.error("orderToPay error!", "参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + JSONObject jsonObject = JSONObject.parseObject(reqBodyStr); + Long orderId = jsonObject.getLong("orderId"); + + if (orderId == null) { + log.error("orderToPay error!", "参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } + + HighOrder order = highOrderService.getOrderById(orderId); + if(order == null) { + log.error("OrderController --> orderToPay() ERROR", "未找到订单信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); + } + //校验订单状态 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + if(order.getOrderStatus() != 1) { + log.error("OrderController --> orderToPay() ERROR", "订单不处于待支付状态"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.ORDER_NO_STAY_PAY, ""); + } + + // 商品类型 1:卡卷 2:金币充值 + for (HighChildOrder childOrder : order.getHighChildOrderList()) { + if (childOrder.getGoodsType() == 2) { + HighCouponModel coupon = highCouponService.getCouponById(childOrder.getGoodsId()); + // 支付类型:1.微信支付 2.金币支付 + if (coupon.getPayType() != 2) { + log.error("OrderController --> orderToPay() ERROR", "只支持金币支持"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + ",只支持金币支付"); + } + } + } + + highOrderService.goldPayOrder(order.getMemId(), order.getId()); + + return ResponseMsgUtil.success("支付成功"); + } catch (Exception e) { + log.error("orderToPay error!", e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/hai-cweb/src/main/resources/dev/config.properties b/hai-cweb/src/main/resources/dev/config.properties index 37a2a39c..9c355143 100644 --- a/hai-cweb/src/main/resources/dev/config.properties +++ b/hai-cweb/src/main/resources/dev/config.properties @@ -9,3 +9,4 @@ notifyUrl=https://hsgcs.dctpay.com//crest/wechatpay/notify fileUrl=/home/project/hsg/filesystem cmsPath=/home/project/hsg/filesystem/cmsPath +couponCodePath=/home/project/hsg/filesystem/couponCode diff --git a/hai-service/pom.xml b/hai-service/pom.xml index 6b21aa7e..2094d06a 100644 --- a/hai-service/pom.xml +++ b/hai-service/pom.xml @@ -199,7 +199,12 @@ com.google.zxing core - 3.0.0 + 3.3.0 + + + com.google.zxing + javase + 3.3.0 diff --git a/hai-service/src/main/java/com/hai/common/QRCodeGenerator.java b/hai-service/src/main/java/com/hai/common/QRCodeGenerator.java new file mode 100644 index 00000000..79d08953 --- /dev/null +++ b/hai-service/src/main/java/com/hai/common/QRCodeGenerator.java @@ -0,0 +1,41 @@ +package com.hai.common; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; + +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Path; + +/** + * @Auther: 胡锐 + * @Description: 生成二维码 + * @Date: 2021/3/27 12:07 + */ +public class QRCodeGenerator { + + public static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException { + QRCodeWriter qrCodeWriter = new QRCodeWriter(); + + BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); + + Path path = FileSystems.getDefault().getPath(filePath); + + MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path); + + } + + public static void main(String[] args) { + try { + generateQRCodeImage("This is my first QR Code", 350, 350, "D:\\qr.png"); + } catch (WriterException e) { + System.out.println("Could not generate QR Code, WriterException :: " + e.getMessage()); + } catch (IOException e) { + System.out.println("Could not generate QR Code, IOException :: " + e.getMessage()); + } + + } +} diff --git a/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java b/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java index 037641d4..79e2f019 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java @@ -39,10 +39,14 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { int deleteByPrimaryKey(Long id); @Insert({ - "insert into high_user_coupon (user_id, coupon_code_id, ", + "insert into high_user_coupon (merchant_id, coupon_id, ", + "user_id, coupon_code_id, ", + "use_end_time, `status`, ", "ext_1, ext_2, ext_3, ", "ext_4)", - "values (#{userId,jdbcType=VARCHAR}, #{couponCodeId,jdbcType=VARCHAR}, ", + "values (#{merchantId,jdbcType=BIGINT}, #{couponId,jdbcType=BIGINT}, ", + "#{userId,jdbcType=BIGINT}, #{couponCodeId,jdbcType=BIGINT}, ", + "#{useEndTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, ", "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR}, ", "#{ext4,jdbcType=VARCHAR})" }) @@ -56,8 +60,12 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @SelectProvider(type=HighUserCouponSqlProvider.class, method="selectByExample") @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), - @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR), - @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.VARCHAR), + @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), + @Result(column="use_end_time", property="useEndTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR), @@ -67,14 +75,19 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @Select({ "select", - "id, user_id, coupon_code_id, ext_1, ext_2, ext_3, ext_4", + "id, merchant_id, coupon_id, user_id, coupon_code_id, use_end_time, `status`, ", + "ext_1, ext_2, ext_3, ext_4", "from high_user_coupon", "where id = #{id,jdbcType=BIGINT}" }) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), - @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR), - @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.VARCHAR), + @Result(column="merchant_id", property="merchantId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_id", property="couponId", jdbcType=JdbcType.BIGINT), + @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), + @Result(column="coupon_code_id", property="couponCodeId", jdbcType=JdbcType.BIGINT), + @Result(column="use_end_time", property="useEndTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR), @@ -93,8 +106,12 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @Update({ "update high_user_coupon", - "set user_id = #{userId,jdbcType=VARCHAR},", - "coupon_code_id = #{couponCodeId,jdbcType=VARCHAR},", + "set merchant_id = #{merchantId,jdbcType=BIGINT},", + "coupon_id = #{couponId,jdbcType=BIGINT},", + "user_id = #{userId,jdbcType=BIGINT},", + "coupon_code_id = #{couponCodeId,jdbcType=BIGINT},", + "use_end_time = #{useEndTime,jdbcType=TIMESTAMP},", + "`status` = #{status,jdbcType=INTEGER},", "ext_1 = #{ext1,jdbcType=VARCHAR},", "ext_2 = #{ext2,jdbcType=VARCHAR},", "ext_3 = #{ext3,jdbcType=VARCHAR},", diff --git a/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java index 83fae1e9..b57d511a 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java @@ -28,12 +28,28 @@ public class HighUserCouponSqlProvider { SQL sql = new SQL(); sql.INSERT_INTO("high_user_coupon"); + if (record.getMerchantId() != null) { + sql.VALUES("merchant_id", "#{merchantId,jdbcType=BIGINT}"); + } + + if (record.getCouponId() != null) { + sql.VALUES("coupon_id", "#{couponId,jdbcType=BIGINT}"); + } + if (record.getUserId() != null) { - sql.VALUES("user_id", "#{userId,jdbcType=VARCHAR}"); + sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}"); } if (record.getCouponCodeId() != null) { - sql.VALUES("coupon_code_id", "#{couponCodeId,jdbcType=VARCHAR}"); + sql.VALUES("coupon_code_id", "#{couponCodeId,jdbcType=BIGINT}"); + } + + if (record.getUseEndTime() != null) { + sql.VALUES("use_end_time", "#{useEndTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } if (record.getExt1() != null) { @@ -62,8 +78,12 @@ public class HighUserCouponSqlProvider { } else { sql.SELECT("id"); } + sql.SELECT("merchant_id"); + sql.SELECT("coupon_id"); sql.SELECT("user_id"); sql.SELECT("coupon_code_id"); + sql.SELECT("use_end_time"); + sql.SELECT("`status`"); sql.SELECT("ext_1"); sql.SELECT("ext_2"); sql.SELECT("ext_3"); @@ -89,12 +109,28 @@ public class HighUserCouponSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); } + if (record.getMerchantId() != null) { + sql.SET("merchant_id = #{record.merchantId,jdbcType=BIGINT}"); + } + + if (record.getCouponId() != null) { + sql.SET("coupon_id = #{record.couponId,jdbcType=BIGINT}"); + } + if (record.getUserId() != null) { - sql.SET("user_id = #{record.userId,jdbcType=VARCHAR}"); + sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); } if (record.getCouponCodeId() != null) { - sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=VARCHAR}"); + sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); + } + + if (record.getUseEndTime() != null) { + sql.SET("use_end_time = #{record.useEndTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } if (record.getExt1() != null) { @@ -122,8 +158,12 @@ public class HighUserCouponSqlProvider { sql.UPDATE("high_user_coupon"); sql.SET("id = #{record.id,jdbcType=BIGINT}"); - sql.SET("user_id = #{record.userId,jdbcType=VARCHAR}"); - sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=VARCHAR}"); + sql.SET("merchant_id = #{record.merchantId,jdbcType=BIGINT}"); + sql.SET("coupon_id = #{record.couponId,jdbcType=BIGINT}"); + sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); + sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); + sql.SET("use_end_time = #{record.useEndTime,jdbcType=TIMESTAMP}"); + sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); @@ -138,12 +178,28 @@ public class HighUserCouponSqlProvider { SQL sql = new SQL(); sql.UPDATE("high_user_coupon"); + if (record.getMerchantId() != null) { + sql.SET("merchant_id = #{merchantId,jdbcType=BIGINT}"); + } + + if (record.getCouponId() != null) { + sql.SET("coupon_id = #{couponId,jdbcType=BIGINT}"); + } + if (record.getUserId() != null) { - sql.SET("user_id = #{userId,jdbcType=VARCHAR}"); + sql.SET("user_id = #{userId,jdbcType=BIGINT}"); } if (record.getCouponCodeId() != null) { - sql.SET("coupon_code_id = #{couponCodeId,jdbcType=VARCHAR}"); + sql.SET("coupon_code_id = #{couponCodeId,jdbcType=BIGINT}"); + } + + if (record.getUseEndTime() != null) { + sql.SET("use_end_time = #{useEndTime,jdbcType=TIMESTAMP}"); + } + + if (record.getStatus() != null) { + sql.SET("`status` = #{status,jdbcType=INTEGER}"); } if (record.getExt1() != null) { diff --git a/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java b/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java index 5fff3555..8533b6ad 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java @@ -1,6 +1,7 @@ package com.hai.entity; import java.io.Serializable; +import java.util.Date; /** * high_user_coupon @@ -17,15 +18,35 @@ public class HighUserCoupon implements Serializable { */ private Long id; + /** + * 商户 + */ + private Long merchantId; + + /** + * 卡卷 + */ + private Long couponId; + /** * 用户id */ - private String userId; + private Long userId; + + /** + * 卡卷销售码id + */ + private Long couponCodeId; /** - * 昵称 + * 使用截止时间 */ - private String couponCodeId; + private Date useEndTime; + + /** + * 状态 0:已过期 1:未使用 2:已使用 + */ + private Integer status; private String ext1; @@ -45,22 +66,54 @@ public class HighUserCoupon implements Serializable { this.id = id; } - public String getUserId() { + public Long getMerchantId() { + return merchantId; + } + + public void setMerchantId(Long merchantId) { + this.merchantId = merchantId; + } + + public Long getCouponId() { + return couponId; + } + + public void setCouponId(Long couponId) { + this.couponId = couponId; + } + + public Long getUserId() { return userId; } - public void setUserId(String userId) { + public void setUserId(Long userId) { this.userId = userId; } - public String getCouponCodeId() { + public Long getCouponCodeId() { return couponCodeId; } - public void setCouponCodeId(String couponCodeId) { + public void setCouponCodeId(Long couponCodeId) { this.couponCodeId = couponCodeId; } + public Date getUseEndTime() { + return useEndTime; + } + + public void setUseEndTime(Date useEndTime) { + this.useEndTime = useEndTime; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + public String getExt1() { return ext1; } @@ -106,8 +159,12 @@ public class HighUserCoupon implements Serializable { } HighUserCoupon other = (HighUserCoupon) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getMerchantId() == null ? other.getMerchantId() == null : this.getMerchantId().equals(other.getMerchantId())) + && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getCouponCodeId() == null ? other.getCouponCodeId() == null : this.getCouponCodeId().equals(other.getCouponCodeId())) + && (this.getUseEndTime() == null ? other.getUseEndTime() == null : this.getUseEndTime().equals(other.getUseEndTime())) + && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) && (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2())) && (this.getExt3() == null ? other.getExt3() == null : this.getExt3().equals(other.getExt3())) @@ -119,8 +176,12 @@ public class HighUserCoupon implements Serializable { final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getMerchantId() == null) ? 0 : getMerchantId().hashCode()); + result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getCouponCodeId() == null) ? 0 : getCouponCodeId().hashCode()); + result = prime * result + ((getUseEndTime() == null) ? 0 : getUseEndTime().hashCode()); + result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode()); result = prime * result + ((getExt3() == null) ? 0 : getExt3().hashCode()); @@ -135,8 +196,12 @@ public class HighUserCoupon implements Serializable { sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); + sb.append(", merchantId=").append(merchantId); + sb.append(", couponId=").append(couponId); sb.append(", userId=").append(userId); sb.append(", couponCodeId=").append(couponCodeId); + sb.append(", useEndTime=").append(useEndTime); + sb.append(", status=").append(status); sb.append(", ext1=").append(ext1); sb.append(", ext2=").append(ext2); sb.append(", ext3=").append(ext3); diff --git a/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java b/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java index 0ababa73..4ea7d575 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java @@ -1,6 +1,7 @@ package com.hai.entity; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class HighUserCouponExample { @@ -184,6 +185,126 @@ public class HighUserCouponExample { return (Criteria) this; } + public Criteria andMerchantIdIsNull() { + addCriterion("merchant_id is null"); + return (Criteria) this; + } + + public Criteria andMerchantIdIsNotNull() { + addCriterion("merchant_id is not null"); + return (Criteria) this; + } + + public Criteria andMerchantIdEqualTo(Long value) { + addCriterion("merchant_id =", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdNotEqualTo(Long value) { + addCriterion("merchant_id <>", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdGreaterThan(Long value) { + addCriterion("merchant_id >", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdGreaterThanOrEqualTo(Long value) { + addCriterion("merchant_id >=", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdLessThan(Long value) { + addCriterion("merchant_id <", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdLessThanOrEqualTo(Long value) { + addCriterion("merchant_id <=", value, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdIn(List values) { + addCriterion("merchant_id in", values, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdNotIn(List values) { + addCriterion("merchant_id not in", values, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdBetween(Long value1, Long value2) { + addCriterion("merchant_id between", value1, value2, "merchantId"); + return (Criteria) this; + } + + public Criteria andMerchantIdNotBetween(Long value1, Long value2) { + addCriterion("merchant_id not between", value1, value2, "merchantId"); + return (Criteria) this; + } + + public Criteria andCouponIdIsNull() { + addCriterion("coupon_id is null"); + return (Criteria) this; + } + + public Criteria andCouponIdIsNotNull() { + addCriterion("coupon_id is not null"); + return (Criteria) this; + } + + public Criteria andCouponIdEqualTo(Long value) { + addCriterion("coupon_id =", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdNotEqualTo(Long value) { + addCriterion("coupon_id <>", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdGreaterThan(Long value) { + addCriterion("coupon_id >", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdGreaterThanOrEqualTo(Long value) { + addCriterion("coupon_id >=", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdLessThan(Long value) { + addCriterion("coupon_id <", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdLessThanOrEqualTo(Long value) { + addCriterion("coupon_id <=", value, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdIn(List values) { + addCriterion("coupon_id in", values, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdNotIn(List values) { + addCriterion("coupon_id not in", values, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdBetween(Long value1, Long value2) { + addCriterion("coupon_id between", value1, value2, "couponId"); + return (Criteria) this; + } + + public Criteria andCouponIdNotBetween(Long value1, Long value2) { + addCriterion("coupon_id not between", value1, value2, "couponId"); + return (Criteria) this; + } + public Criteria andUserIdIsNull() { addCriterion("user_id is null"); return (Criteria) this; @@ -194,62 +315,52 @@ public class HighUserCouponExample { return (Criteria) this; } - public Criteria andUserIdEqualTo(String value) { + public Criteria andUserIdEqualTo(Long value) { addCriterion("user_id =", value, "userId"); return (Criteria) this; } - public Criteria andUserIdNotEqualTo(String value) { + public Criteria andUserIdNotEqualTo(Long value) { addCriterion("user_id <>", value, "userId"); return (Criteria) this; } - public Criteria andUserIdGreaterThan(String value) { + public Criteria andUserIdGreaterThan(Long value) { addCriterion("user_id >", value, "userId"); return (Criteria) this; } - public Criteria andUserIdGreaterThanOrEqualTo(String value) { + public Criteria andUserIdGreaterThanOrEqualTo(Long value) { addCriterion("user_id >=", value, "userId"); return (Criteria) this; } - public Criteria andUserIdLessThan(String value) { + public Criteria andUserIdLessThan(Long value) { addCriterion("user_id <", value, "userId"); return (Criteria) this; } - public Criteria andUserIdLessThanOrEqualTo(String value) { + public Criteria andUserIdLessThanOrEqualTo(Long value) { addCriterion("user_id <=", value, "userId"); return (Criteria) this; } - public Criteria andUserIdLike(String value) { - addCriterion("user_id like", value, "userId"); - return (Criteria) this; - } - - public Criteria andUserIdNotLike(String value) { - addCriterion("user_id not like", value, "userId"); - return (Criteria) this; - } - - public Criteria andUserIdIn(List values) { + public Criteria andUserIdIn(List values) { addCriterion("user_id in", values, "userId"); return (Criteria) this; } - public Criteria andUserIdNotIn(List values) { + public Criteria andUserIdNotIn(List values) { addCriterion("user_id not in", values, "userId"); return (Criteria) this; } - public Criteria andUserIdBetween(String value1, String value2) { + public Criteria andUserIdBetween(Long value1, Long value2) { addCriterion("user_id between", value1, value2, "userId"); return (Criteria) this; } - public Criteria andUserIdNotBetween(String value1, String value2) { + public Criteria andUserIdNotBetween(Long value1, Long value2) { addCriterion("user_id not between", value1, value2, "userId"); return (Criteria) this; } @@ -264,63 +375,173 @@ public class HighUserCouponExample { return (Criteria) this; } - public Criteria andCouponCodeIdEqualTo(String value) { + public Criteria andCouponCodeIdEqualTo(Long value) { addCriterion("coupon_code_id =", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotEqualTo(String value) { + public Criteria andCouponCodeIdNotEqualTo(Long value) { addCriterion("coupon_code_id <>", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdGreaterThan(String value) { + public Criteria andCouponCodeIdGreaterThan(Long value) { addCriterion("coupon_code_id >", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdGreaterThanOrEqualTo(String value) { + public Criteria andCouponCodeIdGreaterThanOrEqualTo(Long value) { addCriterion("coupon_code_id >=", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdLessThan(String value) { + public Criteria andCouponCodeIdLessThan(Long value) { addCriterion("coupon_code_id <", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdLessThanOrEqualTo(String value) { + public Criteria andCouponCodeIdLessThanOrEqualTo(Long value) { addCriterion("coupon_code_id <=", value, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdLike(String value) { - addCriterion("coupon_code_id like", value, "couponCodeId"); + public Criteria andCouponCodeIdIn(List values) { + addCriterion("coupon_code_id in", values, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotLike(String value) { - addCriterion("coupon_code_id not like", value, "couponCodeId"); + public Criteria andCouponCodeIdNotIn(List values) { + addCriterion("coupon_code_id not in", values, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdIn(List values) { - addCriterion("coupon_code_id in", values, "couponCodeId"); + public Criteria andCouponCodeIdBetween(Long value1, Long value2) { + addCriterion("coupon_code_id between", value1, value2, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdNotIn(List values) { - addCriterion("coupon_code_id not in", values, "couponCodeId"); + public Criteria andCouponCodeIdNotBetween(Long value1, Long value2) { + addCriterion("coupon_code_id not between", value1, value2, "couponCodeId"); return (Criteria) this; } - public Criteria andCouponCodeIdBetween(String value1, String value2) { - addCriterion("coupon_code_id between", value1, value2, "couponCodeId"); + public Criteria andUseEndTimeIsNull() { + addCriterion("use_end_time is null"); return (Criteria) this; } - public Criteria andCouponCodeIdNotBetween(String value1, String value2) { - addCriterion("coupon_code_id not between", value1, value2, "couponCodeId"); + public Criteria andUseEndTimeIsNotNull() { + addCriterion("use_end_time is not null"); + return (Criteria) this; + } + + public Criteria andUseEndTimeEqualTo(Date value) { + addCriterion("use_end_time =", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeNotEqualTo(Date value) { + addCriterion("use_end_time <>", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeGreaterThan(Date value) { + addCriterion("use_end_time >", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeGreaterThanOrEqualTo(Date value) { + addCriterion("use_end_time >=", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeLessThan(Date value) { + addCriterion("use_end_time <", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeLessThanOrEqualTo(Date value) { + addCriterion("use_end_time <=", value, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeIn(List values) { + addCriterion("use_end_time in", values, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeNotIn(List values) { + addCriterion("use_end_time not in", values, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeBetween(Date value1, Date value2) { + addCriterion("use_end_time between", value1, value2, "useEndTime"); + return (Criteria) this; + } + + public Criteria andUseEndTimeNotBetween(Date value1, Date value2) { + addCriterion("use_end_time not between", value1, value2, "useEndTime"); + return (Criteria) this; + } + + public Criteria andStatusIsNull() { + addCriterion("`status` is null"); + return (Criteria) this; + } + + public Criteria andStatusIsNotNull() { + addCriterion("`status` is not null"); + return (Criteria) this; + } + + public Criteria andStatusEqualTo(Integer value) { + addCriterion("`status` =", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotEqualTo(Integer value) { + addCriterion("`status` <>", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThan(Integer value) { + addCriterion("`status` >", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThanOrEqualTo(Integer value) { + addCriterion("`status` >=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThan(Integer value) { + addCriterion("`status` <", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThanOrEqualTo(Integer value) { + addCriterion("`status` <=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusIn(List values) { + addCriterion("`status` in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotIn(List values) { + addCriterion("`status` not in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusBetween(Integer value1, Integer value2) { + addCriterion("`status` between", value1, value2, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotBetween(Integer value1, Integer value2) { + addCriterion("`status` not between", value1, value2, "status"); return (Criteria) this; } diff --git a/hai-service/src/main/java/com/hai/service/HighGoldRecService.java b/hai-service/src/main/java/com/hai/service/HighGoldRecService.java new file mode 100644 index 00000000..ae4369b7 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighGoldRecService.java @@ -0,0 +1,29 @@ +package com.hai.service; + +import com.hai.entity.HighGoldRec; + +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: 金币记录 + * @Date: 2021/3/27 10:01 + */ +public interface HighGoldRecService { + + /** + * @Author 胡锐 + * @Description 增加记录 + * @Date 2021/3/27 10:02 + **/ + void insertGoldRec(HighGoldRec highGoldRec); + + + /** + * @Author 胡锐 + * @Description 查询记录 + * @Date 2021/3/27 10:03 + **/ + List getGoldRec(Map map); +} diff --git a/hai-service/src/main/java/com/hai/service/HighOrderService.java b/hai-service/src/main/java/com/hai/service/HighOrderService.java index 5e163c17..ca33705f 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -17,7 +17,14 @@ public interface HighOrderService { * @Description 增加订单 * @Date 2021/3/26 23:05 **/ - void insertOrder(HighOrder highOrder); + void insertOrder(HighOrder highOrder) throws Exception; + + /** + * @Author 胡锐 + * @Description 金币支付订单 + * @Date 2021/3/27 11:20 + **/ + void goldPayOrder(Long userId, Long orderId); /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/HighUserService.java b/hai-service/src/main/java/com/hai/service/HighUserService.java index a4fceb05..e9d7b737 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserService.java @@ -75,4 +75,11 @@ public interface HighUserService { */ void insertUser(HighUser highUser); + /** + * @Author 胡锐 + * @Description 用户金币充值、消费 + * @Date 2021/3/27 9:51 + **/ + void goldHandle(Long userId, Integer goldNum, Integer goldType, Integer resType, Long resId); + } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 14ff3b89..0a918a18 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -1,19 +1,27 @@ package com.hai.service.impl; +import com.hai.common.QRCodeGenerator; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.IDGenerator; import com.hai.dao.HighChildOrderMapper; import com.hai.dao.HighOrderMapper; +import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; -import com.hai.service.HighCouponCodeService; -import com.hai.service.HighOrderService; +import com.hai.model.HighCouponHandselModel; +import com.hai.model.HighCouponModel; +import com.hai.service.*; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.File; +import java.math.BigDecimal; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,9 +43,21 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private HighCouponService highCouponService; + + @Resource + private HighCouponHandselService highCouponHandselService; + + @Resource + private HighUserService highUserService; + + @Resource + private HighUserCouponMapper highUserCouponMapper; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) - public void insertOrder(HighOrder highOrder) { + public void insertOrder(HighOrder highOrder) throws Exception { highOrderMapper.insert(highOrder); for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { @@ -54,10 +74,89 @@ public class HighOrderServiceImpl implements HighOrderService { list.get(0).setChildOrderId(childOrder.getId()); list.get(0).setStatus(99); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 highCouponCodeService.updateCouponCode(list.get(0)); + + // 生成二维码 + String qrCodeUrl = "/home/project/hsg/filesystem/couponCode/"+DateUtil.date2String(new Date(),"yyyyMMddHHmmss")+".png"; + QRCodeGenerator.generateQRCodeImage(list.get(0).getSalesCode(), 350, 350, qrCodeUrl); + childOrder.setExt1(qrCodeUrl); + highChildOrderMapper.updateByPrimaryKey(childOrder); + + if(childOrder.getGiveawayType() == false) { + // 查看是否需要赠送卡卷 + List handselListByCoupon = highCouponHandselService.getHandselListByCoupon(childOrder.getGoodsId()); + if (handselListByCoupon != null && handselListByCoupon.size() > 0) { + for (HighCouponHandsel highCouponHandsel : handselListByCoupon) { + // 查询卡卷信息 + HighCouponModel coupon = highCouponService.getCouponById(highCouponHandsel.getId()); + if (coupon == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); + } + + // 查询赠送卡卷 是否有库存,没有就不赠送 + if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { + HighChildOrder highChildOrder = new HighChildOrder(); + highChildOrder.setOrderId(highOrder.getId()); + highChildOrder.setGoodsType(1); + highChildOrder.setGoodsId(coupon.getId()); + highChildOrder.setGoodsName(coupon.getCouponName()); + highChildOrder.setGoodsImg(coupon.getCouponImg()); + highChildOrder.setGoodsSpecName("默认"); + highChildOrder.setGoodsPrice(new BigDecimal(0)); + highChildOrder.setSaleCount(1); + highChildOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); + highChildOrder.setGiveawayType(true); // 是否是赠品 0:否 1:是 + highChildOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + highChildOrder.setPraiseStatus(0); + highOrder.getHighChildOrderList().add(highChildOrder); + } + } + } + } } } } + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void goldPayOrder(Long userId, Long orderId) { + HighOrder highOrder = getOrderById(orderId); + if(highOrder == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, ""); + } + + // 金币 1:100 + Integer goldNum = new BigDecimal(highOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); + highUserService.goldHandle(userId, goldNum, 2, 2, highOrder.getId()); + + highOrder.setPayTime(new Date()); // 支付时间 + highOrder.setPayModel(1); // 支付模式:1 金币,2 第三方平台,3 混合 + highOrder.setPayType(3); // 支付方式: 1:支付宝 2:微信 3:金币 + highOrder.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + + for (HighChildOrder highChildOrder : highOrder.getHighChildOrderList()) { + highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + + // 商品类型 商品类型 1:卡卷 2:金币充值 + if (highChildOrder.getGoodsType() == 1) { + HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); + code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + highCouponCodeService.updateCouponCode(code); + + // 卡卷关联用户 + HighUserCoupon highUserCoupon = new HighUserCoupon(); + highUserCoupon.setMerchantId(code.getMerchantId()); + highUserCoupon.setCouponId(code.getCouponId()); + highUserCoupon.setUserId(highOrder.getMemId()); + highUserCoupon.setCouponCodeId(code.getId()); + highUserCoupon.setUseEndTime(code.getUseEndTime()); + highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponMapper.insert(highUserCoupon); + } + } + + updateOrder(highOrder); + } + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void updateOrder(HighOrder highOrder) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index bdc2d3cf..fd8f8a3c 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -1,14 +1,22 @@ package com.hai.service.impl; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; import com.hai.common.utils.DateUtil; import com.hai.dao.HighUserMapper; +import com.hai.entity.HighGoldRec; import com.hai.entity.HighUser; import com.hai.entity.HighUserExample; +import com.hai.service.HighGoldRecService; import com.hai.service.HighUserService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; import java.util.List; import java.util.Map; @@ -21,6 +29,9 @@ public class HighUserServiceImpl implements HighUserService { @Resource private HighUserMapper highUserMapper; + @Resource + private HighGoldRecService highGoldRecService; + @Override public List getListUser(Map map) { @@ -82,4 +93,37 @@ public class HighUserServiceImpl implements HighUserService { public void insertUser(HighUser highUser) { highUserMapper.insert(highUser); } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void goldHandle(Long userId, Integer goldNum, Integer goldType, Integer resType, Long resId) { + // 查询用户信息 + HighUser user = highUserMapper.selectByPrimaryKey(userId); + if (user == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, ""); + } + + // 金币类型:1收入,2支出 + if (goldType == 1) { + user.setGold(user.getGold() + goldNum); + + } else if (goldType == 2) { + if (goldNum > user.getGold()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "金币数量不足"); + } + user.setGold(user.getGold() - goldNum); + + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户金币处理异常"); + } + + HighGoldRec highGoldRec = new HighGoldRec(); + highGoldRec.setUserId(user.getId()); + highGoldRec.setGoldType(goldType.longValue()); + highGoldRec.setGold(goldNum); + highGoldRec.setCreateTime(new Date()); + highGoldRec.setResType(resType); + highGoldRec.setResId(resId); + highGoldRecService.insertGoldRec(highGoldRec); + } } diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index 4e690c69..f7de2069 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -4,14 +4,16 @@ import com.alibaba.fastjson.JSONObject; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; -import com.hai.entity.HighChildOrder; -import com.hai.entity.HighCouponCode; -import com.hai.entity.HighOrder; +import com.hai.dao.HighUserCouponMapper; +import com.hai.entity.*; import com.hai.service.HighCouponCodeService; import com.hai.service.HighOrderService; +import com.hai.service.HighUserService; import com.hai.service.pay.PayService; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; @@ -33,7 +35,14 @@ public class GoodsOrderServiceImpl implements PayService { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private HighUserService highUserService; + + @Resource + private HighUserCouponMapper highUserCouponMapper; + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) public void paySuccess(Map map, String payType) throws Exception { if (payType.equals("Alipay")) { // 支付宝支付 todo 暂未开发 @@ -55,15 +64,32 @@ public class GoodsOrderServiceImpl implements PayService { for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 - // 商品类型 1:卡卷 + // 商品类型 商品类型 1:卡卷 2:金币充值 if (highChildOrder.getGoodsType() == 1) { - // highCouponCodeService.getCouponCodeById(highChildOrder.get) + HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); + code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + highCouponCodeService.updateCouponCode(code); + + // 卡卷关联用户 + HighUserCoupon highUserCoupon = new HighUserCoupon(); + highUserCoupon.setMerchantId(code.getMerchantId()); + highUserCoupon.setCouponId(code.getCouponId()); + highUserCoupon.setUserId(order.getMemId()); + highUserCoupon.setCouponCodeId(code.getId()); + highUserCoupon.setUseEndTime(code.getUseEndTime()); + highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponMapper.insert(highUserCoupon); + } + + if (highChildOrder.getGoodsType() == 2) { + // 金币 1:100 + Integer goldNum = new BigDecimal(highChildOrder.getTotalPrice().toString()).multiply(new BigDecimal("100")).intValue(); + highUserService.goldHandle(highChildOrder.getGoodsId(), goldNum, 1, 1, highChildOrder.getId()); } } highOrderService.updateOrder(order); - } } } diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/HighGoldRecServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/HighGoldRecServiceImpl.java new file mode 100644 index 00000000..407229f5 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/pay/impl/HighGoldRecServiceImpl.java @@ -0,0 +1,35 @@ +package com.hai.service.pay.impl; + +import com.hai.dao.HighGoldRecMapper; +import com.hai.entity.HighGoldRec; +import com.hai.entity.HighGoldRecExample; +import com.hai.service.HighGoldRecService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/3/27 10:03 + */ +@Service("highGoldRecService") +public class HighGoldRecServiceImpl implements HighGoldRecService { + + @Resource + private HighGoldRecMapper highGoldRecMapper; + + @Override + public void insertGoldRec(HighGoldRec highGoldRec) { + highGoldRecMapper.insert(highGoldRec); + } + + @Override + public List getGoldRec(Map map) { + HighGoldRecExample example = new HighGoldRecExample(); + + return highGoldRecMapper.selectByExample(example); + } +}