Pu Zhibing
2025-05-09 8580866e175ad0050ee9c5ea3f757856fc242c39
UserOKTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserCouponRecordServiceImpl.java
@@ -1,5 +1,8 @@
package com.stylefeng.guns.modular.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.dao.UserCouponRecordMapper;
import com.stylefeng.guns.modular.system.model.UserCouponRecord;
@@ -8,6 +11,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -44,8 +48,30 @@
        pageNum = (pageNum - 1) * size;
        return userCouponRecordMapper.queryCoupon(uid, companyId, state, couponUseType, money, pageNum, size);
    }
    @Override
    public List<Map<String, Object>> queryCoupon1(Integer uid, String cityCode, Integer state, Integer couponUseType, Double money, Integer pageNum, Integer size) throws Exception {
        if(null != pageNum && null != size){
            pageNum = (pageNum - 1) * size;
        }
        List<Map<String, Object>> list = userCouponRecordMapper.queryCoupon1(uid, cityCode, state, couponUseType, money, pageNum, size);
        for (Map<String, Object> map : list) {
            Object citys = map.get("citys");
            if(null != citys){
                List<String> names = new ArrayList<>();
                String s = citys.toString();
                JSONArray jsonArray = JSON.parseArray(s);
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String name = jsonObject.getString("name");
                    names.add(name);
                }
                map.put("citys", JSON.toJSONString(names));
            }
        }
        return list;
    }
    /**
     * 获取优惠券列表
     * @param state
@@ -58,7 +84,22 @@
    @Override
    public List<Map<String, Object>> queryMyCoupons(Integer state, Integer pageNum, Integer size, Integer uid) throws Exception {
        pageNum = (pageNum - 1) * size;
        return userCouponRecordMapper.queryMyCoupons(state, pageNum, size, uid);
        List<Map<String, Object>> list = userCouponRecordMapper.queryMyCoupons(state, pageNum, size, uid);
        for (Map<String, Object> map : list) {
            Object citys = map.get("citys");
            if(null != citys){
                List<String> names = new ArrayList<>();
                String s = citys.toString();
                JSONArray jsonArray = JSON.parseArray(s);
                for (int i = 0; i < jsonArray.size(); i++) {
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String name = jsonObject.getString("name");
                    names.add(name);
                }
                map.put("citys", JSON.toJSONString(names));
            }
        }
        return list;
    }
    /**
@@ -70,7 +111,7 @@
    @Override
    public ResultUtil delMyCoupon(Integer id, Integer uid) throws Exception {
        UserCouponRecord userCouponRecord = userCouponRecordMapper.selectById(id);
        if(userCouponRecord.getUserId() != uid){
        if(!userCouponRecord.getUserId().equals(uid)){
            return ResultUtil.error("您不能删除此优惠券");
        }
        userCouponRecordMapper.deleteById(id);