'完成优惠券改造、修复已知问题'

dev-discount
199901012 4 years ago
parent c9d783f815
commit cf47a6607c
  1. 5
      hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java
  2. 4
      hai-cweb/src/main/java/com/cweb/controller/HighCouponController.java
  3. 5
      hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java
  4. 4
      hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java
  5. 12
      hai-service/src/main/java/com/hai/common/QRCodeGenerator.java
  6. 7
      hai-service/src/main/java/com/hai/service/HighOrderService.java
  7. 10
      hai-service/src/main/java/com/hai/service/impl/HighCouponCodeServiceImpl.java
  8. 9
      hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java
  9. 12
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java
  10. 22
      hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java
  11. 11
      hai-service/src/main/java/com/hai/service/impl/HighUserCouponServiceImpl.java

@ -99,11 +99,12 @@ public class HighDiscountAgentRelController {
log.error("HighDiscountAgentRelController -> insertDiscountAgent() error!", discount.getDiscountName() + "重复分配给" + agent.getAgentName());
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, discount.getDiscountName() + "重复分配给" + agent.getAgentName());
}
highDiscountAgentRel.setCreateTime(new Date());
highDiscountAgentRel.setStatus(1);
highDiscountAgentRelService.insertDiscountAgentRel(highDiscountAgentRel);
// 生成二维码
/* // 生成二维码
String qrCodeImg = DateUtil.date2String(new Date(),agent.getId() + discount.getId() + "yyyyMMddHHmmss") + IDGenerator.nextId(2) +".png";
String qrCodeUrl = SysConst.getSysConfig().getAgentQrCode() + "/" + qrCodeImg;
@ -111,7 +112,7 @@ public class HighDiscountAgentRelController {
String url = SysConst.getSysConfig().getAgentQrCodeWxUrl() + highDiscountAgentRel.getId();
QRCodeGenerator.generateQRCodeImage(url, 350, 350, qrCodeUrl);
highDiscountAgentRel.setQrCode(qrCodeImg);
highDiscountAgentRelService.updateDiscountAgentRel(highDiscountAgentRel);
highDiscountAgentRelService.updateDiscountAgentRel(highDiscountAgentRel);*/
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {

@ -158,7 +158,7 @@ public class HighCouponController {
}
Map<String, Object> map = new HashMap<>();
map.put("highUserCoupon", "coupon");
map.put("highUserCoupon", coupon);
map.put("couponInfo", highCouponService.getCouponById(coupon.getCouponId()));
map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(coupon.getCouponCodeId()));
@ -186,7 +186,7 @@ public class HighCouponController {
HighUserCoupon userCoupon = highUserCouponService.againReceiveCoupon(userInfoModel.getHighUser().getId(), couponId);
Map<String, Object> map = new HashMap<>();
map.put("highUserCoupon", "coupon");
map.put("highUserCoupon", userCoupon);
map.put("couponInfo", highCouponService.getCouponById(userCoupon.getCouponId()));
map.put("couponCodeInfo", highCouponCodeService.getCouponCodeById(userCoupon.getCouponCodeId()));
return ResponseMsgUtil.success(map);

@ -32,7 +32,7 @@ import java.util.Map;
* @Date: 2021/4/4 14:46
*/
@Controller
@RequestMapping(value = "/discount")
@RequestMapping(value = "/discount")
@Api(value = "优惠券接口")
public class HighDiscountController {
@ -70,8 +70,9 @@ public class HighDiscountController {
HighDiscountAgentCode discountAgentCode = highDiscountAgentCodeService.getCodeById(id);
if (discountAgentCode != null) {
HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(discountAgentCode.getDiscountAgentId());
if (rel == null) {
if (rel != null) {
rel.setHighDiscountAgentCode(discountAgentCode);
return ResponseMsgUtil.success(rel);
}
}
return ResponseMsgUtil.success(null);

@ -34,7 +34,8 @@ public class HighDiscountSchedule {
* @Description 处理过期的优惠券
* @Date 2021/4/4 22:44
**/
@Scheduled(cron = "5 0 0 * * ?") //每日凌晨12点5秒执行一次
//@Scheduled(cron = "5 0 0 * * ?") //每日凌晨12点5秒执行一次
@Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次
public void expiredDiscount() {
List<HighDiscountUserRel> expiredDiscount = highDiscountUserRelService.getExpiredDiscount();
for (HighDiscountUserRel rel : expiredDiscount) {
@ -52,7 +53,6 @@ public class HighDiscountSchedule {
log.error("HighCouponSchedule --> expiredCoupon() error!", e);
}
}
}
}

@ -6,6 +6,7 @@ import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
@ -22,15 +23,18 @@ public class QRCodeGenerator {
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
Path path = FileSystems.getDefault().getPath(filePath);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
File file = new File(filePath);
if(!file.exists()){
file.mkdirs();
}
//Path path = FileSystems.getDefault().getPath(filePath);
MatrixToImageWriter.writeToFile(bitMatrix, "PNG", file);
}
public static void main(String[] args) {
try {
generateQRCodeImage("This is my first QR Code", 350, 350, "D:\\qr.png");
generateQRCodeImage("This is my first QR Code", 350, 350, "D:\\/ss/qr1.png");
} catch (WriterException e) {
System.out.println("Could not generate QR Code, WriterException :: " + e.getMessage());
} catch (IOException e) {

@ -49,6 +49,13 @@ public interface HighOrderService {
**/
HighChildOrder getChildOrderById(Long childOrderId);
/**
* @Author 胡锐
* @Description 根据用户和商品id 查询
* @Date 2021/4/15 21:38
**/
HighChildOrder getChildOrderByUserGoods(Long userId,Integer goodsType,Long goodsId);
/**
* 根据订单id 查询子商品
* @param orderId

@ -98,7 +98,7 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
}
// 卡券来源:1.中石化
if (coupon.getCouponSource() == 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "此卡券无法消核");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "中石化卡券无法消核,请前往中石化门店");
}
salesCode.setStoreId(userInfoModel.getMerchantStore().getId());
salesCode.setConsumeTime(new Date());
@ -110,12 +110,16 @@ public class HighCouponCodeServiceImpl implements HighCouponCodeService {
if (userCoupon == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡卷状态异常");
}
HighChildOrder order = highOrderService.getChildOrderByUserGoods(userCoupon.getUserId(), 1, userCoupon.getCouponCodeId());
if (order == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单");
}
userCoupon.setStoreId(userInfoModel.getMerchantStore().getId());
userCoupon.setConsumeTime(new Date());
userCoupon.setStatus(2); // 状态 0:已过期 1:未使用 2:已使用
highUserCouponService.updateUserCoupon(userCoupon);
highOrderService.childOrderComplete(salesCode.getChildOrderId());
highOrderService.childOrderComplete(order.getId());
}
@Override

@ -49,9 +49,10 @@ public class HighDiscountAgentRelServiceImpl implements HighDiscountAgentRelServ
map.put("type", "DISCOUNT");
HighDiscountAgentCode code;
String path = "/home/project/hsg/filesystem/agentQrCode/";
String folder = highDiscountAgentRel.getAgentId() + "/" + highDiscountAgentRel.getDiscountId() + "/";
for (int i = 0;i < highDiscountAgentRel.getStockCount();i++) {
String qrCodeImg = DateUtil.date2String(new Date(),highDiscountAgentRel.getId()+"yyyyMMddHHmmss") + IDGenerator.nextId(10) +".png";
String qrCodeUrl = "/home/project/hsg/filesystem/agentQrCode/" + qrCodeImg;
code = new HighDiscountAgentCode();
code.setDiscountAgentId(highDiscountAgentRel.getId());
code.setStatus(1);
@ -59,9 +60,11 @@ public class HighDiscountAgentRelServiceImpl implements HighDiscountAgentRelServ
highDiscountAgentCodeService.insertCode(code);
// 二维码参数
map.put("id", code.getId());
String qrCodeImg = DateUtil.date2String(new Date(),highDiscountAgentRel.getId()+"yyyyMMddHHmmss") + IDGenerator.nextId(10) +".png";
// 生成二维码
String param = "https://hsgcs.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map)));
QRCodeGenerator.generateQRCodeImage(param, 350, 350, qrCodeUrl);
QRCodeGenerator.generateQRCodeImage(param, 350, 350, path + folder + qrCodeImg);
code.setQrCode(qrCodeImg);
highDiscountAgentCodeService.updateCode(code);
}

@ -8,6 +8,8 @@ import com.hai.entity.*;
import com.hai.service.*;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@ -41,7 +43,7 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE)
public void receiveDiscount(Long userId, Long codeId) {
// 查询优惠券二维码
@ -54,6 +56,8 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
if(code.getStatus() != 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在或已被领取");
}
code.setStatus(2);
highDiscountAgentCodeService.updateCode(code);
// 查询优惠券信息
HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(code.getDiscountAgentId());
@ -65,9 +69,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
// 校验卡卷状态
if (rel.getHighDiscount().getStatus() != 2) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "卡券已下架");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券已过期");
}
if (rel.getStockCount() <= 0) {
/* if (rel.getStockCount() <= 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.DISCOUNT_STOCK_COUNT_ERROR, "");
}
@ -76,7 +80,7 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
example.createCriteria().andUserIdEqualTo(userId).andDiscountIdEqualTo(rel.getDiscountId()).andStatusEqualTo(1);
if (highDiscountUserRelMapper.selectByExample(example).size() > 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复领取卡券,请使用后再进行领取");
}
}*/
HighDiscountUserRel userRel = new HighDiscountUserRel();
userRel.setDiscountId(rel.getDiscountId());

@ -60,6 +60,9 @@ public class HighOrderServiceImpl implements HighOrderService {
@Resource
private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public void insertOrder(HighOrder highOrder) throws Exception {
@ -71,6 +74,10 @@ public class HighOrderServiceImpl implements HighOrderService {
discountUserRel.setUseTime(new Date()); // 使用时间
discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用
highDiscountUserRelService.updateDiscountUserRel(discountUserRel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId());
code.setStatus(3);
highDiscountAgentCodeService.updateCode(code);
}
for (int i = 0; i < highOrder.getHighChildOrderList().size();i++) {
@ -214,6 +221,17 @@ public class HighOrderServiceImpl implements HighOrderService {
return highChildOrderMapper.selectByPrimaryKey(childOrderId);
}
@Override
public HighChildOrder getChildOrderByUserGoods(Long userId, Integer goodsType, Long goodsId) {
HighChildOrderExample example = new HighChildOrderExample();
example.createCriteria().andMemIdEqualTo(userId).andGoodsTypeEqualTo(goodsType).andGoodsIdEqualTo(goodsId);
List<HighChildOrder> list = highChildOrderMapper.selectByExample(example);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
@Override
public List<HighChildOrder> getChildOrderByOrder(Long orderId) {
HighChildOrderExample example = new HighChildOrderExample();
@ -372,6 +390,10 @@ public class HighOrderServiceImpl implements HighOrderService {
rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
rel.setUseTime(null);
highDiscountUserRelService.updateDiscountUserRel(rel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId());
code.setStatus(4);
highDiscountAgentCodeService.updateCode(code);
}
}
updateOrder(order);

@ -102,7 +102,7 @@ public class HighUserCouponServiceImpl implements HighUserCouponService {
@Override
public HighUserCoupon getUserCoupon(Long userId, Long couponId) {
HighUserCouponExample example = new HighUserCouponExample();
example.createCriteria().andUserIdEqualTo(userId).andCouponIdEqualTo(couponId);
example.createCriteria().andUserIdEqualTo(userId).andCouponIdEqualTo(couponId).andStatusNotEqualTo(100);
List<HighUserCoupon> coupons = highUserCouponMapper.selectByExample(example);
if (coupons != null && coupons.size() > 0) {
return coupons.get(0);
@ -133,20 +133,22 @@ public class HighUserCouponServiceImpl implements HighUserCouponService {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法重新领取");
}
userCoupon.setStatus(100); // 删除
highUserCouponMapper.updateByPrimaryKey(userCoupon);
HighCoupon coupon = highCouponService.getCouponById(userCoupon.getCouponId());
if (coupon == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到卡卷");
}
// 查询待销售
List<HighCouponCode> list = highCouponCodeService.getNoSaleCode(coupon.getId());
if (list == null || list.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, coupon.getCouponName() + "暂无库存,请联系客服");
}
HighCouponCode highCouponCode = list.get(0);
highCouponCode.setChildOrderId(userCoupon.getId());
//highCouponCode.setChildOrderId(userCoupon.getId());
highCouponCode.setStatus(2); // 状态:1.待销售 2.未使用 3.已使用 99.预支付
highCouponCode.setReceiveTime(new Date());
highCouponCodeService.updateCouponCode(highCouponCode);
// 卡卷关联用户
@ -166,6 +168,7 @@ public class HighUserCouponServiceImpl implements HighUserCouponService {
highUserCoupon.setUseEndTime(userEndTime.getTime());
}
highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
highUserCoupon.setQrCodeImg(highCouponCode.getExt1());
highUserCouponMapper.insert(highUserCoupon);
return highUserCoupon;
@ -187,7 +190,7 @@ public class HighUserCouponServiceImpl implements HighUserCouponService {
// 查询卡券信息
HighCoupon coupon = highCouponService.getCouponById(highUserCoupon.getCouponId());
HighChildOrder childOrder = highOrderService.getChildOrderById(couponCode.getChildOrderId());
HighChildOrder childOrder = highOrderService.getChildOrderByUserGoods(highUserCoupon.getUserId(),1, highUserCoupon.getCouponCodeId());
HighOrder order = highOrderService.getOrderById(childOrder.getOrderId());
// 归库记录

Loading…
Cancel
Save