diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponController.java
index 5223bd4..6372447 100644
--- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponController.java
+++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtCouponController.java
@@ -2,6 +2,8 @@ package com.ruoyi.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.system.domain.vo.CouponVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -101,4 +103,15 @@ public class EtCouponController extends BaseController
{
return toAjax(etCouponService.deleteEtCouponByCouponIds(couponIds));
}
+
+ /**
+ * 派发优惠券
+ */
+ @PreAuthorize("@ss.hasPermi('system:coupon:discount')")
+ @Log(title = "优惠券", businessType = BusinessType.INSERT)
+ @PostMapping("/issue")
+ public AjaxResult issue(@RequestBody CouponVo couponVo)
+ {
+ return toAjax(etCouponService.issue(couponVo));
+ }
}
diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/vo/CouponVo.java b/electripper-system/src/main/java/com/ruoyi/system/domain/vo/CouponVo.java
new file mode 100644
index 0000000..2ee458b
--- /dev/null
+++ b/electripper-system/src/main/java/com/ruoyi/system/domain/vo/CouponVo.java
@@ -0,0 +1,17 @@
+package com.ruoyi.system.domain.vo;
+
+import lombok.Data;
+
+/**
+ * 优惠券视图对象
+ *
+ * @author 邱贞招
+ * @date 2024-09-04
+ */
+@Data
+public class CouponVo {
+
+ private String couponId;
+
+ private Long[] userIds;
+}
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponService.java
index bfe35cb..f1d8358 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponService.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtCouponService.java
@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.EtCoupon;
+import com.ruoyi.system.domain.vo.CouponVo;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
/**
@@ -67,4 +68,12 @@ public interface IEtCouponService
* @return
*/
PrepayWithRequestPaymentResponse couponBuy(Long userId, Long couponId);
+
+ /**
+ * 下发优惠券
+ *
+ * @param couponVo
+ * @return 结果
+ */
+ public int issue(CouponVo couponVo);
}
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java
index 15f56b7..6612336 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/CallbackServiceImpl.java
@@ -146,9 +146,6 @@ public class CallbackServiceImpl implements CallbackService {
@Resource
private EtMsgLogMapper etMsgLogMapper;
-// @Value("${et.handlingCharge}")
-// private String handlingCharge;
-
/**
* 微信支付回调
@@ -286,11 +283,13 @@ public class CallbackServiceImpl implements CallbackService {
logger.error("【微信支付回调】更新订单信息失败");
throw new ServiceException("【微信支付回调】更新订单信息失败");
}
- logger.info("=================【微信支付回调】开始更新用户信息==================");
- int updateUser = userService.updateUser(asUser);
- if(updateUser==0){
- logger.error("【微信支付回调】更新用户押金失败");
- throw new ServiceException("【微信支付回调】更新用户押金失败");
+ if(attachVo.getType().equals(ServiceConstants.BUSINESS_TYPE_DEPOSIT)){
+ logger.info("=================【微信支付回调】开始更新用户信息==================");
+ int updateUser = userService.updateUser(asUser);
+ if(updateUser==0){
+ logger.error("【微信支付回调】更新用户押金失败");
+ throw new ServiceException("【微信支付回调】更新用户押金失败");
+ }
}
logger.info("=================【微信支付回调】全部结束!!!!!==================");
}
@@ -298,6 +297,7 @@ public class CallbackServiceImpl implements CallbackService {
}
private void couponSuccessHandle(EtOrder order) {
+ logger.info("【微信支付回调】优惠券支付-------------1");
/**
* 购买分为抵用券订单,会员卡订单、折扣卡订单
* 1. 插入一条记录,et_coupon_user_log 获取方式是购买
@@ -311,10 +311,12 @@ public class CallbackServiceImpl implements CallbackService {
if(ObjectUtil.isNull(asUser)){
throw new ServiceException("用户【"+userId+"】不存在");
}
+ logger.info("【微信支付回调】优惠券支付-------------2");
EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(couponId);
if(ObjectUtil.isNull(etCoupon)){
throw new ServiceException("优惠券【"+couponId+"】不存在");
}
+ logger.info("【微信支付回调】优惠券支付-------------3");
EtCouponUserLog etCouponUserLog = new EtCouponUserLog();
etCouponUserLog.setCouponId(couponId);
etCouponUserLog.setUserId(userId);
@@ -323,8 +325,15 @@ public class CallbackServiceImpl implements CallbackService {
etCouponUserLog.setGainMethod(ServiceConstants.COUPON_GAIN_METHOD_BUY);
etCouponUserLog.setAreaId(etCoupon.getAreaId());
etCouponUserLog.setAreaName(etCoupon.getAreaName());
+ if(ObjectUtil.isNull(etCoupon.getValidityUnit())){
+ throw new ServiceException("优惠券【有效期单位--validityUnit】为空");
+ }
+ if(ObjectUtil.isNull(etCoupon.getValidityValue())){
+ throw new ServiceException("优惠券【有效期值--validityValue】为空");
+ }
etCouponUserLog.setExpirationTime(DateUtils.addValidity(new Date(),etCoupon.getValidityUnit(),etCoupon.getValidityValue()));
if(ServiceConstants.COUPON_TYPE_TIME_CARD.equals(etCoupon.getType()) || ServiceConstants.COUPON_TYPE_VIP_CARD.equals(etCoupon.getType())){
+ logger.info("【微信支付回调】优惠券支付-------------4");
AsUser asUser1 = new AsUser(userId);
asUser1.setVipType(etCoupon.getType());
Date expirationTime;
@@ -341,10 +350,11 @@ public class CallbackServiceImpl implements CallbackService {
if(i1 == 0){
throw new ServiceException("保存优惠券领取记录失败");
}
-
+ logger.info("【微信支付回调】优惠券支付-------------5");
// 增加优惠券账变
callbackService.capitalFlowRecords(order,ServiceConstants.FLOW_TYPE_INCOME,
ServiceConstants.ORDER_TYPE_COUPON_INCOME,ServiceConstants.OWNER_TYPE_OPERATOR,null,ServiceConstants.PAY_TYPE_WX);
+ logger.info("【微信支付回调】优惠券支付-------------6");
}
private void asynchronousMsg(EtOrder order, BigDecimal amount) {
diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java
index 903e8f0..1999776 100644
--- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java
+++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtCouponServiceImpl.java
@@ -7,9 +7,12 @@ import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.domain.EtCoupon;
+import com.ruoyi.system.domain.EtCouponUserLog;
import com.ruoyi.system.domain.EtOrder;
+import com.ruoyi.system.domain.vo.CouponVo;
import com.ruoyi.system.domain.vo.PrepayWithRequestPaymentResponseVo;
import com.ruoyi.system.mapper.AsUserMapper;
+import com.ruoyi.system.mapper.EtCouponClaimLogMapper;
import com.ruoyi.system.mapper.EtCouponMapper;
import com.ruoyi.system.mapper.EtOrderMapper;
import com.ruoyi.system.service.IEtCouponService;
@@ -23,6 +26,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
+import java.util.Date;
import java.util.List;
/**
@@ -47,6 +51,9 @@ public class EtCouponServiceImpl implements IEtCouponService
@Autowired
private IWxPayService wxPayService;
+ @Resource
+ private EtCouponClaimLogMapper etCouponClaimLogMapper;
+
/**
* 查询优惠券
*
@@ -147,6 +154,61 @@ public class EtCouponServiceImpl implements IEtCouponService
return responseVo;
}
+ /**
+ * 下发优惠券
+ *
+ * @param couponVo 优惠券
+ * @return 结果
+ */
+ @Override
+ public int issue(CouponVo couponVo) {
+ Long[] userIds = couponVo.getUserIds();
+ Long couponId = Long.parseLong(couponVo.getCouponId());
+ for (Long userId : userIds) {
+ AsUser asUser = userMapper.selectUserById(userId);
+ if(ObjectUtil.isNull(asUser)){
+ throw new ServiceException("用户【"+userId+"】不存在");
+ }
+ EtCoupon etCoupon = etCouponMapper.selectEtCouponByCouponId(couponId);
+ if(ObjectUtil.isNull(etCoupon)){
+ throw new ServiceException("优惠券【"+couponId+"】不存在");
+ }
+ EtCouponUserLog etCouponUserLog = new EtCouponUserLog();
+ etCouponUserLog.setCouponId(couponId);
+ etCouponUserLog.setUserId(userId);
+ etCouponUserLog.setUserName(asUser.getUserName());
+ etCouponUserLog.setCreateTime(DateUtils.getNowDate());
+ etCouponUserLog.setGainMethod(ServiceConstants.COUPON_GAIN_METHOD_ISSUE);
+ etCouponUserLog.setAreaId(etCoupon.getAreaId());
+ etCouponUserLog.setAreaName(etCoupon.getAreaName());
+ if(ObjectUtil.isNull(etCoupon.getValidityUnit())){
+ throw new ServiceException("优惠券【有效期单位--validityUnit】为空");
+ }
+ if(ObjectUtil.isNull(etCoupon.getValidityValue())){
+ throw new ServiceException("优惠券【有效期值--validityValue】为空");
+ }
+ etCouponUserLog.setExpirationTime(DateUtils.addValidity(new Date(),etCoupon.getValidityUnit(),etCoupon.getValidityValue()));
+ if(ServiceConstants.COUPON_TYPE_TIME_CARD.equals(etCoupon.getType()) || ServiceConstants.COUPON_TYPE_VIP_CARD.equals(etCoupon.getType())){
+ AsUser asUser1 = new AsUser(userId);
+ asUser1.setVipType(etCoupon.getType());
+ Date expirationTime;
+ if(ObjectUtil.isNull(asUser.getExpirationTime())){
+ expirationTime = DateUtils.getNowDate();
+ }else{
+ expirationTime = asUser.getExpirationTime();
+ }
+ asUser1.setExpirationTime(DateUtils.addValidity(expirationTime,etCoupon.getValidityUnit(),etCoupon.getValidityValue()));
+ asUser1.setUserId(userId);
+ int updateUser = userMapper.updateUser(asUser1);
+ }
+ int i1 = etCouponClaimLogMapper.insertEtCouponClaimLog(etCouponUserLog);
+ if(i1 == 0){
+ throw new ServiceException("保存优惠券领取记录失败");
+ }
+ }
+ return 1;
+ }
+
private EtOrder createOrder(EtCoupon etCoupon,AsUser user) {
EtOrder etOrder = new EtOrder();
@@ -161,6 +223,7 @@ public class EtCouponServiceImpl implements IEtCouponService
etOrder.setType(ServiceConstants.ORDER_TYPE_COUPON);
etOrder.setTotalFee(etCoupon.getRetailPrice());
etOrder.setPayFee(etCoupon.getRetailPrice());
+ etOrder.setCouponId(etCoupon.getCouponId());
int i = etOrderMapper.insertEtOrder(etOrder);
if(i == 0){
throw new ServiceException("订单生成失败");
diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml
index 0c4bd4a..25f89a8 100644
--- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml
+++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml
@@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
@@ -58,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- select order_id, area_id, order_no, out_trade_no, user_id, rule_id,
+ select order_id, area_id, order_no, out_trade_no, user_id, rule_id, coupon_id,
device_mac, sn, pay_time, paid, pay_type, type, total_fee, pay_fee, dispatch_fee,
manage_fee, riding_fee, appointment_fee, mark, duration, distance, status,
create_time, appointment_start_time, appointment_end_time,appointment_timeout, unlock_time,return_time,
@@ -68,7 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- select order_id, area_id, order_no, out_trade_no, user_id, rule_id,
+ select order_id, area_id, order_no, out_trade_no, user_id, rule_id, coupon_id,
device_mac, sn, pay_time, paid, pay_type, type, total_fee, pay_fee, dispatch_fee,
manage_fee, riding_fee, appointment_fee, mark, duration, distance, status,
create_time, appointment_start_time, appointment_end_time,appointment_timeout, unlock_time,return_time,
@@ -89,6 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
o.out_trade_no,
o.user_id,
o.rule_id,
+ o.coupon_id,
o.device_mac,
o.sn,
de.vehicle_num,
@@ -183,6 +185,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
o.out_trade_no,
o.user_id,
o.rule_id,
+ o.coupon_id,
o.device_mac,
o.sn,
de.vehicle_num,
@@ -272,6 +275,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
u.user_name AS userName,
u.phonenumber AS phonenumber,
o.rule_id,
+ o.coupon_id,
o.device_mac,
o.sn,
o.pay_time,
@@ -724,6 +728,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
o.out_trade_no,
o.user_id,
o.rule_id,
+ o.coupon_id,
o.device_mac,
o.sn,
o.pay_time,
@@ -801,6 +806,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order_no,
user_id,
rule_id,
+ coupon_id,
device_mac,
sn,
pay_time,
@@ -843,6 +849,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{orderNo},
#{userId},
#{ruleId},
+ #{couponId},
#{deviceMac},
#{sn},
#{payTime},
@@ -888,6 +895,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
out_trade_no = #{outTradeNo},
user_id = #{userId},
rule_id = #{ruleId},
+ coupon_id = #{couponId},
device_mac = #{deviceMac},
sn = #{sn},
pay_time = #{payTime},
@@ -941,6 +949,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
user_id = #{userId},
out_trade_no = #{outTradeNo},
rule_id = #{ruleId},
+ coupon_id = #{couponId},
device_mac = #{deviceMac},
sn = #{sn},
pay_time = #{payTime},