diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java index c038e633..d40a3d8f 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/controller/admin/CustomerActiveController.java @@ -43,7 +43,37 @@ public class CustomerActiveController { @PostMapping("/attendActive") @Operation(summary = "参加活动") public CommonResult attendActive(@RequestBody CustomerActiveSaveReqVO createReqVO) { - customerActiveService.attendActive(createReqVO); + customerActiveService.attendActiveOrder(createReqVO); + return success(true); + } + + /** + * 新版参加活动 + * + * @param createReqVO CustomerActiveSaveReqVO + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + * @author PQZ + * @date 9:49 2024/9/21 + **/ + @PostMapping("/attendActiveOrder") + @Operation(summary = "参加活动") + public CommonResult attendActiveOrder(@RequestBody CustomerActiveSaveReqVO createReqVO) { + customerActiveService.attendActiveOrder(createReqVO); + return success(true); + } + + /** + * 充值 + * + * @param createReqVO CustomerActiveSaveReqVO实体 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult + * @author PQZ + * @date 16:34 2024/9/28 + **/ + @PostMapping("/recharge") + @Operation(summary = "充值") + public CommonResult recharge(@RequestBody CustomerActiveSaveReqVO createReqVO) { + customerActiveService.recharge(createReqVO); return success(true); } @@ -73,11 +103,10 @@ public class CustomerActiveController { /** - * + * @param pageReqVO ActiveMainPageReqVO实体 + * @return cn.iocoder.yudao.framework.common.pojo.CommonResult> * @author PQZ * @date 16:12 2024/9/23 - * @param pageReqVO ActiveMainPageReqVO实体 - * @return cn.iocoder.yudao.framework.common.pojo.CommonResult> **/ @GetMapping("/list") @Operation(summary = "可参与营销活动") diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java index 84e58074..17566477 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CustomerActiveService.java @@ -31,12 +31,23 @@ public interface CustomerActiveService extends IService { /** - * 用户参与活动 + * 新版参与活动方法 * @author PQZ - * @date 10:18 2024/9/27 - * @param saveReqVO CustomerActiveSaveReqVO实体 + * @date 11:38 2024/9/28 + * @param saveReqVO CustomerActiveSaveReqVO + * @return cn.iocoder.yudao.module.order.entity.RepairOrderInfo **/ - void cusAttendActive(CustomerActiveSaveReqVO saveReqVO); + RepairOrderInfo attendActiveOrder(CustomerActiveSaveReqVO saveReqVO); + + + /** + * 充值 + * @author PQZ + * @date 16:25 2024/9/28 + * @param saveReqVO CustomerActiveSaveReqVO 实体 + * @return cn.iocoder.yudao.module.order.entity.RepairOrderInfo + **/ + RepairOrderInfo recharge(CustomerActiveSaveReqVO saveReqVO); /** diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java index 04106b2a..e99c8f26 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CustomerActiveServiceImpl.java @@ -66,9 +66,8 @@ public class CustomerActiveServiceImpl extends ServiceImpl couponList = active.getCouponList(); //转换卡券信息 @@ -115,7 +114,7 @@ public class CustomerActiveServiceImpl extends ServiceImpl ids = saveReqVO.getSelectCoupon().stream().map(MemberCoupon::getId).collect(Collectors.toList()); //查询选中卡片信息 List couponList = couponService.listByIds(ids, false); - if (CollectionUtil.isNotEmpty(couponList)){ + if (CollectionUtil.isNotEmpty(couponList)) { MemberCoupon item = couponList.get(0); RepairOrderInfo orderInfo = new RepairOrderInfo(); orderInfo.setOrderNo(System.currentTimeMillis() + Math.abs(item.getId().hashCode() % 1000) + ""); @@ -143,11 +142,11 @@ public class CustomerActiveServiceImpl extends ServiceImpl changeList = new ArrayList<>(); + //需要保存的参与活动日志 + CustomerActive customerActive = new CustomerActive(); + //需保保存的用户卡券领取内容 + List customerCouponList = null; + //需保保存的用户积分余额信息 + CustomerBalance balance; + //要返回的订单数据 + RepairOrderInfo resultOrder = null; + /*2、各类型活动处理*/ + if ("zcyl".equals(active.getType())) { + //注册有礼 + List couponList = active.getCouponList(); + //转换卡券信息 + customerCouponList = customerCouponService.transCoupon(active.getId(), customer.getId(), customer.getUserId(), couponList); + //转换日志信息 + changeList = changeService.transChange(customer.getId(), customer.getUserId(), active.getName(), couponList); + } else if ("kkyl".equals(active.getType())) { + //开卡有礼 + if (null == saveReqVO.getSelectCoupon() || saveReqVO.getSelectCoupon().isEmpty()) { + throw exception(CUSTOMER_ACTIVE_ONE_COUPON); + } + //查询出当前选中的卡券及附属卡券 + List ids = saveReqVO.getSelectCoupon().stream().map(MemberCoupon::getId).collect(Collectors.toList()); + //查询选中卡片信息 + List couponList = couponService.listByIds(ids, false); + if (CollectionUtil.isNotEmpty(couponList)) { + //选择的开卡内容设定为单选 + MemberCoupon item = couponList.get(0); + RepairOrderInfo orderInfo = new RepairOrderInfo(); + orderInfo.setOrderNo(System.currentTimeMillis() + Math.abs(item.getId().hashCode() % 1000) + ""); + orderInfo.setGoodsId(item.getId()); + orderInfo.setActiveId(active.getId()); + orderInfo.setGoodsTitle(item.getName()); + orderInfo.setTenantName(ORDER_TENANT_NAME); + orderInfo.setGoodsType(ORDER_KKYL); + orderInfo.setUserId(customer.getUserId()); + orderInfo.setCusId(customer.getId()); + orderInfo.setCusName(customer.getCusName()); + orderInfo.setCusPhone(customer.getPhoneNumber()); + orderInfo.setGoodsPrice(item.getAmount()); + orderInfo.setPayMoney(item.getAmount()); + orderInfo.setOrderTime(LocalDateTime.now()); + orderInfo.setOrderStatus("0"); + orderInfo.setPayType(saveReqVO.getAccountType()); + repairOrderInfoService.save(orderInfo); + resultOrder = repairOrderInfoService.getById(orderInfo.getId()); + } + } else if ("czyl".equals(active.getType())) { + // 充值有礼 + if (null == active.getRuleList() || active.getRuleList().isEmpty()) { + //校验是否存在充值规则 + throw exception(CUSTOMER_ACTIVE_NO_RULE); + } + //记录日志 + CustomerBalanceChange change = changeService.initChange(customer.getId(), + customer.getUserId(), null, BALANCE_CHANGE_TYPE_CZ, BALANCE_CHANGE_MAIN_YE, + null, saveReqVO.getTopUpAmount(), new BigDecimal(0), "参加" + active.getName() + "活动充值" + saveReqVO.getTopUpAmount() + "元"); + changeService.save(change); + RepairOrderInfo orderInfo = new RepairOrderInfo(); + orderInfo.setOrderNo(System.currentTimeMillis() + Math.abs(change.getId().hashCode() % 1000) + ""); + orderInfo.setGoodsId(change.getId()); + orderInfo.setActiveId(active.getId()); + orderInfo.setGoodsTitle(active.getName()); + orderInfo.setTenantName(ORDER_TENANT_NAME); + orderInfo.setGoodsType(ORDER_HYCZ); + orderInfo.setUserId(customer.getUserId()); + orderInfo.setCusId(customer.getId()); + orderInfo.setCusName(customer.getCusName()); + orderInfo.setCusPhone(customer.getPhoneNumber()); + orderInfo.setGoodsPrice(saveReqVO.getTopUpAmount()); + orderInfo.setPayMoney(saveReqVO.getTopUpAmount()); + orderInfo.setOrderTime(LocalDateTime.now()); + orderInfo.setOrderStatus("0"); + orderInfo.setPayType(saveReqVO.getAccountType()); + repairOrderInfoService.save(orderInfo); + resultOrder = repairOrderInfoService.getById(orderInfo.getId()); } + + //保存用户卡券 + if (null != customerCouponList) { + customerCouponService.saveBatch(customerCouponList); + } + /*4、保存参与活动信息*/ + customerActive.setActiveId(active.getId()); + customerActive.setUserId(customer.getUserId()); + customerActive.setCusId(customer.getId()); + customerActive.setActiveName(active.getName()); + customerActive.setActiveType(active.getType()); + customerActive.setRemark(active.getRemark()); + save(customerActive); + + /*5、保存变动日志*/ + //保存变动日志 + changeService.saveBatch(changeList); + return resultOrder; } + /** + * 充值 + * + * @param saveReqVO CustomerActiveSaveReqVO 实体 + * @return cn.iocoder.yudao.module.order.entity.RepairOrderInfo + * @author PQZ + * @date 16:25 2024/9/28 + **/ + @Override + public RepairOrderInfo recharge(CustomerActiveSaveReqVO saveReqVO) { + //当前客户信息 + CustomerMainRespVO customer = customerMainService.getCustomerById(saveReqVO.getCusId()); + //变更信息 + CustomerBalanceChange change = changeService.initChange(customer.getId(), + customer.getUserId(), null, BALANCE_CHANGE_TYPE_CZ, BALANCE_CHANGE_MAIN_YE, + null, saveReqVO.getTopUpAmount(), new BigDecimal(0), "充值" + saveReqVO.getTopUpAmount() + "元"); + + RepairOrderInfo orderInfo = new RepairOrderInfo(); + orderInfo.setOrderNo(System.currentTimeMillis() + Math.abs(change.getId().hashCode() % 1000) + ""); + orderInfo.setGoodsId(change.getId()); + orderInfo.setActiveId(null); + orderInfo.setGoodsTitle("用户充值"); + orderInfo.setTenantName(ORDER_TENANT_NAME); + orderInfo.setGoodsType(ORDER_HYCZ); + orderInfo.setUserId(customer.getUserId()); + orderInfo.setCusId(customer.getId()); + orderInfo.setCusName(customer.getCusName()); + orderInfo.setCusPhone(customer.getPhoneNumber()); + orderInfo.setGoodsPrice(saveReqVO.getTopUpAmount()); + orderInfo.setPayMoney(saveReqVO.getTopUpAmount()); + orderInfo.setOrderTime(LocalDateTime.now()); + orderInfo.setIsOnline("01"); + orderInfo.setOrderStatus("0"); + orderInfo.setPayType(saveReqVO.getAccountType()); + //保存变更日志 + changeService.save(change); + //保存订单信息 + repairOrderInfoService.save(orderInfo); + return repairOrderInfoService.getById(orderInfo.getId()); + } + + + + /** * 转换余额