刘帅
2026-09-21 673b4f9d4dce17a2e1c116b2b12646a9fdd74829
cloud-server-activity/src/main/java/com/dsh/activity/controller/HuiminController.java
@@ -7,6 +7,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.activity.entity.*;
import com.dsh.activity.enums.HuiminCardPaymentTypeEnum;
import com.dsh.activity.feignclient.account.AppUserClient;
import com.dsh.activity.feignclient.account.CityClient;
import com.dsh.activity.feignclient.account.StoreStaffClient;
@@ -28,6 +29,7 @@
import com.dsh.activity.model.response.*;
import com.dsh.activity.service.*;
import com.dsh.activity.util.*;
import com.dsh.activity.util.wx.WxV3PayConfig;
import com.google.gson.Gson;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
@@ -52,7 +54,7 @@
 */
@RestController
@RequestMapping("/huimin")
@Api(tags = "惠民卡新增")
@Api(tags = "玩湃惠民卡新增")
public class HuiminController {
    @Autowired
@@ -79,6 +81,10 @@
    private HuiminRecordService huiminRecordService;
    @Resource
    private StudentClient studentClient;
    @Resource
    private UserCouponService userCouponService;
    @Resource
    private CouponStoreService couponStoreService;
    @Autowired
@@ -86,19 +92,21 @@
    private String smid = "2088330203191220";//平台支付宝商户号
    /**
     * 查看惠民卡详情
     * 查看玩湃惠民卡详情
     */
    @ResponseBody
    @PostMapping("/payHuiminCard")
    @ApiOperation(value = "购买惠民卡")
    @ApiOperation(value = "购买玩湃惠民卡")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "玩湃惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "支付方式1微信2支付宝", name = "payType", dataType = "int", required = true),
            @ApiImplicitParam(value = "绑定学员ids多,个逗号拼接", name = "studentIds", dataType = "String", required = true),
            @ApiImplicitParam(value = "用户优惠券领取记录id;不使用时不传", name = "couponId", dataType = "long", required = false),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<THuiminCard> payHuiminCard(Integer id, Integer payType, String studentIds) {
    public ResultUtil<?> payHuiminCard(Integer id, Integer payType, String studentIds, Long couponId) {
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if (null == uid) {
@@ -106,12 +114,12 @@
            }
            THuiminCard huiminCard = huiminCardService.getById(id);
            if (huiminCard.getEndTime() != null && huiminCard.getEndTime().before(new Date())) {
                return ResultUtil.error("该惠民卡已过期");
                return ResultUtil.error("该玩湃惠民卡已过期");
            }
            if (huiminCard.getGrantCount() != null) {
                if (huiminCard.getGrantCount() <= payHuiminService.lambdaQuery().eq(TPayHuimin::getCardId, huiminCard.getId())
                        .eq(TPayHuimin::getStatus, 2).count()) {
                    return ResultUtil.error("该惠民卡已售完");
                    return ResultUtil.error("该玩湃惠民卡已售完");
                }
            }
            if (huiminCard.getLimitCount() != null) {
@@ -119,13 +127,54 @@
                        .eq(TPayHuimin::getStatus, 2)
                        .eq(TPayHuimin::getAppUserId, uid)
                        .count()) {
                    return ResultUtil.error("该惠民卡购买次数已达上限");
                    return ResultUtil.error("该玩湃惠民卡购买次数已达上限");
                }
            }
            TPayHuimin tPayHuimin = new TPayHuimin();
            String[] split = studentIds.split(",");
            tPayHuimin.setSalesMoney(huiminCard.getSalesMoney().multiply(new BigDecimal(split.length)).setScale(2));
            BigDecimal salesMoney = huiminCard.getSalesMoney().multiply(new BigDecimal(split.length)).setScale(2);
            UserCoupon userCoupon = null;
            if (couponId != null && couponId != 0) {
                if (payType != 1 && payType != 2) {
                    return ResultUtil.error("优惠券仅支持微信或支付宝支付");
                }
                userCoupon = userCouponService.getById(couponId);
                if (userCoupon == null || !uid.equals(userCoupon.getUserId()) || !Integer.valueOf(1).equals(userCoupon.getStatus())) {
                    return ResultUtil.error("优惠券不可用");
                }
                Coupon coupon = couponService.getById(userCoupon.getCouponId());
                if (coupon == null || coupon.getEndTime() == null || !coupon.getEndTime().after(new Date())) {
                    return ResultUtil.error("优惠券已过期");
                }
                if (Integer.valueOf(3).equals(coupon.getUseScope())) {
                    Set<Integer> cardStoreIds = Arrays.stream((huiminCard.getStoreIds() == null ? "" : huiminCard.getStoreIds()).split(","))
                            .filter(value -> !value.trim().isEmpty()).map(Integer::valueOf).collect(Collectors.toSet());
                    boolean available = couponStoreService.lambdaQuery().eq(CouponStore::getCouponId, coupon.getId()).list()
                            .stream().map(CouponStore::getStoreId).anyMatch(cardStoreIds::contains);
                    if (!available) {
                        return ResultUtil.error("该优惠券不适用于此惠民卡");
                    }
                }
                if (coupon.getType() == 1) {
                    JSONObject rule = JSON.parseObject(coupon.getContent());
                    BigDecimal condition = rule.getBigDecimal("conditionalAmount");
                    BigDecimal deduction = rule.getBigDecimal("deductionAmount");
                    if (condition == null || deduction == null || salesMoney.compareTo(condition) < 0) {
                        return ResultUtil.error("该优惠券无法使用");
                    }
                    salesMoney = salesMoney.subtract(deduction).max(BigDecimal.ZERO).setScale(2);
                } else if (coupon.getType() == 2) {
                    BigDecimal deduction = JSON.parseObject(coupon.getContent()).getBigDecimal("conditionalAmount");
                    if (deduction == null) {
                        return ResultUtil.error("该优惠券无法使用");
                    }
                    salesMoney = salesMoney.subtract(deduction).max(BigDecimal.ZERO).setScale(2);
                } else {
                    return ResultUtil.error("该优惠券不支持购买惠民卡");
                }
            }
            tPayHuimin.setSalesMoney(salesMoney);
            tPayHuimin.setAppUserId(uid);
            tPayHuimin.setStudentId(studentIds);
            switch (huiminCard.getHuiMinType()) {
@@ -152,19 +201,45 @@
            tPayHuimin.setPaymentType(payType);
            tPayHuimin.setRefundStatus(1);
            tPayHuimin.setCardId(huiminCard.getId());
            tPayHuimin.setUserCouponId(couponId);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            tPayHuimin.setCode(sdf.format(new Date()) + UUIDUtil.getNumberRandom(5));
            System.err.println("支付数据" + tPayHuimin);
            payHuiminService.save(tPayHuimin);
            if (userCoupon != null) {
                // t_user_coupon 以 userId 分片;updateById 会把 userId 放入 SET,
                // ShardingSphere 会拒绝更新分片键。只更新状态,并在 WHERE 中带上 userId。
                boolean couponUpdated = userCouponService.lambdaUpdate()
                        .set(UserCoupon::getStatus, 2)
                        .eq(UserCoupon::getId, userCoupon.getId())
                        .eq(UserCoupon::getUserId, uid)
                        .eq(UserCoupon::getStatus, 1)
                        .update();
                if (!couponUpdated) {
                    return ResultUtil.error("优惠券已被使用");
                }
            }
            BigDecimal bigDecimal = new BigDecimal(studentIds.split(",").length);
            if (tPayHuimin.getSalesMoney().compareTo(BigDecimal.ZERO)==0){
                // 零元购
                tPayHuimin.setStatus(2);
                tPayHuimin.setPaymentTime(new Date());
                payHuiminService.updateById(tPayHuimin);
                JSONObject data = new JSONObject();
                data.put("paySuccess", true);
                return ResultUtil.success(data);
            }
            switch (payType) {
                case 1:
                    return payMoneyUtil.weixinpay("购买惠民卡" + "-" + 0, "", tPayHuimin.getCode(), tPayHuimin.getSalesMoney().toString(),
                            "/base/huimin/callBack/weixinPayHuiminCallback", "APP", "");
                    // todo 惠民卡收入属于平台商户 定死
                    return appendPaySuccess(payMoneyUtil.weixinpay("购买玩湃惠民卡", "", tPayHuimin.getCode(), tPayHuimin.getSalesMoney().toString(),
                            "/base/huimin/callBack/weixinPayHuiminCallback", "APP", ""));
//                return payMoneyUtil.weixinpayV3("1720719391","购买玩湃惠民卡",tPayHuimin.getCode(),
//                        "/base/huimin/callBack/weixinPayHuiminCallback1",tPayHuimin.getSalesMoney().toString());
                case 2:
                    String string = tPayHuimin.getSalesMoney().toString();
                    return payMoneyUtil.alipay(smid, "购买惠民卡", "购买惠民卡", "", tPayHuimin.getCode(), string,
                            "/base/huimin/callBack/aliPayHuiminCallback");
                    return appendPaySuccess(payMoneyUtil.alipay(smid, "购买玩湃惠民卡", "购买玩湃惠民卡", "", tPayHuimin.getCode(), string,
                            "/base/huimin/callBack/aliPayHuiminCallback"));
            }
        } catch (Exception e) {
@@ -174,15 +249,28 @@
        return ResultUtil.success();
    }
    /**
     * 支付参数生成成功不代表实际支付成功,前端仍需拉起第三方支付。
     */
    private ResultUtil<?> appendPaySuccess(ResultUtil<?> paymentResult) {
        JSONObject data = paymentResult.getData() == null ? new JSONObject()
                : JSON.parseObject(JSON.toJSONString(paymentResult.getData()));
        if (data == null) {
            data = new JSONObject();
        }
        data.put("paySuccess", false);
        return ResultUtil.getResult(paymentResult.getCode(), paymentResult.getMsg(), data);
    }
    /**
     * 查看惠民卡详情
     * 查看玩湃惠民卡详情
     */
    @ResponseBody
    @PostMapping("/getHuiminCardDetail")
    @ApiOperation(value = "查看惠民卡详情")
    @ApiOperation(value = "查看玩湃惠民卡详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "玩湃惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "门店id", name = "storeId", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
@@ -252,11 +340,11 @@
    }
    /**
     * 惠民卡富文本内容-惠民卡列表
     * 玩湃惠民卡富文本内容-玩湃惠民卡列表
     */
    @ResponseBody
    @PostMapping("/getHuiminAgreementAndList")
    @ApiOperation(value = "惠民卡富文本内容-惠民卡列表")
    @ApiOperation(value = "玩湃惠民卡富文本内容-玩湃惠民卡列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageSize", dataType = "int", required = true),
            @ApiImplicitParam(value = "页条数", name = "pageNo", dataType = "int", required = true),
@@ -269,13 +357,14 @@
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            HuiminAgreementVO huiminAgreementVO = new HuiminAgreementVO();
            List<THuiminCard> cardList = huiminCardService.getHuiminAgreementAndList(pageNo, pageSize, storeId);
            List<THuiminCard> list = huiminCardService.list();
            List<THuiminCard> cardListNolimit = huiminCardService.getHuiminAgreementAndListNolimit(storeId);
            if (cardListNolimit.isEmpty()) {
                // 没有配置惠民卡 展示富文本内容
                // 没有配置玩湃惠民卡 展示富文本内容
                huiminAgreementVO.setShowType(1);
            } else {
                huiminAgreementVO.setShowType(2);
@@ -326,6 +415,13 @@
                huiminCardVO1.setHuiminName(huiminCard.getHuiMinName());
                huiminCardVO1.setCover(huiminCard.getBuyCover());
                huiminCardVO1.setIsBuy(1);
                int count = huiminRecordService.list(new LambdaQueryWrapper<THuiminRecord>()
                        .eq(THuiminRecord::getPayId, payHuimin.getId())).size();
                if (count>0){
                    huiminCardVOS.add(huiminCardVO1);
                    integers.add(payHuimin.getCardId());
                    continue;
                }
                String siteIds = "";
                if (huiminCard.getUseScope() == 2) {
                    siteIds = huiminCard.getUseIds();
@@ -369,17 +465,39 @@
                                Date start = DateUtil.parse(s1, "yyyy-MM-dd HH:mm:ss");
                                Date end = DateUtil.parse(e1, "yyyy-MM-dd HH:mm:ss");
                                if (new Date().after(start) && new Date().before(end)) {
//                                    jsonObject2.put("start_time", start.getTime() / 1000);
//
                                    Date date1 = new Date();
                                    jsonObject2.put("start_time", date1.getTime() / 1000);
                                    jsonObject2.put("start_time", date1.getTime()/ 1000);
                                    date1.setTime(date1.getTime() + 30 * 1000);
                                    if (start.before(end)) {
                                        jsonObject2.put("end_time", date1.getTime() / 1000);
                                        jsonObject2.put("end_time", date1.getTime()/ 1000);
                                        jsonArray.add(jsonObject2);
                                    }
                                }
                            }
                        }
                        if (jsonArray.isEmpty()){
                            // 返回过期的二维码 保证开门失败即可
                            JSONObject jsonObject3 = new JSONObject();
                            Date date1 = new Date();
                            date1.setTime(date1.getTime() - 300 * 1000);
                            jsonObject3.put("end_time", date1.getTime()/ 1000);
                            jsonObject3.put("start_time", date1.getTime()/ 1000);
                            jsonArray.add(jsonObject3);
                        }
                    }
                }
                else{
                    if (jsonArray.isEmpty()){
                        // 返回过期的二维码 保证开门失败即可
                        JSONObject jsonObject3 = new JSONObject();
                        Date date1 = new Date();
                        date1.setTime(date1.getTime() - 300 * 1000);
                        jsonObject3.put("end_time", date1.getTime()/ 1000);
                        jsonObject3.put("start_time", date1.getTime()/ 1000);
                        jsonArray.add(jsonObject3);
                    }
                }
                if (!jsonArray.isEmpty()) {
@@ -387,9 +505,17 @@
                    TStudent tStudent = tStudents.stream().filter(e -> e.getId().equals(Integer.valueOf(payHuimin.getStudentId().split(",")[0]))).findFirst().orElse(null);
                    if (tStudent!=null){
                        huiminCardVO1.setStudentName(tStudent.getName());
//                        String temp = "{\"id\":"+payHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tStudent.getId() + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + ",\"codeType\":"+4+"\"dataId\":"+payHuimin.getId()+"}";
                        String temp = "{\"id\":"+payHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tStudent.getId() + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 +"}";
                        huiminCardVO1.setQrCode(temp);
                    }else{
                        huiminCardVO1.setStudentName("");
//                        String temp = "{\"id\":"+payHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + 0 + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + ",\"codeType\":"+4+"\"dataId\":"+payHuimin.getId()+"}";
                        String temp = "{\"id\":"+payHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + 0 + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 +"}";
                        huiminCardVO1.setQrCode(temp);
                    }
                    String temp = "{\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + payHuimin.getStudentId().split(",")[0] + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + "}";
                    huiminCardVO1.setQrCode(temp);
                    huiminCardVOS.add(huiminCardVO1);
                    integers.add(payHuimin.getCardId());
@@ -425,14 +551,14 @@
            int startIndex = (pageNo - 1) * pageSize;
            int endIndex = Math.min(startIndex + pageSize, huiminCardVOS.size());
// 防止 startIndex 超过 huiminCardVOS.size()
            // 防止 startIndex 超过 huiminCardVOS.size()
            if (startIndex > huiminCardVOS.size()) {
                startIndex = huiminCardVOS.size();
            }
            List<HuiminCardVO> paginatedHuiminCardVOS = huiminCardVOS.subList(startIndex, endIndex);
// 将分页后的数据设置到 huiminAgreementVO 中
            // 将分页后的数据设置到 huiminAgreementVO 中
            huiminAgreementVO.setCardList(paginatedHuiminCardVOS);
// 将分页后的数据设置到 huiminAgreementVO 中
            // 将分页后的数据设置到 huiminAgreementVO 中
            huiminAgreementVO.setCardList(paginatedHuiminCardVOS);
//            huiminAgreementVO.setCardList(huiminCardVOS);
            return ResultUtil.success(huiminAgreementVO);
@@ -443,13 +569,13 @@
    }
    /**
     * 惠民卡列表-根据惠民卡获取已购买绑定惠民卡的学员列表
     * 玩湃惠民卡列表-根据玩湃惠民卡获取已购买绑定玩湃惠民卡的学员列表
     */
    @ResponseBody
    @PostMapping("/getStudentListByCarId")
    @ApiOperation(value = "惠民卡列表-根据惠民卡获取已购买绑定惠民卡的学员列表")
    @ApiOperation(value = "玩湃惠民卡列表-根据玩湃惠民卡获取已购买绑定玩湃惠民卡的学员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "玩湃惠民卡id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<TStudent>> getStudentListByCarId(Integer id) {
@@ -458,6 +584,7 @@
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<TPayHuimin> payHuimins = payHuiminService.list(new LambdaQueryWrapper<TPayHuimin>()
                    .eq(TPayHuimin::getAppUserId, uid)
                    .eq(TPayHuimin::getCardId, id)
@@ -513,17 +640,38 @@
                                    Date start = DateUtil.parse(s1, "yyyy-MM-dd HH:mm:ss");
                                    Date end = DateUtil.parse(e1, "yyyy-MM-dd HH:mm:ss");
                                    if (new Date().after(start) && new Date().before(end)) {
//                                    jsonObject2.put("start_time", start.getTime() / 1000);
//
                                        Date date1 = new Date();
                                        jsonObject2.put("start_time", date1.getTime() / 1000);
                                        jsonObject2.put("start_time", date1.getTime()/ 1000);
                                        date1.setTime(date1.getTime() + 30 * 1000);
                                        if (start.before(end)) {
                                            jsonObject2.put("end_time", date1.getTime() / 1000);
                                            jsonObject2.put("end_time", date1.getTime()/ 1000);
                                            jsonArray.add(jsonObject2);
                                        }
                                    }
                                }
                            }
                            if (jsonArray.isEmpty()){
                                // 返回过期的二维码 保证开门失败即可
                                JSONObject jsonObject3 = new JSONObject();
                                Date date1 = new Date();
                                date1.setTime(date1.getTime() - 300 * 1000);
                                jsonObject3.put("end_time", date1.getTime()/ 1000);
                                jsonObject3.put("start_time", date1.getTime()/ 1000);
                                jsonArray.add(jsonObject3);
                            }
                        }
                    }else{
                        if (jsonArray.isEmpty()){
                            // 返回过期的二维码 保证开门失败即可
                            JSONObject jsonObject3 = new JSONObject();
                            Date date1 = new Date();
                            date1.setTime(date1.getTime() - 300 * 1000);
                            jsonObject3.put("end_time", date1.getTime()/ 1000);
                            jsonObject3.put("start_time", date1.getTime()/ 1000);
                            jsonArray.add(jsonObject3);
                        }
                    }
                    if (!jsonArray.isEmpty()) {
@@ -544,13 +692,13 @@
    }
    /**
     * 惠民卡列表-选择学员后返回对应的二维码生成规则和有效期结束时间
     * 玩湃惠民卡列表-选择学员后返回对应的二维码生成规则和有效期结束时间
     */
    @ResponseBody
    @PostMapping("/getQrCodeByStudentId")
    @ApiOperation(value = "惠民卡列表-选择学员后返回对应的二维码生成规则和有效期结束时间")
    @ApiOperation(value = "玩湃惠民卡列表-选择学员后返回对应的二维码生成规则和有效期结束时间")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "惠民卡id", name = "cardId", dataType = "int", required = true),
            @ApiImplicitParam(value = "玩湃惠民卡id", name = "cardId", dataType = "int", required = true),
            @ApiImplicitParam(value = "学员id", name = "studentId", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
@@ -560,6 +708,7 @@
            if (null == uid) {
                return ResultUtil.tokenErr();
            }
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<TStudent> tStudents = studentClient.queryStudentList(uid);
            List<TPayHuimin> payHuimins = payHuiminService.list(new LambdaQueryWrapper<TPayHuimin>()
@@ -621,29 +770,56 @@
                                // 转化为Date类型
                                Date start = DateUtil.parse(s1, "yyyy-MM-dd HH:mm:ss");
                                Date end = DateUtil.parse(e1, "yyyy-MM-dd HH:mm:ss");
                                jsonObject2.put("start_time", start.getTime() / 1000);
                                start.setTime(start.getTime() + 30 * 1000);
                                if (new Date().after(start) && new Date().before(end)) {
//                                    jsonObject2.put("start_time", start.getTime() / 1000);
//
                                    Date date1 = new Date();
                                    jsonObject2.put("start_time", date1.getTime() / 1000);
                                    jsonObject2.put("start_time", date1.getTime()/ 1000);
                                    date1.setTime(date1.getTime() + 30 * 1000);
                                    if (start.before(end)) {
                                        jsonObject2.put("end_time", date1.getTime() / 1000);
                                        jsonObject2.put("end_time", date1.getTime()/ 1000);
                                        jsonArray.add(jsonObject2);
                                    }
                                }
                            }
                        }
                        if (jsonArray.isEmpty()){
                            // 返回过期的二维码 保证开门失败即可
                            JSONObject jsonObject3 = new JSONObject();
                            Date date1 = new Date();
                            date1.setTime(date1.getTime() - 300 * 1000);
                            jsonObject3.put("end_time", date1.getTime()/ 1000);
                            jsonObject3.put("start_time", date1.getTime()/ 1000);
                            jsonArray.add(jsonObject3);
                        }
                    }
                }else{
                    if (jsonArray.isEmpty()){
                        // 返回过期的二维码 保证开门失败即可
                        JSONObject jsonObject3 = new JSONObject();
                        Date date1 = new Date();
                        date1.setTime(date1.getTime() - 300 * 1000);
                        jsonObject3.put("end_time", date1.getTime()/ 1000);
                        jsonObject3.put("start_time", date1.getTime()/ 1000);
                        jsonArray.add(jsonObject3);
                    }
                }
                String temp = "{\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + studentId + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + "}";
                huiminCardStudentVO.setQrCode(temp);
                TStudent tStudent = tStudents.stream().filter(e -> e.getId().equals(studentId)).findFirst().orElse(null);
                if (tStudent!=null){
                    huiminCardStudentVO.setStudentName(tStudent.getName());
//                    String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tStudent.getId() + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + ",\"codeType\":"+4+"\"dataId\":"+tPayHuimin.getId()+"}";
                    String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tStudent.getId() + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 +"}";
                    huiminCardStudentVO.setQrCode(temp);
                }else{
                    huiminCardStudentVO.setStudentName("");
//                    String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + 0 + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + ",\"codeType\":"+4+"\"dataId\":"+tPayHuimin.getId()+"}";
                    String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + 0 + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 +"}";
                    huiminCardStudentVO.setQrCode(temp);
                }
            }
@@ -654,11 +830,11 @@
    }
    /**
     * 惠民卡富文本内容-惠民卡列表
     * 玩湃惠民卡富文本内容-玩湃惠民卡列表
     */
    @ResponseBody
    @PostMapping("/myHuiminCardList")
    @ApiOperation(value = "个人中心-我的惠民卡")
    @ApiOperation(value = "个人中心-我的玩湃惠民卡")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码,首页1", name = "pageSize", dataType = "int", required = true),
            @ApiImplicitParam(value = "页条数", name = "pageNo", dataType = "int", required = true),
@@ -678,15 +854,20 @@
                myHuiminCardVO.setEndTime(byId.getEndTime());
                myHuiminCardVO.setSalesMoney(byId.getSalesMoney());
                int count = huiminRecordService.count(new LambdaQueryWrapper<THuiminRecord>()
                        .eq(THuiminRecord::getHuiminCardId, myHuiminCardVO.getCardId()));
                        .eq(THuiminRecord::getPayId, byId.getId()));
                // 购卡7日内没有使用记录可退款。超过7日不管有没有使用记录都不能退款
                if (new Date().after(DateUtil.addDay(myHuiminCardVO.getPaymentTime(), 7))) {
                    // 超过七天不可退款
                    myHuiminCardVO.setIsRefund(0);
                } else if (count >= 7) {
                } else if (count > 0) {
                    myHuiminCardVO.setIsRefund(0);
                } else {
                    myHuiminCardVO.setIsRefund(1);
                }
                if (byId.getStatus()==4){
                    // 退款中
                    myHuiminCardVO.setIsRefund(2);
                }
                THuiminCard huiminCard = list.stream().filter(e -> e.getId().equals(myHuiminCardVO.getCardId())).findFirst().orElse(null);
                if (null != huiminCard) {
@@ -713,11 +894,11 @@
    }
    /**
     * 个人中心-我的惠民卡-退款
     * 个人中心-我的玩湃惠民卡-退款
     */
    @ResponseBody
    @PostMapping("/refund")
    @ApiOperation(value = "个人中心-我的惠民卡-退款")
    @ApiOperation(value = "个人中心-我的玩湃惠民卡-退款")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "支付记录id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
@@ -732,22 +913,27 @@
            if (tPayHuimin == null) {
                return ResultUtil.error("订单不存在");
            }
            if (HuiminCardPaymentTypeEnum.isGift(tPayHuimin.getPaymentType())){
                return ResultUtil.error("赠送惠民卡不允许退款");
            }
            if (tPayHuimin.getStatus() == 3 && tPayHuimin.getRefundStatus() != 1) {
                return ResultUtil.error("不可重复退款");
            }
            if (tPayHuimin.getEndTime().before(new Date())) {
                // 已过期
                return ResultUtil.error("惠民卡已过期,不可退款");
                return ResultUtil.error("玩湃惠民卡已过期,不可退款");
            }
            int count = huiminRecordService.count(new LambdaQueryWrapper<THuiminRecord>()
                    .eq(THuiminRecord::getHuiminCardId, tPayHuimin.getCardId()));
            payHuiminService.updateById(tPayHuimin);
            int count = huiminRecordService.list(new LambdaQueryWrapper<THuiminRecord>()
                    .eq(THuiminRecord::getPayId, tPayHuimin.getId())).size();
            // 购卡7日内没有使用记录可退款。超过7日不管有没有使用记录都不能退款
            if (new Date().after(DateUtil.addDay(tPayHuimin.getPaymentTime(), 7))) {
                // 超过七天不可退款
                return ResultUtil.error("惠民卡购买超过七天,不可退款");
            } else if (count >= 7) {
                // 使用记录大于等于7次不可退款
                return ResultUtil.error("惠民卡使用记录大于等于7次,不可退款");
                return ResultUtil.error("玩湃惠民卡购买超过七天,不可退款");
            } else if (count > 0) {
                return ResultUtil.error("玩湃惠民卡已使用,不可退款");
            }
            if (tPayHuimin.getPaymentType() == 1) {
                Map<String, String> map = payMoneyUtil.wxRefund(tPayHuimin.getOrderNumber(), tPayHuimin.getCode(),
@@ -778,75 +964,14 @@
        }
    }
    public static void main(String[] args) {
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        LocalDateTime localDateTime = LocalDateTime.now().plusDays(365);
//        // 将LocalDateTime转换为Date类型
//        Date date = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
//        String format = simpleDateFormat.format(date);
//        System.err.println(format);
//        String storeIds = "1001,1002";
//        JSONArray jsonArray = JSONArray.parseArray(Arrays.toString(storeIds.split(",")));
//        System.err.println(jsonArray);
//
//        // 获取当前日期
//        LocalDate today = LocalDate.now();
//
//        // 获取当前日期是周几
//        DayOfWeek dayOfWeek = today.getDayOfWeek();
//
//        // 输出当前是周几,使用中文显示
//        System.out.println("今天是: " + dayOfWeek.getValue());
        Date start = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.err.println(simpleDateFormat.format(start));
        start.setTime(start.getTime() + 30 * 1000);
        System.err.println(simpleDateFormat.format(start));
//        String temp = "[{\"days\":[{\"value\":\"1\",\"label\":\"星期一\",\"checked\":true},{\"value\":\"2\",\"label\":\"星期二\",\"checked\":true},{\"value\":\"3\",\"label\":\"星期三\",\"checked\":true},{\"value\":\"4\",\"label\":\"星期四\",\"checked\":true},{\"value\":\"5\",\"label\":\"星期五\",\"checked\":true},{\"value\":\"6\",\"label\":\"星期六\",\"checked\":false},{\"value\":\"7\",\"label\":\"星期日\",\"checked\":false}],\"startTime\":\"00:00\",\"endTime\":\"23:59\"}]";
//        // 可用时间
//        LocalDate today = LocalDate.now();
//
//        int week = today.getDayOfWeek().getValue();
//
//        JSONArray time = JSONArray.parseArray(temp);
//        int i = 0;
//        JSONArray jsonArray = new JSONArray();
//
//        StringBuilder startTime = new StringBuilder();
//        StringBuilder endTime = new StringBuilder();
//
//        String string = LocalDate.now().toString();
//
//        for (Object o : time) {
//            JSONObject jsonObject = (JSONObject) o;
//            for (Object days : jsonObject.getJSONArray("days")) {
//                JSONObject jsonObject1 = (JSONObject) days;
//                if (jsonObject1.getString("value").equals(String.valueOf(week))&&jsonObject1.getBoolean("checked")){
//                    JSONObject jsonObject2 = new JSONObject();
//                    String s1 = string+" "+jsonObject.getString("startTime")+":00";
//                    String e1 = string+" "+jsonObject.getString("endTime")+":00";
//                    // 转化为Date类型
//                    Date start = DateUtil.parse(s1,"yyyy-MM-dd HH:mm:ss");
//                    Date end = DateUtil.parse(e1,"yyyy-MM-dd HH:mm:ss");
//                    jsonObject2.put("startTime",start.getTime());
//                    jsonObject2.put("endTime",end.getTime());
//                    jsonArray.add(jsonObject2);
//                }
//
//
//            }
//            i++;
//        }
//        System.err.println(jsonArray);
    }
    /**
     * 个人中心-我的惠民卡-查看详情
     * 个人中心-我的玩湃惠民卡-查看详情
     */
    @ResponseBody
    @PostMapping("/myHuiminCardDetail")
    @ApiOperation(value = "个人中心-我的惠民卡-查看详情")
    @ApiOperation(value = "个人中心-我的玩湃惠民卡-查看详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "支付记录id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
@@ -859,8 +984,9 @@
            }
            TPayHuimin tPayHuimin = payHuiminService.getById(id);
            if (tPayHuimin == null) {
                return ResultUtil.error("惠民卡不存在");
                return ResultUtil.error("玩湃惠民卡不存在");
            }
            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            THuiminCard byId = huiminCardService.getById(tPayHuimin.getCardId());
            MyHuiminCardDetailVO myHuiminCardDetailVO = new MyHuiminCardDetailVO();
            List<TStudent> studentByIds1 = studentClient.getStudentByIds(tPayHuimin.getStudentId());
@@ -911,24 +1037,46 @@
                            // 转化为Date类型
                            Date start = DateUtil.parse(s1, "yyyy-MM-dd HH:mm:ss");
                            Date end = DateUtil.parse(e1, "yyyy-MM-dd HH:mm:ss");
                            jsonObject2.put("start_time", start.getTime() / 1000);
                            start.setTime(start.getTime() + 30 * 1000);
                            if (new Date().after(start) && new Date().before(end)) {
//                                    jsonObject2.put("start_time", start.getTime() / 1000);
//
                                Date date1 = new Date();
                                jsonObject2.put("start_time", date1.getTime() / 1000);
                                jsonObject2.put("start_time", date1.getTime()/ 1000);
                                date1.setTime(date1.getTime() + 30 * 1000);
                                if (start.before(end)) {
                                    jsonObject2.put("end_time", date1.getTime() / 1000);
                                    jsonObject2.put("end_time", date1.getTime()/ 1000);
                                    jsonArray.add(jsonObject2);
                                }
                            }
                        }
                    }
                    if (jsonArray.isEmpty()){
                        // 返回过期的二维码 保证开门失败即可
                        JSONObject jsonObject3 = new JSONObject();
                        Date date1 = new Date();
                        date1.setTime(date1.getTime() - 300 * 1000);
                        jsonObject3.put("end_time", date1.getTime()/ 1000);
                        jsonObject3.put("start_time", date1.getTime()/ 1000);
                        jsonArray.add(jsonObject3);
                    }
                }
            }else{
                if (jsonArray.isEmpty()){
                    // 返回过期的二维码 保证开门失败即可
                    JSONObject jsonObject3 = new JSONObject();
                    Date date1 = new Date();
                    date1.setTime(date1.getTime() - 300 * 1000);
                    jsonObject3.put("end_time", date1.getTime()/ 1000);
                    jsonObject3.put("start_time", date1.getTime()/ 1000);
                    jsonArray.add(jsonObject3);
                }
            }
            String temp = "{\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tPayHuimin.getStudentId() + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + "}";
//            String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tPayHuimin.getStudentId().split(",")[0] + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 + ",\"codeType\":"+4+"\"dataId\":"+tPayHuimin.getId()+"}";
            String temp = "{\"id\":"+tPayHuimin.getId()  + ","+"\"sid\":" + sid.toJSONString() + "," + "\"rid\":" + rid + "," + "\"uid\":\"" + tPayHuimin.getStudentId().split(",")[0] + "\"," + "\"time\":" + jsonArray.toJSONString() + ",\"type\":" + 2 +"}";
            myHuiminCardDetailVO.setQrCode(temp);
            myHuiminCardDetailVO.setCardId(tPayHuimin.getCardId());
            myHuiminCardDetailVO.setHuiminCard(byId);
@@ -944,6 +1092,7 @@
        }
    }
    /**
     * 获取添加人员、选择人员说明文案
     */