1. 派发优惠券给用户

This commit is contained in:
邱贞招 2024-09-04 21:45:18 +08:00
parent e06236c512
commit af994ca491
6 changed files with 132 additions and 11 deletions

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -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("订单生成失败");

View File

@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="outTradeNo" column="out_trade_no" />
<result property="userId" column="user_id" />
<result property="ruleId" column="rule_id" />
<result property="couponId" column="coupon_id" />
<result property="deviceMac" column="device_mac" />
<result property="sn" column="sn" />
<result property="vehicleNum" column="vehicle_num" />
@ -58,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectEtOrderVo">
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"
</sql>
<sql id="selectEtOrderVoNoRoute">
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"
<if test="orderNo != null and orderNo != ''">order_no,</if>
<if test="userId != null">user_id,</if>
<if test="ruleId != null">rule_id,</if>
<if test="couponId != null">coupon_id,</if>
<if test="deviceMac != null">device_mac,</if>
<if test="sn != null">sn,</if>
<if test="payTime != null">pay_time,</if>
@ -843,6 +849,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="orderNo != null and orderNo != ''">#{orderNo},</if>
<if test="userId != null">#{userId},</if>
<if test="ruleId != null">#{ruleId},</if>
<if test="couponId != null">#{couponId},</if>
<if test="deviceMac != null">#{deviceMac},</if>
<if test="sn != null">#{sn},</if>
<if test="payTime != null">#{payTime},</if>
@ -888,6 +895,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="outTradeNo != null and outTradeNo != ''">out_trade_no = #{outTradeNo},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="ruleId != null">rule_id = #{ruleId},</if>
<if test="couponId != null">coupon_id = #{couponId},</if>
<if test="deviceMac != null">device_mac = #{deviceMac},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="payTime != null">pay_time = #{payTime},</if>
@ -941,6 +949,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="userId != null">user_id = #{userId},</if>
<if test="outTradeNo != null and outTradeNo != ''">out_trade_no = #{outTradeNo},</if>
<if test="ruleId != null">rule_id = #{ruleId},</if>
<if test="couponId != null">coupon_id = #{couponId},</if>
<if test="deviceMac != null">device_mac = #{deviceMac},</if>
<if test="sn != null">sn = #{sn},</if>
<if test="payTime != null">pay_time = #{payTime},</if>