提交代码

new-dev
胡锐 2 years ago
parent 1fdfac517f
commit 9e79be27a5
  1. 14
      hai-order/src/main/java/com/web/rocketmq/consumer/OrderCancelConsumer.java
  2. 14
      hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java
  3. 23
      hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java
  4. 53
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java
  5. 91
      hai-user/src/main/java/com/web/controller/DiscountController.java

@ -20,10 +20,16 @@ public class OrderCancelConsumer implements RocketMQListener<HighOrder> {
@Override @Override
public void onMessage(HighOrder order) { public void onMessage(HighOrder order) {
HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo()); try {
if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) { Thread.sleep(1000*10); // 休眠 10 秒钟
// 取消订单 HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo());
orderService.cancelOrder(highOrder, null); if (highOrder != null && highOrder.getOrderStatus().equals(OrderStatus.STATUS1.getNumber())) {
// 取消订单
orderService.cancelOrder(highOrder, null);
}
} catch (InterruptedException e) {
System.out.println(e);
throw new RuntimeException(e);
} }
} }
} }

@ -84,4 +84,18 @@ public interface HighDiscountUserRelService {
*/ */
Integer receiveDiscountCount(Long userId,Long discountId); Integer receiveDiscountCount(Long userId,Long discountId);
/**
* 惠支付用户优惠券使用
* @param userDiscountId
* @param phone
*/
void hzfUserDiscountUse(Long userDiscountId,String phone);
/**
* 惠支付用户优惠券退回
* @param userDiscountId
* @param phone
*/
void hzfUserDiscountReturn(Long userDiscountId,String phone);
} }

@ -356,7 +356,6 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
} }
@Override @Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public String giveAway(Long packageId, List<String> phoneList) throws Exception { public String giveAway(Long packageId, List<String> phoneList) throws Exception {
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class); UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class);
@ -385,22 +384,17 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
discountPackageDeliver.setOpUserName(userInfoModel.getSecUser().getUserName()); discountPackageDeliver.setOpUserName(userInfoModel.getSecUser().getUserName());
discountPackageDeliverService.insertDeliver(discountPackageDeliver); discountPackageDeliverService.insertDeliver(discountPackageDeliver);
// 查询出来系统中的用户
Map<String, String> userMap = new HashMap<>();
userMap.put("status", "1");
List<HighUser> listUser = highUserService.getListUser(userMap);
new Thread(() -> { new Thread(() -> {
int alreadyProcessedNum = 0; int alreadyProcessedNum = 0;
for (String phone : phoneList) { for (String phone : phoneList) {
try { try {
// 根据手机号查询用户 // 根据手机号查询用户
List<HighUser> userList = listUser.stream().filter(p -> p.getPhone().equals(phone)).collect(Collectors.toList()); HighUser highUser = highUserService.findByPhone(phone);
if (userList.size() > 0) { if (highUser != null) {
Map<String, Object> freeMap = new HashMap<>(); Map<String, Object> freeMap = new HashMap<>();
freeMap.put("discountPackageId", packageId); freeMap.put("discountPackageId", packageId);
freeMap.put("userId", userList.get(0).getId()); freeMap.put("userId", highUser.getId());
freeMap.put("userPhone", userList.get(0).getPhone()); freeMap.put("userPhone", highUser.getPhone());
HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap); HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap);
HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser(); HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser();
@ -409,8 +403,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
deliverUser.setPackageId(packageId); deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle()); deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue()); deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(userList.get(0).getId()); deliverUser.setUserId(highUser.getId());
deliverUser.setUserPhone(userList.get(0).getPhone()); deliverUser.setUserPhone(highUser.getPhone());
deliverUser.setStatus(2); deliverUser.setStatus(2);
deliverUser.setOpUserId(userInfoModel.getSecUser().getId()); deliverUser.setOpUserId(userInfoModel.getSecUser().getId());
deliverUser.setOpUserName(userInfoModel.getSecUser().getUserName()); deliverUser.setOpUserName(userInfoModel.getSecUser().getUserName());
@ -439,8 +433,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
deliverUser.setPackageId(packageId); deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle()); deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue()); deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(userList.get(0).getId()); deliverUser.setUserId(highUser.getId());
deliverUser.setUserPhone(userList.get(0).getPhone()); deliverUser.setUserPhone(highUser.getPhone());
deliverUser.setStatus(2); deliverUser.setStatus(2);
discountPackageDeliverService.insertDeliverUser(deliverUser); discountPackageDeliverService.insertDeliverUser(deliverUser);
} }
@ -455,6 +449,7 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
discountPackageDeliverService.updateDeliver(discountPackageDeliver); discountPackageDeliverService.updateDeliver(discountPackageDeliver);
redisUtil.del(serialNum); redisUtil.del(serialNum);
}).start(); }).start();
return serialNum; return serialNum;
} }
} }

@ -38,6 +38,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
@Resource @Resource
private HighAgentService highAgentService; private HighAgentService highAgentService;
@Resource
private HighUserService userService;
@Resource @Resource
private HighDiscountService highDiscountService; private HighDiscountService highDiscountService;
@ -293,4 +296,54 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
public Integer receiveDiscountCount(Long userId, Long discountId) { public Integer receiveDiscountCount(Long userId, Long discountId) {
return highDiscountUserRelMapper.receiveDiscountCount(userId, discountId); return highDiscountUserRelMapper.receiveDiscountCount(userId, discountId);
} }
@Override
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW)
public void hzfUserDiscountUse(Long userDiscountId, String phone) {
HighDiscountUserRel discountUserRel = getRelById(userDiscountId);
if (discountUserRel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券");
}
HighUser user = userService.findByUserId(discountUserRel.getUserId());
if (user == null){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户");
}
if (!user.getPhone().equals(phone)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "拥有人和使用人不一致");
}
discountUserRel.setUseTime(new Date()); // 使用时间
discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用
updateDiscountUserRel(discountUserRel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId());
code.setStatus(3);
highDiscountAgentCodeService.updateCode(code);
}
@Override
@Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW)
public void hzfUserDiscountReturn(Long userDiscountId, String phone) {
HighDiscountUserRel discountUserRel = getRelById(userDiscountId);
if (discountUserRel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券");
}
HighUser user = userService.findByUserId(discountUserRel.getUserId());
if (user == null){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的用户");
}
if (!user.getPhone().equals(phone)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "拥有人和使用人不一致");
}
discountUserRel.setUseTime(null); // 使用时间
discountUserRel.setStatus(1); //状态 0:已过期 1:未使用 2:已使用
updateDiscountUserRel(discountUserRel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId());
code.setStatus(1);
highDiscountAgentCodeService.updateCode(code);
}
} }

@ -10,6 +10,7 @@ import com.hai.common.security.UserCenter;
import com.hai.common.utils.HttpsUtils; import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.CommonSysConst; import com.hai.config.CommonSysConst;
import com.hai.entity.HighDiscountAgentCode;
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;
@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -41,6 +43,7 @@ public class DiscountController {
@Resource @Resource
private HighDiscountUserRelService discountUserRelService; private HighDiscountUserRelService discountUserRelService;
@RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET) @RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询用户优惠券列表") @ApiOperation(value = "查询用户优惠券列表")
@ -104,60 +107,6 @@ public class DiscountController {
} }
} }
@RequestMapping(value="/useUserDiscount",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "使用优惠券")
public ResponseData useUserDiscount(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId) {
try {
HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class);
if (userInfoModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
}
HighDiscountUserRel rel = discountUserRelService.getRelById(userDiscountId);
if (rel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券");
}
return ResponseMsgUtil.success(rel);
} catch (Exception e) {
log.error("HighDiscountController -> getUserDiscountDetail() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/cancelUserDiscount",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "取消使用优惠券")
public ResponseData cancelUserDiscount(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId) {
try {
HighUserModel userInfoModel = userCenter.getSessionModel(HighUserModel.class);
if (userInfoModel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SEC_USER_EXPIRED, "");
}
HighDiscountUserRel rel = discountUserRelService.getRelById(userDiscountId);
if (rel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券");
}
JSONObject param = new JSONObject();
param.put("id", rel.getId());
param.put("userId", rel.getUserId());
param.put("discountId", rel.getDiscountId());
param.put("discountName", rel.getDiscountName());
param.put("discountType", rel.getDiscountType());
param.put("discountCondition", rel.getDiscountCondition());
param.put("discountPrice", rel.getDiscountPrice());
param.put("receiveTime", rel.getCreateTime());
param.put("status", rel.getStatus());
return ResponseMsgUtil.success(param);
} catch (Exception e) {
log.error("HighDiscountController -> getUserDiscountDetail() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/queryUserDiscountList",method = RequestMethod.GET) @RequestMapping(value="/queryUserDiscountList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询用户优惠券列表") @ApiOperation(value = "查询用户优惠券列表")
@ -192,6 +141,40 @@ public class DiscountController {
} }
} }
@RequestMapping(value="/hzfUserDiscountUse",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "【惠支付】优惠券使用")
public ResponseData hzfUserDiscountUse(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId,
@RequestParam(name = "userPhone", required = true) String userPhone) {
try {
discountUserRelService.hzfUserDiscountUse(userDiscountId, userPhone);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("HighDiscountController -> getUserDiscountDetail() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/hzfUserDiscountReturn",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "【惠支付】优惠券退款")
public ResponseData hzfUserDiscountReturn(@RequestParam(name = "userDiscountId", required = true) Long userDiscountId,
@RequestParam(name = "userPhone", required = true) String userPhone) {
try {
discountUserRelService.hzfUserDiscountReturn(userDiscountId, userPhone);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
log.error("HighDiscountController -> getUserDiscountDetail() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/queryHzfDiscountList",method = RequestMethod.GET) @RequestMapping(value="/queryHzfDiscountList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询【惠支付】优惠列表") @ApiOperation(value = "查询【惠支付】优惠列表")

Loading…
Cancel
Save