Bladeren bron

feat(store): 实现立减金优惠券的购买与查询功能

- 新增立减金类型优惠券的查询逻辑,区分普通优惠券与立减金
- 修改支付流程以支持立减金购买,使用面值作为支付金额
- 更新优惠券发放条件,排除立减金类型(couponType=3)- 调整支付接口参数,关联公司与用户信息
- 集成汇付支付接口,处理立减金购买的支付请求- 优化优惠券用户列表查询,过滤立减金类型数据
- 修复支付金额设置错误问题,确保金额正确传递
xw 1 maand geleden
bovenliggende
commit
61659f1627

+ 27 - 5
fs-service/src/main/java/com/fs/his/service/impl/FsStorePaymentServiceImpl.java

@@ -1209,7 +1209,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         if (StringUtils.isBlank(user.getMaOpenId())){
             return R.error("用户未绑定微信!");
         }
-        payParam.setCompanyId(302L);
+        payParam.setCompanyId(300L);
         Company company = companyService.selectCompanyById(payParam.getCompanyId());
         if (company==null || company.getStatus()==0){
             return R.error("服务商不存在,或已被停用!");
@@ -1217,7 +1217,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         if(payParam.getPayMoney().compareTo(new BigDecimal(0.0))<1){
             return R.error("支付金额必须大于0");
         }
-        payParam.setCompanyUserId(9590L);
+        payParam.setCompanyUserId(9587L);
         if (payParam.getCompanyUserId()!=null){
             CompanyUser companyUser = companyUserService.selectCompanyUserById(payParam.getCompanyUserId());
             if(companyUser == null || companyUser.getStatus().equals("1")){
@@ -1232,7 +1232,7 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         }
         storePayment.setStatus(0);
         storePayment.setPayCode(IdUtil.getSnowflake(0, 0).nextIdStr());
-        storePayment.setPayMoney(payParam.getPayMoney());
+        storePayment.setPayMoney(payParam.getCouponPrice());
         storePayment.setCreateTime(new Date());
         storePayment.setPayTypeCode("weixin");
         storePayment.setBusinessType(3);
@@ -1243,7 +1243,29 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         if (fsStorePaymentScrmMapper.insertFsStorePayment(storePayment) <= 0) {
             throw new CustomException("支付订单创建失败");
         }
-        return R.ok();
+
+        //汇付支付
+        HuiFuCreateOrder o = new HuiFuCreateOrder();
+        o.setTradeType("T_MINIAPP");
+        o.setOpenid(user.getMaOpenId());
+        o.setReqSeqId("payment-"+storePayment.getPayCode());
+        // 使用立减金面值作为支付金额
+        o.setTransAmt(storePayment.getPayMoney().toString());
+        o.setGoodsDesc("立减金购买");
+        HuifuCreateOrderResult result = huiFuService.createOrder(o);
+        if(result.getResp_code()!=null&&(result.getResp_code().equals("00000000")||result.getResp_code().equals("00000100"))){
+            FsStorePayment mt=new FsStorePayment();
+            mt.setPaymentId(storePayment.getPaymentId());
+            mt.setTradeNo(result.getHf_seq_id());
+            fsStorePaymentMapper.updateFsStorePayment(mt);
+            Map<String, Object> resultMap = com.alibaba.fastjson.JSON.parseObject(result.getPay_info(), new TypeReference<Map<String, Object>>() {});
+            String s = (String) resultMap.get("package");
+            resultMap.put("packageValue",s);
+            return R.ok().put("result",resultMap);
+        }
+        else{
+            return R.error(result.getResp_desc());
+        }
     }
 
 
@@ -1310,4 +1332,4 @@ public class FsStorePaymentServiceImpl implements IFsStorePaymentService {
         }
     }
 
-}
+}

+ 2 - 2
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreCouponIssueScrmMapper.java

@@ -87,12 +87,12 @@ public interface FsStoreCouponIssueScrmMapper
     void updateFsStoreCouponIssueCount(Long id);
     @Select({"<script> " +
             "select i.*,c.coupon_price,c.use_min_price,c.coupon_time   from fs_store_coupon_issue_scrm i left join fs_store_coupon_scrm c on c.coupon_id=i.coupon_id  " +
-            "where i.limit_time &gt; now() and i.is_del=0 and i.status=1  and i.coupon_type= !3  " +
+            "where i.limit_time &gt; now() and i.is_del=0 and i.status=1  and i.coupon_type!=3  " +
             "<if test = 'maps.cateId != null and maps.cateId!=0     '> " +
             "and find_in_set(#{maps.cateId},c.package_cate_ids) " +
             "</if>" +
             "<if test = 'maps.couponType != null     '> " +
-            "and i.coupon_type in (0,1,2) " +
+            "and i.coupon_type =#{maps.couponType} " +
             "</if>" +
             "<if test = 'maps.couponPrice != null     '> " +
             "and c.coupon_price =  #{maps.couponPrice} " +

+ 2 - 2
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreCouponUserScrmMapper.java

@@ -85,8 +85,8 @@ public interface FsStoreCouponUserScrmMapper
             "</script>"})
     List<FsStoreCouponUserScrm> selectFsStoreCouponUserListByEnable(@Param("maps")FsCouponUserEnableParam param);
     @Select({"<script> " +
-            "select cu.*,u.nickname,u.phone from fs_store_coupon_user_scrm cu inner join fs_user u  on u.user_id=cu.user_id  " +
-            "where  cu.is_del=0 " +
+            "select cu.*,u.nickname,u.phone from fs_store_coupon_user_scrm cu inner join fs_user u  on u.user_id=cu.user_id inner join fs_store_coupon_scrm c on c.coupon_id = cu.coupon_id  " +
+            "where  cu.is_del=0 and c.type!=3 " +
             "<if test = 'maps.status != null     '> " +
             "and cu.status =#{maps.status} " +
             "</if>" +

+ 0 - 1
fs-service/src/main/java/com/fs/hisStore/param/FsCouponIssueParam.java

@@ -9,7 +9,6 @@ import java.math.BigDecimal;
 @Data
 public class FsCouponIssueParam extends BaseQueryParam implements Serializable
 {
-
     private Integer cateId;
     private Integer couponType;
     private BigDecimal couponPrice;

+ 2 - 0
fs-service/src/main/java/com/fs/hisStore/param/FsCouponUserParam.java

@@ -7,6 +7,8 @@ import java.io.Serializable;
 @Data
 public class FsCouponUserParam  implements Serializable
 {
+    private Long couponId;
+    private Integer couponType;
 
 
 }

+ 8 - 3
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCouponIssueScrmServiceImpl.java

@@ -13,6 +13,7 @@ import com.fs.hisStore.param.FsStoreCouponReceiveParam;
 import com.fs.hisStore.param.FsStorePaymentPayParam;
 import com.fs.hisStore.service.IFsStoreCouponIssueScrmService;
 import com.fs.hisStore.vo.FsStoreCouponIssueVO;
+
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 优惠券领取Service业务层处理
@@ -230,8 +232,8 @@ public class FsStoreCouponIssueScrmServiceImpl implements IFsStoreCouponIssueScr
         payParam.setCouponPrice(coupon.getCouponPrice()); // 支付金额为立减金面额
         payParam.setBusinessType(3); // 设置业务类型为3,表示购买立减金
         payParam.setUserId(Long.parseLong(userId));
-//        payParam.setCompanyId(couponIssue.getCompanyId());
-//        payParam.setCompanyUserId(couponIssue.getCompanyUserId());
+        payParam.setCompanyId(couponIssue.getCompanyId());
+        payParam.setCompanyUserId(couponIssue.getCompanyUserId());
         payParam.setPayMoney(coupon.getCouponPrice()); // 支付金额为立减金面额
 
         try {
@@ -266,7 +268,10 @@ public class FsStoreCouponIssueScrmServiceImpl implements IFsStoreCouponIssueScr
             couponUser.setType("purchase"); // 设置获取方式为购买
             couponUser.setStatus(0); // 设置为未使用状态
             fsStoreCouponUserMapper.insertFsStoreCouponUser(couponUser);
-            return R.ok("购买成功").put("data", payResult.get("data"));
+            
+            // 获取支付结果中的resultMap并返回
+            Map<String, Object> resultMap = (Map<String, Object>) payResult.get("result");
+            return R.ok("购买成功!").put("result", resultMap);
 
         } catch (Exception e) {
             // 记录详细日志并触发支付退款

+ 11 - 2
fs-user-app/src/main/java/com/fs/app/controller/store/CouponScrmController.java

@@ -15,6 +15,7 @@ import com.fs.hisStore.service.IFsStoreCouponIssueScrmService;
 import com.fs.hisStore.service.IFsStoreCouponScrmService;
 import com.fs.hisStore.service.IFsStoreCouponUserScrmService;
 import com.fs.hisStore.vo.FsStoreCouponIssueVO;
+import com.fs.hisStore.vo.FsStoreCouponUserVO;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
@@ -67,7 +68,15 @@ public class CouponScrmController extends AppBaseController {
             FsStoreCouponUserScrm map=new FsStoreCouponUserScrm();
             map.setIsDel(0);
             map.setUserId(Long.parseLong(getUserId()));
-            List<FsStoreCouponUserScrm> list=fsStoreCouponUserService.selectFsStoreCouponUserList(map);
+            List<FsStoreCouponUserVO> list;
+            if (param.getCouponType() != null && param.getCouponType() == 3) {
+                // 处理 couponType=3 的情况,查询立减金
+                list = fsStoreCouponUserService.selectFsStoreCouponUserListVOForCash(map);
+            } else {
+                // 处理其他 couponType 的情况,查询普通优惠券
+                list = fsStoreCouponUserService.selectFsStoreCouponUserListVO(map);
+            }
+            
             return R.ok().put("data",list);
         } catch (Exception e){
             return R.error("操作异常");
@@ -149,4 +158,4 @@ public class CouponScrmController extends AppBaseController {
     }
 
 
-}
+}