diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java index ff446f8..c4f6561 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java @@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import java.math.RoundingMode; import java.text.DateFormat; import java.time.LocalDate; import java.util.*; @@ -4582,18 +4583,25 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht totalAmount = totalAmount.add(itemPrice); // 判断商品类型并创建相应订单 + BigDecimal DeductionPrice = new BigDecimal("0"); if (serviceGoods.getType() == 2) { // 创建服务订单 String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; + CouponUser coupon=null; if (coupon_id!=null){ - CouponUser coupon = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); + coupon = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); if (coupon==null){ return AppletControllerUtil.appletWarning("优惠券不存在"); } - - } - + if (coupon != null) { + DeductionPrice= new BigDecimal(coupon.getCouponPrice()).divide(new BigDecimal(params.size()),2, RoundingMode.HALF_UP); + } + if (coupon != null) { + coupon.setStatus(2L); + } + //coupon.setUseTime(new Date().getTime()); + couponUserService.updateCouponUser(coupon) ; // 创建商品订单 GoodsOrder goodsOrder = new GoodsOrder(); goodsOrder.setType(2); @@ -4608,7 +4616,7 @@ public AjaxResult createServiceOrder(@RequestBody Map params, Ht goodsOrder.setTotalPrice(itemPrice); goodsOrder.setGoodPrice(serviceGoods.getPrice()); goodsOrder.setPayPrice(itemPrice); - goodsOrder.setDeduction(new BigDecimal(0)); + goodsOrder.setDeduction(DeductionPrice); goodsOrder.setStatus(1L); // 待支付状态 goodsOrder.setAddressId(addressId); goodsOrder.setSku(sku); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java index ec2e412..c70df71 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java @@ -6,18 +6,21 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.*; -import com.ruoyi.system.service.IGoodsCartService; -import com.ruoyi.system.service.IServiceGoodsService; -import com.ruoyi.system.service.IUserAddressService; -import com.ruoyi.system.service.IUsersService; +import com.ruoyi.system.service.*; import com.github.pagehelper.PageInfo; +import java.io.InputStream; +import java.io.OutputStream; +import java.math.BigDecimal; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; /** * 小程序控制器工具类 - * + *

* 提供小程序相关的数据处理、响应实体转换等工具方法 * 主要功能: * 1. 服务商品响应数据格式化 @@ -27,115 +30,116 @@ import java.util.*; * 5. 统一响应格式处理 * * @author Mr. Zhang Pan - * @date 2025-01-03 * @version 1.0 + * @date 2025-01-03 */ public class AppletControllerUtil { - private static final IUsersService usersService= SpringUtils.getBean(IUsersService.class); - private static final IUserAddressService userAddressService= SpringUtils.getBean(IUserAddressService.class); + private static final IUsersService usersService = SpringUtils.getBean(IUsersService.class); + private static final IUserAddressService userAddressService = SpringUtils.getBean(IUserAddressService.class); // ============================== 统一响应处理方法 ============================== - + /** * 成功响应 - code: 200 - * + * * @param data 响应数据 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletSuccess(Object data) { - com.ruoyi.common.core.domain.AjaxResult result = new com.ruoyi.common.core.domain.AjaxResult(); + public static AjaxResult appletSuccess(Object data) { + AjaxResult result = new AjaxResult(); result.put("code", 200); result.put("msg", "OK"); result.put("data", data); return result; } - + /** * 成功响应 - code: 200,无数据 - * + * * @param message 成功消息 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletSuccess(String message) { + public static AjaxResult appletSuccess(String message) { return appletSuccess((Object) message); } - + /** * 成功响应 - code: 200,默认消息 - * + * * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletSuccess() { + public static AjaxResult appletSuccess() { return appletSuccess("操作成功"); } - + /** * 业务提示响应 - code: 422 - * + * * @param message 提示消息 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletWarning(String message) { - com.ruoyi.common.core.domain.AjaxResult result = new com.ruoyi.common.core.domain.AjaxResult(); + public static AjaxResult appletWarning(String message) { + AjaxResult result = new AjaxResult(); result.put("code", 422); result.put("msg", message); - result.put("data", new java.util.ArrayList<>()); + result.put("data", new ArrayList<>()); return result; } - + /** * 业务提示响应 - code: 422,带数据 - * + * * @param message 提示消息 - * @param data 响应数据 + * @param data 响应数据 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletWarning(String message, Object data) { - com.ruoyi.common.core.domain.AjaxResult result = new com.ruoyi.common.core.domain.AjaxResult(); + public static AjaxResult appletWarning(String message, Object data) { + AjaxResult result = new AjaxResult(); result.put("code", 422); result.put("msg", message); - result.put("data", data != null ? data : new java.util.ArrayList<>()); + result.put("data", data != null ? data : new ArrayList<>()); return result; } - + /** * Token验证失败响应 - code: 332 - * + * * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletUnauthorized() { + public static AjaxResult appletUnauthorized() { return appletUnauthorized("用户未登录或token无效,请重新登录"); } - + /** * Token验证失败响应 - code: 332,自定义消息 - * + * * @param message 提示消息 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletUnauthorized(String message) { - com.ruoyi.common.core.domain.AjaxResult result = new com.ruoyi.common.core.domain.AjaxResult(); + public static AjaxResult appletUnauthorized(String message) { + AjaxResult result = new AjaxResult(); result.put("code", 332); result.put("msg", message); - result.put("data", new java.util.ArrayList<>()); + result.put("data", new ArrayList<>()); return result; } - + /** * 系统错误响应 - code: 500 - * + * * @param message 错误消息 * @return AjaxResult */ - public static com.ruoyi.common.core.domain.AjaxResult appletError(String message) { - com.ruoyi.common.core.domain.AjaxResult result = new com.ruoyi.common.core.domain.AjaxResult(); + public static AjaxResult appletError(String message) { + AjaxResult result = new AjaxResult(); result.put("code", 500); result.put("msg", message); - result.put("data", new java.util.ArrayList<>()); + result.put("data", new ArrayList<>()); return result; } + /** * 判断字符串是否能转换为 JSONArray * @@ -154,12 +158,13 @@ public class AppletControllerUtil { return false; } } + /** * 服务商品详情响应实体类 - * + *

* 用于格式化服务商品数据,统一小程序端的数据结构 * 将数据库实体ServiceGoods转换为前端需要的JSON格式 - * + *

* 主要特性: * - 自动处理图片URL添加CDN前缀 * - 支持JSON数组和逗号分隔的字符串解析 @@ -167,105 +172,163 @@ public class AppletControllerUtil { * - 设置合理的默认值避免空值异常 */ public static class ServiceGoodsResponse { - - /** 商品ID */ + + /** + * 商品ID + */ private Long id; - - /** 商品标题 */ + + /** + * 商品标题 + */ private String title; - - /** 商品图标(自动添加CDN前缀) */ + + /** + * 商品图标(自动添加CDN前缀) + */ private String icon; - - /** 商品轮播图数组(自动添加CDN前缀) */ + + /** + * 商品轮播图数组(自动添加CDN前缀) + */ private List imgs; - - /** 商品副标题 */ + + /** + * 商品副标题 + */ private String sub_title; - - /** 商品简介 */ + + /** + * 商品简介 + */ private String info; - - /** 商品价格(字符串格式) */ + + /** + * 商品价格(字符串格式) + */ private String price; - - /** 列表价格显示(字符串格式) */ + + /** + * 列表价格显示(字符串格式) + */ private String price_in; - - /** 销量 */ + + /** + * 销量 + */ private Integer sales; - - /** 库存 */ + + /** + * 库存 + */ private Integer stock; - - /** 状态 */ + + /** + * 状态 + */ private String status; - - /** 商品详情描述 */ + + /** + * 商品详情描述 + */ private String description; - - /** 规格类型 1:单规格 2:多规格 */ + + /** + * 规格类型 1:单规格 2:多规格 + */ private Integer sku_type; - - /** SKU规格对象 */ + + /** + * SKU规格对象 + */ private Map sku; - - /** 纬度 */ + + /** + * 纬度 + */ private String latitude; - - /** 经度 */ + + /** + * 经度 + */ private String longitude; - - /** 类型 1:服务 2:商品 */ + + /** + * 类型 1:服务 2:商品 + */ private Integer type; - - /** 分类ID */ + + /** + * 分类ID + */ private Long cate_id; - - /** 服务项目 */ + + /** + * 服务项目 + */ private String project; - - /** 排序 */ + + /** + * 排序 + */ private Integer sort; - - /** 物料费用 */ + + /** + * 物料费用 + */ private String material; - - /** 邮费(字符串格式) */ + + /** + * 邮费(字符串格式) + */ private String postage; - - /** 基检现象数组 */ + + /** + * 基检现象数组 + */ private List basic; - - /** 保证金(字符串格式) */ + + /** + * 保证金(字符串格式) + */ private String margin; - - /** 所需技能ID */ + + /** + * 所需技能ID + */ private String skill_ids; - - /** 创建时间 */ + + /** + * 创建时间 + */ private String created_at; - - /** 更新时间 */ + + /** + * 更新时间 + */ private String updated_at; - - /** 删除时间 */ + + /** + * 删除时间 + */ private String deleted_at; - - /** 评论对象(预留扩展) */ + + /** + * 评论对象(预留扩展) + */ private Map comment; /** * 构造方法 - 将ServiceGoods实体转换为响应格式 - * + * * @param goods ServiceGoods实体对象 - * - * 主要处理: - * 1. 基础字段映射和类型转换 - * 2. 图片URL添加CDN前缀 - * 3. 数组字段解析(支持JSON和逗号分隔) - * 4. 空值处理和默认值设置 - * 5. 特殊对象构建(SKU、评论等) + *

+ * 主要处理: + * 1. 基础字段映射和类型转换 + * 2. 图片URL添加CDN前缀 + * 3. 数组字段解析(支持JSON和逗号分隔) + * 4. 空值处理和默认值设置 + * 5. 特殊对象构建(SKU、评论等) */ public ServiceGoodsResponse(ServiceGoods goods) { // 基础字段映射 @@ -274,21 +337,21 @@ public class AppletControllerUtil { this.icon = buildImageUrl(goods.getIcon()); this.sub_title = goods.getSubTitle(); this.info = goods.getInfo(); - + // 价格字段处理 - BigDecimal转String避免精度问题 this.price = goods.getPrice() != null ? goods.getPrice().toString() : "0.00"; this.price_in = goods.getPriceZn() != null ? goods.getPriceZn() : ""; - + // 数值字段处理 - Long转Integer并设置默认值 this.sales = goods.getSales() != null ? goods.getSales().intValue() : 0; this.stock = goods.getStock() != null ? goods.getStock().intValue() : 0; this.sort = goods.getSort() != null ? goods.getSort().intValue() : 1; - + // 状态和类型字段 this.status = goods.getStatus() != null ? goods.getStatus() : "1"; this.type = goods.getType() != null ? goods.getType().intValue() : 1; this.sku_type = goods.getSkuType() != null ? goods.getSkuType().intValue() : 1; - + // 文本字段 this.description = goods.getDescription(); this.latitude = goods.getLatitude(); @@ -297,115 +360,260 @@ public class AppletControllerUtil { this.project = goods.getProject(); this.material = goods.getMaterial(); this.skill_ids = goods.getSkillIds(); - + // 金额字段处理 - BigDecimal转String this.postage = goods.getPostage() != null ? goods.getPostage().toString() : ""; this.margin = goods.getMargin() != null ? goods.getMargin().toString() : ""; - + // 时间字段处理 this.created_at = goods.getCreatedAt() != null ? goods.getCreatedAt().toString() : ""; this.updated_at = goods.getUpdatedAt() != null ? goods.getUpdatedAt().toString() : ""; this.deleted_at = goods.getDeletedAt() != null ? goods.getDeletedAt().toString() : null; - + // 数组字段解析 this.imgs = parseStringToImageList(goods.getImgs()); this.basic = parseStringToList(goods.getBasic()); - + // 构建SKU对象 - 默认单规格 this.sku = new HashMap<>(); this.sku.put("type", "single"); - + // 构建评论对象 - 预留扩展 this.comment = new HashMap<>(); } // Getter和Setter方法(完整实现) - public Long getId() { return id; } - public void setId(Long id) { this.id = id; } - - public String getTitle() { return title; } - public void setTitle(String title) { this.title = title; } - - public String getIcon() { return icon; } - public void setIcon(String icon) { this.icon = icon; } - - public List getImgs() { return imgs; } - public void setImgs(List imgs) { this.imgs = imgs; } - - public String getSub_title() { return sub_title; } - public void setSub_title(String sub_title) { this.sub_title = sub_title; } - - public String getInfo() { return info; } - public void setInfo(String info) { this.info = info; } - - public String getPrice() { return price; } - public void setPrice(String price) { this.price = price; } - - public String getPrice_in() { return price_in; } - public void setPrice_in(String price_in) { this.price_in = price_in; } - - public Integer getSales() { return sales; } - public void setSales(Integer sales) { this.sales = sales; } - - public Integer getStock() { return stock; } - public void setStock(Integer stock) { this.stock = stock; } - - public String getStatus() { return status; } - public void setStatus(String status) { this.status = status; } - - public String getDescription() { return description; } - public void setDescription(String description) { this.description = description; } - - public Integer getSku_type() { return sku_type; } - public void setSku_type(Integer sku_type) { this.sku_type = sku_type; } - - public Map getSku() { return sku; } - public void setSku(Map sku) { this.sku = sku; } - - public String getLatitude() { return latitude; } - public void setLatitude(String latitude) { this.latitude = latitude; } - - public String getLongitude() { return longitude; } - public void setLongitude(String longitude) { this.longitude = longitude; } - - public Integer getType() { return type; } - public void setType(Integer type) { this.type = type; } - - public Long getCate_id() { return cate_id; } - public void setCate_id(Long cate_id) { this.cate_id = cate_id; } - - public String getProject() { return project; } - public void setProject(String project) { this.project = project; } - - public Integer getSort() { return sort; } - public void setSort(Integer sort) { this.sort = sort; } - - public String getMaterial() { return material; } - public void setMaterial(String material) { this.material = material; } - - public String getPostage() { return postage; } - public void setPostage(String postage) { this.postage = postage; } - - public List getBasic() { return basic; } - public void setBasic(List basic) { this.basic = basic; } - - public String getMargin() { return margin; } - public void setMargin(String margin) { this.margin = margin; } - - public String getSkill_ids() { return skill_ids; } - public void setSkill_ids(String skill_ids) { this.skill_ids = skill_ids; } - - public String getCreated_at() { return created_at; } - public void setCreated_at(String created_at) { this.created_at = created_at; } - - public String getUpdated_at() { return updated_at; } - public void setUpdated_at(String updated_at) { this.updated_at = updated_at; } - - public String getDeleted_at() { return deleted_at; } - public void setDeleted_at(String deleted_at) { this.deleted_at = deleted_at; } - - public Map getComment() { return comment; } - public void setComment(Map comment) { this.comment = comment; } + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public List getImgs() { + return imgs; + } + + public void setImgs(List imgs) { + this.imgs = imgs; + } + + public String getSub_title() { + return sub_title; + } + + public void setSub_title(String sub_title) { + this.sub_title = sub_title; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + + public String getPrice_in() { + return price_in; + } + + public void setPrice_in(String price_in) { + this.price_in = price_in; + } + + public Integer getSales() { + return sales; + } + + public void setSales(Integer sales) { + this.sales = sales; + } + + public Integer getStock() { + return stock; + } + + public void setStock(Integer stock) { + this.stock = stock; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getSku_type() { + return sku_type; + } + + public void setSku_type(Integer sku_type) { + this.sku_type = sku_type; + } + + public Map getSku() { + return sku; + } + + public void setSku(Map sku) { + this.sku = sku; + } + + public String getLatitude() { + return latitude; + } + + public void setLatitude(String latitude) { + this.latitude = latitude; + } + + public String getLongitude() { + return longitude; + } + + public void setLongitude(String longitude) { + this.longitude = longitude; + } + + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public Long getCate_id() { + return cate_id; + } + + public void setCate_id(Long cate_id) { + this.cate_id = cate_id; + } + + public String getProject() { + return project; + } + + public void setProject(String project) { + this.project = project; + } + + public Integer getSort() { + return sort; + } + + public void setSort(Integer sort) { + this.sort = sort; + } + + public String getMaterial() { + return material; + } + + public void setMaterial(String material) { + this.material = material; + } + + public String getPostage() { + return postage; + } + + public void setPostage(String postage) { + this.postage = postage; + } + + public List getBasic() { + return basic; + } + + public void setBasic(List basic) { + this.basic = basic; + } + + public String getMargin() { + return margin; + } + + public void setMargin(String margin) { + this.margin = margin; + } + + public String getSkill_ids() { + return skill_ids; + } + + public void setSkill_ids(String skill_ids) { + this.skill_ids = skill_ids; + } + + public String getCreated_at() { + return created_at; + } + + public void setCreated_at(String created_at) { + this.created_at = created_at; + } + + public String getUpdated_at() { + return updated_at; + } + + public void setUpdated_at(String updated_at) { + this.updated_at = updated_at; + } + + public String getDeleted_at() { + return deleted_at; + } + + public void setDeleted_at(String deleted_at) { + this.deleted_at = deleted_at; + } + + public Map getComment() { + return comment; + } + + public void setComment(Map comment) { + this.comment = comment; + } } /** @@ -416,10 +624,10 @@ public class AppletControllerUtil { /** * 构建完整的图片URL - * + * * @param imagePath 图片路径 * @return 完整的图片URL(包含CDN前缀) - * + *

* 处理逻辑: * - 如果图片路径为空,返回空字符串 * - 自动添加CDN域名前缀 @@ -434,14 +642,14 @@ public class AppletControllerUtil { /** * 解析字符串为图片URL列表 - * + * * @param imgsString 图片字符串(支持JSON数组或逗号分隔) * @return 图片URL列表(已添加CDN前缀) - * + *

* 支持的格式: * 1. JSON数组格式:["img1.jpg", "img2.jpg"] * 2. 逗号分隔格式:img1.jpg,img2.jpg - * + *

* 处理特性: * - 自动识别数据格式 * - 过滤空值和空白字符 @@ -449,8 +657,8 @@ public class AppletControllerUtil { * - 异常容错处理 */ public static List parseStringToImageList(String imgsString) { - List imageList = new java.util.ArrayList<>(); - + List imageList = new ArrayList<>(); + if (imgsString == null || imgsString.trim().isEmpty()) { return imageList; } @@ -474,30 +682,30 @@ public class AppletControllerUtil { } } } - + return imageList; } /** * 解析字符串为普通字符串列表 - * + * * @param dataString 数据字符串(支持JSON数组或逗号分隔) * @return 字符串列表 - * + *

* 用于解析基检现象、标签等文本数组数据 - * + *

* 支持的格式: * 1. JSON数组格式:["现象1", "现象2"] * 2. 逗号分隔格式:现象1,现象2 - * + *

* 处理特性: * - 自动识别数据格式 * - 过滤空值和空白字符 * - 异常容错处理 */ public static List parseStringToList(String dataString) { - List dataList = new java.util.ArrayList<>(); - + List dataList = new ArrayList<>(); + if (dataString == null || dataString.trim().isEmpty()) { return dataList; } @@ -521,58 +729,58 @@ public class AppletControllerUtil { } } } - + return dataList; } /** * 构建分类数据 - * - * @param category 分类信息 - * @param keywords 搜索关键词(可选) + * + * @param category 分类信息 + * @param keywords 搜索关键词(可选) * @param serviceGoodsService 服务商品Service * @return 格式化的分类数据 - * + *

* 返回数据结构: * { - * "id": 分类ID, - * "title": 分类标题, - * "icon": 分类图标URL, - * "type": 分类类型, - * "cate_id": 分类ID, - * "goods": [商品列表] + * "id": 分类ID, + * "title": 分类标题, + * "icon": 分类图标URL, + * "type": 分类类型, + * "cate_id": 分类ID, + * "goods": [商品列表] * } - * + *

* 功能特性: * - 查询分类下的所有商品 * - 支持关键词搜索过滤 * - 自动添加图片CDN前缀 * - 返回统一的数据格式 */ - public static Map buildCategoryData(ServiceCate category, String keywords, - IServiceGoodsService serviceGoodsService) { + public static Map buildCategoryData(ServiceCate category, String keywords, + IServiceGoodsService serviceGoodsService) { Map categoryData = new HashMap<>(); - + // 分类基础信息 categoryData.put("id", category.getId()); categoryData.put("title", category.getTitle()); categoryData.put("icon", buildImageUrl(category.getIcon())); categoryData.put("type", category.getType()); categoryData.put("cate_id", category.getId()); - + // 查询该分类下的商品 ServiceGoods serviceGoodsQuery = new ServiceGoods(); serviceGoodsQuery.setCateId(category.getId()); - + // 如果有关键词,添加搜索条件 if (keywords != null && !keywords.trim().isEmpty()) { serviceGoodsQuery.setTitle(keywords.trim()); } - + // 查询商品列表 List goodsList = serviceGoodsService.selectServiceGoodsList(serviceGoodsQuery); - List> goodsDataList = new java.util.ArrayList<>(); - + List> goodsDataList = new ArrayList<>(); + // 构建商品数据列表 for (ServiceGoods goods : goodsList) { Map goodsData = new HashMap<>(); @@ -583,27 +791,27 @@ public class AppletControllerUtil { goodsData.put("cate_id", goods.getCateId()); goodsDataList.add(goodsData); } - + categoryData.put("goods", goodsDataList); return categoryData; } /** * 获取用户数据 - * - * @param token 用户令牌 + * + * @param token 用户令牌 * @param usersService 用户Service * @return 用户数据Map - * + *

* 返回数据结构: * - code: 200(成功) / 302(未登录) / 400(令牌无效) * - user: 用户信息对象(成功时返回) - * + *

* 状态码说明: * - 200: 令牌有效,用户存在 * - 302: 未提供令牌,需要登录 * - 400: 令牌无效或用户不存在 - * + *

* 主要用途: * - 验证用户登录状态 * - 获取用户基础信息 @@ -611,7 +819,7 @@ public class AppletControllerUtil { */ public static Map getUserData(String token, IUsersService usersService) { Map resultMap = new HashMap<>(); - + if (token == null || token.trim().isEmpty()) { // 未提供令牌 resultMap.put("code", 302); @@ -630,32 +838,32 @@ public class AppletControllerUtil { resultMap.put("message", "令牌无效或用户不存在"); } } - + return resultMap; } /** * 微信用户登录方法 - * - * @param openid 微信用户openid + * + * @param openid 微信用户openid * @param usersService 用户Service * @return 登录结果Map - * + *

* 返回数据结构: * { - * "success": true/false, // 登录是否成功 - * "token": "用户token", // 登录成功时返回 - * "userInfo": {...}, // 用户信息 - * "message": "提示信息" // 操作结果消息 + * "success": true/false, // 登录是否成功 + * "token": "用户token", // 登录成功时返回 + * "userInfo": {...}, // 用户信息 + * "message": "提示信息" // 操作结果消息 * } - * + *

* 登录流程: * 1. 验证openid的有效性 * 2. 查询或创建用户记录 * 3. 生成用户token * 4. 更新用户登录信息 * 5. 返回登录结果 - * + *

* 业务逻辑: * - 首次登录:创建新用户记录 * - 再次登录:更新登录时间和token @@ -663,7 +871,7 @@ public class AppletControllerUtil { */ public static Map wechatUserLogin(String openid, IUsersService usersService) { Map result = new HashMap<>(); - + try { // 1. 参数验证 if (openid == null || openid.trim().isEmpty()) { @@ -671,9 +879,9 @@ public class AppletControllerUtil { result.put("message", "openid不能为空"); return result; } - + String trimmedOpenid = openid.trim(); - + // 2. 验证openid有效性 Map validationResult = WechatApiUtil.validateOpenid(trimmedOpenid); if (!(Boolean) validationResult.get("valid")) { @@ -681,16 +889,16 @@ public class AppletControllerUtil { result.put("message", "openid验证失败:" + validationResult.get("errorMsg")); return result; } - + // 3. 获取微信用户信息 Map wechatUserInfo = (Map) validationResult.get("userInfo"); - + // 4. 查询数据库中是否已存在该用户 Users existingUser = usersService.selectUsersByOpenid(trimmedOpenid); - + Users userRecord; boolean isNewUser = false; - + if (existingUser == null) { // 4.1 首次登录,创建新用户记录 userRecord = createNewWechatUser(trimmedOpenid, wechatUserInfo); @@ -699,11 +907,11 @@ public class AppletControllerUtil { // 4.2 用户已存在,更新用户信息 userRecord = updateExistingWechatUser(existingUser, wechatUserInfo); } - + // 5. 生成新的用户token String userToken = WechatApiUtil.generateUserToken(trimmedOpenid); userRecord.setRememberToken(userToken); - + // 6. 保存或更新用户记录到数据库 if (isNewUser) { // 插入新用户 @@ -722,32 +930,32 @@ public class AppletControllerUtil { return result; } } - + // 7. 构建返回数据 Map responseUserInfo = buildUserResponseInfo(userRecord, wechatUserInfo); - + result.put("success", true); result.put("token", userToken); result.put("userInfo", responseUserInfo); result.put("isNewUser", isNewUser); result.put("loginTime", System.currentTimeMillis()); result.put("message", isNewUser ? "注册并登录成功" : "登录成功"); - + } catch (Exception e) { result.put("success", false); result.put("message", "登录过程中发生错误:" + e.getMessage()); } - + return result; } /** * 创建新的微信用户记录 - * - * @param openid 微信openid + * + * @param openid 微信openid * @param wechatUserInfo 微信用户信息 * @return 新创建的用户记录 - * + *

* 用户字段设置: * - 基础信息:openid、昵称、头像等 * - 状态信息:启用状态、注册时间等 @@ -755,40 +963,40 @@ public class AppletControllerUtil { */ private static Users createNewWechatUser(String openid, Map wechatUserInfo) { Users newUser = new Users(); - + // 基础信息 newUser.setOpenid(openid); newUser.setNickname((String) wechatUserInfo.get("nickname")); newUser.setAvatar((String) wechatUserInfo.get("avatar")); - + // 用户名使用openid(可以根据业务需求调整) newUser.setName("wx_" + openid.substring(openid.length() - 8)); - + // 设置默认密码(微信登录不需要密码) newUser.setPassword(""); // 实际项目中可能需要加密的默认密码 - + // 状态信息 newUser.setStatus(1); // 启用状态:1启用 0关闭 newUser.setType("1"); // 用户类型:1普通用户 2师傅 - + // 时间信息 - java.util.Date now = new java.util.Date(); + Date now = new Date(); newUser.setCreateTime(now); newUser.setUpdateTime(now); - + // 其他信息 newUser.setRemark("微信小程序用户"); - + return newUser; } /** * 更新现有微信用户记录 - * - * @param existingUser 现有用户记录 + * + * @param existingUser 现有用户记录 * @param wechatUserInfo 微信用户信息 * @return 更新后的用户记录 - * + *

* 更新策略: * - 同步微信最新信息:昵称、头像等 * - 更新登录时间 @@ -798,20 +1006,20 @@ public class AppletControllerUtil { // 更新微信相关信息 existingUser.setNickname((String) wechatUserInfo.get("nickname")); existingUser.setAvatar((String) wechatUserInfo.get("avatar")); - + // 更新登录时间 - existingUser.setUpdateTime(new java.util.Date()); - + existingUser.setUpdateTime(new Date()); + return existingUser; } /** * 构建用户响应信息 - * - * @param userRecord 用户数据库记录 + * + * @param userRecord 用户数据库记录 * @param wechatUserInfo 微信用户信息 * @return 格式化的用户信息 - * + *

* 返回字段: * - 基础信息:用户ID、昵称、头像等 * - 微信信息:openid等 @@ -820,43 +1028,43 @@ public class AppletControllerUtil { */ private static Map buildUserResponseInfo(Users userRecord, Map wechatUserInfo) { Map userInfo = new HashMap<>(); - + // 基础用户信息 userInfo.put("userId", userRecord.getId()); userInfo.put("username", userRecord.getName()); userInfo.put("nickname", userRecord.getNickname()); userInfo.put("avatar", userRecord.getAvatar()); userInfo.put("openid", userRecord.getOpenid()); - + // 状态信息 userInfo.put("status", userRecord.getStatus()); userInfo.put("userType", userRecord.getType()); userInfo.put("createTime", userRecord.getCreateTime()); userInfo.put("updateTime", userRecord.getUpdateTime()); - + // 微信附加信息 userInfo.put("gender", wechatUserInfo.get("gender")); userInfo.put("city", wechatUserInfo.get("city")); userInfo.put("province", wechatUserInfo.get("province")); userInfo.put("country", wechatUserInfo.get("country")); - + return userInfo; } /** * 验证用户token有效性 - * - * @param token 用户token + * + * @param token 用户token * @param usersService 用户Service * @return 验证结果Map - * + *

* 返回数据结构: * { - * "valid": true/false, // token是否有效 - * "userInfo": {...}, // 用户信息(有效时返回) - * "message": "提示信息" // 验证结果消息 + * "valid": true/false, // token是否有效 + * "userInfo": {...}, // 用户信息(有效时返回) + * "message": "提示信息" // 验证结果消息 * } - * + *

* 验证逻辑: * 1. 检查token格式是否正确 * 2. 从数据库查询token对应的用户 @@ -866,7 +1074,7 @@ public class AppletControllerUtil { */ public static Map validateUserToken(String token, IUsersService usersService) { Map result = new HashMap<>(); - + try { // 1. 参数验证 if (token == null || token.trim().isEmpty()) { @@ -874,16 +1082,16 @@ public class AppletControllerUtil { result.put("message", "token不能为空"); return result; } - + String trimmedToken = token.trim(); - + // 2. 检查token格式 if (!WechatApiUtil.isValidTokenFormat(trimmedToken)) { result.put("valid", false); result.put("message", "token格式无效"); return result; } - + // 3. 从数据库查询token对应的用户 Users user = usersService.selectUsersByRememberToken(trimmedToken); if (user == null) { @@ -891,14 +1099,14 @@ public class AppletControllerUtil { result.put("message", "token无效或已过期"); return result; } - + // 4. 检查用户状态 if (!"1".equals(user.getStatus())) { result.put("valid", false); result.put("message", "用户账号已被禁用"); return result; } - + // 5. 构建用户信息(过滤敏感字段) Map userInfo = new HashMap<>(); userInfo.put("userId", user.getId()); @@ -910,16 +1118,16 @@ public class AppletControllerUtil { userInfo.put("userType", user.getType()); userInfo.put("createTime", user.getCreateTime()); userInfo.put("updateTime", user.getUpdateTime()); - + result.put("valid", true); result.put("userInfo", userInfo); result.put("message", "token验证成功"); - + } catch (Exception e) { result.put("valid", false); result.put("message", "验证token时发生错误:" + e.getMessage()); } - + return result; } @@ -932,14 +1140,14 @@ public class AppletControllerUtil { * @param addressId 要更新的地址ID * @param userId 用户ID,用于权限验证 * @return UserAddress对象,包含更新后的地址信息 - * + *

* 功能说明: * - 从请求参数中提取地址信息并构建UserAddress对象 * - 自动处理参数类型转换和空值验证 * - 用于地址编辑功能的数据转换 */ - public static com.ruoyi.system.domain.UserAddress buildUpdateAddress(Map params, Long addressId, Long userId) { - com.ruoyi.system.domain.UserAddress address = new com.ruoyi.system.domain.UserAddress(); + public static UserAddress buildUpdateAddress(Map params, Long addressId, Long userId) { + UserAddress address = new UserAddress(); address.setId(addressId); address.setUid(userId); @@ -997,13 +1205,13 @@ public class AppletControllerUtil { * * @param address 需要验证的地址对象 * @return 验证错误信息,null表示验证通过 - * + *

* 功能说明: * - 验证地址对象的必填字段是否完整 * - 验证手机号格式是否正确(11位数字) * - 为地址新增和编辑功能提供统一的参数验证 */ - public static String validateAddressParams(com.ruoyi.system.domain.UserAddress address) { + public static String validateAddressParams(UserAddress address) { if (address.getName() == null || address.getName().isEmpty()) { return "收货人姓名不能为空"; } @@ -1030,14 +1238,14 @@ public class AppletControllerUtil { * @param params 请求参数Map,包含新地址的各个字段信息 * @param userId 当前登录用户的ID * @return UserAddress对象,包含新地址的完整信息 - * + *

* 功能说明: * - 从请求参数中提取地址信息并构建UserAddress对象 * - 智能处理is_default字段的多种数据类型(boolean/number/string) * - 为地址新增功能提供数据转换和默认值设置 */ - public static com.ruoyi.system.domain.UserAddress buildNewAddress(Map params, Long userId) { - com.ruoyi.system.domain.UserAddress address = new com.ruoyi.system.domain.UserAddress(); + public static UserAddress buildNewAddress(Map params, Long userId) { + UserAddress address = new UserAddress(); address.setUid(userId); // 设置收货人姓名 @@ -1081,7 +1289,7 @@ public class AppletControllerUtil { // 处理布尔值或数字值 Object isDefaultObj = params.get("is_default"); Long isDefault = 0L; - + if (isDefaultObj instanceof Boolean) { isDefault = ((Boolean) isDefaultObj) ? 1L : 0L; } else if (isDefaultObj instanceof Number) { @@ -1092,7 +1300,7 @@ public class AppletControllerUtil { isDefault = 1L; } } - + address.setIsDefault(isDefault); } catch (Exception e) { // 如果转换失败,设为非默认 @@ -1110,10 +1318,10 @@ public class AppletControllerUtil { /** * 检查订单状态是否允许申请售后 - * + * * @param orderStatus 订单状态 * @return true=允许申请售后,false=不允许 - * + *

* 功能说明: * - 根据订单状态判断是否可以申请售后 * - 一般已完成的订单才能申请售后 @@ -1123,7 +1331,7 @@ public class AppletControllerUtil { if (orderStatus == null) { return false; } - + // 订单状态定义(根据实际业务调整): // 1=待接单, 2=已接单, 3=服务中, 4=已完成, 5=已取消, 6=售后中, 7=已退款 // 只有已完成(4)的订单才能申请售后 @@ -1132,27 +1340,27 @@ public class AppletControllerUtil { /** * 处理售后返修申请业务逻辑 - * - * @param order 订单对象 - * @param phone 联系电话 - * @param mark 返修原因 - * @param user 用户信息 + * + * @param order 订单对象 + * @param phone 联系电话 + * @param mark 返修原因 + * @param user 用户信息 * @param orderReworkService 售后服务 - * @param orderService 订单服务 + * @param orderService 订单服务 * @return true=处理成功,false=处理失败 - * + *

* 功能说明: * - 创建售后返修记录到order_rework表 * - 更新订单状态为售后处理中 * - 记录完整的售后申请信息 */ - public static boolean processReworkApplication(com.ruoyi.system.domain.Order order, String phone, String mark, - com.ruoyi.system.domain.Users user, - com.ruoyi.system.service.IOrderReworkService orderReworkService, - com.ruoyi.system.service.IOrderService orderService) { + public static boolean processReworkApplication(Order order, String phone, String mark, + Users user, + IOrderReworkService orderReworkService, + IOrderService orderService) { try { // 1. 创建售后返修记录 - com.ruoyi.system.domain.OrderRework orderRework = new com.ruoyi.system.domain.OrderRework(); + OrderRework orderRework = new OrderRework(); orderRework.setUid(user.getId()); // 用户ID orderRework.setUname(user.getNickname()); // 用户名称 orderRework.setOid(order.getId()); // 订单ID @@ -1160,18 +1368,18 @@ public class AppletControllerUtil { orderRework.setPhone(phone); // 联系电话 orderRework.setMark(mark); // 返修原因 orderRework.setStatus(0); // 状态:0-待处理,1-已处理 - + // 插入售后返修记录 int reworkResult = orderReworkService.insertOrderRework(orderRework); - + if (reworkResult > 0) { // 2. 更新订单状态为售后处理中 (状态6) - com.ruoyi.system.domain.Order updateOrder = new com.ruoyi.system.domain.Order(); + Order updateOrder = new Order(); updateOrder.setId(order.getId()); updateOrder.setStatus(6L); // 售后处理中状态 - + int updateResult = orderService.updateOrder(updateOrder); - + if (updateResult > 0) { System.out.println("订单[" + order.getOrderId() + "]售后申请成功,售后记录ID:" + orderRework.getId()); return true; @@ -1183,7 +1391,7 @@ public class AppletControllerUtil { System.err.println("售后记录创建失败,订单ID:" + order.getId()); return false; } - + } catch (Exception e) { System.err.println("处理售后申请业务逻辑异常:" + e.getMessage()); return false; @@ -1194,92 +1402,92 @@ public class AppletControllerUtil { /** * 构建合作申请对象 - * + * * @param params 请求参数Map,包含合作申请的各个字段信息 - * @param uid 用户ID(可为null) - * @param uname 用户名称(可为null) + * @param uid 用户ID(可为null) + * @param uname 用户名称(可为null) * @return Cooperate对象,包含完整的合作申请信息 - * + *

* 功能说明: * - 从请求参数中提取合作申请信息并构建Cooperate对象 * - 设置默认状态为0(待处理) * - 为合作申请功能提供数据转换 */ - public static com.ruoyi.system.domain.Cooperate buildCooperateApplication(Map params, Long uid, String uname) { - com.ruoyi.system.domain.Cooperate cooperate = new com.ruoyi.system.domain.Cooperate(); - + public static Cooperate buildCooperateApplication(Map params, Long uid, String uname) { + Cooperate cooperate = new Cooperate(); + // 设置用户信息(如果有的话) cooperate.setUid(uid); cooperate.setUname(uname); - + // 设置公司名称 if (params.get("company") != null) { cooperate.setCompany(params.get("company").toString().trim()); } - + // 设置联系人姓名 if (params.get("name") != null) { cooperate.setName(params.get("name").toString().trim()); } - + // 设置联系电话 if (params.get("phone") != null) { cooperate.setPhone(params.get("phone").toString().trim()); } - + // 设置联系地址 if (params.get("address") != null) { cooperate.setAddress(params.get("address").toString().trim()); } - + // 设置合作意向 if (params.get("info") != null) { cooperate.setInfo(params.get("info").toString().trim()); } - + // 设置默认状态:0-待处理,1-已联系,2-合作中,3-已拒绝 cooperate.setStatus(0L); - + return cooperate; } /** * 验证合作申请参数 - * + * * @param cooperate 需要验证的合作申请对象 * @return 验证错误信息,null表示验证通过 - * + *

* 功能说明: * - 验证合作申请对象的必填字段是否完整 * - 验证手机号格式是否正确 * - 为合作申请功能提供统一的参数验证 */ - public static String validateCooperateParams(com.ruoyi.system.domain.Cooperate cooperate) { + public static String validateCooperateParams(Cooperate cooperate) { if (cooperate.getCompany() == null || cooperate.getCompany().isEmpty()) { return "公司名称不能为空"; } - + if (cooperate.getName() == null || cooperate.getName().isEmpty()) { return "联系人姓名不能为空"; } - + if (cooperate.getPhone() == null || cooperate.getPhone().isEmpty()) { return "联系电话不能为空"; } - + // 验证手机号格式 if (!cooperate.getPhone().matches("^1[3-9]\\d{9}$")) { return "联系电话格式不正确"; } - + if (cooperate.getAddress() == null || cooperate.getAddress().isEmpty()) { return "联系地址不能为空"; } - + if (cooperate.getInfo() == null || cooperate.getInfo().isEmpty()) { return "合作意向不能为空"; } - + return null; // 验证通过 } @@ -1290,12 +1498,12 @@ public class AppletControllerUtil { * * @param paymentInfo 支付信息Map,包含订单号、交易号、金额等 * @param isPayFor 是否为代付订单,true=代付订单,false=普通订单 - * - * 功能说明: - * - 根据订单类型执行不同的支付成功后处理逻辑 - * - 普通订单:更新订单状态、发送通知、处理库存等 - * - 代付订单:处理代付逻辑、给被代付人转账等 - * - 为微信支付回调提供业务处理支持 + *

+ * 功能说明: + * - 根据订单类型执行不同的支付成功后处理逻辑 + * - 普通订单:更新订单状态、发送通知、处理库存等 + * - 代付订单:处理代付逻辑、给被代付人转账等 + * - 为微信支付回调提供业务处理支持 */ public static void handlePaymentSuccess(Map paymentInfo, boolean isPayFor) { try { @@ -1328,21 +1536,21 @@ public class AppletControllerUtil { /** * 构建积分订单列表数据 - * - * @param integralOrderList 积分订单列表 + * + * @param integralOrderList 积分订单列表 * @param integralProductService 积分商品服务 * @return 格式化的订单列表 */ - public static java.util.List> buildIntegralOrderList( - java.util.List integralOrderList, - com.ruoyi.system.service.IIntegralProductService integralProductService) { - - java.util.List> formattedOrderList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - for (com.ruoyi.system.domain.IntegralOrder order : integralOrderList) { - java.util.Map orderData = new java.util.HashMap<>(); - + public static List> buildIntegralOrderList( + List integralOrderList, + IIntegralProductService integralProductService) { + + List> formattedOrderList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (IntegralOrder order : integralOrderList) { + Map orderData = new HashMap<>(); + // 基础订单信息 orderData.put("id", order.getId()); orderData.put("order_id", order.getOrderId()); @@ -1359,38 +1567,38 @@ public class AppletControllerUtil { orderData.put("delivery_id", order.getDeliveryId()); orderData.put("delivery_num", order.getDeliveryNum()); orderData.put("mark", order.getMark()); - + // 格式化时间字段 orderData.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); orderData.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); // 添加商品信息 orderData.put("product", buildIntegralProductInfo(order.getProductId(), integralProductService)); - + formattedOrderList.add(orderData); } - + return formattedOrderList; } /** * 构建积分商品信息 - * - * @param productId 商品ID + * + * @param productId 商品ID * @param integralProductService 积分商品服务 * @return 商品信息Map */ - public static java.util.Map buildIntegralProductInfo(Long productId, - com.ruoyi.system.service.IIntegralProductService integralProductService) { - + public static Map buildIntegralProductInfo(Long productId, + IIntegralProductService integralProductService) { + if (productId == null) { return null; } - + try { - com.ruoyi.system.domain.IntegralProduct product = integralProductService.selectIntegralProductById(productId); + IntegralProduct product = integralProductService.selectIntegralProductById(productId); if (product != null) { - java.util.Map productData = new java.util.HashMap<>(); + Map productData = new HashMap<>(); productData.put("id", product.getId()); productData.put("title", product.getTitle()); productData.put("image", buildImageUrl(product.getImage())); @@ -1402,24 +1610,24 @@ public class AppletControllerUtil { } catch (Exception e) { System.err.println("查询积分商品信息异常:" + e.getMessage()); } - + return null; } /** * 构建积分日志列表数据 - * + * * @param integralLogList 积分日志列表 * @return 格式化的日志列表 */ - public static java.util.List> buildIntegralLogList( - java.util.List integralLogList) { - - java.util.List> formattedLogList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - for (com.ruoyi.system.domain.IntegralLog log : integralLogList) { - java.util.Map logData = new java.util.HashMap<>(); + public static List> buildIntegralLogList( + List integralLogList) { + + List> formattedLogList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (IntegralLog log : integralLogList) { + Map logData = new HashMap<>(); logData.put("id", log.getId()); logData.put("order_id", log.getOrderId()); logData.put("title", log.getTitle()); @@ -1427,34 +1635,37 @@ public class AppletControllerUtil { logData.put("uid", log.getUid()); logData.put("type", log.getType()); logData.put("num", log.getNum()); - + // 格式化时间字段 logData.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); logData.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); - + formattedLogList.add(logData); } - + return formattedLogList; } /** * 构建优惠券列表数据 - * - * @param couponUserList 优惠券用户列表 + * + * @param couponUserList 优惠券用户列表 * @param serviceCateService 服务分类服务 * @return 格式化的优惠券列表 */ - public static java.util.List> buildCouponUserList( - java.util.List couponUserList, - com.ruoyi.system.service.IServiceCateService serviceCateService) { - - java.util.List> resultList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static List> buildCouponUserList( + List couponUserList, + IServiceCateService serviceCateService, IServiceGoodsService serviceGoodsService, String productId, BigDecimal totalPrice) { - for (com.ruoyi.system.domain.CouponUser couponUser : couponUserList) { - java.util.Map couponData = new java.util.HashMap<>(); - + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (CouponUser couponUser : couponUserList) { + Map couponData = new HashMap<>(); + ServiceGoods serviceGoods = null; + if (couponUser.getProductId() != null && couponUser.getProductId() > 0) { + serviceGoods=serviceGoodsService.selectServiceGoodsById(couponUser.getProductId()); + } // 基础字段 couponData.put("id", couponUser.getId()); couponData.put("uid", couponUser.getUid()); @@ -1471,7 +1682,7 @@ public class AppletControllerUtil { // 时间字段格式化 if (couponUser.getAddTime() != null) { - java.util.Date addTime = new java.util.Date(couponUser.getAddTime() * 1000L); + Date addTime = new Date(couponUser.getAddTime() * 1000L); couponData.put("add_time", sdf.format(addTime)); } else { couponData.put("add_time", null); @@ -1481,21 +1692,57 @@ public class AppletControllerUtil { couponData.put("updated_at", couponUser.getUpdatedAt() != null ? sdf.format(couponUser.getUpdatedAt()) : null); // 添加 is_used 字段 - boolean isUsed = couponUser.getStatus() != null && couponUser.getStatus() == 2L; - couponData.put("is_used", isUsed); + boolean isUsed = true; + // 添加 suit_title 字段 String suitTitle = ""; if (couponUser.getCateId() != null && couponUser.getCateId() > 0) { try { - com.ruoyi.system.domain.ServiceCate serviceCate = serviceCateService.selectServiceCateById(couponUser.getCateId()); + ServiceCate serviceCate = serviceCateService.selectServiceCateById(couponUser.getCateId()); if (serviceCate != null && serviceCate.getTitle() != null) { suitTitle = serviceCate.getTitle(); } } catch (Exception e) { System.err.println("查询服务分类异常:" + e.getMessage()); } + if (serviceGoods != null && Objects.equals(serviceGoods.getCateId(), couponUser.getCateId())) { + isUsed=false; + } + if (totalPrice!=null){ + if (totalPrice.compareTo(new BigDecimal(couponUser.getMinPrice()))>0){ + isUsed=false; + } + } + } + if (couponUser.getProductId() != null && couponUser.getProductId() > 0) { + try { + serviceGoods = serviceGoodsService.selectServiceGoodsById(couponUser.getProductId()); + if (serviceGoods != null && serviceGoods.getTitle() != null) { + suitTitle = serviceGoods.getTitle(); + } + } catch (Exception e) { + System.err.println("查询服务分类异常:" + e.getMessage()); + } + if (serviceGoods != null && Objects.equals(serviceGoods.getId(),productId)) { + isUsed=false; + } + if (totalPrice!=null){ + if (totalPrice.compareTo(new BigDecimal(couponUser.getMinPrice()))>0){ + isUsed=false; + } + } + + } + if (couponUser.getReceiveType().equals("1")){ + if (totalPrice!=null){ + if (totalPrice.compareTo(new BigDecimal(couponUser.getMinPrice()))>0){ + isUsed=false; + } + } + } + couponData.put("is_used", isUsed); couponData.put("suit_title", suitTitle); // 添加 tag 字段 @@ -1524,61 +1771,130 @@ public class AppletControllerUtil { return resultList; } + + /** + * 构建优惠券列表数据 + * + * @return 格式化的优惠券列表 + */ + public static List> buildCouponDataList(List couponsList, IServiceCateService serviceCateService, IServiceGoodsService serviceGoodsService) { + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (Coupons coupons : couponsList) { + Map couponData = new HashMap<>(); + couponData.put("id", coupons.getId()); + couponData.put("title", coupons.getId()); + couponData.put("price", coupons.getPrice()); + couponData.put("min_price", coupons.getMinPrice()); + couponData.put("start_time", coupons.getStartTime()); + couponData.put("end_time", coupons.getEndTime()); + couponData.put("count", coupons.getCount()); + couponData.put("is_permanent", coupons.getIsPermanent()); + couponData.put("status", coupons.getStatus()); + couponData.put("coupon_time", coupons.getCouponTime()); + couponData.put("product_id", coupons.getProductId()); + couponData.put("type", coupons.getType()); + couponData.put("receive_type", coupons.getReceiveType()); + couponData.put("sort", coupons.getSort()); + couponData.put("cate_id", coupons.getCateId()); + couponData.put("user_ids", coupons.getUserIds()); + couponData.put("created_at", coupons.getCreatedAt() != null ? sdf.format(coupons.getCreatedAt()) : null); + couponData.put("updated_at", coupons.getCreatedAt() != null ? sdf.format(coupons.getCreatedAt()) : null); + couponData.put("deleted_at", coupons.getCreatedAt() != null ? sdf.format(coupons.getCreatedAt()) : null); + couponData.put("cate", coupons.getId()); + couponData.put("product", coupons.getId()); + if (coupons.getCateId()!=null){ + JSONObject cate = new JSONObject(); + ServiceCate serviceCate = serviceCateService.selectServiceCateById(coupons.getCateId()); + if (serviceCate!=null){ + cate.put("id", serviceCate.getId()); + cate.put("title", serviceCate.getTitle()); + couponData.put("cate", cate); + } + } + if (coupons.getProductId()!=null){ + JSONObject product = new JSONObject(); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(coupons.getProductId()); + if (serviceGoods != null) { + product.put("id", serviceGoods.getId()); + product.put("title", serviceGoods.getTitle()); + couponData.put("product", product); + } + } + // 添加 tag 字段 + String tag = ""; + if (coupons.getReceiveType() != null) { + String receiveType = String.valueOf(coupons.getReceiveType()); + tag = switch (receiveType) { + case "1" -> "通用券"; + case "2" -> "品类券"; + case "3" -> "商品券"; + default -> "优惠券"; + }; + } + couponData.put("suit_title", tag); + + resultList.add(couponData); + } + return resultList; + } + + /** * 构建积分订单日志列表 - * - * @param orderId 订单ID + * + * @param orderId 订单ID * @param integralOrderLogService 积分订单日志服务 * @return 格式化的日志列表 */ - public static java.util.List> buildIntegralOrderLogList(Long orderId, - com.ruoyi.system.service.IIntegralOrderLogService integralOrderLogService) { - - java.util.List> logList = new java.util.ArrayList<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - + public static List> buildIntegralOrderLogList(Long orderId, + IIntegralOrderLogService integralOrderLogService) { + + List> logList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + try { - com.ruoyi.system.domain.IntegralOrderLog logQuery = new com.ruoyi.system.domain.IntegralOrderLog(); + IntegralOrderLog logQuery = new IntegralOrderLog(); logQuery.setOid(orderId); - java.util.List orderLogs = integralOrderLogService.selectIntegralOrderLogList(logQuery); - - for (com.ruoyi.system.domain.IntegralOrderLog log : orderLogs) { - java.util.Map logData = new java.util.HashMap<>(); + List orderLogs = integralOrderLogService.selectIntegralOrderLogList(logQuery); + + for (IntegralOrderLog log : orderLogs) { + Map logData = new HashMap<>(); logData.put("id", log.getId()); logData.put("oid", log.getOid()); logData.put("order_id", log.getOrderId()); logData.put("title", log.getTitle()); logData.put("content", log.getContent()); logData.put("type", log.getType()); - + logData.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); logData.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); - + logList.add(logData); } } catch (Exception e) { System.err.println("查询订单日志异常:" + e.getMessage()); } - + return logList; } /** * 构建积分订单详情数据 - * - * @param integralOrder 积分订单 - * @param integralProductService 积分商品服务 + * + * @param integralOrder 积分订单 + * @param integralProductService 积分商品服务 * @param integralOrderLogService 积分订单日志服务 * @return 格式化的订单详情 */ - public static java.util.Map buildIntegralOrderDetail( - com.ruoyi.system.domain.IntegralOrder integralOrder, - com.ruoyi.system.service.IIntegralProductService integralProductService, - com.ruoyi.system.service.IIntegralOrderLogService integralOrderLogService) { - - java.util.Map orderData = new java.util.HashMap<>(); - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - + public static Map buildIntegralOrderDetail( + IntegralOrder integralOrder, + IIntegralProductService integralProductService, + IIntegralOrderLogService integralOrderLogService) { + + Map orderData = new HashMap<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 基础订单信息 orderData.put("id", integralOrder.getId()); orderData.put("order_id", integralOrder.getOrderId()); @@ -1595,7 +1911,7 @@ public class AppletControllerUtil { orderData.put("delivery_id", integralOrder.getDeliveryId()); orderData.put("delivery_num", integralOrder.getDeliveryNum()); orderData.put("mark", integralOrder.getMark()); - + // 格式化时间字段 orderData.put("created_at", integralOrder.getCreatedAt() != null ? sdf.format(integralOrder.getCreatedAt()) : null); orderData.put("updated_at", integralOrder.getUpdatedAt() != null ? sdf.format(integralOrder.getUpdatedAt()) : null); @@ -1603,9 +1919,9 @@ public class AppletControllerUtil { // 添加商品信息 if (integralOrder.getProductId() != null) { try { - com.ruoyi.system.domain.IntegralProduct product = integralProductService.selectIntegralProductById(integralOrder.getProductId()); + IntegralProduct product = integralProductService.selectIntegralProductById(integralOrder.getProductId()); if (product != null) { - java.util.Map productData = new java.util.HashMap<>(); + Map productData = new HashMap<>(); productData.put("id", product.getId()); productData.put("title", product.getTitle()); productData.put("image", buildImageUrl(product.getImage())); @@ -1631,12 +1947,12 @@ public class AppletControllerUtil { /** * 构建用户数据信息 - * + * * @param user 用户对象 * @return 格式化的用户数据 */ - public static java.util.Map buildUserDataInfo(com.ruoyi.system.domain.Users user) { - java.util.Map userData = new java.util.HashMap<>(); + public static Map buildUserDataInfo(Users user) { + Map userData = new HashMap<>(); userData.put("id", user.getId()); userData.put("name", user.getName()); userData.put("nickname", user.getNickname()); @@ -1672,18 +1988,18 @@ public class AppletControllerUtil { /** * 构建分页数据响应 - * - * @param pageInfo 分页信息 + * + * @param pageInfo 分页信息 * @param formattedData 格式化的数据列表 - * @param baseUrl 基础URL + * @param baseUrl 基础URL * @return 分页响应数据 */ - public static java.util.Map buildPaginationResponse( - com.github.pagehelper.PageInfo pageInfo, - java.util.List> formattedData, + public static Map buildPaginationResponse( + PageInfo pageInfo, + List> formattedData, String baseUrl) { - - java.util.Map responseData = new java.util.HashMap<>(); + + Map responseData = new HashMap<>(); responseData.put("current_page", pageInfo.getPageNum()); responseData.put("data", formattedData); responseData.put("from", pageInfo.getStartRow()); @@ -1694,20 +2010,20 @@ public class AppletControllerUtil { // 构建分页链接信息 responseData.put("first_page_url", baseUrl + "?page=1"); - - java.util.List> links = new java.util.ArrayList<>(); - + + List> links = new ArrayList<>(); + // Previous link - java.util.Map prevLink = new java.util.HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); prevLink.put("label", "« Previous"); prevLink.put("active", false); links.add(prevLink); // Page numbers for (int i = 1; i <= pageInfo.getPages(); i++) { - java.util.Map pageLink = new java.util.HashMap<>(); + Map pageLink = new HashMap<>(); pageLink.put("url", baseUrl + "?page=" + i); pageLink.put("label", String.valueOf(i)); pageLink.put("active", i == pageInfo.getPageNum()); @@ -1715,19 +2031,19 @@ public class AppletControllerUtil { } // Next link - java.util.Map nextLink = new java.util.HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); nextLink.put("label", "Next »"); nextLink.put("active", false); links.add(nextLink); responseData.put("links", links); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); responseData.put("path", baseUrl); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); return responseData; @@ -1735,81 +2051,81 @@ public class AppletControllerUtil { /** * 过滤优惠券列表(按价格) - * + * * @param couponUserList 优惠券列表 - * @param price 价格筛选条件 + * @param price 价格筛选条件 * @return 过滤后的优惠券列表 */ - public static java.util.List filterCouponsByPrice( - java.util.List couponUserList, Integer price) { - + public static List filterCouponsByPrice( + List couponUserList, Integer price) { + if (price == null || price <= 0) { return couponUserList; } - - java.util.List filteredList = new java.util.ArrayList<>(); - for (com.ruoyi.system.domain.CouponUser coupon : couponUserList) { + + List filteredList = new ArrayList<>(); + for (CouponUser coupon : couponUserList) { if (coupon.getMinPrice() == null || coupon.getMinPrice() >= price) { filteredList.add(coupon); } } - + return filteredList; } /** * 构建积分商品列表数据 - * + * * @param integralProductList 积分商品列表 * @return 格式化的积分商品列表 */ - public static java.util.List> buildIntegralProductList( - java.util.List integralProductList) { - - java.util.List> formattedProductList = new java.util.ArrayList<>(); - - for (com.ruoyi.system.domain.IntegralProduct product : integralProductList) { - java.util.Map productData = new java.util.HashMap<>(); - + public static List> buildIntegralProductList( + List integralProductList) { + + List> formattedProductList = new ArrayList<>(); + + for (IntegralProduct product : integralProductList) { + Map productData = new HashMap<>(); + productData.put("id", product.getId()); productData.put("title", product.getTitle()); productData.put("image", buildImageUrl(product.getImage())); productData.put("num", product.getNum()); productData.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); productData.put("sales", product.getSales() != null ? product.getSales() : 0); - productData.put("tags", new java.util.ArrayList<>()); // 默认空的tags数组 - + productData.put("tags", new ArrayList<>()); // 默认空的tags数组 + formattedProductList.add(productData); } - + return formattedProductList; } /** * 构建积分商品详情数据 - * + * * @param integralProduct 积分商品对象 * @return 格式化的积分商品详情 */ - public static java.util.Map buildIntegralProductDetail( - com.ruoyi.system.domain.IntegralProduct integralProduct) { - - java.util.Map productDetail = new java.util.HashMap<>(); - + public static Map buildIntegralProductDetail( + IntegralProduct integralProduct) { + + Map productDetail = new HashMap<>(); + productDetail.put("id", integralProduct.getId()); productDetail.put("title", integralProduct.getTitle()); productDetail.put("cate_id", integralProduct.getCateId()); productDetail.put("contetnt", integralProduct.getContetnt() != null ? integralProduct.getContetnt() : ""); - productDetail.put("created_at", integralProduct.getCreatedAt() != null ? - new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(integralProduct.getCreatedAt()) : null); + productDetail.put("created_at", integralProduct.getCreatedAt() != null ? + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(integralProduct.getCreatedAt()) : null); productDetail.put("image", buildImageUrl(integralProduct.getImage())); - + // 处理轮播图数组 - java.util.List imagesList = new java.util.ArrayList<>(); + List imagesList = new ArrayList<>(); if (integralProduct.getImages() != null && !integralProduct.getImages().trim().isEmpty()) { try { // 尝试解析JSON数组 - com.alibaba.fastjson2.JSONArray imagesArray = com.alibaba.fastjson2.JSONArray.parseArray(integralProduct.getImages()); + JSONArray imagesArray = JSONArray.parseArray(integralProduct.getImages()); for (Object imgObj : imagesArray) { imagesList.add(buildImageUrl(imgObj.toString())); } @@ -1824,17 +2140,17 @@ public class AppletControllerUtil { } } productDetail.put("images", imagesList); - + productDetail.put("num", integralProduct.getNum()); productDetail.put("price", integralProduct.getPrice() != null ? integralProduct.getPrice().toString() : "0.00"); productDetail.put("sales", integralProduct.getSales() != null ? integralProduct.getSales() : 0); - + // 处理SKU信息 - java.util.Map skuInfo = new java.util.HashMap<>(); + Map skuInfo = new HashMap<>(); if (integralProduct.getSku() != null && !integralProduct.getSku().trim().isEmpty()) { try { // 尝试解析SKU的JSON格式 - com.alibaba.fastjson2.JSONObject skuJson = com.alibaba.fastjson2.JSONObject.parseObject(integralProduct.getSku()); + JSONObject skuJson = JSONObject.parseObject(integralProduct.getSku()); skuInfo.putAll(skuJson); } catch (Exception e) { // 如果不是JSON格式,设置为字符串 @@ -1843,18 +2159,18 @@ public class AppletControllerUtil { } skuInfo.put("type", integralProduct.getSkuType() != null && integralProduct.getSkuType() == 1 ? "single" : "multiple"); productDetail.put("sku", skuInfo); - + productDetail.put("sku_type", integralProduct.getSkuType()); productDetail.put("sort", integralProduct.getSort()); productDetail.put("status", integralProduct.getStatus()); productDetail.put("stock", integralProduct.getStock()); - + // 处理标签 - java.util.List tagsList = new java.util.ArrayList<>(); + List tagsList = new ArrayList<>(); if (integralProduct.getTags() != null && !integralProduct.getTags().trim().isEmpty()) { try { // 尝试解析JSON数组 - com.alibaba.fastjson2.JSONArray tagsArray = com.alibaba.fastjson2.JSONArray.parseArray(integralProduct.getTags()); + JSONArray tagsArray = JSONArray.parseArray(integralProduct.getTags()); for (Object tagObj : tagsArray) { tagsList.add(tagObj.toString()); } @@ -1869,73 +2185,73 @@ public class AppletControllerUtil { } } productDetail.put("tags", tagsList); - - productDetail.put("updated_at", integralProduct.getUpdatedAt() != null ? - new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(integralProduct.getUpdatedAt()) : null); - + + productDetail.put("updated_at", integralProduct.getUpdatedAt() != null ? + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(integralProduct.getUpdatedAt()) : null); + return productDetail; } /** * 构建小程序通知订阅状态数据 - * + * * @param user 用户对象 * @return 小程序通知订阅状态数据 */ - public static java.util.Map buildMiniProgramNotificationStatus(com.ruoyi.system.domain.Users user) { - java.util.Map notificationStatus = new java.util.HashMap<>(); - + public static Map buildMiniProgramNotificationStatus(Users user) { + Map notificationStatus = new HashMap<>(); + // 定义三个消息模板ID String integralTemplate = "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"; // 积分相关通知 String successTemplate = "YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8"; // 成功通知 String workerTemplate = "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"; // 工作人员通知 - + // 构建不同类型的通知订阅状态 - java.util.List integralList = new java.util.ArrayList<>(); + List integralList = new ArrayList<>(); integralList.add(integralTemplate); notificationStatus.put("integral", integralList); - - java.util.List makeSuccessList = new java.util.ArrayList<>(); + + List makeSuccessList = new ArrayList<>(); makeSuccessList.add(successTemplate); makeSuccessList.add(workerTemplate); notificationStatus.put("make_success", makeSuccessList); - + notificationStatus.put("is", workerTemplate); - - java.util.List newSuccessList = new java.util.ArrayList<>(); + + List newSuccessList = new ArrayList<>(); newSuccessList.add(integralTemplate); notificationStatus.put("new_success", newSuccessList); - + notificationStatus.put("s", integralTemplate); - - java.util.List workersList = new java.util.ArrayList<>(); + + List workersList = new ArrayList<>(); workersList.add(workerTemplate); notificationStatus.put("workers", workersList); - + notificationStatus.put("a", workerTemplate); - + return notificationStatus; } /** * 验证积分兑换参数 - * + * * @param params 请求参数 * @return 验证结果,null表示验证通过,否则返回错误信息 */ - public static String validateIntegralExchangeParams(java.util.Map params) { + public static String validateIntegralExchangeParams(Map params) { if (params.get("id") == null) { return "积分商品ID不能为空"; } - + if (params.get("address_id") == null) { return "收货地址ID不能为空"; } - + if (params.get("num") == null) { return "购买数量不能为空"; } - + try { Long id = Long.valueOf(params.get("id").toString()); if (id <= 0) { @@ -1944,7 +2260,7 @@ public class AppletControllerUtil { } catch (NumberFormatException e) { return "积分商品ID格式错误"; } - + try { Long addressId = Long.valueOf(params.get("address_id").toString()); if (addressId <= 0) { @@ -1953,7 +2269,7 @@ public class AppletControllerUtil { } catch (NumberFormatException e) { return "收货地址ID格式错误"; } - + try { Integer num = Integer.valueOf(params.get("num").toString()); if (num <= 0) { @@ -1965,18 +2281,18 @@ public class AppletControllerUtil { } catch (NumberFormatException e) { return "购买数量格式错误"; } - + return null; } /** * 检查用户积分是否足够 - * - * @param user 用户信息 + * + * @param user 用户信息 * @param totalIntegral 需要的总积分 * @return 是否足够 */ - public static boolean checkUserIntegralSufficient(com.ruoyi.system.domain.Users user, Long totalIntegral) { + public static boolean checkUserIntegralSufficient(Users user, Long totalIntegral) { if (user.getIntegral() == null) { return false; } @@ -1985,12 +2301,12 @@ public class AppletControllerUtil { /** * 生成积分订单号 - * + * * @return 订单号 */ public static String generateIntegralOrderId() { - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMddHHmmss"); - String timestamp = sdf.format(new java.util.Date()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String timestamp = sdf.format(new Date()); // 添加4位随机数 int random = (int) (Math.random() * 9000) + 1000; return "JF" + timestamp + random; @@ -1998,99 +2314,99 @@ public class AppletControllerUtil { /** * 构建积分订单对象 - * - * @param params 请求参数 - * @param user 用户信息 + * + * @param params 请求参数 + * @param user 用户信息 * @param product 积分商品信息 * @param address 收货地址信息 * @return 积分订单对象 */ - public static com.ruoyi.system.domain.IntegralOrder buildIntegralOrder( - java.util.Map params, - com.ruoyi.system.domain.Users user, - com.ruoyi.system.domain.IntegralProduct product, - com.ruoyi.system.domain.UserAddress address) { - - com.ruoyi.system.domain.IntegralOrder order = new com.ruoyi.system.domain.IntegralOrder(); - + public static IntegralOrder buildIntegralOrder( + Map params, + Users user, + IntegralProduct product, + UserAddress address) { + + IntegralOrder order = new IntegralOrder(); + // 订单基本信息 order.setOrderId(generateIntegralOrderId()); order.setUid(user.getId()); order.setUname(user.getNickname() != null ? user.getNickname() : user.getPhone()); - + // 收货信息 order.setUserName(address.getName()); order.setUserPhone(address.getPhone()); - order.setUserAddress(address.getAddressName() + " " + - (address.getInfo() != null ? address.getInfo() : "")); - + order.setUserAddress(address.getAddressName() + " " + + (address.getInfo() != null ? address.getInfo() : "")); + // 商品信息 order.setProductId(product.getId()); - + // 数量和价格 Integer num = Integer.valueOf(params.get("num").toString()); order.setNum(num.longValue()); order.setPrice(product.getNum()); // 单价积分 order.setTotalPrice(product.getNum() * num); // 总积分 - + // SKU信息 String sku = params.get("sku") != null ? params.get("sku").toString() : ""; order.setSku(sku); - + // 备注 String mark = params.get("mark") != null ? params.get("mark").toString() : ""; order.setMark(mark); - + // 订单状态:1-待发货 order.setStatus("1"); - + // 时间 - java.util.Date now = new java.util.Date(); + Date now = new Date(); order.setCreatedAt(now); order.setUpdatedAt(now); - + return order; } /** * 构建积分日志对象 - * - * @param user 用户信息 + * + * @param user 用户信息 * @param integralAmount 积分数量(负数表示扣减) - * @param orderId 订单号 - * @param productTitle 商品名称 + * @param orderId 订单号 + * @param productTitle 商品名称 * @return 积分日志对象 */ - public static com.ruoyi.system.domain.IntegralLog buildIntegralLog( - com.ruoyi.system.domain.Users user, + public static IntegralLog buildIntegralLog( + Users user, Long integralAmount, String orderId, String productTitle) { - - com.ruoyi.system.domain.IntegralLog log = new com.ruoyi.system.domain.IntegralLog(); - + + IntegralLog log = new IntegralLog(); + log.setUid(user.getId()); log.setUname(user.getNickname() != null ? user.getNickname() : user.getPhone()); log.setNum(integralAmount); // 使用num字段存储积分值 log.setTitle("积分商品兑换"); log.setMark("兑换商品:" + productTitle + ",订单号:" + orderId); // 使用mark字段 log.setType(2L); // 类型:2-减少 - - java.util.Date now = new java.util.Date(); + + Date now = new Date(); log.setCreatedAt(now); log.setUpdatedAt(now); - + return log; } /** * 构建服务订单详情数据 - * - * @param order 订单信息 - * @param orderLogService 订单日志服务 + * + * @param order 订单信息 + * @param orderLogService 订单日志服务 * @param serviceGoodsService 商品服务 * @return 完整的订单详情数据 - * + *

* 功能说明: * - 整合订单基本信息、订单日志和商品信息 * - 格式化时间字段 @@ -2098,13 +2414,13 @@ public class AppletControllerUtil { * - 添加商品信息(标题、图标、价格等) * - 返回完全符合前端要求的数据结构 */ - public static java.util.Map buildServiceOrderDetail( - com.ruoyi.system.domain.Order order, - com.ruoyi.system.service.IOrderLogService orderLogService, - com.ruoyi.system.service.IServiceGoodsService serviceGoodsService) { - - java.util.Map orderDetail = new java.util.HashMap<>(); - + public static Map buildServiceOrderDetail( + Order order, + IOrderLogService orderLogService, + IServiceGoodsService serviceGoodsService) { + + Map orderDetail = new HashMap<>(); + try { // 1. 映射订单基本信息 orderDetail.put("id", order.getId()); @@ -2122,14 +2438,14 @@ public class AppletControllerUtil { orderDetail.put("make_time", AppletControllerUtil.timeStamp2Date(order)); orderDetail.put("make_hour", order.getMakeHour()); orderDetail.put("num", order.getNum()); - + // 2. 处理价格字段(转换为字符串格式) orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); orderDetail.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); orderDetail.put("service_price", order.getServicePrice() != null ? order.getServicePrice().toString() : null); orderDetail.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); orderDetail.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); - + // 3. 其他基本字段 orderDetail.put("coupon_id", order.getCouponId()); orderDetail.put("pay_time", order.getPayTime()); @@ -2154,41 +2470,41 @@ public class AppletControllerUtil { orderDetail.put("log_json", order.getLogJson()); orderDetail.put("json_status", order.getJsonStatus()); orderDetail.put("log_images", order.getLogImages()); - + // 4. 处理时间字段 - java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); orderDetail.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); orderDetail.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); orderDetail.put("deleted_at", order.getDeletedAt()); - + // 5. 查询并构建订单日志 - com.ruoyi.system.domain.OrderLog orderLogQuery = new com.ruoyi.system.domain.OrderLog(); + OrderLog orderLogQuery = new OrderLog(); orderLogQuery.setOid(order.getId()); - java.util.List orderLogList = orderLogService.selectOrderLogList(orderLogQuery); - - java.util.List> logArray = new java.util.ArrayList<>(); - for (com.ruoyi.system.domain.OrderLog orderLog : orderLogList) { - java.util.Map logItem = new java.util.HashMap<>(); - + List orderLogList = orderLogService.selectOrderLogList(orderLogQuery); + + List> logArray = new ArrayList<>(); + for (OrderLog orderLog : orderLogList) { + Map logItem = new HashMap<>(); + logItem.put("id", orderLog.getId()); logItem.put("oid", orderLog.getOid()); logItem.put("order_id", orderLog.getOrderId()); logItem.put("log_order_id", orderLog.getLogOrderId()); logItem.put("title", orderLog.getTitle()); logItem.put("type", orderLog.getType()); - + // 处理content字段(可能是JSON字符串) Object content = null; if (orderLog.getContent() != null && !orderLog.getContent().trim().isEmpty()) { try { - content = com.alibaba.fastjson2.JSONObject.parseObject(orderLog.getContent()); + content = JSONObject.parseObject(orderLog.getContent()); } catch (Exception e) { // 如果不是JSON格式,直接使用字符串 content = orderLog.getContent(); } } logItem.put("content", content); - + logItem.put("deposit", orderLog.getDeposit()); logItem.put("dep_paid", orderLog.getDepPaid()); logItem.put("dep_pay_time", orderLog.getDepPayTime()); @@ -2198,7 +2514,7 @@ public class AppletControllerUtil { // payTime是Long类型的时间戳,需要转换为Date后再格式化 if (orderLog.getPayTime() != null) { try { - java.util.Date payDate = new java.util.Date(orderLog.getPayTime() * 1000L); // 假设是秒级时间戳 + Date payDate = new Date(orderLog.getPayTime() * 1000L); // 假设是秒级时间戳 logItem.put("pay_time", dateFormat.format(payDate)); } catch (Exception e) { logItem.put("pay_time", "2025-06-10 17:40:58"); // 默认时间 @@ -2219,10 +2535,10 @@ public class AppletControllerUtil { logItem.put("created_at", orderLog.getCreatedAt() != null ? dateFormat.format(orderLog.getCreatedAt()) : null); logItem.put("updated_at", orderLog.getUpdatedAt() != null ? dateFormat.format(orderLog.getUpdatedAt()) : null); logItem.put("deleted_at", orderLog.getDeletedAt()); - + // 处理工人信息 if (orderLog.getWorkerId() != null) { - java.util.Map workerInfo = new java.util.HashMap<>(); + Map workerInfo = new HashMap<>(); workerInfo.put("id", orderLog.getWorkerId()); // 使用OrderLog中的workerName字段 workerInfo.put("name", orderLog.getWorkerName() != null ? orderLog.getWorkerName() : "工人姓名"); @@ -2232,16 +2548,16 @@ public class AppletControllerUtil { } else { logItem.put("worker", null); } - + logArray.add(logItem); } orderDetail.put("log", logArray); - + // 6. 查询并构建商品信息 if (order.getProductId() != null) { - com.ruoyi.system.domain.ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); if (serviceGoods != null) { - java.util.Map productInfo = new java.util.HashMap<>(); + Map productInfo = new HashMap<>(); productInfo.put("id", serviceGoods.getId()); productInfo.put("icon", buildImageUrl(serviceGoods.getIcon())); productInfo.put("info", serviceGoods.getInfo()); @@ -2256,12 +2572,12 @@ public class AppletControllerUtil { } else { orderDetail.put("product", null); } - + } catch (Exception e) { System.err.println("构建服务订单详情数据异常:" + e.getMessage()); e.printStackTrace(); } - + return orderDetail; } @@ -2269,30 +2585,30 @@ public class AppletControllerUtil { /** * 构建城市树状结构 - * + * * @param cityList 城市列表 * @return 树状结构的城市数据 */ - public static List> buildCityTree(List cityList) { + public static List> buildCityTree(List cityList) { // 转换为Map便于处理 Map> cityMap = new HashMap<>(); List> rootCities = new ArrayList<>(); - + // 第一遍:创建所有节点 - for (com.ruoyi.system.domain.DiyCity city : cityList) { + for (DiyCity city : cityList) { Map cityData = new HashMap<>(); cityData.put("id", city.getId()); cityData.put("title", city.getTitle()); cityData.put("pid", city.getParentId() != null ? city.getParentId() : 0); cityData.put("child", new ArrayList>()); - + cityMap.put(city.getId(), cityData); } - + // 第二遍:构建父子关系 - for (com.ruoyi.system.domain.DiyCity city : cityList) { + for (DiyCity city : cityList) { Map currentCity = cityMap.get(city.getId()); - + if (city.getParentId() == null || city.getParentId() == 0) { // 顶级城市 rootCities.add(currentCity); @@ -2306,14 +2622,14 @@ public class AppletControllerUtil { } } } - + return rootCities; } /** * 从完整URL中提取路径部分 - * - * @param fullUrl 完整URL + * + * @param fullUrl 完整URL * @param domainPrefix 域名前缀 * @return 路径部分 */ @@ -2326,37 +2642,37 @@ public class AppletControllerUtil { /** * 构建时间段列表 - * + * * @param day 预约日期 * @return 时间段列表 */ public static List> buildTimeSlotList(String day) { List> timeSlotList = new ArrayList<>(); - + // 预定义的时间段配置 String[] timeSlots = { - "8:00-10:00", - "10:00-12:00", - "14:00-16:00", - "16:00-18:00", - "18:00-20:00", - "20:00-22:00", - "22:00-24:00" + "8:00-10:00", + "10:00-12:00", + "14:00-16:00", + "16:00-18:00", + "18:00-20:00", + "20:00-22:00", + "22:00-24:00" }; // 为每个时间段构建数据 for (String timeSlot : timeSlots) { Map slotData = new HashMap<>(); - + // 判断时间段是否可用 boolean isAvailable = isTimeSlotAvailable(day, timeSlot); int residueNum = getResidueNumber(day, timeSlot); - + slotData.put("click", isAvailable); slotData.put("value", timeSlot); slotData.put("prove", isAvailable ? "可预约" : "已满"); slotData.put("residue_num", residueNum); - + timeSlotList.add(slotData); } @@ -2382,41 +2698,41 @@ public class AppletControllerUtil { // } Users worker = usersService.selectUsersById(2l); return worker; - } + } /** * 判断时间段是否可用 - * - * @param day 日期 + * + * @param day 日期 * @param timeSlot 时间段 * @return 是否可用 */ public static boolean isTimeSlotAvailable(String day, String timeSlot) { try { // 获取当前时间 - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); - java.util.Date appointmentDate = sdf.parse(day); - java.util.Date currentDate = new java.util.Date(); - + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date appointmentDate = sdf.parse(day); + Date currentDate = new Date(); + // 如果是今天,需要检查当前时间是否已过 if (isSameDay(appointmentDate, currentDate)) { - String currentTime = new java.text.SimpleDateFormat("HH:mm").format(new java.util.Date()); + String currentTime = new SimpleDateFormat("HH:mm").format(new Date()); String slotStartTime = timeSlot.split("-")[0]; - + // 如果当前时间已超过时间段开始时间,则不可预约 if (currentTime.compareTo(slotStartTime) > 0) { return false; } } - + // 模拟一些时间段已满的情况(实际应查询数据库) if ("22:00-24:00".equals(timeSlot)) { return false; // 假设深夜时段暂停服务 } - + return true; // 默认可预约 - + } catch (Exception e) { return true; // 异常时默认可用 } @@ -2424,8 +2740,8 @@ public class AppletControllerUtil { /** * 获取剩余预约数量 - * - * @param day 日期 + * + * @param day 日期 * @param timeSlot 时间段 * @return 剩余数量 */ @@ -2433,7 +2749,7 @@ public class AppletControllerUtil { if (!isTimeSlotAvailable(day, timeSlot)) { return 0; // 不可用时段剩余数量为0 } - + // 模拟不同时间段的剩余数量 switch (timeSlot) { case "8:00-10:00": @@ -2453,13 +2769,13 @@ public class AppletControllerUtil { /** * 验证日期格式是否正确 - * + * * @param dateStr 日期字符串 * @return 是否为有效格式 */ public static boolean isValidDateFormat(String dateStr) { try { - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); sdf.setLenient(false); // 严格模式 sdf.parse(dateStr); return true; @@ -2470,20 +2786,20 @@ public class AppletControllerUtil { /** * 判断日期是否为过去时间 - * + * * @param dateStr 日期字符串 * @return 是否为过去时间 */ public static boolean isPastDate(String dateStr) { try { - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); - java.util.Date appointmentDate = sdf.parse(dateStr); - java.util.Date currentDate = new java.util.Date(); - + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date appointmentDate = sdf.parse(dateStr); + Date currentDate = new Date(); + // 移除时间部分,只比较日期 String currentDateStr = sdf.format(currentDate); - java.util.Date currentDateOnly = sdf.parse(currentDateStr); - + Date currentDateOnly = sdf.parse(currentDateStr); + return appointmentDate.before(currentDateOnly); } catch (Exception e) { return false; @@ -2492,34 +2808,34 @@ public class AppletControllerUtil { /** * 判断两个日期是否为同一天 - * + * * @param date1 日期1 * @param date2 日期2 * @return 是否为同一天 */ - public static boolean isSameDay(java.util.Date date1, java.util.Date date2) { - java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd"); + public static boolean isSameDay(Date date1, Date date2) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date1).equals(sdf.format(date2)); } /** * 查找购物车中已存在的商品 - * - * @param userId 用户ID - * @param goodId 商品ID - * @param sku 商品规格 + * + * @param userId 用户ID + * @param goodId 商品ID + * @param sku 商品规格 * @param goodsCartService 购物车服务 * @return 购物车商品记录 */ - public static com.ruoyi.system.domain.GoodsCart findExistingCartItem(Long userId, Long goodId, String sku, - com.ruoyi.system.service.IGoodsCartService goodsCartService) { + public static GoodsCart findExistingCartItem(Long userId, Long goodId, String sku, + IGoodsCartService goodsCartService) { try { - com.ruoyi.system.domain.GoodsCart queryCart = new com.ruoyi.system.domain.GoodsCart(); + GoodsCart queryCart = new GoodsCart(); queryCart.setUid(userId); queryCart.setGoodId(goodId); queryCart.setSku(sku); - - List cartList = goodsCartService.selectGoodsCartList(queryCart); + + List cartList = goodsCartService.selectGoodsCartList(queryCart); return cartList.isEmpty() ? null : cartList.get(0); } catch (Exception e) { System.err.println("查询购物车商品异常:" + e.getMessage()); @@ -2529,33 +2845,33 @@ public class AppletControllerUtil { /** * 更新购物车商品数量 - * - * @param cartItem 购物车商品记录 - * @param serviceGoods 商品信息 + * + * @param cartItem 购物车商品记录 + * @param serviceGoods 商品信息 * @param goodsCartService 购物车服务 * @return 更新结果 */ - public static com.ruoyi.common.core.domain.AjaxResult updateCartItemQuantity( - com.ruoyi.system.domain.GoodsCart cartItem, - com.ruoyi.system.domain.ServiceGoods serviceGoods, - com.ruoyi.system.service.IGoodsCartService goodsCartService) { + public static AjaxResult updateCartItemQuantity( + GoodsCart cartItem, + ServiceGoods serviceGoods, + IGoodsCartService goodsCartService) { try { // 数量加1 Long newQuantity = (cartItem.getGoodNum() != null ? cartItem.getGoodNum() : 0L) + 1L; - + // 检查库存限制 if (serviceGoods.getStock() != null && newQuantity > serviceGoods.getStock()) { return appletWarning("购物车中该商品数量已达到库存上限"); } - + // 更新购物车记录 - com.ruoyi.system.domain.GoodsCart updateCart = new com.ruoyi.system.domain.GoodsCart(); + GoodsCart updateCart = new GoodsCart(); updateCart.setId(cartItem.getId()); updateCart.setGoodNum(newQuantity); - updateCart.setUpdatedAt(new java.util.Date()); - + updateCart.setUpdatedAt(new Date()); + int updateResult = goodsCartService.updateGoodsCart(updateCart); - + if (updateResult > 0) { return appletSuccess("商品数量已更新"); } else { @@ -2569,10 +2885,10 @@ public class AppletControllerUtil { /** * 新增购物车商品记录 - * - * @param user 用户信息 - * @param serviceGoods 商品信息 - * @param sku 商品规格 + * + * @param user 用户信息 + * @param serviceGoods 商品信息 + * @param sku 商品规格 * @param goodsCartService 购物车服务 * @return 添加结果 */ @@ -2583,17 +2899,17 @@ public class AppletControllerUtil { IGoodsCartService goodsCartService) { try { // 构建购物车记录 - com.ruoyi.system.domain.GoodsCart newCartItem = new com.ruoyi.system.domain.GoodsCart(); + GoodsCart newCartItem = new GoodsCart(); newCartItem.setUid(user.getId()); newCartItem.setGoodId(serviceGoods.getId()); newCartItem.setSku(sku); newCartItem.setGoodNum(1L); // 默认数量为1 - newCartItem.setCreatedAt(new java.util.Date()); - newCartItem.setUpdatedAt(new java.util.Date()); + newCartItem.setCreatedAt(new Date()); + newCartItem.setUpdatedAt(new Date()); // 插入购物车记录 int insertResult = goodsCartService.insertGoodsCart(newCartItem); - + if (insertResult > 0) { return appletSuccess("商品已添加到购物车"); } else { @@ -2607,17 +2923,17 @@ public class AppletControllerUtil { /** * 获取购物车商品详细信息 - * - * @param goodId 商品ID + * + * @param goodId 商品ID * @param serviceGoodsService 商品服务 * @return 商品详细信息 */ - public static Map getGoodDetailForCart(Long goodId, - com.ruoyi.system.service.IServiceGoodsService serviceGoodsService) { + public static Map getGoodDetailForCart(Long goodId, + IServiceGoodsService serviceGoodsService) { Map goodInfo = new HashMap<>(); - + try { - com.ruoyi.system.domain.ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); if (serviceGoods != null) { goodInfo.put("id", serviceGoods.getId()); goodInfo.put("title", serviceGoods.getTitle()); @@ -2653,19 +2969,19 @@ public class AppletControllerUtil { goodInfo.put("sku_type", 1); goodInfo.put("type", 1); } - + return goodInfo; } /** * 构建服务商品数据 - * + * * @param goods 商品信息 * @return 格式化的商品数据 */ - public static Map buildServiceGoodsData(com.ruoyi.system.domain.ServiceGoods goods) { + public static Map buildServiceGoodsData(ServiceGoods goods) { Map goodsData = new HashMap<>(); - + goodsData.put("id", goods.getId()); goodsData.put("title", goods.getTitle()); goodsData.put("icon", buildImageUrl(goods.getIcon())); @@ -2676,15 +2992,16 @@ public class AppletControllerUtil { goodsData.put("stock", goods.getStock() != null ? goods.getStock() : 0); goodsData.put("sub_title", goods.getSubTitle()); goodsData.put("type", goods.getType()); - + return goodsData; } /** * 构建分页响应结构,适用于小程序worker相关接口 + * * @param pageInfo PageInfo对象 * @param dataList 数据列表 - * @param baseUrl 分页url前缀 + * @param baseUrl 分页url前缀 * @return Map分页结构 */ public static Map buildPageResult(PageInfo pageInfo, List dataList, String baseUrl) { @@ -2730,6 +3047,7 @@ public class AppletControllerUtil { * 用于接收云信平台推送的语音通知结果,解析callId、result、message等字段。 * 该方法可直接作为Controller层的回调接口方法使用。 *

+ * * @param requestBody 云信平台推送的JSON字符串 * @return 标准响应结果 */ @@ -2737,7 +3055,7 @@ public class AppletControllerUtil { Map resultMap = new HashMap<>(); try { // 解析JSON请求体 - com.alibaba.fastjson2.JSONObject json = com.alibaba.fastjson2.JSONObject.parseObject(requestBody); + JSONObject json = JSONObject.parseObject(requestBody); String callId = json.getString("callId"); String result = json.getString("result"); String message = json.getString("message"); @@ -2757,6 +3075,7 @@ public class AppletControllerUtil { } return resultMap; } + //完成订单的初步创建之后开始进行派单和发送订阅,以及预约师傅的操作 public static Map creatOrderTheNext(String imageUrl) { Map imageData = new HashMap<>(); @@ -2770,23 +3089,24 @@ public class AppletControllerUtil { /** * 发送微信小程序订阅消息(自动获取accessToken) - * @param touser 接收者(用户)的openid + * + * @param touser 接收者(用户)的openid * @param templateId 订阅消息模板ID - * @param page 跳转页面路径(可选,可为null) - * @param data 模板内容(如{"thing1":{"value":"内容"}}) + * @param page 跳转页面路径(可选,可为null) + * @param data 模板内容(如{"thing1":{"value":"内容"}}) * @return 微信接口响应字符串(JSON格式) * @throws Exception 异常信息 - * - * 使用示例: - * Map data = new HashMap<>(); - * Map thing1 = new HashMap<>(); - * thing1.put("value", "测试内容"); - * data.put("thing1", thing1); - * String result = AppletControllerUtil.WXSendMsgUtil(openid, templateId, "pages/index/index", data); + *

+ * 使用示例: + * Map data = new HashMap<>(); + * Map thing1 = new HashMap<>(); + * thing1.put("value", "测试内容"); + * data.put("thing1", thing1); + * String result = AppletControllerUtil.WXSendMsgUtil(openid, templateId, "pages/index/index", data); */ public static String WXSendMsgUtil(String touser, String templateId, String page, Map data) throws Exception { // 1. 获取accessToken - String accessToken = com.ruoyi.system.ControllerUtil.WechatApiUtil.getAccessToken().get("access_token").toString(); + String accessToken = WechatApiUtil.getAccessToken().get("access_token").toString(); // 2. 微信订阅消息接口地址 String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; // 3. 组装请求参数 @@ -2797,22 +3117,22 @@ public class AppletControllerUtil { param.put("page", page); } param.put("data", data); - String body = com.alibaba.fastjson2.JSON.toJSONString(param); + String body = JSON.toJSONString(param); // 4. 发送POST请求 - java.net.HttpURLConnection conn = (java.net.HttpURLConnection) new java.net.URL(url).openConnection(); + HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setDoOutput(true); - try (java.io.OutputStream os = conn.getOutputStream()) { - os.write(body.getBytes(java.nio.charset.StandardCharsets.UTF_8)); + try (OutputStream os = conn.getOutputStream()) { + os.write(body.getBytes(StandardCharsets.UTF_8)); } // 5. 读取响应 - java.io.InputStream is = conn.getInputStream(); + InputStream is = conn.getInputStream(); StringBuilder sb = new StringBuilder(); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) != -1) { - sb.append(new String(buf, 0, len, java.nio.charset.StandardCharsets.UTF_8)); + sb.append(new String(buf, 0, len, StandardCharsets.UTF_8)); } is.close(); return sb.toString(); @@ -2820,16 +3140,16 @@ public class AppletControllerUtil { //时间转化,将int的时间戳转换为时间,这个方法用于订单详情里面的预约时间 - public static String timeStamp2Date(Order order) { + public static String timeStamp2Date(Order order) { // 定义日期格式化模式 - String formattedDate=""; + String formattedDate = ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");// 注意:Java的Date构 - if(order!=null){ - if (order.getMakeTime() != null){ + if (order != null) { + if (order.getMakeTime() != null) { // 将时间戳转换为Date对象 Date date = new Date((long) order.getMakeTime() * 1000); formattedDate = sdf.format(date); - if (order.getMakeHour() != null){ + if (order.getMakeHour() != null) { formattedDate += " " + order.getMakeHour(); } } @@ -2840,6 +3160,7 @@ public class AppletControllerUtil { /** * 生成自定义前缀+16位唯一数字码 * 例如:FEEB724145038871780 + * * @param prefix 前缀字母(可为null或空,自动生成4位大写字母) * @return 生成的码 */ @@ -2870,16 +3191,16 @@ public class AppletControllerUtil { String finalNumber = numberPart.substring(0, 16); return codePrefix + finalNumber; } - + /** * 构建type=2商品的响应数据(按照json.txt格式) - * + * * @param goods ServiceGoods商品对象 * @return 格式化的商品响应数据 */ public static Map buildType2ServiceGoodsResponse(ServiceGoods goods) { Map data = new HashMap<>(); - + // 基础信息 data.put("id", goods.getId()); data.put("title", goods.getTitle()); @@ -2904,27 +3225,27 @@ public class AppletControllerUtil { data.put("basic", parseBasicStringToArray(goods.getBasic())); data.put("margin", goods.getMargin() != null ? goods.getMargin().toString() : null); data.put("skill_ids", goods.getSkillIds()); - + // 处理图片数组 data.put("imgs", parseImagesStringToArray(goods.getImgs())); - + // 处理SKU数据 data.put("sku", parseSkuStringToObject(goods.getSku())); - + // 时间字段 data.put("created_at", formatDateToString(goods.getCreatedAt())); data.put("updated_at", formatDateToString(goods.getUpdatedAt())); data.put("deleted_at", goods.getDeletedAt() != null ? formatDateToString(goods.getDeletedAt()) : null); - + // 评论对象(预留) data.put("comment", null); - + return data; } - + /** * 解析图片字符串为数组(支持JSON和逗号分隔) - * + * * @param imgs 图片字符串 * @return 图片URL列表 */ @@ -2933,7 +3254,7 @@ public class AppletControllerUtil { if (imgs != null && !imgs.trim().isEmpty()) { try { // 尝试解析为JSON数组 - com.alibaba.fastjson2.JSONArray jsonArray = com.alibaba.fastjson2.JSONArray.parseArray(imgs); + JSONArray jsonArray = JSONArray.parseArray(imgs); for (int i = 0; i < jsonArray.size(); i++) { String img = jsonArray.getString(i); if (img != null && !img.trim().isEmpty()) { @@ -2952,10 +3273,10 @@ public class AppletControllerUtil { } return imageList; } - + /** * 解析基础现象字符串为数组 - * + * * @param basic 基础现象字符串 * @return 基础现象列表,如果为空则返回null */ @@ -2963,11 +3284,11 @@ public class AppletControllerUtil { if (basic == null || basic.trim().isEmpty()) { return null; } - + List basicList = new ArrayList<>(); try { // 尝试解析为JSON数组 - com.alibaba.fastjson2.JSONArray jsonArray = com.alibaba.fastjson2.JSONArray.parseArray(basic); + JSONArray jsonArray = JSONArray.parseArray(basic); for (int i = 0; i < jsonArray.size(); i++) { String item = jsonArray.getString(i); if (item != null && !item.trim().isEmpty()) { @@ -2985,10 +3306,10 @@ public class AppletControllerUtil { } return basicList.isEmpty() ? null : basicList; } - + /** * 解析SKU字符串为对象 - * + * * @param sku SKU字符串 * @return SKU对象,解析失败返回null */ @@ -2996,7 +3317,7 @@ public class AppletControllerUtil { if (sku == null || sku.trim().isEmpty()) { return null; } - + try { // 尝试解析为JSON对象 JSONObject skuJson = JSONObject.parseObject(sku); @@ -3006,13 +3327,13 @@ public class AppletControllerUtil { return null; } } - + /** * 将字符串转换为JSON对象(通用工具方法) - * + *

* 支持将JSON字符串转换为Map对象 * 如果字符串为空或解析失败,返回null - * + * * @param jsonString JSON字符串 * @return JSON对象,解析失败返回null */ @@ -3020,13 +3341,13 @@ public class AppletControllerUtil { if (jsonString == null || jsonString.trim().isEmpty()) { return null; } - + try { // 预处理字符串,移除可能的特殊字符 String cleanJsonString = cleanJsonString(jsonString); - + // 尝试解析为JSON对象 - JSONObject jsonObject = JSONObject.parseObject(cleanJsonString); + JSONObject jsonObject = JSONObject.parseObject(cleanJsonString); return jsonObject.toJavaObject(Map.class); } catch (Exception e) { // 解析失败,打印详细错误信息并返回null @@ -3034,10 +3355,10 @@ public class AppletControllerUtil { return null; } } - + /** * 清理JSON字符串,移除可能导致解析失败的字符 - * + * * @param jsonString 原始JSON字符串 * @return 清理后的JSON字符串 */ @@ -3045,30 +3366,30 @@ public class AppletControllerUtil { if (jsonString == null) { return null; } - + // 移除BOM字符 if (jsonString.startsWith("\uFEFF")) { jsonString = jsonString.substring(1); } - + // 去除首尾空白字符 jsonString = jsonString.trim(); - + // 如果不是以{或[开头,可能不是有效的JSON if (!jsonString.startsWith("{") && !jsonString.startsWith("[")) { return "{}"; // 返回空对象 } - + return jsonString; } - + /** * 将字符串转换为JSON对象(带默认值) - * + *

* 支持将JSON字符串转换为Map对象 * 如果字符串为空或解析失败,返回提供的默认值 - * - * @param jsonString JSON字符串 + * + * @param jsonString JSON字符串 * @param defaultValue 解析失败时的默认值 * @return JSON对象,解析失败返回默认值 */ @@ -3076,14 +3397,14 @@ public class AppletControllerUtil { Map result = parseStringToJson(jsonString); return result != null ? result : defaultValue; } - + /** * 格式化日期为字符串 - * + * * @param date 日期对象 * @return 格式化后的日期字符串,格式为 "yyyy-MM-dd HH:mm:ss" */ - public static String formatDateToString(java.util.Date date) { + public static String formatDateToString(Date date) { if (date == null) { return null; } @@ -3093,6 +3414,7 @@ public class AppletControllerUtil { /** * 处理SKU参数,确保以JSON字符串格式存储 + * * @param skuParam 前端传递的SKU参数 * @return JSON字符串格式的SKU */ @@ -3100,11 +3422,11 @@ public class AppletControllerUtil { if (skuParam == null) { return ""; } - + if (skuParam instanceof Map) { // 如果是Map对象,转换为JSON字符串 try { - return com.alibaba.fastjson2.JSON.toJSONString(skuParam); + return JSON.toJSONString(skuParam); } catch (Exception e) { System.err.println("SKU转换JSON失败:" + e.getMessage()); return skuParam.toString();