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 7195d84a..3ce4a0b3 100644 --- a/hai-cweb/src/main/java/com/cweb/config/SysConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/SysConfig.java @@ -15,6 +15,9 @@ public class SysConfig { private String wxAppSecret; private String wxApiKey; private String wxMchId; + private String wxMchAppId; + private String wxSubAppId; + private String wxSubMchId; private String wxUnifiedOrderUrl; private String couponCodePath; private String notifyUrl; @@ -82,4 +85,28 @@ public class SysConfig { public void setCouponCodePath(String couponCodePath) { this.couponCodePath = couponCodePath; } + + public String getWxSubMchId() { + return wxSubMchId; + } + + public void setWxSubMchId(String wxSubMchId) { + this.wxSubMchId = wxSubMchId; + } + + public String getWxMchAppId() { + return wxMchAppId; + } + + public void setWxMchAppId(String wxMchAppId) { + this.wxMchAppId = wxMchAppId; + } + + public String getWxSubAppId() { + return wxSubAppId; + } + + public void setWxSubAppId(String wxSubAppId) { + this.wxSubAppId = wxSubAppId; + } } diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java index ea7dd28c..355a2a68 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java @@ -9,6 +9,9 @@ import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.BsCompany; +import com.hai.entity.HighUserCoupon; +import com.hai.model.HighUserCouponModel; +import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; import com.hai.service.*; @@ -39,15 +42,9 @@ public class HighCouponController { @Autowired private UserCenter userCenter; - @Resource - private HighMerchantService highMerchantService; - @Resource private HighCouponService highCouponService; - @Resource - private HighCouponHandselService highCouponHandselService; - @Resource private BsCompanyService bsCompanyService; @@ -55,7 +52,7 @@ public class HighCouponController { private HighCouponCodeService highCouponCodeService; @Resource - private HighApproveService highApproveService; + private HighUserCouponService highUserCouponService; @RequestMapping(value="/getCouponList",method = RequestMethod.GET) @ResponseBody @@ -104,4 +101,67 @@ public class HighCouponController { } } + + + @RequestMapping(value = "/getUserCouponList", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取用户卡卷") + public ResponseData getUserCouponList(@RequestParam(name = "status", required = false) Integer status, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize, + HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + map.put("userId", userInfoModel.getHighUser().getId()); + + PageHelper.startPage(pageNum, pageSize); + List list = highUserCouponService.getUserCouponList(map); + for (HighUserCouponModel highUserCouponModel : list) { + highUserCouponModel.setHighCouponModel(highCouponService.getCouponById(highUserCouponModel.getCouponId())); + } + return ResponseMsgUtil.success(new PageInfo<>()); + + } catch (Exception e) { + log.error("HighCouponController --> getUserCouponList() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + @RequestMapping(value = "/getUserCouponDetail", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取用户卡卷") + public ResponseData getUserCouponDetail(@RequestParam(name = "couponId", required = true) Long couponId, + HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + HighUserCoupon coupon = highUserCouponService.getUserCoupon(userInfoModel.getHighUser().getId(), couponId); + if (coupon == null) { + log.error("HighCouponController --> getUserCouponDetail() error!", "卡卷库存数量不足"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); + } + + Map map = new HashMap<>(); + map.put("highUserCoupon", "coupon"); + map.put("couponInfo", highCouponService.getCouponById(coupon.getCouponId())); + map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(coupon.getCouponCodeId())); + + return ResponseMsgUtil.success(map); + + } catch (Exception e) { + log.error("HighCouponController --> getUserCouponDetail() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + } 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 0bd61200..f6c92d21 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -106,7 +106,6 @@ public class HighOrderController { childOrder.setGoodsImg(coupon.getCouponImg()); childOrder.setGoodsSpecName("默认"); childOrder.setGoodsPrice(coupon.getDiscountPrice()); - childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); } if (childOrder.getGoodsType() == 2) { @@ -124,15 +123,15 @@ public class HighOrderController { childOrder.setGoodsName(user.getName()); childOrder.setGoodsImg(user.getHeaderImg()); childOrder.setGoodsSpecName("默认"); - childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); } + 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()); + totalPrice = totalPrice.add(childOrder.getTotalPrice()); } highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); @@ -145,7 +144,7 @@ public class HighOrderController { highOrderService.insertOrder(highOrder); - return ResponseMsgUtil.success("操作成功"); + return ResponseMsgUtil.success(highOrder); } catch (Exception e) { log.error("HighOrderController -> addOrder() error!",e); @@ -168,6 +167,22 @@ public class HighOrderController { } } + @RequestMapping(value = "/cancelOrder", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "取消订单") + public ResponseData cancelOrder(@RequestParam(name = "orderId", required = true) Long orderId) { + try { + + highOrderService.cancelOrder(orderId); + + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("HighOrderController --> cancelOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) @ResponseBody diff --git a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java index 42413bd6..42a2c899 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java @@ -135,6 +135,7 @@ public class WechatController { user.setOpenId(openId); user.setRegTime(new Date()); user.setStatus(1); + user.setGold(0); user.setPhone(phoneNoInfo.getPurePhoneNumber()); highUserService.insertUser(user); } else { @@ -154,6 +155,7 @@ public class WechatController { } catch (Exception e) { return ResponseMsgUtil.exception(e); + } } @@ -189,6 +191,7 @@ public class WechatController { user.setOpenId(openId); user.setRegTime(new Date()); user.setStatus(1); + user.setGold(0); user.setHeaderImg(userInfo.getAvatarUrl()); user.setName(userInfo.getNickName()); highUserService.insertUser(user); 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 3bea8460..ca949161 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 @@ -128,9 +128,12 @@ public class OrderController { String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8"); int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue(); WeChatPayReqInfo weChatPayReqInfo = new WeChatPayReqInfo(); - weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxAppId()); //公众号id - weChatPayReqInfo.setOpenid(openId); + weChatPayReqInfo.setAppid(SysConst.getSysConfig().getWxMchAppId()); //公众号id weChatPayReqInfo.setMch_id(SysConst.getSysConfig().getWxMchId()); //商户号 + weChatPayReqInfo.setSub_appid(SysConst.getSysConfig().getWxSubAppId()); //商户号 + weChatPayReqInfo.setSub_mch_id(SysConst.getSysConfig().getWxSubMchId()); //子商户号 + + weChatPayReqInfo.setOpenid(openId); weChatPayReqInfo.setNonce_str(nonce_str); //随机字符串 weChatPayReqInfo.setBody(map.get("body").toString()); //商品描述 weChatPayReqInfo.setOut_trade_no(map.get("orderNo").toString()); //商户订单号 @@ -141,7 +144,7 @@ public class OrderController { // weChatPayReqInfo.setAttach(map.get("orderScene").toString()); //附加数据,区分订单类型 Map payMap = new HashMap<>(); - payMap.put("app_id",SysConst.getSysConfig().getWxAppId()); + payMap.put("app_id",SysConst.getSysConfig().getWxSubAppId()); payMap.put("api_key",SysConst.getSysConfig().getWxApiKey()); payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl()); SortedMap sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap); diff --git a/hai-cweb/src/main/resources/dev/config.properties b/hai-cweb/src/main/resources/dev/config.properties index 9c355143..1f5c584b 100644 --- a/hai-cweb/src/main/resources/dev/config.properties +++ b/hai-cweb/src/main/resources/dev/config.properties @@ -1,8 +1,13 @@ # ΢ wxAppId=wx8d49e2f83025229d wxAppSecret=d8d6dcaef77d3b659258a01b5ddba5df + + wxApiKey=HfkjWxPayHaiShengGuang0123456789 -wxMchId=1603942866 +wxMchAppId=wx637bd6f7314daa46 +wxMchId=1289663601 +wxSubAppId=wx8d49e2f83025229d +wxSubMchId=1603942866 wxUnifiedOrderUrl=https://api.mch.weixin.qq.com/pay/unifiedorder notifyUrl=https://hsgcs.dctpay.com//crest/wechatpay/notify diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java new file mode 100644 index 00000000..387ee4f1 --- /dev/null +++ b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java @@ -0,0 +1,31 @@ +package com.hai.schedule; + +import com.hai.entity.HighUserCoupon; +import com.hai.service.HighUserCouponService; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @Auther: 胡锐 + * @Description: 卡卷定时任务 + * @Date: 2021/3/27 15:39 + */ +@Configuration +public class HighCouponSchedule { + + @Resource + private HighUserCouponService highUserCouponService; + + // @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + @Scheduled(cron = "0 0 0 * * ?") //每天 凌晨0点执行 + public void certification() { + List userCoupons = highUserCouponService.getOverdueCoupon(); + for (HighUserCoupon highUserCoupon : userCoupons) { + highUserCoupon.setStatus(0); // 状态 0:已过期 1:未使用 2:已使用 + highUserCouponService.updateUserCoupon(highUserCoupon); + } + } +} diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java new file mode 100644 index 00000000..13830483 --- /dev/null +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -0,0 +1,33 @@ +package com.hai.schedule; + +import com.hai.entity.HighOrder; +import com.hai.service.HighOrderService; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +import javax.annotation.Resource; +import javax.xml.ws.RespectBinding; +import java.util.List; + +/** + * @Auther: 胡锐 + * @Description: 订单定时任务 + * @Date: 2021/3/27 15:41 + */ +@Configuration +public class HighOrderSchedule { + + @Resource + private HighOrderService highOrderService; + + @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + public void certification() { + + List orderList = highOrderService.getCloseOrder(); + if (orderList != null && orderList.size() > 0) { + for (HighOrder order : orderList) { + highOrderService.cancelOrder(order.getId()); + } + } + } +} diff --git a/hai-service/src/main/java/com/hai/common/pay/entity/WeChatPayReqInfo.java b/hai-service/src/main/java/com/hai/common/pay/entity/WeChatPayReqInfo.java index 7cbe4873..22cd300d 100644 --- a/hai-service/src/main/java/com/hai/common/pay/entity/WeChatPayReqInfo.java +++ b/hai-service/src/main/java/com/hai/common/pay/entity/WeChatPayReqInfo.java @@ -9,6 +9,8 @@ public class WeChatPayReqInfo implements Serializable { private static final long serialVersionUID = -7642108447915413137L; private String appid; // 公众号id 必填 private String mch_id; // 商户号 必填 + private String sub_appid; // 微信支付分配的子商户号 必填 + private String sub_mch_id; // 微信支付分配的子商户号 必填 private String nonce_str; // 随机字符串 必填 private String sign; // 签名 必填 private String device_info; // 设备号 可以为终端设备号(门店号或收银设备ID),PC网页或公众号内支付可以传"WEB" @@ -202,4 +204,19 @@ public class WeChatPayReqInfo implements Serializable { this.scene_info = scene_info; } + public String getSub_mch_id() { + return sub_mch_id; + } + + public void setSub_mch_id(String sub_mch_id) { + this.sub_mch_id = sub_mch_id; + } + + public String getSub_appid() { + return sub_appid; + } + + public void setSub_appid(String sub_appid) { + this.sub_appid = sub_appid; + } } diff --git a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java index 9be3e394..05c05150 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderMapperExt.java @@ -1,7 +1,41 @@ package com.hai.dao; +import com.hai.entity.HighOrder; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.type.JdbcType; + +import java.util.List; + /** * mapper扩展类 */ public interface HighOrderMapperExt { -} \ No newline at end of file + + @Select({"SELECT * FROM high_order ho WHERE TIMESTAMPDIFF(MINUTE,ho.create_time,SYSDATE()) > 15 AND ho.order_status = 1"}) + @Results({ + @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true), + @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT), + @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR), + @Result(column="pay_model", property="payModel", jdbcType=JdbcType.INTEGER), + @Result(column="pay_type", property="payType", jdbcType=JdbcType.INTEGER), + @Result(column="pay_gold", property="payGold", jdbcType=JdbcType.INTEGER), + @Result(column="pay_price", property="payPrice", jdbcType=JdbcType.DECIMAL), + @Result(column="pay_real_price", property="payRealPrice", jdbcType=JdbcType.DECIMAL), + @Result(column="pay_serial_no", property="paySerialNo", jdbcType=JdbcType.VARCHAR), + @Result(column="order_status", property="orderStatus", jdbcType=JdbcType.INTEGER), + @Result(column="total_price", property="totalPrice", jdbcType=JdbcType.DECIMAL), + @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="pay_time", property="payTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="cancel_time", property="cancelTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="finish_time", property="finishTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="remarks", property="remarks", jdbcType=JdbcType.VARCHAR), + @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) + }) + List getCloseOrder(); + +} 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 79e2f019..a813d021 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserCouponMapper.java @@ -41,14 +41,14 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @Insert({ "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)", + "create_time, use_end_time, ", + "`status`, ext_1, ext_2, ", + "ext_3, ext_4)", "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})" + "#{createTime,jdbcType=TIMESTAMP}, #{useEndTime,jdbcType=TIMESTAMP}, ", + "#{status,jdbcType=INTEGER}, #{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, ", + "#{ext3,jdbcType=VARCHAR}, #{ext4,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighUserCoupon record); @@ -64,6 +64,7 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @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="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @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), @@ -75,8 +76,8 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @Select({ "select", - "id, merchant_id, coupon_id, user_id, coupon_code_id, use_end_time, `status`, ", - "ext_1, ext_2, ext_3, ext_4", + "id, merchant_id, coupon_id, user_id, coupon_code_id, create_time, use_end_time, ", + "`status`, ext_1, ext_2, ext_3, ext_4", "from high_user_coupon", "where id = #{id,jdbcType=BIGINT}" }) @@ -86,6 +87,7 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { @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="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @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), @@ -110,6 +112,7 @@ public interface HighUserCouponMapper extends HighUserCouponMapperExt { "coupon_id = #{couponId,jdbcType=BIGINT},", "user_id = #{userId,jdbcType=BIGINT},", "coupon_code_id = #{couponCodeId,jdbcType=BIGINT},", + "create_time = #{createTime,jdbcType=TIMESTAMP},", "use_end_time = #{useEndTime,jdbcType=TIMESTAMP},", "`status` = #{status,jdbcType=INTEGER},", "ext_1 = #{ext1,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 b57d511a..c5b027e1 100644 --- a/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighUserCouponSqlProvider.java @@ -44,6 +44,10 @@ public class HighUserCouponSqlProvider { sql.VALUES("coupon_code_id", "#{couponCodeId,jdbcType=BIGINT}"); } + if (record.getCreateTime() != null) { + sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); + } + if (record.getUseEndTime() != null) { sql.VALUES("use_end_time", "#{useEndTime,jdbcType=TIMESTAMP}"); } @@ -82,6 +86,7 @@ public class HighUserCouponSqlProvider { sql.SELECT("coupon_id"); sql.SELECT("user_id"); sql.SELECT("coupon_code_id"); + sql.SELECT("create_time"); sql.SELECT("use_end_time"); sql.SELECT("`status`"); sql.SELECT("ext_1"); @@ -125,6 +130,10 @@ public class HighUserCouponSqlProvider { sql.SET("coupon_code_id = #{record.couponCodeId,jdbcType=BIGINT}"); } + if (record.getCreateTime() != null) { + sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); + } + if (record.getUseEndTime() != null) { sql.SET("use_end_time = #{record.useEndTime,jdbcType=TIMESTAMP}"); } @@ -162,6 +171,7 @@ public class HighUserCouponSqlProvider { 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("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("use_end_time = #{record.useEndTime,jdbcType=TIMESTAMP}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); @@ -194,6 +204,10 @@ public class HighUserCouponSqlProvider { sql.SET("coupon_code_id = #{couponCodeId,jdbcType=BIGINT}"); } + if (record.getCreateTime() != null) { + sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); + } + if (record.getUseEndTime() != null) { sql.SET("use_end_time = #{useEndTime,jdbcType=TIMESTAMP}"); } 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 8533b6ad..0ddca157 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserCoupon.java @@ -38,6 +38,11 @@ public class HighUserCoupon implements Serializable { */ private Long couponCodeId; + /** + * 创建时间 + */ + private Date createTime; + /** * 使用截止时间 */ @@ -98,6 +103,14 @@ public class HighUserCoupon implements Serializable { this.couponCodeId = couponCodeId; } + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + public Date getUseEndTime() { return useEndTime; } @@ -163,6 +176,7 @@ public class HighUserCoupon implements Serializable { && (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.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (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())) @@ -180,6 +194,7 @@ public class HighUserCoupon implements Serializable { 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 + ((getCreateTime() == null) ? 0 : getCreateTime().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()); @@ -200,6 +215,7 @@ public class HighUserCoupon implements Serializable { sb.append(", couponId=").append(couponId); sb.append(", userId=").append(userId); sb.append(", couponCodeId=").append(couponCodeId); + sb.append(", createTime=").append(createTime); sb.append(", useEndTime=").append(useEndTime); sb.append(", status=").append(status); sb.append(", ext1=").append(ext1); 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 4ea7d575..821bf507 100644 --- a/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighUserCouponExample.java @@ -425,6 +425,66 @@ public class HighUserCouponExample { return (Criteria) this; } + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + public Criteria andUseEndTimeIsNull() { addCriterion("use_end_time is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/model/HighUserCouponModel.java b/hai-service/src/main/java/com/hai/model/HighUserCouponModel.java new file mode 100644 index 00000000..6a0c73bf --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/HighUserCouponModel.java @@ -0,0 +1,21 @@ +package com.hai.model; + +import com.hai.entity.HighUserCoupon; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/3/27 17:19 + */ +public class HighUserCouponModel extends HighUserCoupon { + + private HighCouponModel highCouponModel; + + public HighCouponModel getHighCouponModel() { + return highCouponModel; + } + + public void setHighCouponModel(HighCouponModel highCouponModel) { + this.highCouponModel = highCouponModel; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java index 54084960..c1214810 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponCodeService.java @@ -57,6 +57,13 @@ public interface HighCouponCodeService { **/ HighCouponCode getCouponCodeBySalesCode(String code); + /** + * @Author 胡锐 + * @Description 根据id 查询 + * @Date 2021/3/27 17:52 + **/ + HighCouponCode getCouponCodeById(Long id); + /** * * @Title: getStockCountByCoupon 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 533102eb..b32fce52 100644 --- a/hai-service/src/main/java/com/hai/service/HighOrderService.java +++ b/hai-service/src/main/java/com/hai/service/HighOrderService.java @@ -61,6 +61,13 @@ public interface HighOrderService { **/ List getOrderList(Map map); + /** + * @Author 胡锐 + * @Description 查询需要关闭的订单列表 + * @Date 2021/3/27 15:43 + **/ + List getCloseOrder(); + /** * @Author 胡锐 * @Description 子订单完成 @@ -68,4 +75,11 @@ public interface HighOrderService { **/ void childOrderComplete(Long childOrderId); + /** + * @Author 胡锐 + * @Description 取消订单 + * @Date 2021/3/27 15:50 + **/ + void cancelOrder(Long orderId); + } diff --git a/hai-service/src/main/java/com/hai/service/HighUserCouponService.java b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java new file mode 100644 index 00000000..6917116b --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighUserCouponService.java @@ -0,0 +1,51 @@ +package com.hai.service; + +import com.hai.entity.HighUserCoupon; +import com.hai.model.HighUserCouponModel; + +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: 用户的卡卷 + * @Date: 2021/3/27 16:06 + */ +public interface HighUserCouponService { + + /** + * @Author 胡锐 + * @Description 增加 + * @Date 2021/3/27 16:08 + **/ + void insertUserCoupon(HighUserCoupon highUserCoupon); + + /** + * @Author 胡锐 + * @Description 修改 + * @Date 2021/3/27 16:08 + **/ + void updateUserCoupon(HighUserCoupon highUserCoupon); + + /** + * @Author 胡锐 + * @Description 获取已到期的卡卷 + * @Date 2021/3/27 16:09 + **/ + List getOverdueCoupon(); + + /** + * @Author 胡锐 + * @Description 查询用户列表 + * @Date 2021/3/27 17:21 + **/ + List getUserCouponList(Map map); + + /** + * @Author 胡锐 + * @Description 根据用户id 和 卡卷id查询 + * @Date 2021/3/27 17:42 + **/ + HighUserCoupon getUserCoupon(Long userId, Long couponId); + +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java index 2cdeb6d9..f51d3a1e 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java @@ -107,6 +107,11 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService { return null; } + @Override + public HighCouponCode getCouponCodeById(Long id) { + return highCouponCodeMapper.selectByPrimaryKey(id); + } + @Override public Integer getStockCountByCoupon(Long couponId) { HighCouponCodeExample example = new HighCouponCodeExample(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java index 2cbe4f05..c0a642cd 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java @@ -286,7 +286,7 @@ public class HighCouponServiceImpl implements HighCouponService { HighCouponModel model = new HighCouponModel(); BeanUtils.copyProperties(highCoupon, model); // 查询有效库存 - model.setSalesCount(highCouponCodeService.getStockCountByCoupon(highCoupon.getId())); + model.setStockCount(highCouponCodeService.getStockCountByCoupon(highCoupon.getId())); // 查询赠送卡卷列表 List coupon = highCouponHandselService.getHandselListByCoupon(highCoupon.getId()); 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 eaebe53a..5ff8c608 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 @@ -8,6 +8,7 @@ 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.HighOrderMapperExt; import com.hai.dao.HighUserCouponMapper; import com.hai.entity.*; import com.hai.model.HighCouponHandselModel; @@ -21,10 +22,7 @@ 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; +import java.util.*; /** * @Auther: 胡锐 @@ -37,6 +35,9 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighOrderMapper highOrderMapper; + @Resource + private HighOrderMapperExt highOrderMapperExt; + @Resource private HighChildOrderMapper highChildOrderMapper; @@ -60,7 +61,8 @@ public class HighOrderServiceImpl implements HighOrderService { public void insertOrder(HighOrder highOrder) throws Exception { highOrderMapper.insert(highOrder); - for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) { + for (int i = 0; i < highOrder.getHighChildOrderList().size();i++) { + HighChildOrder childOrder = highOrder.getHighChildOrderList().get(i); childOrder.setOrderId(highOrder.getId()); highChildOrderMapper.insert(childOrder); @@ -76,7 +78,8 @@ public class HighOrderServiceImpl implements HighOrderService { highCouponCodeService.updateCouponCode(list.get(0)); // 生成二维码 - String qrCodeUrl = "/home/project/hsg/filesystem/couponCode/"+DateUtil.date2String(new Date(),"yyyyMMddHHmmss")+".png"; + //String qrCodeUrl = "/home/project/hsg/filesystem/couponCode/"+DateUtil.date2String(new Date(),"yyyyMMddHHmmss")+".png"; + String qrCodeUrl = "F:\\"+DateUtil.date2String(new Date(),"yyyyMMddHHmmss")+".png"; QRCodeGenerator.generateQRCodeImage(list.get(0).getSalesCode(), 350, 350, qrCodeUrl); childOrder.setExt1(qrCodeUrl); highChildOrderMapper.updateByPrimaryKey(childOrder); @@ -87,13 +90,13 @@ public class HighOrderServiceImpl implements HighOrderService { if (handselListByCoupon != null && handselListByCoupon.size() > 0) { for (HighCouponHandsel highCouponHandsel : handselListByCoupon) { // 查询卡卷信息 - HighCouponModel coupon = highCouponService.getCouponById(highCouponHandsel.getId()); + HighCouponModel coupon = highCouponService.getCouponById(highCouponHandsel.getHandselCouponId()); if (coupon == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); } // 查询赠送卡卷 是否有库存,没有就不赠送 - if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) <= 0) { + if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) > 0) { HighChildOrder highChildOrder = new HighChildOrder(); highChildOrder.setOrderId(highOrder.getId()); highChildOrder.setGoodsType(1); @@ -103,7 +106,7 @@ public class HighOrderServiceImpl implements HighOrderService { highChildOrder.setGoodsSpecName("默认"); highChildOrder.setGoodsPrice(new BigDecimal(0)); highChildOrder.setSaleCount(1); - highChildOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); + highChildOrder.setTotalPrice(new BigDecimal(0)); highChildOrder.setGiveawayType(true); // 是否是赠品 0:否 1:是 highChildOrder.setChildOrdeStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 highChildOrder.setPraiseStatus(0); @@ -140,6 +143,7 @@ public class HighOrderServiceImpl implements HighOrderService { if (highChildOrder.getGoodsType() == 1) { HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + code.setReceiveTime(new Date()); highCouponCodeService.updateCouponCode(code); // 卡卷关联用户 @@ -148,6 +152,7 @@ public class HighOrderServiceImpl implements HighOrderService { highUserCoupon.setCouponId(code.getCouponId()); highUserCoupon.setUserId(highOrder.getMemId()); highUserCoupon.setCouponCodeId(code.getId()); + highUserCoupon.setCreateTime(new Date()); highUserCoupon.setUseEndTime(code.getUseEndTime()); highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); @@ -226,6 +231,11 @@ public class HighOrderServiceImpl implements HighOrderService { return highOrderMapper.selectByExample(example); } + @Override + public List getCloseOrder() { + return highOrderMapperExt.getCloseOrder(); + } + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void childOrderComplete(Long childOrderId) { @@ -245,4 +255,27 @@ public class HighOrderServiceImpl implements HighOrderService { highOrderMapper.updateByPrimaryKey(order); } } + + @Override + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void cancelOrder(Long orderId) { + HighOrder order = getOrderById(orderId); + if (order != null) { + order.setOrderStatus(5); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + order.setCancelTime(new Date()); + + for (HighChildOrder highChildOrder : order.getHighChildOrderList()) { + // 商品类型 1:卡卷 2:金币充值 + if (highChildOrder.getGoodsType() == 1) { + // 查询卡卷详情 + HighCouponCode couponCode = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); + couponCode.setChildOrderId(null); + couponCode.setStatus(1); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + highCouponCodeService.updateCouponCode(couponCode); + } + highChildOrder.setChildOrdeStatus(5); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + } + updateOrder(order); + } + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java new file mode 100644 index 00000000..7acee4f8 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java @@ -0,0 +1,77 @@ +package com.hai.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hai.dao.HighUserCouponMapper; +import com.hai.entity.HighUserCoupon; +import com.hai.entity.HighUserCouponExample; +import com.hai.model.HighUserCouponModel; +import com.hai.service.HighUserCouponService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * @Auther: 胡锐 + * @Description: + * @Date: 2021/3/27 16:10 + */ +@Service("highUserCouponService") +public class HighUserCouponServiceImpl implements HighUserCouponService { + + @Resource + private HighUserCouponMapper highUserCouponMapper; + + @Override + public void insertUserCoupon(HighUserCoupon highUserCoupon) { + highUserCouponMapper.insert(highUserCoupon); + } + + @Override + public void updateUserCoupon(HighUserCoupon highUserCoupon) { + highUserCouponMapper.updateByPrimaryKey(highUserCoupon); + } + + @Override + public List getOverdueCoupon() { + HighUserCouponExample example = new HighUserCouponExample(); + example.createCriteria().andStatusEqualTo(1).andUseEndTimeGreaterThanOrEqualTo(new Date()); + return highUserCouponMapper.selectByExample(example); + } + + @Override + public List getUserCouponList(Map map) { + HighUserCouponExample example = new HighUserCouponExample(); + HighUserCouponExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getLong(map, "userId") != null) { + criteria.andUserIdEqualTo(MapUtils.getLong(map, "userId")); + } + + if (MapUtils.getInteger(map, "status") != null) { + criteria.andStatusEqualTo(MapUtils.getInteger(map, "status")); + } + + example.setOrderByClause("create_time desc"); + List highUserCoupons = highUserCouponMapper.selectByExample(example); + if (highUserCoupons != null && highUserCoupons.size() > 0) { + return JSON.parseArray(JSON.toJSONString(highUserCoupons), HighUserCouponModel.class); + } + return new ArrayList<>(); + } + + @Override + public HighUserCoupon getUserCoupon(Long userId, Long couponId) { + HighUserCouponExample example = new HighUserCouponExample(); + example.createCriteria().andUserIdEqualTo(userId).andCouponIdEqualTo(couponId); + List coupons = highUserCouponMapper.selectByExample(example); + if (coupons != null && coupons.size() > 0) { + return coupons.get(0); + } + return null; + } +} 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 1bc58098..aa703bb5 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 @@ -67,6 +67,7 @@ public class GoodsOrderServiceImpl implements PayService { highChildOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 HighCouponCode code = highCouponCodeService.getCouponCodeByOrderId(highChildOrder.getId()); code.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付 + code.setReceiveTime(new Date()); highCouponCodeService.updateCouponCode(code); // 卡卷关联用户 @@ -75,6 +76,7 @@ public class GoodsOrderServiceImpl implements PayService { highUserCoupon.setCouponId(code.getCouponId()); highUserCoupon.setUserId(order.getMemId()); highUserCoupon.setCouponCodeId(code.getId()); + highUserCoupon.setCreateTime(new Date()); highUserCoupon.setUseEndTime(code.getUseEndTime()); highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon);