Merge remote-tracking branch 'origin/2.0-dev' into 2.0-dev

new-dev
袁野 2 years ago
commit 55ed59f511
  1. 6
      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
public void onMessage(HighOrder order) {
try {
Thread.sleep(1000*10); // 休眠 10 秒钟
HighOrder highOrder = orderService.getOrderDetailByNo(order.getOrderNo());
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);
/**
* 惠支付用户优惠券使用
* @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
@Transactional(propagation= Propagation.REQUIRES_NEW)
public String giveAway(Long packageId, List<String> phoneList) throws Exception {
UserInfoModel userInfoModel = userCenter.getSessionModel(UserInfoModel.class);
@ -385,22 +384,17 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
discountPackageDeliver.setOpUserName(userInfoModel.getSecUser().getUserName());
discountPackageDeliverService.insertDeliver(discountPackageDeliver);
// 查询出来系统中的用户
Map<String, String> userMap = new HashMap<>();
userMap.put("status", "1");
List<HighUser> listUser = highUserService.getListUser(userMap);
new Thread(() -> {
int alreadyProcessedNum = 0;
for (String phone : phoneList) {
try {
// 根据手机号查询用户
List<HighUser> userList = listUser.stream().filter(p -> p.getPhone().equals(phone)).collect(Collectors.toList());
if (userList.size() > 0) {
HighUser highUser = highUserService.findByPhone(phone);
if (highUser != null) {
Map<String, Object> freeMap = new HashMap<>();
freeMap.put("discountPackageId", packageId);
freeMap.put("userId", userList.get(0).getId());
freeMap.put("userPhone", userList.get(0).getPhone());
freeMap.put("userId", highUser.getId());
freeMap.put("userPhone", highUser.getPhone());
HighDiscountPackageActual packageActual = freeUserDiscountPackage(freeMap);
HighDiscountPackageDeliverUser deliverUser = new HighDiscountPackageDeliverUser();
@ -409,8 +403,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(userList.get(0).getId());
deliverUser.setUserPhone(userList.get(0).getPhone());
deliverUser.setUserId(highUser.getId());
deliverUser.setUserPhone(highUser.getPhone());
deliverUser.setStatus(2);
deliverUser.setOpUserId(userInfoModel.getSecUser().getId());
deliverUser.setOpUserName(userInfoModel.getSecUser().getUserName());
@ -439,8 +433,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
deliverUser.setPackageId(packageId);
deliverUser.setPackageName(discountPackage.getTitle());
deliverUser.setPackageActualId(packageActual.getId().longValue());
deliverUser.setUserId(userList.get(0).getId());
deliverUser.setUserPhone(userList.get(0).getPhone());
deliverUser.setUserId(highUser.getId());
deliverUser.setUserPhone(highUser.getPhone());
deliverUser.setStatus(2);
discountPackageDeliverService.insertDeliverUser(deliverUser);
}
@ -455,6 +449,7 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic
discountPackageDeliverService.updateDeliver(discountPackageDeliver);
redisUtil.del(serialNum);
}).start();
return serialNum;
}
}

@ -38,6 +38,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
@Resource
private HighAgentService highAgentService;
@Resource
private HighUserService userService;
@Resource
private HighDiscountService highDiscountService;
@ -293,4 +296,54 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
public Integer receiveDiscountCount(Long userId, Long 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.ResponseMsgUtil;
import com.hai.config.CommonSysConst;
import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighDiscountUserRel;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
@ -25,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -41,6 +43,7 @@ public class DiscountController {
@Resource
private HighDiscountUserRelService discountUserRelService;
@RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET)
@ResponseBody
@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)
@ResponseBody
@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)
@ResponseBody
@ApiOperation(value = "查询【惠支付】优惠列表")

Loading…
Cancel
Save