Преглед на файлове

红德堂-疗法券指定项目后仅能在相同项目套餐包下使用

Long преди 2 седмици
родител
ревизия
9fe9ce1f1e

+ 2 - 14
fs-service/src/main/java/com/fs/his/mapper/FsUserCouponMapper.java

@@ -99,21 +99,9 @@ public interface FsUserCouponMapper
     Integer selectFsUserCouponByUserIdCount(@Param("userId") Long userId, @Param("couponType")Integer couponType);
     @Update("UPDATE fs_user_coupon SET `status`=2 WHERE id in (SELECT * FROM(SELECT uc.id FROM fs_user_coupon uc LEFT JOIN fs_coupon c ON c.coupon_id=uc.coupon_id WHERE uc.status=0 and DATE(c.limit_time)<DATE(NOW())) t)")
     Integer updateFsUserCouponStatusByLimtTime();
-    @Select({"<script> " +
-            "select uc.id,uc.coupon_code,uc.status,uc.use_time,c.limit_time,c.title,c.price,c.min_price  from fs_user_coupon uc left join fs_coupon c on c.coupon_id=uc.coupon_id    " +
-            "where uc.status=0    " +
-            "<if test = ' maps.userId != null '> " +
-            "and uc.user_id = #{maps.userId} " +
-            "</if>" +
-            "<if test = ' maps.couponType != null and maps.cateId!=0 '> " +
-            "and find_in_set(c.coupon_type,#{maps.couponType})  and find_in_set(#{maps.cateId},REPLACE(REPLACE(c.cate_ids, '[', ''), ']', '')) " +
-            "</if>" +
-            "<if test = ' maps.couponType != null and maps.cateId==0 '> " +
-            "and find_in_set(c.coupon_type,#{maps.couponType})  " +
-            "</if>" +
-            " order by uc.create_time desc "+
-            "</script>"})
+
     List<FsUserCouponListUVO> getMyEnableCouponList(@Param("maps")FsUserCouponUParam param);
+
     @Select("select ifnull(count(1),0) from fs_user_coupon where coupon_id=#{couponId} and user_id=#{userId}")
     int checkReceive(@Param("userId")Long userId,@Param("couponId")Long couponId);
 

+ 1 - 0
fs-service/src/main/java/com/fs/his/param/FsUserCouponUParam.java

@@ -12,4 +12,5 @@ public class FsUserCouponUParam  extends BaseParam implements Serializable {
     Integer status;
     Long cateId=0l;
     private Long goodsId;
+    private Long orderId;
 }

+ 8 - 1
fs-service/src/main/java/com/fs/his/service/impl/FsPackageOrderServiceImpl.java

@@ -397,6 +397,10 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
             if (userCoupon != null) {
                 if (Objects.equals(userCoupon.getBusinessId(), param.getOrderId()) || userCoupon.getStatus() == 0) {
                     FsCoupon coupon = couponService.selectFsCouponByCouponId(userCoupon.getCouponId());
+                    FsPackage fsPackage = fsPackageOrderMapper.selectFsPackageByOrderId(param.getOrderId());
+                    if (coupon.getProjectId() != null && coupon.getProjectId().equals(fsPackage.getProjectId())) {
+                        throw new CustomException("优惠券项目与套餐包不匹配");
+                    }
                     if (coupon.getCouponType().equals(1)) {
                         if (coupon.getMinPrice().compareTo(orderPrice) <=0) {
                             if (coupon.getPrice().compareTo(orderPrice) >= 0) {
@@ -484,7 +488,7 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
                     payMoney=new BigDecimal(payMoney.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                     // 如果小程序需要支付的金额小于0.01元,不能走物流代收,让走货到付款 xgb
                     if (payMoney.compareTo(new BigDecimal("0.01")) < 0) {
-                        return R.error("物流代收计算支付金额为0,不允许选择物流代收");
+                        throw new CustomException("物流代收计算支付金额为0,不允许选择物流代收");
                     }
                 }
 //                if (sysConfig.getRetainer() != null && sysConfig.getRate() != null && sysConfig.getRate().compareTo(new BigDecimal(0)) > 0) {
@@ -2062,6 +2066,9 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
             if (coupon.getLimitTime() != null && coupon.getLimitTime().before(new Date())) {
                 return R.error("优惠券已过期");
             }
+            if (coupon.getProjectId() != null && coupon.getProjectId().equals(fsPackage.getProjectId())) {
+                return R.error("优惠券项目与套餐包不匹配");
+            }
             userCoupon = fsUserCouponMapper.selectByCouponIdAndUserId(param.getCouponId(), param.getUserId());
             if (userCoupon == null) {
                 return R.error("该用户的优惠券不存在");

+ 3 - 0
fs-service/src/main/java/com/fs/his/vo/FsUserCouponListUVO.java

@@ -45,4 +45,7 @@ public class FsUserCouponListUVO implements Serializable {
     /** 简称 **/
     private String shortName;
 
+    /** 指定项目 **/
+    private Integer projectId;
+
 }

+ 23 - 0
fs-service/src/main/resources/mapper/his/FsUserCouponMapper.xml

@@ -42,6 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectFsUserCouponVo"/>
         where id = #{id}
     </select>
+
     <select id="selectFsUserCouponListUVO" resultType="com.fs.his.vo.FsUserCouponListUVO">
         select
         uc.id,uc.coupon_code,uc.status,uc.use_time,c.limit_time,c.title,c.price,c.min_price,c.coupon_type,c.free_goods_id,c.logo,
@@ -69,6 +70,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
          order by uc.create_time desc
     </select>
 
+    <select id="getMyEnableCouponList" resultType="com.fs.his.vo.FsUserCouponListUVO">
+        select uc.id,uc.coupon_code,uc.status,uc.use_time,c.limit_time,c.title,c.price,c.min_price,c.coupon_type,c.free_goods_id,c.logo,
+            CASE
+                WHEN c.coupon_type IN (3, 7) THEN '免单券'
+                WHEN c.coupon_type IN (5, 6) THEN
+                    IF(c.project_id IS NOT NULL, '优惠券', '现金券')
+                ELSE ''
+            END AS shortName, c.project_id
+        from fs_user_coupon uc left join fs_coupon c on c.coupon_id=uc.coupon_id
+        where uc.status=0
+        <if test = ' maps.userId != null '>
+           and uc.user_id = #{maps.userId}
+        </if>
+        <if test = ' maps.couponType != null and maps.cateId!=0 '>
+           and find_in_set(c.coupon_type,#{maps.couponType})  and find_in_set(#{maps.cateId},REPLACE(REPLACE(c.cate_ids, '[', ''), ']', ''))
+        </if>
+        <if test = ' maps.couponType != null and maps.cateId==0 '>
+           and find_in_set(c.coupon_type,#{maps.couponType})
+         </if>
+         order by uc.create_time desc
+    </select>
+
     <insert id="insertFsUserCoupon" parameterType="FsUserCoupon" useGeneratedKeys="true" keyProperty="id">
         insert into fs_user_coupon
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 29 - 7
fs-user-app/src/main/java/com/fs/app/controller/UserController.java

@@ -18,15 +18,13 @@ import com.fs.company.service.ICompanyUserService;
 import com.fs.course.service.IFsUserCompanyUserService;
 import com.fs.course.service.IFsUserCourseVideoService;
 import com.fs.his.domain.FsDoctor;
+import com.fs.his.domain.FsPackage;
 import com.fs.his.domain.FsUser;
 import com.fs.his.dto.FindUsersByDTO;
 import com.fs.his.param.FindUserByParam;
 import com.fs.his.param.FsUserCouponUParam;
 import com.fs.his.param.FsUserEditPushParam;
-import com.fs.his.service.IFsDoctorService;
-import com.fs.his.service.IFsPackageService;
-import com.fs.his.service.IFsUserCouponService;
-import com.fs.his.service.IFsUserService;
+import com.fs.his.service.*;
 import com.fs.his.utils.PhoneUtil;
 import com.fs.his.vo.FsUserCouponCountUVO;
 import com.fs.his.vo.FsUserCouponListUVO;
@@ -55,10 +53,9 @@ import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.*;
 import java.util.List;
-import java.util.Map;
+import java.util.stream.Collectors;
 
 import static com.fs.his.utils.PhoneUtil.decryptPhoneMk;
 import static com.fs.his.utils.PhoneUtil.encryptPhone;
@@ -83,6 +80,8 @@ public class UserController extends  AppBaseController {
     private IQwAppContactWayService qwAppContactWayService;
     @Autowired
     private IFsUserCourseVideoService courseVideoService;
+    @Autowired
+    private IFsPackageOrderService packageOrderService;
 
 
     @Autowired
@@ -298,8 +297,31 @@ public class UserController extends  AppBaseController {
     public R getMyEnableCouponList(FsUserCouponUParam param, HttpServletRequest request){
         param.setUserId(Long.parseLong(getUserId()));
         List<FsUserCouponListUVO> list=couponService.getMyEnableCouponList(param);
+
+        // 尝试获取疗法券关联的套餐项目ID(仅券类型含5或6且有orderId时)
+        Integer packageProjectId = resolvePackageProjectId(param);
+
+        // 过滤:有projectId限制的券,必须与套餐项目匹配;无限制的券(projectId为null)始终保留
+        list = list.stream()
+                .filter(coupon -> coupon.getProjectId() == null || coupon.getProjectId().equals(packageProjectId))
+                .collect(Collectors.toList());
+
         return R.ok().put("data",list);
     }
+
+    private Integer resolvePackageProjectId(FsUserCouponUParam param) {
+        if (StringUtils.isBlank(param.getCouponType()) || param.getOrderId() == null) {
+            return null;
+        }
+        String[] types = param.getCouponType().split(",");
+        boolean isTherapyCoupon = Arrays.stream(types).anyMatch(t -> Arrays.asList("5", "6").contains(t));
+        if (!isTherapyCoupon) {
+            return null;
+        }
+        FsPackage fsPackage = packageOrderService.selectFsPackageByOrderId(param.getOrderId());
+        return (fsPackage != null) ? fsPackage.getProjectId() : null;
+    }
+
     @Login
     @ApiOperation("获取用户优惠券数量")
     @GetMapping("/getMyCouponCount")