'提交代码'

dev-discount
199901012 4 years ago
parent 2aae301d8d
commit c9d783f815
  1. 28
      hai-cweb/src/main/java/com/cweb/controller/HighDiscountController.java
  2. 8
      hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java
  3. 12
      hai-schedule/src/main/java/com/hai/schedule/HighDiscountSchedule.java
  4. 12
      hai-service/src/main/java/com/hai/model/HighDiscountAgentRelModel.java
  5. 7
      hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java
  6. 2
      hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java
  7. 5
      hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java
  8. 2
      hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentRelServiceImpl.java
  9. 29
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java

@ -1,12 +1,17 @@
package com.cweb.controller; package com.cweb.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.Base64Util; import com.hai.common.Base64Util;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil; import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighDiscountAgentRel;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.service.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountAgentRelService; import com.hai.service.HighDiscountAgentRelService;
import com.hai.service.HighDiscountCouponRelService; import com.hai.service.HighDiscountCouponRelService;
import com.hai.service.HighDiscountService; import com.hai.service.HighDiscountService;
@ -18,6 +23,8 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -37,6 +44,9 @@ public class HighDiscountController {
@Resource @Resource
private HighDiscountCouponRelService highDiscountCouponRelService; private HighDiscountCouponRelService highDiscountCouponRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Resource @Resource
private HighDiscountService highDiscountService; private HighDiscountService highDiscountService;
@ -45,14 +55,26 @@ public class HighDiscountController {
@ApiOperation(value = "根据二维码Code查询") @ApiOperation(value = "根据二维码Code查询")
public ResponseData getDiscountByQrCode(@RequestParam(name = "code", required = true) String code) { public ResponseData getDiscountByQrCode(@RequestParam(name = "code", required = true) String code) {
try { try {
String relId; String jsonData;
try { try {
relId = AESEncodeUtil.aesDecrypt(Base64Util.decode(code)); jsonData = AESEncodeUtil.aesDecrypt(Base64Util.decode(code));
} catch (Exception e) { } catch (Exception e) {
log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误"); log.error("HighDiscountController -> getDiscountByQrCode() error!","code解码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "code解码错误");
} }
return ResponseMsgUtil.success(highDiscountAgentRelService.getRelById(Long.parseLong(relId)));
JSONObject jsonObject = JSON.parseObject(jsonData);
String type = jsonObject.getString("type");
Long id = jsonObject.getLong("id");
HighDiscountAgentCode discountAgentCode = highDiscountAgentCodeService.getCodeById(id);
if (discountAgentCode != null) {
HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(discountAgentCode.getDiscountAgentId());
if (rel == null) {
rel.setHighDiscountAgentCode(discountAgentCode);
}
}
return ResponseMsgUtil.success(null);
} catch (Exception e) { } catch (Exception e) {
log.error("HighDiscountController -> getDiscountByQrCode() error!",e); log.error("HighDiscountController -> getDiscountByQrCode() error!",e);

@ -10,10 +10,12 @@ 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.HighDiscount;
import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighDiscountCouponRel; import com.hai.entity.HighDiscountCouponRel;
import com.hai.entity.HighDiscountUserRel; 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.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountCouponRelService; 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;
@ -64,13 +66,13 @@ public class HighUserDiscountController {
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
JSONObject jsonObject = JSONObject.parseObject(reqBody); JSONObject jsonObject = JSONObject.parseObject(reqBody);
Long discountAgentId = jsonObject.getLong("discountAgentId"); Long codeId = jsonObject.getLong("codeId");
if (discountAgentId == null) { if (codeId == null) {
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(), codeId);
return ResponseMsgUtil.success("领取成功"); return ResponseMsgUtil.success("领取成功");
} catch (Exception e) { } catch (Exception e) {

@ -1,7 +1,9 @@
package com.hai.schedule; package com.hai.schedule;
import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighDiscountUserRel; import com.hai.entity.HighDiscountUserRel;
import com.hai.entity.HighOrder; import com.hai.entity.HighOrder;
import com.hai.service.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountUserRelService; import com.hai.service.HighDiscountUserRelService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,6 +26,9 @@ public class HighDiscountSchedule {
@Resource @Resource
private HighDiscountUserRelService highDiscountUserRelService; private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 处理过期的优惠券 * @Description 处理过期的优惠券
@ -36,6 +41,13 @@ public class HighDiscountSchedule {
try { try {
rel.setStatus(0); rel.setStatus(0);
highDiscountUserRelService.updateDiscountUserRel(rel); highDiscountUserRelService.updateDiscountUserRel(rel);
// 二维码
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId());
if (code != null) {
code.setStatus(4); // 状态 0:删除 1:待领取 2:待使用 3:已使用 4:已过期
highDiscountAgentCodeService.updateCode(code);
}
} catch (Exception e) { } catch (Exception e) {
log.error("HighCouponSchedule --> expiredCoupon() error!", e); log.error("HighCouponSchedule --> expiredCoupon() error!", e);
} }

@ -2,6 +2,7 @@ package com.hai.model;
import com.hai.entity.HighAgent; import com.hai.entity.HighAgent;
import com.hai.entity.HighDiscount; import com.hai.entity.HighDiscount;
import com.hai.entity.HighDiscountAgentCode;
/** /**
* @Auther: 胡锐 * @Auther: 胡锐
@ -13,6 +14,9 @@ public class HighDiscountAgentRelModel {
// 优惠券信息 // 优惠券信息
private HighDiscount highDiscount; private HighDiscount highDiscount;
// 优惠券二维码
private HighDiscountAgentCode highDiscountAgentCode;
// 代理商信息 // 代理商信息
private HighAgent highAgent; private HighAgent highAgent;
@ -24,6 +28,14 @@ public class HighDiscountAgentRelModel {
this.highDiscount = highDiscount; this.highDiscount = highDiscount;
} }
public HighDiscountAgentCode getHighDiscountAgentCode() {
return highDiscountAgentCode;
}
public void setHighDiscountAgentCode(HighDiscountAgentCode highDiscountAgentCode) {
this.highDiscountAgentCode = highDiscountAgentCode;
}
public HighAgent getHighAgent() { public HighAgent getHighAgent() {
return highAgent; return highAgent;
} }

@ -31,4 +31,11 @@ public interface HighDiscountAgentCodeService {
* @Date 2021/4/14 22:32 * @Date 2021/4/14 22:32
**/ **/
void updateCode(HighDiscountAgentCode highDiscountAgentCode); void updateCode(HighDiscountAgentCode highDiscountAgentCode);
/**
* @Author 胡锐
* @Description 根据id 查询二维码
* @Date 2021/4/14 23:38
**/
HighDiscountAgentCode getCodeById(Long id);
} }

@ -18,7 +18,7 @@ public interface HighDiscountUserRelService {
* @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 codeId);
/** /**
* @Author 胡锐 * @Author 胡锐

@ -33,4 +33,9 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe
public void updateCode(HighDiscountAgentCode highDiscountAgentCode) { public void updateCode(HighDiscountAgentCode highDiscountAgentCode) {
highDiscountAgentCodeMapper.updateByPrimaryKey(highDiscountAgentCode); highDiscountAgentCodeMapper.updateByPrimaryKey(highDiscountAgentCode);
} }
@Override
public HighDiscountAgentCode getCodeById(Long id) {
return highDiscountAgentCodeMapper.selectByPrimaryKey(id);
}
} }

@ -58,7 +58,7 @@ public class HighDiscountAgentRelServiceImpl implements HighDiscountAgentRelServ
code.setCreateTime(new Date()); code.setCreateTime(new Date());
highDiscountAgentCodeService.insertCode(code); highDiscountAgentCodeService.insertCode(code);
// 二维码参数 // 二维码参数
map.put("id", highDiscountAgentRel.getId()); map.put("id", code.getId());
// 生成二维码 // 生成二维码
String param = "https://hsgcs.dctpay.com/wx/?action=gogogo&id=" + Base64Util.encode(AESEncodeUtil.aesEncrypt(JSON.toJSONString(map))); 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, qrCodeUrl);

@ -4,14 +4,8 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.dao.HighDiscountUserRelMapper; import com.hai.dao.HighDiscountUserRelMapper;
import com.hai.entity.HighDiscount; import com.hai.entity.*;
import com.hai.entity.HighDiscountAgentRel; import com.hai.service.*;
import com.hai.entity.HighDiscountUserRel;
import com.hai.entity.HighDiscountUserRelExample;
import com.hai.service.HighAgentService;
import com.hai.service.HighDiscountAgentRelService;
import com.hai.service.HighDiscountService;
import com.hai.service.HighDiscountUserRelService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
@ -43,12 +37,26 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
@Resource @Resource
private HighDiscountService highDiscountService; private HighDiscountService highDiscountService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Override @Override
@Transactional(propagation= Propagation.REQUIRES_NEW) @Transactional(propagation= Propagation.REQUIRES_NEW)
public void receiveDiscount(Long userId, Long discountAgentId) { public void receiveDiscount(Long userId, Long codeId) {
// 查询优惠券二维码
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(codeId);
if(code == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在");
}
// 状态 0:删除 1:待领取 2:待使用 3:已使用 4:已过期
if(code.getStatus() != 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在或已被领取");
}
// 查询优惠券信息 // 查询优惠券信息
HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(discountAgentId); HighDiscountAgentRel rel = highDiscountAgentRelService.getRelById(code.getDiscountAgentId());
if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){ if (rel == null || rel.getHighDiscount() == null || rel.getAgentId() == null){
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_DISCOUNT, "");
} }
@ -76,6 +84,7 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
userRel.setUserId(userId); userRel.setUserId(userId);
userRel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 userRel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
userRel.setCreateTime(new Date()); userRel.setCreateTime(new Date());
userRel.setDiscountAgentCodeId(code.getId());
// 计算使用有效期 // 计算使用有效期
Calendar userEndTime = Calendar.getInstance(); Calendar userEndTime = Calendar.getInstance();
userEndTime.setTime(new Date()); userEndTime.setTime(new Date());

Loading…
Cancel
Save