'提交代码'

dev-discount
199901012 4 years ago
parent 62452074c5
commit e04766d22d
  1. 8
      hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java
  2. 47
      hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java
  3. 22
      hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java
  4. 37
      hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java
  5. 2
      hai-service/src/main/java/com/hai/dao/SecUserMapperExt.java
  6. 7
      hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java
  7. 2
      hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java
  8. 16
      hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java
  9. 5
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java
  10. 12
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java
  11. 4
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

@ -134,6 +134,14 @@ public class HighCouponController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.MERCHANT_NOF_FOUND, "");
} }
// 计算销售截止时间
Calendar salesEndTime = Calendar.getInstance();
salesEndTime.setTime(highCoupon.getSalesEndTime());
salesEndTime.set(Calendar.HOUR_OF_DAY, 23);
salesEndTime.set(Calendar.MINUTE, 59);
salesEndTime.set(Calendar.SECOND, 59);
highCoupon.setSalesEndTime(salesEndTime.getTime());
String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddHHmmss"); //订单号生成 年月日小时分秒 + 5位随机数 String setCouponKey = DateUtil.date2String(new Date(), "yyyyMMddHHmmss"); //订单号生成 年月日小时分秒 + 5位随机数
highCoupon.setCouponKey(setCouponKey); highCoupon.setCouponKey(setCouponKey);
highCoupon.setCompanyId(merchant.getCompanyId()); highCoupon.setCompanyId(merchant.getCompanyId());

@ -1,5 +1,6 @@
package com.bweb.controller; package com.bweb.controller;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
@ -7,6 +8,7 @@ import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighDiscount; import com.hai.entity.HighDiscount;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
@ -23,6 +25,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -73,11 +77,19 @@ public class HighDiscountController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 计算销售截止时间
Calendar salesEndTime = Calendar.getInstance();
salesEndTime.setTime(highDiscount.getSalesEndTime());
salesEndTime.set(Calendar.HOUR_OF_DAY, 23);
salesEndTime.set(Calendar.MINUTE, 59);
salesEndTime.set(Calendar.SECOND, 59);
highDiscount.setSalesEndTime(salesEndTime.getTime());
highDiscount.setDiscountKey(DateUtil.date2String(new Date(), "yyyyMMddHHmmss"));
highDiscount.setCompanyId(userInfoModel.getBsCompany().getId()); highDiscount.setCompanyId(userInfoModel.getBsCompany().getId());
highDiscount.setOperatorId(userInfoModel.getSecUser().getId()); highDiscount.setOperatorId(userInfoModel.getSecUser().getId());
highDiscount.setOperatorName(userInfoModel.getSecUser().getUserName()); highDiscount.setOperatorName(userInfoModel.getSecUser().getUserName());
highDiscount.setStatus(1); highDiscount.setStatus(1);
highDiscountService.insertDiscount(highDiscount); highDiscountService.insertDiscount(highDiscount);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -114,11 +126,18 @@ public class HighDiscountController {
log.error("HighDiscountController -> updateDiscount() error!","未找到优惠券信息"); log.error("HighDiscountController -> updateDiscount() error!","未找到优惠券信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, "");
} }
// 计算销售截止时间
Calendar salesEndTime = Calendar.getInstance();
salesEndTime.setTime(highDiscount.getSalesEndTime());
salesEndTime.set(Calendar.HOUR_OF_DAY, 23);
salesEndTime.set(Calendar.MINUTE, 59);
salesEndTime.set(Calendar.SECOND, 59);
discount.setSalesEndTime(salesEndTime.getTime());
discount.setDiscountName(highDiscount.getDiscountName()); discount.setDiscountName(highDiscount.getDiscountName());
discount.setDiscountImg(highDiscount.getDiscountImg()); discount.setDiscountImg(highDiscount.getDiscountImg());
discount.setDiscountCarouselImg(highDiscount.getDiscountCarouselImg()); discount.setDiscountCarouselImg(highDiscount.getDiscountCarouselImg());
discount.setEffectiveDay(highDiscount.getEffectiveDay()); discount.setEffectiveDay(highDiscount.getEffectiveDay());
discount.setSalesEndTime(highDiscount.getSalesEndTime());
highDiscountService.updateDiscount(highDiscount); highDiscountService.updateDiscount(highDiscount);
@ -130,6 +149,29 @@ public class HighDiscountController {
} }
@RequestMapping(value="/updateDiscountStatus",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "修改优惠券状态")
public ResponseData updateDiscountStatus(@RequestParam(name = "discountId", required = true) Long discountId,
@RequestParam(name = "status", required = true) Integer status) {
try {
// 查询优惠券
HighDiscount discount = highDiscountService.getDiscountById(discountId);
if (discount == null) {
log.error("HighDiscountController -> updateDiscountStatus() error!","未找到优惠券信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, "");
}
discount.setStatus(status);
discount.setUpdateTime(new Date());
highDiscountService.updateDiscount(discount);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("HighDiscountController -> updateDiscountStatus() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getDiscountById",method = RequestMethod.GET) @RequestMapping(value="/getDiscountById",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "根据id查询") @ApiOperation(value = "根据id查询")
@ -168,5 +210,4 @@ public class HighDiscountController {
} }
} }
} }

@ -26,9 +26,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.*;
import java.util.HashMap; import java.util.stream.Collectors;
import java.util.Map;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -57,6 +56,9 @@ public class HighOrderController {
@Resource @Resource
private HighDiscountUserRelService highDiscountUserRelService; private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountCouponRelService highDiscountCouponRelService;
@Resource @Resource
private HighUserService highUserService; private HighUserService highUserService;
@ -96,6 +98,20 @@ public class HighOrderController {
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
} }
// 校验优惠券是否可用
if (highOrder.getMemDiscountId() != null) {
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId());
if (discountCouponRelList.size() > 0) {
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList());
if (collect == null || collect.size() == 0) {
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券");
}
}
}
// 是否到底限购数量 // 是否到底限购数量
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) {
log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); log.error("HighOrderController --> addOrder() error!", "已达到限购数量");

@ -9,8 +9,12 @@ import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighDiscount;
import com.hai.entity.HighDiscountCouponRel;
import com.hai.entity.HighDiscountUserRel;
import com.hai.model.HighUserModel; import com.hai.model.HighUserModel;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.service.HighDiscountCouponRelService;
import com.hai.service.HighDiscountUserRelService; import com.hai.service.HighDiscountUserRelService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -22,8 +26,11 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -43,6 +50,9 @@ public class HighUserDiscountController {
@Resource @Resource
private HighDiscountUserRelService highDiscountUserRelService; private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountCouponRelService highDiscountCouponRelService;
@RequestMapping(value="/receiveDiscount",method = RequestMethod.POST) @RequestMapping(value="/receiveDiscount",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "用户领取优惠券") @ApiOperation(value = "用户领取优惠券")
@ -59,7 +69,7 @@ public class HighUserDiscountController {
log.error("HighDiscountController -> receiveDiscount() error!", "参数错误"); log.error("HighDiscountController -> receiveDiscount() error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 领取成功 // 领取
highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), discountAgentId); highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), discountAgentId);
return ResponseMsgUtil.success("操作成功"); return ResponseMsgUtil.success("操作成功");
@ -97,8 +107,8 @@ public class HighUserDiscountController {
@RequestMapping(value="/getUserNormalDiscountList",method = RequestMethod.GET) @RequestMapping(value="/getUserNormalDiscountList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "获取用户的【可以使用】的优惠券列表") @ApiOperation(value = "根据卡券,查询【可以使用】优惠券列表")
public ResponseData getUserNormalDiscountList(HttpServletRequest request) { public ResponseData getDiscountListByCoupon(@RequestParam(name = "couponId", required = true) Long couponId,HttpServletRequest request) {
try { try {
// 用户 // 用户
@ -108,10 +118,27 @@ public class HighUserDiscountController {
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
map.put("userId", userInfoModel.getHighUser().getId()); map.put("userId", userInfoModel.getHighUser().getId());
map.put("status", 1); map.put("status", 1);
return ResponseMsgUtil.success(highDiscountUserRelService.getDiscountList(map));
List<HighDiscountUserRel> list = new ArrayList<>();
// 查询用户的优惠券
List<HighDiscountUserRel> userRels = highDiscountUserRelService.getDiscountList(map);
if (userRels.size() > 0) {
// 查询当前卡券有哪些优惠券
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(couponId);
if (discountCouponRelList.size() > 0) {
for (HighDiscountCouponRel highDiscountCouponRel : discountCouponRelList) {
List<HighDiscountUserRel> collect = userRels.stream().filter(o -> o.getDiscountId().equals(highDiscountCouponRel.getDiscountId())).collect(Collectors.toList());
if (collect != null && collect.size() > 0) {
list.add(collect.get(0));
}
}
}
}
return ResponseMsgUtil.success(list);
} catch (Exception e) { } catch (Exception e) {
log.error("HighDiscountController -> getUserNormalDiscountList() error!",e); log.error("HighDiscountController -> getDiscountListByCoupon() error!",e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);
} }
} }

@ -62,9 +62,9 @@ public interface SecUserMapperExt {
" sec_user su " + " sec_user su " +
" WHERE" + " WHERE" +
" STATUS = 1 " + " STATUS = 1 " +
" AND su.`password` = #{password}" +
" AND su.login_name = #{loginName} " + " AND su.login_name = #{loginName} " +
" OR su.telephone = #{loginName} " + " OR su.telephone = #{loginName} " +
" AND su.`password` = #{password}" +
"</script>" "</script>"
}) })
@Results({ @Results({

@ -47,6 +47,13 @@ public interface HighDiscountCouponRelService {
**/ **/
HighDiscountCouponRel getRelByDiscountCoupon(Long discountId,Long couponId); HighDiscountCouponRel getRelByDiscountCoupon(Long discountId,Long couponId);
/**
* @Author 胡锐
* @Description 根据卡券查询
* @Date 2021/4/4 20:23
**/
List<HighDiscountCouponRel> getRelByCoupon(Long couponId);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 根据优惠券查询 * @Description 根据优惠券查询

@ -15,7 +15,7 @@ public interface HighDiscountUserRelService {
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 领取 * @Description 领取优惠
* @Date 2021/4/4 15:12 * @Date 2021/4/4 15:12
**/ **/
void receiveDiscount(Long userId,Long discountAgentId); void receiveDiscount(Long userId,Long discountAgentId);

@ -53,8 +53,7 @@ public class HighDiscountCouponRelServiceImpl implements HighDiscountCouponRelSe
@Override @Override
public HighDiscountCouponRel getRelByDiscountCoupon(Long discountId, Long couponId) { public HighDiscountCouponRel getRelByDiscountCoupon(Long discountId, Long couponId) {
HighDiscountCouponRelExample example = new HighDiscountCouponRelExample(); HighDiscountCouponRelExample example = new HighDiscountCouponRelExample();
example.createCriteria().andDiscountIdEqualTo(discountId).andCouponIdEqualTo(couponId); example.createCriteria().andDiscountIdEqualTo(discountId).andCouponIdEqualTo(couponId).andStatusEqualTo(1);
List<HighDiscountCouponRel> list = highDiscountCouponRelMapper.selectByExample(example); List<HighDiscountCouponRel> list = highDiscountCouponRelMapper.selectByExample(example);
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
return list.get(0); return list.get(0);
@ -62,10 +61,21 @@ public class HighDiscountCouponRelServiceImpl implements HighDiscountCouponRelSe
return null; return null;
} }
@Override
public List<HighDiscountCouponRel> getRelByCoupon(Long couponId) {
HighDiscountCouponRelExample example = new HighDiscountCouponRelExample();
example.createCriteria().andCouponIdEqualTo(couponId).andStatusEqualTo(1);
List<HighDiscountCouponRel> list = highDiscountCouponRelMapper.selectByExample(example);
for (HighDiscountCouponRel rel : list) {
rel.setHighCoupon(highCouponService.getCouponDetail(rel.getCouponId()));
}
return list;
}
@Override @Override
public List<HighDiscountCouponRel> getRelByDiscount(Long discountId) { public List<HighDiscountCouponRel> getRelByDiscount(Long discountId) {
HighDiscountCouponRelExample example = new HighDiscountCouponRelExample(); HighDiscountCouponRelExample example = new HighDiscountCouponRelExample();
example.createCriteria().andDiscountIdEqualTo(discountId); example.createCriteria().andDiscountIdEqualTo(discountId).andStatusEqualTo(1);;
List<HighDiscountCouponRel> list = highDiscountCouponRelMapper.selectByExample(example); List<HighDiscountCouponRel> list = highDiscountCouponRelMapper.selectByExample(example);
for (HighDiscountCouponRel rel : list) { for (HighDiscountCouponRel rel : list) {
rel.setHighCoupon(highCouponService.getCouponDetail(rel.getCouponId())); rel.setHighCoupon(highCouponService.getCouponDetail(rel.getCouponId()));

@ -75,7 +75,12 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
userRel.setCreateTime(new Date()); userRel.setCreateTime(new Date());
// 计算使用有效期 // 计算使用有效期
Calendar userEndTime = Calendar.getInstance(); Calendar userEndTime = Calendar.getInstance();
userEndTime.setTime(new Date());
userEndTime.set(Calendar.HOUR_OF_DAY, 23);
userEndTime.set(Calendar.MINUTE, 59);
userEndTime.set(Calendar.SECOND, 59);
userEndTime.add(Calendar.DATE, rel.getHighDiscount().getEffectiveDay()); userEndTime.add(Calendar.DATE, rel.getHighDiscount().getEffectiveDay());
if (userEndTime.getTime().compareTo(rel.getHighDiscount().getSalesEndTime()) == 1) { if (userEndTime.getTime().compareTo(rel.getHighDiscount().getSalesEndTime()) == 1) {
userRel.setUseEndTime(rel.getHighDiscount().getSalesEndTime()); userRel.setUseEndTime(rel.getHighDiscount().getSalesEndTime());
} else { } else {

@ -167,7 +167,12 @@ public class HighOrderServiceImpl implements HighOrderService {
// 计算使用有效期 // 计算使用有效期
Calendar userEndTime = Calendar.getInstance(); Calendar userEndTime = Calendar.getInstance();
userEndTime.setTime(new Date());
userEndTime.set(Calendar.HOUR_OF_DAY, 23);
userEndTime.set(Calendar.MINUTE, 59);
userEndTime.set(Calendar.SECOND, 59);
userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); userEndTime.add(Calendar.DATE, coupon.getRecycleDay());
if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) {
highUserCoupon.setUseEndTime(code.getUseEndTime()); highUserCoupon.setUseEndTime(code.getUseEndTime());
} else { } else {
@ -351,6 +356,13 @@ public class HighOrderServiceImpl implements HighOrderService {
} }
highChildOrder.setChildOrdeStatus(5); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 highChildOrder.setChildOrdeStatus(5); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
} }
if (order.getMemDiscountId() != null) {
HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId());
rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
rel.setUseTime(new Date());
highDiscountUserRelService.updateDiscountUserRel(rel);
}
updateOrder(order); updateOrder(order);
} }
} }

@ -81,6 +81,10 @@ public class GoodsOrderServiceImpl implements PayService {
// 计算使用有效期 // 计算使用有效期
Calendar userEndTime = Calendar.getInstance(); Calendar userEndTime = Calendar.getInstance();
userEndTime.setTime(new Date());
userEndTime.set(Calendar.HOUR_OF_DAY, 23);
userEndTime.set(Calendar.MINUTE, 59);
userEndTime.set(Calendar.SECOND, 59);
userEndTime.add(Calendar.DATE, coupon.getRecycleDay()); userEndTime.add(Calendar.DATE, coupon.getRecycleDay());
if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) { if (userEndTime.getTime().compareTo(code.getUseEndTime()) == 1) {
highUserCoupon.setUseEndTime(code.getUseEndTime()); highUserCoupon.setUseEndTime(code.getUseEndTime());

Loading…
Cancel
Save