From 9f9fe430e3764f18dfe9129f19feefd63cb9f161 Mon Sep 17 00:00:00 2001 From: "925116093-qq.com" <925116093@qq.com> Date: Fri, 18 Jul 2025 18:06:06 +0800 Subject: [PATCH] 202507181805 --- .../controller/AppleMemberController.java | 8 + .../controller/AppleOrderController.java | 1546 +++++++++++++---- .../system/controller/AppletController.java | 304 +++- .../controller/ServiceGoodsController.java | 14 + .../controllerUtil/AppletControllerUtil.java | 57 +- .../system/controllerUtil/CartOrderUtil.java | 201 +++ .../system/controllerUtil/PayBeforeUtil.java | 338 ++++ .../system/domain/AppleDoMain/OrderApple.java | 20 +- .../com/ruoyi/system/domain/GoodsCart.java | 11 + .../com/ruoyi/system/domain/GoodsOrder.java | 27 + .../java/com/ruoyi/system/domain/Order.java | 12 + .../com/ruoyi/system/domain/ServiceGoods.java | 30 + .../mapper/system/GoodsOrderMapper.xml | 10 +- .../resources/mapper/system/OrderMapper.xml | 19 +- .../mapper/system/ServiceGoodsMapper.xml | 16 +- ruoyi-ui/src/api/system/ServiceGoods.js | 11 + .../src/views/system/GoodsShangPin/index.vue | 81 +- 17 files changed, 2372 insertions(+), 333 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CartOrderUtil.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java index a79809b..1fc5757 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleMemberController.java @@ -786,6 +786,7 @@ public class AppleMemberController extends BaseController { // 7. 处理报价 UserDemandQuotation quoteRecord; + boolean isFirstQuote = false; if (existingQuotes != null && !existingQuotes.isEmpty()) { // 已有报价,更新 quoteRecord = existingQuotes.getFirst(); @@ -805,6 +806,13 @@ public class AppleMemberController extends BaseController { quoteRecord.setWorkerimage(user.getAvatar()); quoteRecord.setCreateTime(new Date()); userDemandQuotationService.insertUserDemandQuotation(quoteRecord); + isFirstQuote = true; + } + + // 8. 如果是第一次报价,更新订单状态为待选择(12) + if (isFirstQuote) { + order.setStatus(12L); + orderService.updateOrder(order); } return AppletControllerUtil.appletSuccess("报价成功"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java index a80c48e..2ad3e05 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppleOrderController.java @@ -8,6 +8,7 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.system.ControllerUtil.*; +import com.ruoyi.system.ControllerUtil.CartOrderUtil; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; import org.apache.commons.lang3.StringUtils; @@ -21,8 +22,11 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; +import java.util.Calendar; import com.ruoyi.system.service.IShopAddressService; import com.ruoyi.system.domain.ShopAddress; +import com.ruoyi.system.domain.GoodsCart; +import com.ruoyi.system.service.IGoodsCartService; /** * 苹果订单控制器 @@ -83,7 +87,18 @@ public class AppleOrderController extends BaseController { @Autowired private IGoodsOrderService goodsOrderService; + @Autowired + private IGoodsCartService goodsCartService; + @Autowired + private IUserDemandQuotationService userDemandQuotationService; + + @Autowired + private IDiyCityService diyCityService; + @Autowired + private ISiteSkillService siteSkillService; + @Autowired + private IOrderCommentService orderCommentService; /** * 查询用户优惠券列表 @@ -158,6 +173,12 @@ public class AppleOrderController extends BaseController { // 按is_use排序 return AjaxResult.success(); } + + + + + + /** * 通用订单预支接口 * @@ -499,304 +520,305 @@ public class AppleOrderController extends BaseController { - /** - * 创建服务订单(支持多商品批量下单) - * - * @param params 请求参数,包含多个商品信息、地址信息和预约时间 - * @param request HTTP请求对象 - * @return 返回创建结果 - */ - @PostMapping("/api/service/create/order") - public AjaxResult createServiceOrder(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证订单参数 - if (params == null || params.isEmpty()) { - return AppletControllerUtil.appletWarning("订单参数不能为空"); - } - - // 4. 生成主订单号 - String mainOrderId = GenerateCustomCode.generCreateOrder("WXB"); - - // 5. 存储所有订单信息 - List> orderList = new ArrayList<>(); - BigDecimal totalAmount = BigDecimal.ZERO; // 总金额 - - // 6. 遍历所有订单项 - for (String key : params.keySet()) { - // 跳过非数字键 - if (!key.matches("\\d+")) { - continue; - } - - Map orderParams = (Map) params.get(key); - - // 验证必要参数 - if (orderParams.get("product_id") == null || orderParams.get("address_id") == null) { - return AppletControllerUtil.appletWarning("商品ID或地址ID不能为空"); - } - - - Long productId = Long.valueOf(orderParams.get("product_id").toString()); - Long addressId = Long.valueOf(orderParams.get("address_id").toString()); - Long num = orderParams.get("num") != null ? Long.valueOf(orderParams.get("num").toString()) : 1L; - - // 处理SKU参数 - String sku = AppletControllerUtil.processSkuParam(orderParams.get("sku")); - - // 查询商品信息 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); - if (serviceGoods == null) { - return AppletControllerUtil.appletWarning("商品ID " + productId + " 不存在"); - } - - // 查询地址信息(只需要查询一次,假设所有订单使用相同地址) - UserAddress userAddress = userAddressService.selectUserAddressById(addressId); - if (userAddress == null) { - return AppletControllerUtil.appletWarning("地址不存在"); - } - - // 计算单个订单金额 - BigDecimal itemPrice; - if (serviceGoods.getType() == 2) { - // 商品订单,判断sku - String skuStr = sku; - BigDecimal unitPrice = serviceGoods.getPrice(); - if (skuStr != null && !skuStr.trim().isEmpty()) { - try { - JSONObject skuJson = JSONObject.parseObject(skuStr); - if (skuJson.containsKey("price")) { - unitPrice = new BigDecimal(skuJson.getString("price")); - } - } catch (Exception e) { - // 解析失败,忽略,使用默认价格 - } - } - itemPrice = unitPrice.multiply(BigDecimal.valueOf(num)); - } else { - // 服务订单 - itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); - } - totalAmount = totalAmount.add(itemPrice); - - // 判断商品类型并创建相应订单 - BigDecimal DeductionPrice = new BigDecimal("0"); - if (serviceGoods.getType() == 2) { - Long isself = orderParams.get("isself") != null ? Long.valueOf(orderParams.get("isself").toString()) : null;; - // 创建服务订单 - String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; - System.out.println("coupon_id:"+coupon_id); - CouponUser coupon=null; - if (coupon_id!=null&& !coupon_id.isEmpty()){ - 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); - } - couponUserService.updateCouponUser(coupon) ; - } - // 创建商品订单 - GoodsOrder goodsOrder = new GoodsOrder(); - goodsOrder.setType(2); - goodsOrder.setMainOrderId(mainOrderId); - goodsOrder.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 - goodsOrder.setUid(user.getId()); - goodsOrder.setProductId(productId); - goodsOrder.setName(userAddress.getName()); - goodsOrder.setPhone(userAddress.getPhone()); - goodsOrder.setAddress(userAddress.getAddressName()); - goodsOrder.setNum(num); - if (isself==1L){ - goodsOrder.setShopadresssid(1L); - - } - goodsOrder.setIsself(isself); - - - goodsOrder.setTotalPrice(itemPrice); - goodsOrder.setGoodPrice(serviceGoods.getPrice()); - goodsOrder.setPayPrice(itemPrice); - goodsOrder.setDeduction(DeductionPrice); - if (coupon_id!=null&& !coupon_id.isEmpty()){ - goodsOrder.setCouponId(Long.valueOf(coupon_id)); - } - - goodsOrder.setStatus(1L); // 待支付状态 - goodsOrder.setAddressId(addressId); - goodsOrder.setSku(sku); - // 保存商品订单 - int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); - if (insertResult <= 0) { - return AppletControllerUtil.appletWarning("商品订单创建失败,请稍后重试"); - } - // 添加到订单列表 - Map orderInfo = new HashMap<>(); - orderInfo.put("type", "goods"); - orderInfo.put("orderId", goodsOrder.getId()); - orderInfo.put("orderNo", goodsOrder.getOrderId()); - orderInfo.put("productName", serviceGoods.getTitle()); - orderInfo.put("price", itemPrice.toString()); - orderList.add(orderInfo); - } else { - // 创建服务订单 - String makeTime = orderParams.get("make_time") != null ? orderParams.get("make_time").toString() : ""; - String fileData = orderParams.get("fileData") != null ? orderParams.get("fileData").toString() : ""; - Order order = new Order(); - order.setType(1); // 1:服务项目 - order.setCreateType(1); // 1:用户自主下单 - order.setUid(user.getId()); - order.setUname(user.getName()); - order.setProductId(productId); - order.setProductName(serviceGoods.getTitle()); - order.setName(userAddress.getName()); - order.setFileData(fileData != null ? JSON.toJSONString(fileData) : null); - order.setPhone(userAddress.getPhone()); - order.setAddress(userAddress.getAddressInfo()); - order.setAddressId(addressId); - order.setSku(sku); - order.setMainOrderId(mainOrderId); - order.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 - // 处理预约时间 - if (makeTime != null && !makeTime.isEmpty()) { - String[] makeTimeArr = makeTime.split(" "); - if (makeTimeArr.length == 2) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date date = sdf.parse(makeTimeArr[0]); - order.setMakeTime(date.getTime() / 1000); - order.setMakeHour(makeTimeArr[1]); - } catch (Exception e) { - logger.warn("预约时间格式错误: " + makeTime); - } - } - } - order.setNum(num); - order.setTotalPrice(itemPrice); - order.setGoodPrice(serviceGoods.getPrice()); - order.setServicePrice(BigDecimal.ZERO); - order.setPayPrice(itemPrice); - order.setStatus(1L); // 1:待接单 - order.setReceiveType(1L); // 1:自由抢单 - order.setIsAccept(0); - order.setIsComment(0); - order.setIsPause(1); - order.setDeduction(new BigDecimal(0)); - // 保存服务订单 - int result = orderService.insertOrder(order); - if (result <= 0) { - return AppletControllerUtil.appletWarning("服务订单创建失败,请稍后重试"); - } - // 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("订单生成"); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", "预约成功,将尽快为主人派单"); - orderLog.setType(new BigDecimal(1.0)); - orderLog.setContent(jsonObject.toString()); - orderLogService.insertOrderLog(orderLog); - - // 系统派单和消息通知逻辑 - Order orderNewData = orderService.selectOrderById(order.getId()); - String wxsendmsg = WXsendMsgUtil.sendMsgForUserInfo(user.getOpenid(), orderNewData, serviceGoods); - Users worker = AppletControllerUtil.creatWorkerForOrder(orderNewData); - - if (worker != null) { - // 更新订单状态为已派单 - orderNewData.setWorkerId(worker.getId()); - orderNewData.setStatus(2l); - orderNewData.setIsPause(1); - orderNewData.setReceiveTime(new Date()); - orderNewData.setReceiveType(3l); - orderNewData.setLogStatus(9); - JSONObject jSONObject = new JSONObject(); - jSONObject.put("type", 9); - orderNewData.setLogJson(jSONObject.toJSONString()); - orderService.updateOrder(orderNewData); - // 添加派单日志 - OrderLog orderLognew = new OrderLog(); - orderLognew.setOid(orderNewData.getId()); - orderLognew.setOrderId(orderNewData.getOrderId()); - orderLognew.setTitle("平台派单"); - orderLognew.setType(new BigDecimal(1.1)); - JSONObject jSONObject1 = new JSONObject(); - jSONObject1.put("name", "师傅收到派单信息"); - orderLognew.setContent(jSONObject1.toJSONString()); - orderLognew.setWorkerId(worker.getId()); - orderLognew.setWorkerLogId(worker.getId()); - orderLogService.insertOrderLog(orderLognew); - // 发送通知 - WXsendMsgUtil.sendMsgForWorkerInfo(worker.getOpenid(), orderNewData, serviceGoods); - YunXinPhoneUtilAPI.httpsAxbTransfer(worker.getPhone()); - } - - // 添加到订单列表 - Map orderInfo = new HashMap<>(); - orderInfo.put("type", "service"); - orderInfo.put("orderId", order.getId()); - orderInfo.put("orderNo", order.getOrderId()); - orderInfo.put("productName", serviceGoods.getTitle()); - orderInfo.put("price", itemPrice.toString()); - orderList.add(orderInfo); - } - } - // 7. 如果有商品订单,需要发起微信支付 - boolean hasGoodsOrder = orderList.stream().anyMatch(order -> "goods".equals(order.get("type"))); - if (hasGoodsOrder && totalAmount.compareTo(BigDecimal.ZERO) > 0) { - //插入预支付订单,随后进行支付 - String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, mainOrderId, null, null, 5L, null, null, null, null, null,2L); - Map result1 = new HashMap<>(); - result1.put("type", "2"); - result1.put("orderid", payBeforeId); - return AppletControllerUtil.appletSuccess(result1); - // 使用工具类简化微信支付参数组装 -// Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), wechatPayUtil.PAY_FH+"api/goods/pay/notify"); -// if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { -// Map responseData = new HashMap<>(); -// responseData.put("mainOrderId", mainOrderId); -// responseData.put("orderList", orderList); -// responseData.put("totalAmount", totalAmount.toString()); -// responseData.put("prepayId", payResult.get("prepayId")); -// // 直接合并所有支付参数 -// responseData.putAll(payResult); -// return AppletControllerUtil.appletSuccess(responseData); -// } else { -// String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; -// return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); +// /** +// * 创建服务订单(支持多商品批量下单) +// * +// * @param params 请求参数,包含多个商品信息、地址信息和预约时间 +// * @param request HTTP请求对象 +// * @return 返回创建结果 +// */ +// @PostMapping("/api/service/create/order") +// public AjaxResult createServiceOrder(@RequestBody Map params, HttpServletRequest request) { +// try { +// // 1. 验证用户登录状态 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletWarning("用户未登录或token无效"); +// } +// PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); +// // 2. 获取用户信息 +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// +// // 3. 验证订单参数 +// if (params == null || params.isEmpty()) { +// return AppletControllerUtil.appletWarning("订单参数不能为空"); +// } +// +// // 4. 生成主订单号 +// String mainOrderId = GenerateCustomCode.generCreateOrder("WXB"); +// +// // 5. 存储所有订单信息 +// List> orderList = new ArrayList<>(); +// BigDecimal totalAmount = BigDecimal.ZERO; // 总金额 +// +// // 6. 遍历所有订单项 +// for (String key : params.keySet()) { +// // 跳过非数字键 +// if (!key.matches("\\d+")) { +// continue; // } - } else { - // 没有商品订单,只有服务订单,直接返回成功 - Map responseData = new HashMap<>(); - responseData.put("mainOrderId", mainOrderId); - responseData.put("orderList", orderList); - responseData.put("totalAmount", totalAmount.toString()); - return AppletControllerUtil.appletSuccess(responseData); - } - - } catch (Exception e) { - logger.error("创建订单异常:", e); - return AppletControllerUtil.appletWarning("创建订单失败:" + e.getMessage()); - } - } +// +// Map orderParams = (Map) params.get(key); +// +// // 验证必要参数 +// if (orderParams.get("product_id") == null || orderParams.get("address_id") == null) { +// return AppletControllerUtil.appletWarning("商品ID或地址ID不能为空"); +// } +// +// +// Long productId = Long.valueOf(orderParams.get("product_id").toString()); +// String carid = orderParams.get("carid").toString(); +// Long addressId = Long.valueOf(orderParams.get("address_id").toString()); +// Long num = orderParams.get("num") != null ? Long.valueOf(orderParams.get("num").toString()) : 1L; +// +// // 处理SKU参数 +// String sku = AppletControllerUtil.processSkuParam(orderParams.get("sku")); +// +// // 查询商品信息 +// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); +// if (serviceGoods == null) { +// return AppletControllerUtil.appletWarning("商品ID " + productId + " 不存在"); +// } +// +// // 查询地址信息(只需要查询一次,假设所有订单使用相同地址) +// UserAddress userAddress = userAddressService.selectUserAddressById(addressId); +// if (userAddress == null) { +// return AppletControllerUtil.appletWarning("地址不存在"); +// } +// +// // 计算单个订单金额 +// BigDecimal itemPrice; +// if (serviceGoods.getType() == 2) { +// // 商品订单,判断sku +// String skuStr = sku; +// BigDecimal unitPrice = serviceGoods.getPrice(); +// if (skuStr != null && !skuStr.trim().isEmpty()) { +// try { +// JSONObject skuJson = JSONObject.parseObject(skuStr); +// if (skuJson.containsKey("price")) { +// unitPrice = new BigDecimal(skuJson.getString("price")); +// } +// } catch (Exception e) { +// // 解析失败,忽略,使用默认价格 +// } +// } +// itemPrice = unitPrice.multiply(BigDecimal.valueOf(num)); +// } else { +// // 服务订单 +// itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); +// } +// totalAmount = totalAmount.add(itemPrice); +// +// // 判断商品类型并创建相应订单 +// BigDecimal DeductionPrice = new BigDecimal("0"); +// if (serviceGoods.getType() == 2) { +// Long isself = orderParams.get("isself") != null ? Long.valueOf(orderParams.get("isself").toString()) : null;; +// // 创建服务订单 +// String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; +// System.out.println("coupon_id:"+coupon_id); +// CouponUser coupon=null; +// if (coupon_id!=null&& !coupon_id.isEmpty()){ +// 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); +// } +// couponUserService.updateCouponUser(coupon) ; +// } +// // 创建商品订单 +// GoodsOrder goodsOrder = new GoodsOrder(); +// goodsOrder.setType(2); +// goodsOrder.setMainOrderId(mainOrderId); +// goodsOrder.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 +// goodsOrder.setUid(user.getId()); +// goodsOrder.setProductId(productId); +// goodsOrder.setName(userAddress.getName()); +// goodsOrder.setPhone(userAddress.getPhone()); +// goodsOrder.setAddress(userAddress.getAddressName()); +// goodsOrder.setNum(num); +// if (isself==1L){ +// goodsOrder.setShopadresssid(1L); +// +// } +// goodsOrder.setIsself(isself); +// +// +// goodsOrder.setTotalPrice(itemPrice); +// goodsOrder.setGoodPrice(serviceGoods.getPrice()); +// goodsOrder.setPayPrice(itemPrice); +// goodsOrder.setDeduction(DeductionPrice); +// if (coupon_id!=null&& !coupon_id.isEmpty()){ +// goodsOrder.setCouponId(Long.valueOf(coupon_id)); +// } +// +// goodsOrder.setStatus(1L); // 待支付状态 +// goodsOrder.setAddressId(addressId); +// goodsOrder.setSku(sku); +// // 保存商品订单 +// int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); +// if (insertResult <= 0) { +// return AppletControllerUtil.appletWarning("商品订单创建失败,请稍后重试"); +// } +// // 添加到订单列表 +// Map orderInfo = new HashMap<>(); +// orderInfo.put("type", "goods"); +// orderInfo.put("orderId", goodsOrder.getId()); +// orderInfo.put("orderNo", goodsOrder.getOrderId()); +// orderInfo.put("productName", serviceGoods.getTitle()); +// orderInfo.put("price", itemPrice.toString()); +// orderList.add(orderInfo); +// } else { +// // 创建服务订单 +// String makeTime = orderParams.get("make_time") != null ? orderParams.get("make_time").toString() : ""; +// String fileData = orderParams.get("fileData") != null ? orderParams.get("fileData").toString() : ""; +// Order order = new Order(); +// order.setType(1); // 1:服务项目 +// order.setCreateType(1); // 1:用户自主下单 +// order.setUid(user.getId()); +// order.setUname(user.getName()); +// order.setProductId(productId); +// order.setProductName(serviceGoods.getTitle()); +// order.setName(userAddress.getName()); +// order.setFileData(AppletControllerUtil.getStringFileData(fileData)); +// order.setPhone(userAddress.getPhone()); +// order.setAddress(userAddress.getAddressInfo()); +// order.setAddressId(addressId); +// order.setSku(sku); +// order.setMainOrderId(mainOrderId); +// order.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 +// // 处理预约时间 +// if (makeTime != null && !makeTime.isEmpty()) { +// String[] makeTimeArr = makeTime.split(" "); +// if (makeTimeArr.length == 2) { +// try { +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); +// Date date = sdf.parse(makeTimeArr[0]); +// order.setMakeTime(date.getTime() / 1000); +// order.setMakeHour(makeTimeArr[1]); +// } catch (Exception e) { +// logger.warn("预约时间格式错误: " + makeTime); +// } +// } +// } +// order.setNum(num); +// order.setTotalPrice(itemPrice); +// order.setGoodPrice(serviceGoods.getPrice()); +// order.setServicePrice(BigDecimal.ZERO); +// order.setPayPrice(itemPrice); +// order.setStatus(1L); // 1:待接单 +// order.setReceiveType(1L); // 1:自由抢单 +// order.setIsAccept(0); +// order.setIsComment(0); +// order.setIsPause(1); +// order.setDeduction(new BigDecimal(0)); +// // 保存服务订单 +// int result = orderService.insertOrder(order); +// if (result <= 0) { +// return AppletControllerUtil.appletWarning("服务订单创建失败,请稍后重试"); +// } +// // 添加订单日志 +// OrderLog orderLog = new OrderLog(); +// orderLog.setOid(order.getId()); +// orderLog.setOrderId(order.getOrderId()); +// orderLog.setTitle("订单生成"); +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("name", "预约成功,将尽快为主人派单"); +// orderLog.setType(new BigDecimal(1.0)); +// orderLog.setContent(jsonObject.toString()); +// orderLogService.insertOrderLog(orderLog); +// +// // 系统派单和消息通知逻辑 +// Order orderNewData = orderService.selectOrderById(order.getId()); +// String wxsendmsg = WXsendMsgUtil.sendMsgForUserInfo(user.getOpenid(), orderNewData, serviceGoods); +// Users worker = AppletControllerUtil.creatWorkerForOrder(orderNewData); +// +// if (worker != null) { +// // 更新订单状态为已派单 +// orderNewData.setWorkerId(worker.getId()); +// orderNewData.setStatus(2l); +// orderNewData.setIsPause(1); +// orderNewData.setReceiveTime(new Date()); +// orderNewData.setReceiveType(3l); +// orderNewData.setLogStatus(9); +// JSONObject jSONObject = new JSONObject(); +// jSONObject.put("type", 9); +// orderNewData.setLogJson(jSONObject.toJSONString()); +// orderService.updateOrder(orderNewData); +// // 添加派单日志 +// OrderLog orderLognew = new OrderLog(); +// orderLognew.setOid(orderNewData.getId()); +// orderLognew.setOrderId(orderNewData.getOrderId()); +// orderLognew.setTitle("平台派单"); +// orderLognew.setType(new BigDecimal(1.1)); +// JSONObject jSONObject1 = new JSONObject(); +// jSONObject1.put("name", "师傅收到派单信息"); +// orderLognew.setContent(jSONObject1.toJSONString()); +// orderLognew.setWorkerId(worker.getId()); +// orderLognew.setWorkerLogId(worker.getId()); +// orderLogService.insertOrderLog(orderLognew); +// // 发送通知 +// WXsendMsgUtil.sendMsgForWorkerInfo(worker.getOpenid(), orderNewData, serviceGoods); +// YunXinPhoneUtilAPI.httpsAxbTransfer(worker.getPhone()); +// } +// +// // 添加到订单列表 +// Map orderInfo = new HashMap<>(); +// orderInfo.put("type", "service"); +// orderInfo.put("orderId", order.getId()); +// orderInfo.put("orderNo", order.getOrderId()); +// orderInfo.put("productName", serviceGoods.getTitle()); +// orderInfo.put("price", itemPrice.toString()); +// orderList.add(orderInfo); +// } +// } +// // 7. 如果有商品订单,需要发起微信支付 +// boolean hasGoodsOrder = orderList.stream().anyMatch(order -> "goods".equals(order.get("type"))); +// if (hasGoodsOrder && totalAmount.compareTo(BigDecimal.ZERO) > 0) { +// //插入预支付订单,随后进行支付 +// String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, mainOrderId, null, null, 5L, null, null, null, null, null,2L); +// Map result1 = new HashMap<>(); +// result1.put("type", "2"); +// result1.put("orderid", payBeforeId); +// return AppletControllerUtil.appletSuccess(result1); +// // 使用工具类简化微信支付参数组装 +//// Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), wechatPayUtil.PAY_FH+"api/goods/pay/notify"); +//// if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { +//// Map responseData = new HashMap<>(); +//// responseData.put("mainOrderId", mainOrderId); +//// responseData.put("orderList", orderList); +//// responseData.put("totalAmount", totalAmount.toString()); +//// responseData.put("prepayId", payResult.get("prepayId")); +//// // 直接合并所有支付参数 +//// responseData.putAll(payResult); +//// return AppletControllerUtil.appletSuccess(responseData); +//// } else { +//// String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; +//// return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); +//// } +// } else { +// // 没有商品订单,只有服务订单,直接返回成功 +// Map responseData = new HashMap<>(); +// responseData.put("mainOrderId", mainOrderId); +// responseData.put("orderList", orderList); +// responseData.put("totalAmount", totalAmount.toString()); +// return AppletControllerUtil.appletSuccess(responseData); +// } +// +// } catch (Exception e) { +// logger.error("创建订单异常:", e); +// return AppletControllerUtil.appletWarning("创建订单失败:" + e.getMessage()); +// } +// } @@ -1404,6 +1426,7 @@ public class AppleOrderController extends BaseController { order.setProductName(serviceGoods.getTitle()); order.setSku(sku); order.setCartid(cikaid); + order.setBigtype(serviceGoods.getServicetype()); // order.setc if (userAddress != null) { order.setAddressId(userAddress.getId()); @@ -1578,6 +1601,7 @@ public class AppleOrderController extends BaseController { order.setUname(user.getName()); order.setProductId(serviceGoods.getId()); order.setProductName(serviceGoods.getTitle()); + order.setBigtype(serviceGoods.getServicetype()); order.setSku(sku); order.setNum(Long.valueOf(num)); if (userAddress != null) { @@ -1709,6 +1733,7 @@ public class AppleOrderController extends BaseController { order.setServicePrice(BigDecimal.ZERO); order.setPayPrice(itemPrice); order.setStatus(8L); // 待待报价 + order.setBigtype(serviceGoods.getServicetype()); order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 order.setIsAccept(0); order.setIsComment(0); @@ -1751,6 +1776,933 @@ public class AppleOrderController extends BaseController { } } + /** + * 购物车下单接口 + * @param params {"carid":[购物车id数组], "address_id":地址id, "make_time":预约时间} + * @param request HTTP请求对象 + * @return 下单结果 + */ + @PostMapping("/api/service/create/order") + public AjaxResult submitCartOrder(@RequestBody Map params, HttpServletRequest request) { + try { + PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + String maincorid=GenerateCustomCode.generCreateOrder("MC"); + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + if (params == null || params.get("carid") == null || params.get("address_id") == null) { + return AppletControllerUtil.appletWarning("carid和address_id不能为空"); + } + List carIds; + try { + carIds = (List) params.get("carid"); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("carid参数格式错误,必须为整型数组"); + } + Long addressId = Long.valueOf(params.get("address_id").toString()); + String makeTime = params.get("make_time") != null ? params.get("make_time").toString() : ""; + + UserAddress userAddress = userAddressService.selectUserAddressById(addressId); + if (userAddress == null) { + return AppletControllerUtil.appletWarning("地址不存在"); + } + + List> orderList = new ArrayList<>(); + BigDecimal totalAmount = BigDecimal.ZERO; + for (Integer carId : carIds) { + GoodsCart cart = goodsCartService.selectGoodsCartById(carId); + if (cart == null || !user.getId().equals(cart.getUid())) { + return AppletControllerUtil.appletWarning("购物车ID " + carId + " 不存在或无权操作"); + } + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(cart.getGoodId()); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("商品ID " + cart.getGoodId() + " 不存在"); + } + Map orderResult; + if (cart.getGoodstype() != null && cart.getGoodstype() == 2) { + // 商品类下单 + orderResult = CartOrderUtil.createGoodsOrderFromCart(user, cart, serviceGoods, userAddress, goodsOrderService,maincorid); + } else { + // 服务类下单 + orderResult = CartOrderUtil.createServiceOrderFromCart(user, cart, serviceGoods, userAddress, makeTime, orderService, orderLogService,maincorid); + } + if (!(Boolean) orderResult.getOrDefault("success", false)) { + return AppletControllerUtil.appletWarning(orderResult.getOrDefault("msg", "下单失败").toString()); + } + + orderList.add(orderResult); + totalAmount = totalAmount.add(new BigDecimal(orderResult.get("allprice").toString())); + //一口价 + if (cart.getGoodstype()==1&&cart.getOrdertype()==2){ + String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, cart.getGoodId(), 6L, cart.getSku(), null, null, null, null,1L); + Map result1 = new HashMap<>(); + result1.put("type", "2"); + result1.put("orderid", maincorid); + return AppletControllerUtil.appletSuccess(result1); + } + } + + if (totalAmount.compareTo(BigDecimal.ZERO) > 0) { + //插入预支付订单,随后进行支付 + String payBeforeId = payBeforeUtil.createPayBefore(user, totalAmount, maincorid, null, null, 5L, null, null, null, null, null,2L); + Map result1 = new HashMap<>(); + result1.put("type", "2"); + result1.put("orderid", maincorid); + return AppletControllerUtil.appletSuccess(result1); + }else{ + Map result1 = new HashMap<>(); + result1.put("type", "1"); + result1.put("orderid", maincorid); + return AppletControllerUtil.appletSuccess(result1); + + } + + + } catch (Exception e) { + logger.error("购物车下单失败:", e); + return AppletControllerUtil.appletError("购物车下单失败:" + e.getMessage()); + } + } + + /** + * 查询服务订单列表 + * @param bigtype 订单类型:1=预约下单 2=报价下单 3=一口价 + * @param status 订单状态:1=待接单 2=待服务 3=服务中 4=已结束 5=已取消 6=师傅完成服务 7=未服务提前结束订单 8=待报价 9=待成团 10=已成团 11=待支付 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @param request HTTP请求对象 + * @return 订单列表 + */ + @GetMapping("/api/service/order/list") + public AjaxResult getServiceOrderList( + @RequestParam(value = "bigtype", required = false) Integer bigtype, + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, + HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 2. 构建查询条件 + Order queryOrder = new Order(); + queryOrder.setUid(user.getId()); + + // 根据bigtype筛选订单类型 + if (bigtype != null) { + switch (bigtype) { + case 1: // 预约下单 + queryOrder.setBigtype(1); + break; + case 2: // 报价下单 + queryOrder.setBigtype(2); + break; + case 3: // 一口价 + queryOrder.setBigtype(3); + break; + default: + return AppletControllerUtil.appletWarning("订单类型参数无效"); + } + } + + // 根据status筛选订单状态 + if (status != null) { + queryOrder.setStatus(Long.valueOf(status)); + } + + // 3. 查询订单列表 + List orderList = orderService.selectOrderList(queryOrder); + + // 4. 分页处理 + int total = orderList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageOrderList = fromIndex < toIndex ? orderList.subList(fromIndex, toIndex) : new ArrayList<>(); + + // 5. 构建返回数据 + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (Order order : pageOrderList) { + Map orderMap = new HashMap<>(); + + // 基本信息 + orderMap.put("id", order.getId()); + orderMap.put("orderId", order.getOrderId()); + orderMap.put("odertype", order.getOdertype()); // 添加odertype字段 + orderMap.put("totalPrice", order.getTotalPrice()); + orderMap.put("status", order.getStatus()); + orderMap.put("orcerCrateTime", sdf.format(order.getCreatedAt())); + orderMap.put("num", order.getNum()); + orderMap.put("statusText", getOrderStatusText(order.getStatus())); + // orderMap.put("createTime", sdf.format(order.getCreateTime())); + + // 订单类型 + orderMap.put("bigtype", getOrderBigType(order.getBigtype())); + orderMap.put("bigtypeText", getOrderBigTypeText(order.getBigtype())); + + // 商品信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods != null) { + orderMap.put("productName", serviceGoods.getTitle()); + orderMap.put("productIcon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); + orderMap.put("productPrice", serviceGoods.getPrice()); + orderMap.put("productFixedPrice", serviceGoods.getFixedprice()); + } + + // 地址信息 + if (order.getAddressId() != null) { + UserAddress userAddress = userAddressService.selectUserAddressById(order.getAddressId()); + if (userAddress != null) { + orderMap.put("address", userAddress.getAddressInfo()); + orderMap.put("contactName", userAddress.getName()); + orderMap.put("contactPhone", userAddress.getPhone()); + } + } + + // 预约时间 + if (order.getMakeTime() != null) { + Date makeDate = new Date(order.getMakeTime() * 1000); + orderMap.put("makeTime", sdf.format(makeDate)); + orderMap.put("makeHour", order.getMakeHour()); + } + + // 报价相关信息(仅报价订单) + if (order.getBigtype() == 2) { + // 当订单状态为8(待报价)或12(待选择)时,返回截止时间毫秒数 + if ((order.getStatus() == 8 || order.getStatus() == 12) && order.getCreatedAt() != null) { + // 计算报价截止时间(创建时间+3天)的毫秒数 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(order.getCreatedAt()); + calendar.add(Calendar.DAY_OF_MONTH, 3); + long deadlineTime = calendar.getTimeInMillis(); + orderMap.put("quoteDeadlineTime", deadlineTime); + } else { + // 其他状态或没有创建时间,返回0 + orderMap.put("quoteDeadlineTime", 0L); + } + // 查询报价师傅数量和详情 + List quotationList = getQuotationList(order.getOrderId()); + orderMap.put("quoteCount", quotationList.size()); + orderMap.put("quotationList", buildQuotationList(quotationList)); + // 师傅信息(如果已派单) + if (order.getWorkerId() != null) { + Users worker = usersService.selectUsersById(order.getWorkerId()); + if (worker != null) { + Map workerMap = new HashMap<>(); + workerMap.put("workerName", worker.getName()); + workerMap.put("workerAvatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); + workerMap.put("workerPhone", worker.getPhone()); + orderMap.put("workerMap", workerMap); + } + } + } + + // 师傅信息(如果已派单) + if (order.getWorkerId() != null) { + Users worker = usersService.selectUsersById(order.getWorkerId()); + if (worker != null) { + orderMap.put("workerName", worker.getName()); + orderMap.put("workerAvatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); + orderMap.put("workerPhone", worker.getPhone()); + } + } + + // 附件信息 + if (order.getFileData() != null && !order.getFileData().trim().isEmpty()) { + try { + List attachments = JSONArray.parseArray(order.getFileData(), String.class); + orderMap.put("attachments", attachments); + orderMap.put("attachmentCount", attachments.size()); + } catch (Exception e) { + orderMap.put("attachments", new ArrayList<>()); + orderMap.put("attachmentCount", 0); + } + } else { + orderMap.put("attachments", new ArrayList<>()); + orderMap.put("attachmentCount", 0); + } + + resultList.add(orderMap); + } + + // 6. 构建分页结果 + Map pageResult = new HashMap<>(); + pageResult.put("total", total); + pageResult.put("pageNum", pageNum); + pageResult.put("pageSize", pageSize); + pageResult.put("data", resultList); + + return AppletControllerUtil.appletSuccess(pageResult); + + } catch (Exception e) { + logger.error("查询服务订单列表失败:", e); + return AppletControllerUtil.appletError("查询服务订单列表失败:" + e.getMessage()); + } + } + + /** + * 获取订单状态文本 + */ + private String getOrderStatusText(Long status) { + if (status == null) return "未知状态"; + switch (status.intValue()) { + case 1: return "待接单"; + case 2: return "待服务"; + case 3: return "服务中"; + case 4: return "已结束"; + case 5: return "已取消"; + case 6: return "师傅完成服务"; + case 7: return "未服务提前结束订单"; + case 8: return "待报价"; + case 9: return "待成团"; + case 10: return "已成团"; + case 11: return "待支付"; + case 12: return "待选择"; + default: return "未知状态"; + } + } + + /** + * 获取订单大类型 + */ + private Integer getOrderBigType(int odertype) { + switch (odertype) { + case 1: return 1; // 预约下单 + case 2: return 2; // 报价下单 + case 3: return 3; // 一口价 + default: return null; + } + } + + /** + * 获取订单大类型文本 + */ + private String getOrderBigTypeText(int odertype) { + switch (odertype) { + case 1: return "预约订单"; + case 2: return "报价订单"; + case 3: return "一口价订单"; + default: return "未知类型"; + } + } + + /** + * 获取报价数量 + */ + private Integer getQuoteCount(Long orderId) { + try { + UserDemandQuotation queryParams = new UserDemandQuotation(); + queryParams.setOrderid(orderId.toString()); + List quotationList = userDemandQuotationService.selectUserDemandQuotationList(queryParams); + return quotationList != null ? quotationList.size() : 0; + } catch (Exception e) { + logger.warn("查询报价数量失败,订单ID: " + orderId + ", 错误: " + e.getMessage()); + return 0; + } + } + + /** + * 获取报价列表 + */ + private List getQuotationList(String orderId) { + try { + UserDemandQuotation queryParams = new UserDemandQuotation(); + queryParams.setOrderid(orderId); + List quotationList = userDemandQuotationService.selectUserDemandQuotationList(queryParams); + return quotationList != null ? quotationList : new ArrayList<>(); + } catch (Exception e) { + logger.warn("查询报价列表失败,订单ID: " + orderId + ", 错误: " + e.getMessage()); + return new ArrayList<>(); + } + } + + /** + * 构建报价列表数据 + */ + private List> buildQuotationList(List quotationList) { + List> result = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (UserDemandQuotation quotation : quotationList) { + Map quoteMap = new HashMap<>(); + quoteMap.put("id", quotation.getId()); + quoteMap.put("orderId", quotation.getOrderid()); + quoteMap.put("money", quotation.getMoney()); + quoteMap.put("workerId", quotation.getWorkerid()); + quoteMap.put("workerName", quotation.getWorkername()); + quoteMap.put("workerImage", AppletControllerUtil.buildImageUrl(quotation.getWorkerimage())); + quoteMap.put("status", quotation.getStatus()); + quoteMap.put("quotationTime", quotation.getQuotationTime() != null ? sdf.format(quotation.getQuotationTime()) : ""); + quoteMap.put("createTime", quotation.getCreatedAt() != null ? sdf.format(quotation.getCreatedAt()) : ""); + + // 获取师傅详细信息 + if (quotation.getWorkerid() != null) { + Users worker = usersService.selectUsersById(quotation.getWorkerid()); + if (worker != null) { + quoteMap.put("workerPhone", worker.getPhone()); + quoteMap.put("workerAvatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); + // 注意:如果Users类没有level和experience字段,可以注释掉这两行 + // quoteMap.put("workerLevel", worker.getLevel()); // 师傅等级 + // quoteMap.put("workerExperience", worker.getExperience()); // 师傅经验 + } + } + + result.add(quoteMap); + } + + return result; + } + + /** + * 查询订单师傅报价详情 + * @param orderId 订单号 + * @param request HTTP请求对象 + * @return 师傅报价详情列表 + */ + @GetMapping("/api/service/order/quotation/detail") + public AjaxResult getOrderQuotationDetail(@RequestParam("orderId") String orderId, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 2. 验证订单是否存在且属于当前用户 + Order order = orderService.selectOrderByOrderId(orderId); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + if (!user.getId().equals(order.getUid())) { + return AppletControllerUtil.appletWarning("无权查看此订单"); + } + + // 3. 查询报价列表 + List quotationList = getQuotationList(orderId); + + // 4. 构建返回数据 + Map result = new HashMap<>(); + result.put("orderId", orderId); + result.put("orderStatus", order.getStatus()); + result.put("orderStatusText", getOrderStatusText(order.getStatus())); + result.put("totalQuotations", quotationList.size()); + result.put("quotationList", buildQuotationList(quotationList)); + + // 5. 如果是报价订单且状态为8(待报价)或12(待选择),添加报价截止时间 + if (order.getBigtype() == 2 && (order.getStatus() == 8 || order.getStatus() == 12)) { + if (order.getCreatedAt() != null) { + // 计算报价截止时间(创建时间+3天)的毫秒数 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(order.getCreatedAt()); + calendar.add(Calendar.DAY_OF_MONTH, 3); + long deadlineTime = calendar.getTimeInMillis(); + result.put("quoteDeadlineTime", deadlineTime); + } else { + result.put("quoteDeadlineTime", 0L); + } + } else { + result.put("quoteDeadlineTime", 0L); + } + + return AppletControllerUtil.appletSuccess(result); + + } catch (Exception e) { + logger.error("查询订单报价详情失败:", e); + return AppletControllerUtil.appletError("查询订单报价详情失败:" + e.getMessage()); + } + } + + /** + * 确认报价接口 + * @param params 请求参数 {"orderid": "订单号", "baojiaid": "报价ID"} + * @param request HTTP请求对象 + * @return 预支付信息 + */ + @PostMapping("/api/service/confirm/quotation") + public AjaxResult confirmQuotation(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 2. 验证请求参数 + if (params == null || params.get("orderid") == null || params.get("baojiaid") == null) { + return AppletControllerUtil.appletWarning("订单号和报价ID不能为空"); + } + + String orderId = params.get("orderid").toString(); + Long baojiaId = Long.valueOf(params.get("baojiaid").toString()); + + // 3. 查询报价数据 + UserDemandQuotation quotation = userDemandQuotationService.selectUserDemandQuotationById(baojiaId); + if (quotation == null) { + return AppletControllerUtil.appletWarning("报价记录不存在"); + } + + // 4. 验证报价是否属于指定订单 + if (!orderId.equals(quotation.getOrderid())) { + return AppletControllerUtil.appletWarning("报价记录与订单不匹配"); + } + + // 5. 查询订单信息 + Order order = orderService.selectOrderByOrderId(orderId); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + // 6. 验证订单是否属于当前用户 + if (!user.getId().equals(order.getUid())) { + return AppletControllerUtil.appletWarning("无权操作此订单"); + } + + // 7. 验证订单状态是否为待选择(12) + if (order.getStatus() != 12) { + return AppletControllerUtil.appletWarning("订单状态不正确,无法确认报价"); + } + + // 8. 验证报价状态是否为已报价(1) + if (quotation.getStatus() != 1) { + return AppletControllerUtil.appletWarning("报价状态不正确"); + } + + // 9. 更新报价状态为被选中(2) + quotation.setStatus(2L); + int updateResult = userDemandQuotationService.updateUserDemandQuotation(quotation); + if (updateResult <= 0) { + return AppletControllerUtil.appletWarning("更新报价状态失败"); + } + + // 10. 更新订单状态为待支付(11) + //为了防止出现支付多条订单为同一个订单号的情况,就需要重新生成订单号 + orderId=GenerateCustomCode.generCreateOrder("XQ"); + order.setStatus(11L); + order.setOrderId(orderId); + order.setWorkerId(quotation.getWorkerid()); + int orderUpdateResult = orderService.updateOrder(order); + if (orderUpdateResult <= 0) { + return AppletControllerUtil.appletWarning("更新订单状态失败"); + } + // 11. 创建预支付记录 + PayBeforeUtil payBeforeUtil = new PayBeforeUtil(); + String payOrderId = payBeforeUtil.createPayBefore( + user, + quotation.getMoney(), + orderId, + order.getId(), + order.getProductId() != null ? order.getProductId().longValue() : 0L, + 4L, // 4=报价订单 + order.getSku() != null ? order.getSku() : "", + "", // grouporderid为空 + order.getAddressId(), + order.getMakeTime() != null ? order.getMakeTime().toString() : "", + order.getFileData() != null ? order.getFileData() : "", + 2L // servicetype=2表示服务类型 + ); + + if (payOrderId == null) { + return AppletControllerUtil.appletWarning("预支付记录创建失败"); + } + + // 12. 返回预支付信息 + Map result = new HashMap<>(); + result.put("orderid", payOrderId); + result.put("type", "1"); // 1表示需要调起支付 + result.put("totalAmount", quotation.getMoney()); + result.put("workerName", quotation.getWorkername()); + result.put("quotationId", baojiaId); + + return AppletControllerUtil.appletSuccess(result); + + } catch (Exception e) { + logger.error("确认报价失败:", e); + return AppletControllerUtil.appletError("确认报价失败:" + e.getMessage()); + } + } + + /** + * 师傅--我的订单查看 + * 查询当前登录师傅(workerId)的所有订单,支持status订单状态筛选,返回格式与/api/service/order/list一致 + * @param status 订单状态筛选 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @param request HTTP请求对象 + * @return 订单列表 + */ + @GetMapping("/api/worker/order/list") + public AjaxResult getWorkerOrderList( + @RequestParam(value = "status", required = false) Integer status, + @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, + HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + List orderList; + // 2. 查询逻辑 + if (status != null && status == 8) { + // 查询所有status=8的订单 + Order queryOrder = new Order(); + queryOrder.setStatus(8L); + orderList = orderService.selectOrderList(queryOrder); + } else if (status != null && status == 10) { + // 查询当前师傅报过价且status=1的报价,查其orderid对应订单 + UserDemandQuotation query = new UserDemandQuotation(); + query.setWorkerid(user.getId()); + query.setStatus(1L); // 1=已报价 + List quoteList = userDemandQuotationService.selectUserDemandQuotationList(query); + List orderIds = new ArrayList<>(); + for (UserDemandQuotation q : quoteList) { + if (q.getOrderid() != null) { + orderIds.add(q.getOrderid()); + } + } + orderList = new ArrayList<>(); + if (!orderIds.isEmpty()) { + for (String oid : orderIds) { + Order o = orderService.selectOrderByOrderId(oid); + if (o != null) orderList.add(o); + } + } + } else { + // 普通师傅订单查询 + Order queryOrder = new Order(); + queryOrder.setWorkerId(user.getId()); + if (status != null) { + queryOrder.setStatus(Long.valueOf(status)); + } + orderList = orderService.selectOrderList(queryOrder); + } + // 3. 分页处理 + int total = orderList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageOrderList = fromIndex < toIndex ? orderList.subList(fromIndex, toIndex) : new ArrayList<>(); + // 4. 构建返回数据(与/api/service/order/list一致) + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdfday = new SimpleDateFormat("yyyy-MM-dd"); + for (Order order : pageOrderList) { + Map orderMap = new HashMap<>(); + // 基本信息 + orderMap.put("id", order.getId()); + orderMap.put("sku",AppletControllerUtil.parseSkuStringToObject(order.getSku())); + orderMap.put("orderId", order.getOrderId()); + orderMap.put("odertype", order.getOdertype()); + orderMap.put("totalPrice", order.getTotalPrice()); + orderMap.put("status", order.getStatus()); + orderMap.put("orcerCrateTime", sdf.format(order.getCreatedAt())); + orderMap.put("num", order.getNum()); + orderMap.put("statusText", getOrderStatusText(order.getStatus())); + // 订单类型 + orderMap.put("bigtype", getOrderBigType(order.getBigtype())); + orderMap.put("bigtypeText", getOrderBigTypeText(order.getBigtype())); + // 商品信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods != null) { + orderMap.put("productName", serviceGoods.getTitle()); + orderMap.put("productIcon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); + orderMap.put("productPrice", serviceGoods.getPrice()); + orderMap.put("productFixedPrice", serviceGoods.getFixedprice()); + } + // 地址信息 + if (order.getAddressId() != null) { + UserAddress userAddress = userAddressService.selectUserAddressById(order.getAddressId()); + if (userAddress != null) { + orderMap.put("address", userAddress.getAddressInfo()); + orderMap.put("contactName", userAddress.getName()); + orderMap.put("contactPhone", userAddress.getPhone()); + } + } + // 预约时间 + if (order.getMakeTime() != null) { + Date makeDate = new Date(order.getMakeTime() * 1000); + orderMap.put("makeTime", sdfday.format(makeDate)); + orderMap.put("makeHour", order.getMakeHour()); + } + // 报价相关信息(仅报价订单) + if (order.getBigtype() == 2) { + if ((order.getStatus() == 8 || order.getStatus() == 12) && order.getCreatedAt() != null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(order.getCreatedAt()); + calendar.add(Calendar.DAY_OF_MONTH, 3); + long deadlineTime = calendar.getTimeInMillis(); + orderMap.put("quoteDeadlineTime", deadlineTime); + } else { + orderMap.put("quoteDeadlineTime", 0L); + } + UserDemandQuotation quotation = new UserDemandQuotation(); + quotation.setWorkerid(user.getId()); + List quotationList =userDemandQuotationService.selectUserDemandQuotationList(quotation); + orderMap.put("quoteCount", quotationList.size()); + orderMap.put("quotationList", buildQuotationList(quotationList)); +// if (order.getWorkerId() != null) { +// Users worker = usersService.selectUsersById(order.getWorkerId()); +// if (worker != null) { +// Map workerMap = new HashMap<>(); +// workerMap.put("workerName", worker.getName()); +// workerMap.put("workerAvatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); +// workerMap.put("workerPhone", worker.getPhone()); +// orderMap.put("workerMap", workerMap); +// } +// } + } + if (order.getFileData() != null && !order.getFileData().trim().isEmpty()) { + try { + List attachments = JSONArray.parseArray(order.getFileData(), String.class); + orderMap.put("attachments", attachments); + orderMap.put("attachmentCount", attachments.size()); + } catch (Exception e) { + orderMap.put("attachments", new ArrayList<>()); + orderMap.put("attachmentCount", 0); + } + } else { + orderMap.put("attachments", new ArrayList<>()); + orderMap.put("attachmentCount", 0); + } + resultList.add(orderMap); + } + Map pageResult = new HashMap<>(); + pageResult.put("total", total); + pageResult.put("pageNum", pageNum); + pageResult.put("pageSize", pageSize); + pageResult.put("data", resultList); + return AppletControllerUtil.appletSuccess(pageResult); + } catch (Exception e) { + logger.error("查询师傅订单列表失败:", e); + return AppletControllerUtil.appletError("查询师傅订单列表失败:" + e.getMessage()); + } + } + + /** + * 查询师傅详情 + * @param id 师傅id + * @return 师傅详情 + */ + @GetMapping("/api/worker/detail") + public AjaxResult getWorkerDetail(@RequestParam("id") Long id) { + try { + // 1. 查询师傅基本信息 + Users worker = usersService.selectUsersById(id); + if (worker == null) { + return AppletControllerUtil.appletWarning("师傅不存在"); + } + Map result = new HashMap<>(); + // 基本信息 + result.put("id", worker.getId()); + result.put("name", worker.getName()); + result.put("avatar", AppletControllerUtil.buildImageUrl(worker.getAvatar())); + result.put("jobNo", worker.getJobNumber()); + result.put("phone", worker.getPhone()); + // 2. 服务区域 + List> cityList = new ArrayList<>(); + try { + if (worker.getServiceCityIds() != null && !worker.getServiceCityIds().trim().isEmpty()) { + List cityIds; + String cityIdsStr = worker.getServiceCityIds().trim(); + if (cityIdsStr.startsWith("[") && cityIdsStr.endsWith("]")) { + cityIds = com.alibaba.fastjson2.JSON.parseArray(cityIdsStr, String.class); + } else { + cityIds = Arrays.asList(cityIdsStr.split(",")); + } + for (String cityId : cityIds) { + if (cityId != null && !cityId.trim().isEmpty()) { + DiyCity city = diyCityService.selectDiyCityById(Math.toIntExact(Long.parseLong(cityId.replaceAll("\"", "").trim()))); + if (city != null) { + Map cityMap = new HashMap<>(); + cityMap.put("id", city.getId()); + cityMap.put("name", city.getTitle()); + cityList.add(cityMap); + } + } + } + } + } catch (Exception e) { + logger.warn("解析师傅服务区域失败:" + e.getMessage()); + } + result.put("serviceCityList", cityList); + // 3. 服务技能 + List> skillList = new ArrayList<>(); + try { + if (worker.getSkillIds() != null && !worker.getSkillIds().trim().isEmpty()) { + List skillIds; + String skillIdsStr = worker.getSkillIds().trim(); + if (skillIdsStr.startsWith("[") && skillIdsStr.endsWith("]")) { + skillIds = com.alibaba.fastjson2.JSON.parseArray(skillIdsStr, String.class); + } else { + skillIds = Arrays.asList(skillIdsStr.split(",")); + } + for (String skillId : skillIds) { + if (skillId != null && !skillId.trim().isEmpty()) { + SiteSkill skill = siteSkillService.selectSiteSkillById(Long.parseLong(skillId.replaceAll("\"", "").trim())); + if (skill != null) { + Map skillMap = new HashMap<>(); + skillMap.put("id", skill.getId()); + skillMap.put("name", skill.getTitle()); + skillList.add(skillMap); + } + } + } + } + } catch (Exception e) { + logger.warn("解析师傅技能失败:" + e.getMessage()); + } + result.put("skillList", skillList); + // 4. 服务评价统计和评价列表 + Map commentStat = new HashMap<>(); + int goodNum = 0, midNum = 0, badNum = 0, totalNum = 0; + List> commentList = new ArrayList<>(); + OrderComment query = new OrderComment(); + query.setWorkerId(id); + List comments = orderCommentService.selectOrderCommentList(query); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + for (OrderComment c : comments) { + if (c.getNumType() != null) { + if (c.getNumType() == 1) goodNum++; + else if (c.getNumType() == 2) midNum++; + else if (c.getNumType() == 3) badNum++; + } + } + totalNum = comments.size(); + commentStat.put("total", totalNum); + commentStat.put("good", goodNum); + commentStat.put("mid", midNum); + commentStat.put("bad", badNum); + + //获取这个产品当前的第一条好评 + OrderComment orderComment =new OrderComment(); + orderComment.setWorkerId(id); + orderComment.setStatus(1); + orderComment.setNumType(1L); + List orderCommentslist = orderCommentService.selectOrderCommentList(orderComment); + if(!orderCommentslist.isEmpty()){ + JSONObject comment = new JSONObject(); + comment.put("content", orderCommentslist.getFirst().getContent()); + comment.put("id", orderCommentslist.getFirst().getId()); + comment.put("labels", JSONArray.parseArray(orderCommentslist.getFirst().getLabels()) ); + comment.put("num", orderCommentslist.getFirst().getNum()); + comment.put("uid", orderCommentslist.getFirst().getUid()); + comment.put("images",JSONArray.parseArray(orderCommentslist.getFirst().getImages()) ); + //comment.put("images",parseImagesStringToArray(orderCommentslist.getFirst().getImages())); + comment.put("commenttime", sdf.format(orderCommentslist.getFirst().getCreatedAt())); + Users u = usersService.selectUsersById(orderCommentslist.getFirst().getUid()); + if (u != null){ + JSONObject user = new JSONObject(); + user.put("id", u.getId()); + user.put("name", u.getName()); + user.put("avatar", u.getAvatar()); + comment.put("user", user); + } + result.put("comment", comment); + }else{ + result.put("comment", null); + } + + result.put("commentStat", commentStat); + + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + logger.error("查询师傅详情失败:", e); + return AppletControllerUtil.appletError("查询师傅详情失败:" + e.getMessage()); + } + } + + /** + * 查询评价接口 + * @param orderId 订单id + * @param productId 商品id + * @param uid 用户id + * @param workerId 师傅id + * @param numType 评价类型 1好评 2中评 3差评 + * @param pageNum 页码 + * @param pageSize 每页数量 + * @return 评价分页列表 + */ + @GetMapping("/api/comment/list") + public AjaxResult getCommentList( + @RequestParam(value = "order_id", required = false) String orderId, + @RequestParam(value = "product_id", required = false) Long productId, + @RequestParam(value = "uid", required = false) Long uid, + @RequestParam(value = "worker_id", required = false) Long workerId, + @RequestParam(value = "num_type", required = false) Integer numType, + @RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize + ) { + try { + OrderComment query = new OrderComment(); + if (orderId != null && !orderId.trim().isEmpty()) query.setOrderId(orderId); + if (productId != null) query.setProductId(productId); + if (uid != null) query.setUid(uid); + if (workerId != null) query.setWorkerId(workerId); + if (numType != null) query.setNumType(Long.valueOf(numType)); + List allList = orderCommentService.selectOrderCommentList(query); + int total = allList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List pageList = fromIndex < toIndex ? allList.subList(fromIndex, toIndex) : new ArrayList<>(); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + for (OrderComment c : pageList) { + Map cMap = new HashMap<>(); + Users usersdata = usersService.selectUsersById(c.getUid()); + cMap.put("userName", usersdata != null ? usersdata.getName() : ""); + cMap.put("userAvatar", usersdata != null ? AppletControllerUtil.buildImageUrl(usersdata.getAvatar()) : ""); + cMap.put("score", c.getNum()); + cMap.put("labels", c.getLabels() != null ? JSON.toJSONString(c.getLabels()) : null); + cMap.put("numType", c.getNumType()); + cMap.put("content", c.getContent()); + cMap.put("date", c.getCreatedAt() != null ? sdf.format(c.getCreatedAt()) : ""); + resultList.add(cMap); + } + Map pageResult = new HashMap<>(); + pageResult.put("total", total); + pageResult.put("pageNum", pageNum); + pageResult.put("pageSize", pageSize); + pageResult.put("data", resultList); + return AppletControllerUtil.appletSuccess(pageResult); + } catch (Exception e) { + logger.error("查询评价列表失败:", e); + return AppletControllerUtil.appletError("查询评价列表失败:" + e.getMessage()); + } + } } 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 37fb124..e5acb46 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 @@ -3183,15 +3183,38 @@ public class AppletController extends BaseController { ordertype = null; } } - - String fileData = null; + + // 处理fileData参数 - 可能是数组或字符串 + String fileData = ""; if (params.get("fileData") != null) { - fileData = params.get("fileData").toString(); + Object fileDataObj = params.get("fileData"); + if (fileDataObj instanceof String) { + fileData = (String) fileDataObj; + } else if (fileDataObj instanceof List) { + try { + @SuppressWarnings("unchecked") + List attachmentList = (List) fileDataObj; + if (attachmentList != null && !attachmentList.isEmpty()) { + // 限制最多9个附件 + if (attachmentList.size() > 9) { + return AppletControllerUtil.appletWarning("附件数量不能超过9个"); + } + // 转换为JSON数组格式的字符串 + fileData = JSONObject.toJSONString(attachmentList); + } + } catch (Exception e) { + logger.warn("附件参数解析失败: " + e.getMessage()); + fileData = ""; + } + } else { + // 其他类型,尝试转换为字符串 + fileData = fileDataObj.toString(); + } } - String remark = null; - if (params.get("remark") != null) { - remark = params.get("remark").toString(); + String reamk = null; + if (params.get("reamk") != null) { + reamk = params.get("reamk").toString(); } // 6. 查询商品信息并验证 @@ -3214,10 +3237,10 @@ public class AppletController extends BaseController { if (existingCartItem != null) { // 如果已存在,更新数量和新参数 - return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService, ordertype, fileData, remark); + return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService, ordertype, fileData, reamk,sku); } else { // 如果不存在,新增购物车记录 - return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService, ordertype, fileData, remark); + return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService, ordertype, fileData, reamk); } } catch (Exception e) { @@ -3228,6 +3251,269 @@ public class AppletController extends BaseController { + /** + * 批量删除购物车商品接口(新版,参数为{"ids":[1,2,3]}) + * @param param {"ids": [id1, id2, ...]} + * @param request HTTP请求对象 + * @return 删除结果 + */ + @PostMapping("/api/cart/delete") + public AjaxResult deleteCartItems(@RequestBody Map> param, HttpServletRequest request) { + try { + // 1. 校验用户登录 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + if (param == null || !param.containsKey("ids") || param.get("ids") == null || param.get("ids").isEmpty()) { + return AppletControllerUtil.appletWarning("请选择要删除的购物车商品"); + } + List idList = param.get("ids"); + // 查询这些购物车项,确保归属当前用户 + List cartList = goodsCartService.selectGoodsCartList(new GoodsCart()); + List toDelete = new ArrayList<>(); + for (GoodsCart cart : cartList) { + if (idList.contains(cart.getId()) && cart.getUid().equals(user.getId())) { + toDelete.add(cart.getId()); + } + } + if (toDelete.isEmpty()) { + return AppletControllerUtil.appletWarning("没有可删除的购物车商品"); + } + int result = goodsCartService.deleteGoodsCartByIds(toDelete.toArray(new Integer[0])); + if (result > 0) { + return AppletControllerUtil.appletSuccess("删除成功"); + } else { + return AppletControllerUtil.appletWarning("删除失败"); + } + } catch (Exception e) { + System.err.println("删除购物车商品异常:" + e.getMessage()); + return AppletControllerUtil.appletError("删除购物车商品失败:" + e.getMessage()); + } + } + + + + + /** + * 批量删除购物车商品接口(新版,参数为{"ids":[1,2,3]}) + * @param param {"ids": [id1, id2, ...]} + * @param request HTTP请求对象 + * @return 删除结果 + */ + @PostMapping("/api/cart/info") + public AjaxResult apicartinfo(@RequestBody Map> param, HttpServletRequest request) { + try { + // 1. 校验用户登录 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + if (param == null || !param.containsKey("ids") || param.get("ids") == null || param.get("ids").isEmpty()) { + return AppletControllerUtil.appletWarning("请选择要查询的购物车商品"); + } + List idList = param.get("ids"); + List> cartList = new ArrayList<>(); + for (Integer id : idList) { + GoodsCart cart = goodsCartService.selectGoodsCartById(id); + if (cart != null) { + Map cartMap = new HashMap<>(); + cartMap.put("id", cart.getId()); + cartMap.put("uid", cart.getUid()); + cartMap.put("goodId", cart.getGoodId()); + cartMap.put("goodNum", cart.getGoodNum()); + if (StringUtils.isNotBlank(cart.getSku())){ + cartMap.put("sku",JSONObject.parseObject(cart.getSku())); + }else{ + cartMap.put("sku", ""); + } + cartMap.put("reamk", cart.getReamk()); + if (StringUtils.isNotBlank(cart.getFileData())){ + //cartMap.put("fileData",AppletControllerUtil.parseImagesStringToArray(cart.getFileData())); + cartMap.put("fileData", JSONArray.parseArray(cart.getFileData())); + }else{ + cartMap.put("fileData", JSONArray.parseArray("[]")); + } +// cartMap.put("fileData", cart.getFileData()); + cartMap.put("ordertype", cart.getOrdertype()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(cart.getGoodId()); + if (serviceGoods != null){ + Map serviceGoodsMap = new HashMap<>(); + serviceGoodsMap.put("id", serviceGoods.getId()); + serviceGoodsMap.put("name", serviceGoods.getTitle()); + serviceGoodsMap.put("icon",AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); + serviceGoodsMap.put("price", serviceGoods.getPrice()); + cartMap.put("serviceGoods", serviceGoodsMap); + } +// //服务 +// if(cart.getGoodstype()==1){ +// +// } +// if(cart.getGoodstype()==2){ +// +// } + + // cartMap.put("goodstype", cart.getg); + cartList.add(cartMap); + } + } + return AppletControllerUtil.appletSuccess(cartList); + } catch (Exception e) { + System.err.println("查询购物车商品异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询购物车商品失败:" + e.getMessage()); + } + } + + + + +// /** +// * 查看购物车详情接口 +// * @param id 购物车ID +// * @param request HTTP请求对象 +// * @return 购物车详情 +// */ +// @GetMapping("/api/cart/info/{id}") +// public AjaxResult getCartInfo(@PathVariable("id") Long id, HttpServletRequest request) { +// try { +// // 校验用户登录 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletUnauthorized(); +// } +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// if (id == null) { +// return AppletControllerUtil.appletWarning("购物车ID不能为空"); +// } +// GoodsCart cart = goodsCartService.selectGoodsCartById(Math.toIntExact(id)); +// if (cart == null || !cart.getUid().equals(user.getId())) { +// return AppletControllerUtil.appletWarning("购物车不存在或无权查看"); +// } +// return AppletControllerUtil.appletSuccess(cart); +// } catch (Exception e) { +// return AppletControllerUtil.appletError("查询购物车详情失败:" + e.getMessage()); +// } +// } + + /** + * 修改购物车接口 + * @param params 前端传递的需要修改的字段,必须包含id + * @param request HTTP请求对象 + * @return 修改结果 + */ + @PostMapping("/api/cart/edit") + public AjaxResult editCart(@RequestBody Map params, HttpServletRequest request) { + try { + // 校验用户登录 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletWarning("购物车ID不能为空"); + } + Long id = Long.valueOf(params.get("id").toString()); + GoodsCart cart = goodsCartService.selectGoodsCartById(Math.toIntExact(id)); + if (cart == null || !cart.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("购物车不存在或无权修改"); + } + // 只更新前端传递的字段 + if (params.containsKey("num")) { + cart.setGoodNum(Long.valueOf(params.get("num").toString())); + } +// if (params.containsKey("sku")) { +// cart.setSku(params.get("sku") != null ? params.get("sku").toString() : null); +// } + String sku = null; + if (params.get("sku") != null) { + Object skuParam = params.get("sku"); + if (skuParam instanceof Map) { + // 如果前端传递的是Map对象,转换为JSON字符串 + try { + sku = JSON.toJSONString(skuParam); + } catch (Exception e) { + System.err.println("SKU转换JSON失败:" + e.getMessage()); + sku = skuParam.toString(); + } + } else { + // 如果前端传递的是字符串,直接使用 + sku = skuParam.toString().trim(); + } + } else { + sku = null; + } + cart.setSku(sku); + if (params.containsKey("ordertype")) { + cart.setOrdertype(params.get("ordertype") != null ? Long.valueOf(params.get("ordertype").toString()) : null); + } + + // 处理fileData参数 - 可能是数组或字符串 + String fileData = ""; + if (params.get("fileData") != null) { + Object fileDataObj = params.get("fileData"); + if (fileDataObj instanceof String) { + fileData = (String) fileDataObj; + } else if (fileDataObj instanceof List) { + try { + @SuppressWarnings("unchecked") + List attachmentList = (List) fileDataObj; + if (attachmentList != null && !attachmentList.isEmpty()) { + // 限制最多9个附件 + if (attachmentList.size() > 9) { + return AppletControllerUtil.appletWarning("附件数量不能超过9个"); + } + // 转换为JSON数组格式的字符串 + fileData = JSONObject.toJSONString(attachmentList); + } + } catch (Exception e) { + logger.warn("附件参数解析失败: " + e.getMessage()); + fileData = ""; + } + } else { + // 其他类型,尝试转换为字符串 + fileData = fileDataObj.toString(); + } + } + cart.setFileData(fileData); +// if (params.containsKey("fileData")) { +// cart.setFileData(params.get("fileData") != null ? params.get("fileData").toString() : null); +// } + if (params.containsKey("reamk")) { + cart.setReamk(params.get("reamk") != null ? params.get("reamk").toString() : null); + } + // 其他字段可按需补充 + cart.setUpdatedAt(new Date()); + int result = goodsCartService.updateGoodsCart(cart); + if (result > 0) { + return AppletControllerUtil.appletSuccess("修改成功"); + } else { + return AppletControllerUtil.appletWarning("修改失败"); + } + } catch (Exception e) { + return AppletControllerUtil.appletError("修改购物车失败:" + e.getMessage()); + } + } + + /** * 查询用户购物车数据,按商品类型分为商城类和服务类(不分页) * @@ -3368,7 +3654,6 @@ public class AppletController extends BaseController { for (GoodsCart cart : cartList) { Map cartData = new HashMap<>(); - // 基本购物车信息 cartData.put("id", cart.getId()); cartData.put("uid", cart.getUid()); @@ -3632,7 +3917,6 @@ public class AppletController extends BaseController { orderDetail.put("mark", order.getMark()); orderDetail.put("address_id", order.getAddressId()); orderDetail.put("sku", order.getSku()); - // 时间字段格式化 orderDetail.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); orderDetail.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ServiceGoodsController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ServiceGoodsController.java index 57f10fc..f310fa6 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ServiceGoodsController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ServiceGoodsController.java @@ -91,6 +91,20 @@ public class ServiceGoodsController extends BaseController { return success(serviceGoodsService.selectServiceGoodsList(serviceGoods)); } + /** + * 获取服务内容详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:ServiceGoods:query')") + @GetMapping(value = "/selectTypeList/{type}") + public AjaxResult selectTypeList(@PathVariable("type") Integer type) { + + ServiceGoods serviceGoods = new ServiceGoods(); + if (type != null){ + serviceGoods.setType(type); + } + return success(serviceGoodsService.selectServiceGoodsList(serviceGoods)); + } + /** * 获取服务内容详细信息 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 29430a8..5b6d580 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 @@ -660,7 +660,11 @@ public class AppletControllerUtil { if (imagePath == null || imagePath.trim().isEmpty()) { return ""; } - return CDN_BASE_URL + imagePath.trim(); + String trimmed = imagePath.trim(); + if (trimmed.contains("img.huafurenjia.cn")) { + return trimmed; + } + return CDN_BASE_URL + trimmed; } /** @@ -2791,7 +2795,7 @@ public class AppletControllerUtil { GoodsCart cartItem, ServiceGoods serviceGoods, IGoodsCartService goodsCartService) { - return updateCartItemQuantity(cartItem, serviceGoods, goodsCartService, null, null, null); + return updateCartItemQuantity(cartItem, serviceGoods, goodsCartService, null, null, null,null); } /** @@ -2811,7 +2815,8 @@ public class AppletControllerUtil { IGoodsCartService goodsCartService, Long ordertype, String fileData, - String remark) { + String remark, + String sku) { try { // 数量加1 Long newQuantity = (cartItem.getGoodNum() != null ? cartItem.getGoodNum() : 0L) + 1L; @@ -2829,6 +2834,7 @@ public class AppletControllerUtil { updateCart.setFileData(fileData); updateCart.setReamk(remark); updateCart.setUpdatedAt(new Date()); + updateCart.setSku(sku); int updateResult = goodsCartService.updateGoodsCart(updateCart); @@ -2869,7 +2875,7 @@ public class AppletControllerUtil { * @param goodsCartService 购物车服务 * @param ordertype 订单类别 * @param fileData 附件 - * @param remark 备注 + * @return 添加结果 */ public static AjaxResult addNewCartItem( @@ -2879,7 +2885,7 @@ public class AppletControllerUtil { IGoodsCartService goodsCartService, Long ordertype, String fileData, - String remark) { + String reamk) { try { // 构建购物车记录 GoodsCart newCartItem = new GoodsCart(); @@ -2889,9 +2895,11 @@ public class AppletControllerUtil { newCartItem.setGoodNum(1L); // 默认数量为1 newCartItem.setOrdertype(ordertype); newCartItem.setFileData(fileData); - newCartItem.setReamk(remark); + newCartItem.setReamk(reamk); newCartItem.setCreatedAt(new Date()); newCartItem.setUpdatedAt(new Date()); + newCartItem.setGoodstype(Long.valueOf(serviceGoods.getType())); + // 插入购物车记录 int insertResult = goodsCartService.insertGoodsCart(newCartItem); @@ -3073,6 +3081,43 @@ public class AppletControllerUtil { return imageData; } + + + + + public static String getStringFileData(String imageUrl) { + String fileData = ""; + + Object fileDataObj = imageUrl; + if (fileDataObj instanceof String) { + fileData = (String) fileDataObj; + } else if (fileDataObj instanceof List) { + try { + @SuppressWarnings("unchecked") + List attachmentList = (List) fileDataObj; + if (attachmentList != null && !attachmentList.isEmpty()) { + // 限制最多9个附件 + // 转换为JSON数组格式的字符串 + return JSONObject.toJSONString(attachmentList); + } + } catch (Exception e) { + return JSONObject.toJSONString("[]"); + } + } else { + // 其他类型,尝试转换为字符串 + return fileDataObj.toString(); + } + + return fileData; + } + + + + + + + + /** * 发送微信小程序订阅消息(自动获取accessToken) * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CartOrderUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CartOrderUtil.java new file mode 100644 index 0000000..3452bd7 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/CartOrderUtil.java @@ -0,0 +1,201 @@ +package com.ruoyi.system.ControllerUtil; + +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.system.domain.*; +import com.ruoyi.system.service.IOrderService; +import com.ruoyi.system.service.IGoodsOrderService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * 购物车生成订单工具类 + */ +public class CartOrderUtil { + private static final Logger logger = LoggerFactory.getLogger(CartOrderUtil.class); + + /** + * 服务类购物车下单 + * @param user 用户 + * @param cart 购物车 + * @param serviceGoods 商品 + * @param userAddress 地址 + * @param makeTime 预约时间 + * @param orderService 服务订单service + * @return 下单结果Map + */ + public static Map createServiceOrderFromCart(Users user, GoodsCart cart, ServiceGoods serviceGoods, UserAddress userAddress, String makeTime, IOrderService orderService, com.ruoyi.system.service.IOrderLogService orderLogService,String maincorid) { + Map result = new HashMap<>(); + try { + BigDecimal itemPrice=BigDecimal.ZERO; + // 判断ordertype=2时的特殊价格逻辑 + if (cart.getOrdertype() != null && cart.getOrdertype() == 2) { + String skuStr = cart.getSku(); + if (skuStr != null && !skuStr.trim().isEmpty()) { + try { + com.alibaba.fastjson2.JSONObject skuJson = com.alibaba.fastjson2.JSONObject.parseObject(skuStr); + if (skuJson.containsKey("seckillprice")) { + BigDecimal seckillPrice = new BigDecimal(skuJson.getString("seckillprice")); + itemPrice = seckillPrice.multiply(BigDecimal.valueOf(cart.getGoodNum())); + } else { + // 没有seckillprice字段,回退用fixedprice + itemPrice = (serviceGoods.getFixedprice() != null ? serviceGoods.getFixedprice() : serviceGoods.getPrice()).multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + } catch (Exception e) { + // 解析失败,回退用fixedprice + itemPrice = (serviceGoods.getFixedprice() != null ? serviceGoods.getFixedprice() : serviceGoods.getPrice()).multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + } else { + // sku为空,直接用fixedprice + itemPrice = BigDecimal.ZERO; + } + } else { + // 其他情况用普通价格 + itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + Order order = new Order(); + order.setType(1); + order.setCreateType(1); + order.setOrderId(GenerateCustomCode.generCreateOrder("B")); + order.setUid(user.getId()); + order.setUname(user.getName()); + order.setProductId(serviceGoods.getId()); + order.setProductName(serviceGoods.getTitle()); + order.setNum(cart.getGoodNum()); + order.setSku(cart.getSku()); + order.setReamk(cart.getReamk()); + order.setFileData(cart.getFileData()); + order.setOdertype(cart.getOrdertype() != null ? cart.getOrdertype().intValue() : 0); + order.setAddressId(userAddress.getId()); + order.setName(userAddress.getName()); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + if (makeTime != null && !makeTime.isEmpty()) { + String[] makeTimeArr = makeTime.split(" "); + if (makeTimeArr.length == 2) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date date = sdf.parse(makeTimeArr[0]); + order.setMakeTime(date.getTime() / 1000); + order.setMakeHour(makeTimeArr[1]); + } catch (Exception e) { + logger.warn("预约时间格式错误: " + makeTime); + } + } + } + order.setTotalPrice(itemPrice); + order.setGoodPrice(serviceGoods.getPrice()); + order.setServicePrice(BigDecimal.ZERO); + order.setPayPrice(itemPrice); + order.setStatus(1L); + order.setReceiveType(1L); + order.setIsAccept(0); + order.setIsComment(0); + order.setIsPause(1); + order.setMainOrderId(maincorid); + order.setDeduction(BigDecimal.ZERO); + int insertResult = orderService.insertOrder(order); + if (insertResult <= 0) { + result.put("success", false); + result.put("msg", "服务订单创建失败"); + return result; + } + // 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + orderLog.setType(BigDecimal.valueOf(1.0)); + com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject(); + jsonObject.put("name", "订单创建成功"); + orderLog.setContent(jsonObject.toJSONString()); + orderLogService.insertOrderLog(orderLog); + result.put("success", true); + result.put("orderId", order.getOrderId()); + result.put("productName", serviceGoods.getTitle()); + result.put("allprice", itemPrice.toString()); + return result; + } catch (Exception e) { + logger.error("服务类购物车下单异常:", e); + result.put("success", false); + result.put("msg", "服务类购物车下单异常:" + e.getMessage()); + return result; + } + } + + /** + * 商品类购物车下单 + * @param user 用户 + * @param cart 购物车 + * @param serviceGoods 商品 + * @param userAddress 地址 + * @param goodsOrderService 商品订单service + * @return 下单结果Map + */ + public static Map createGoodsOrderFromCart(Users user, GoodsCart cart, ServiceGoods serviceGoods, UserAddress userAddress, IGoodsOrderService goodsOrderService,String maincorid) { + Map result = new HashMap<>(); + try { + BigDecimal itemPrice=BigDecimal.ZERO; + String skuStr = cart.getSku(); + if (skuStr != null && !skuStr.trim().isEmpty()) { + try { + JSONObject skuJson = JSONObject.parseObject(skuStr); + if (skuJson.containsKey("price")) { + BigDecimal skuPrice = new BigDecimal(skuJson.getString("price")); + itemPrice = skuPrice.multiply(BigDecimal.valueOf(cart.getGoodNum())); + } else { + // 没有price字段,回退用商品price + itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + } catch (Exception e) { + // 解析失败,回退用商品price + itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + } else { + // sku为空,直接用商品price + itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(cart.getGoodNum())); + } + GoodsOrder goodsOrder = new GoodsOrder(); + goodsOrder.setType(2); + goodsOrder.setOrderId(GenerateCustomCode.generCreateOrder("B")); + goodsOrder.setUid(user.getId()); + goodsOrder.setUname(user.getName()); + goodsOrder.setProductId(serviceGoods.getId()); + goodsOrder.setProductName(serviceGoods.getTitle()); + goodsOrder.setNum(cart.getGoodNum()); + goodsOrder.setSku(cart.getSku()); + goodsOrder.setIsforservice(serviceGoods.getIsforservice()); + goodsOrder.setForserviceid(serviceGoods.getForserviceid()); + goodsOrder.setMark(cart.getReamk()); + goodsOrder.setAddressId(userAddress.getId()); + goodsOrder.setName(userAddress.getName()); + goodsOrder.setPhone(userAddress.getPhone()); + goodsOrder.setAddress(userAddress.getAddressInfo()); + goodsOrder.setTotalPrice(itemPrice); + goodsOrder.setGoodPrice(serviceGoods.getPrice()); + goodsOrder.setPayPrice(itemPrice); + goodsOrder.setStatus(1L); // 待支付 + goodsOrder.setMainOrderId(maincorid); + int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); + if (insertResult <= 0) { + result.put("success", false); + result.put("msg", "商品订单创建失败"); + return result; + } + result.put("success", true); + result.put("orderId", goodsOrder.getOrderId()); + result.put("productName", serviceGoods.getTitle()); + result.put("allprice", itemPrice.toString()); + return result; + } catch (Exception e) { + logger.error("商品类购物车下单异常:", e); + result.put("success", false); + result.put("msg", "商品类购物车下单异常:" + e.getMessage()); + return result; + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java new file mode 100644 index 0000000..036b94f --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/PayBeforeUtil.java @@ -0,0 +1,338 @@ +package com.ruoyi.system.ControllerUtil; + +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.domain.SiteConfig; +import com.ruoyi.system.domain.Users; +import com.ruoyi.system.domain.UsersPayBefor; +import com.ruoyi.system.service.IUsersPayBeforService; +import com.ruoyi.system.service.ISiteConfigService; +import com.ruoyi.system.service.IUsersService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 预支付工具类 + * + * @author ruoyi + * @date 2025-07-17 + */ +@Component +public class PayBeforeUtil { + + + private static final IUsersPayBeforService usersPayBeforService = SpringUtils.getBean(IUsersPayBeforService.class); + private static final ISiteConfigService siteConfigService = SpringUtils.getBean(ISiteConfigService.class); + private static final IUsersService usersService = SpringUtils.getBean(IUsersService.class); + + + + /** + * 创建预支付记录 + * + * @param user 用户信息 + * @param amount 支付金额 + * @param orderId 订单号 + * @param oid 订单ID + * @param serviceId 服务ID + * @param orderType 订单类型 + * @param sku SKU规格信息 + * @param grouporderid 拼团订单ID + * @param addressid 地址ID + * @param maketime 预约时间 + * @param attachments 附件信息 + * @return 预支付记录ID,失败返回null + */ + public String createPayBefore(Users user, BigDecimal amount, String orderId, Long oid, + Long serviceId, Long orderType, String sku, String grouporderid, + Long addressid, String maketime, String attachments,Long servicetype) { + try { + // 计算会员优惠和服务金抵扣 + BigDecimal memberMoney = BigDecimal.ZERO; + BigDecimal serviceMoney = BigDecimal.ZERO; + BigDecimal shopMoney = BigDecimal.ZERO; + try { + SiteConfig configQuery = new SiteConfig(); + configQuery.setName("config_one"); + List configList = siteConfigService.selectSiteConfigList(configQuery); + if (configList != null && !configList.isEmpty()) { + String configValue = configList.get(0).getValue(); + if (configValue != null && !configValue.trim().isEmpty()) { + com.alibaba.fastjson2.JSONObject configJson = com.alibaba.fastjson2.JSONObject.parseObject(configValue); + // 会员优惠 + if (user.getIsmember() != null && user.getIsmember() == 1) { + Integer memberDiscount = configJson.getInteger("member_discount"); + if (memberDiscount != null && memberDiscount > 0) { + BigDecimal discountRate = BigDecimal.valueOf(memberDiscount).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); + memberMoney = amount.multiply(discountRate); + } + } + // 服务金抵扣 + if (servicetype != null && servicetype == 1) { + Integer serviceFee = configJson.getInteger("servicefee"); + if (serviceFee != null && serviceFee > 0) { + Users userDb = usersService.selectUsersById(user.getId()); + if (userDb != null && userDb.getServicefee() != null && userDb.getServicefee().compareTo(BigDecimal.ZERO) > 0) { + BigDecimal serviceRate = BigDecimal.valueOf(serviceFee).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); + serviceMoney = userDb.getServicefee().multiply(serviceRate); + } + } + } + // 购物金抵扣(当servicetype=2时) + if (servicetype != null && servicetype == 2) { + orderType= 5L; + Integer consumption = configJson.getInteger("consumption"); + if (consumption != null && consumption > 0) { + Users userDb = usersService.selectUsersById(user.getId()); + if (userDb != null && userDb.getConsumption() != null && userDb.getConsumption().compareTo(BigDecimal.ZERO) > 0) { + BigDecimal consumptionRate = BigDecimal.valueOf(consumption).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); + shopMoney = userDb.getConsumption().multiply(consumptionRate); + } + } + } + } + } + } catch (Exception e) { + memberMoney = BigDecimal.ZERO; + serviceMoney = BigDecimal.ZERO; + shopMoney = BigDecimal.ZERO; + } + UsersPayBefor payBefore = new UsersPayBefor(); + payBefore.setUid(user.getId()); + payBefore.setOrderid(orderId); + payBefore.setOid(oid); + payBefore.setPaycode(GenerateCustomCode.generCreateOrder("PAY")); + payBefore.setAllmoney(amount); // 原始总金额 + // 微信支付金额 = 总金额 - 会员优惠 - 服务金抵扣 - 购物金抵扣 + BigDecimal wxPayAmount = amount.subtract(memberMoney).subtract(serviceMoney).subtract(shopMoney); + payBefore.setWxmoney(wxPayAmount.compareTo(BigDecimal.ZERO) > 0 ? wxPayAmount : BigDecimal.ZERO); + payBefore.setShopmoney(shopMoney); + payBefore.setServicemoney(serviceMoney); + payBefore.setMtmoney(BigDecimal.ZERO); + payBefore.setYemoney(BigDecimal.ZERO); + payBefore.setCouponmoney(BigDecimal.ZERO); + payBefore.setServicetype(servicetype); + payBefore.setMembermoney(memberMoney); + payBefore.setType(orderType); + payBefore.setSku(sku != null ? sku : ""); + payBefore.setServiceid(serviceId); + payBefore.setGrouporderid(grouporderid != null ? grouporderid : ""); + payBefore.setAddressid(addressid); + payBefore.setMaketime(maketime != null ? maketime : ""); + payBefore.setAttachments(attachments != null ? attachments : ""); + payBefore.setStatus(1L); // 1待支付 + payBefore.setPaytype(1L); // 默认微信支付 + int result = usersPayBeforService.insertUsersPayBefor(payBefore); + if (result > 0) { + return payBefore.getOrderid(); + } + return null; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + + + +// /** +// * 创建预支付记录购物车过来的 +// * +// * @param user 用户信息 +// * @param amount 支付金额 +// * @param orderId 订单号 +// * @param oid 订单ID +// * @param serviceId 服务ID +// * @param orderType 订单类型 +// * @param sku SKU规格信息 +// * @param grouporderid 拼团订单ID +// * @param addressid 地址ID +// * @param maketime 预约时间 +// * @param attachments 附件信息 +// * @return 预支付记录ID,失败返回null +// */ +// public Long createPayBeforeByCar(Users user, BigDecimal amount, String orderId, Long oid, +// Long serviceId, Long orderType, String sku, String grouporderid, +// Long addressid, String maketime, String attachments) { +// try { +// // 计算会员优惠和服务金抵扣 +// BigDecimal memberMoney = BigDecimal.ZERO; +// BigDecimal serviceMoney = BigDecimal.ZERO; +// try { +// SiteConfig configQuery = new SiteConfig(); +// configQuery.setName("config_one"); +// List configList = siteConfigService.selectSiteConfigList(configQuery); +// if (configList != null && !configList.isEmpty()) { +// String configValue = configList.get(0).getValue(); +// if (configValue != null && !configValue.trim().isEmpty()) { +// com.alibaba.fastjson2.JSONObject configJson = com.alibaba.fastjson2.JSONObject.parseObject(configValue); +// // 会员优惠 +// if (user.getIsmember() != null && user.getIsmember() == 1) { +// Integer memberDiscount = configJson.getInteger("member_discount"); +// if (memberDiscount != null && memberDiscount > 0) { +// BigDecimal discountRate = BigDecimal.valueOf(memberDiscount).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); +// memberMoney = amount.multiply(discountRate); +// } +// } +// // 服务金抵扣 +// Integer serviceFee = configJson.getInteger("servicefee"); +// if (serviceFee != null && serviceFee > 0) { +// Users userDb = usersService.selectUsersById(user.getId()); +// if (userDb != null && userDb.getServicefee() != null && userDb.getServicefee().compareTo(BigDecimal.ZERO) > 0) { +// BigDecimal serviceRate = BigDecimal.valueOf(serviceFee).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); +// serviceMoney = userDb.getServicefee().multiply(serviceRate); +// } +// } +// } +// } +// } catch (Exception e) { +// memberMoney = BigDecimal.ZERO; +// serviceMoney = BigDecimal.ZERO; +// } +// UsersPayBefor payBefore = new UsersPayBefor(); +// payBefore.setUid(user.getId()); +// payBefore.setOrderid(orderId); +// payBefore.setOid(oid); +// payBefore.setPaycode(GenerateCustomCode.generCreateOrder("PAY")); +// payBefore.setAllmoney(amount); +// payBefore.setWxmoney(amount); +// payBefore.setShopmoney(BigDecimal.ZERO); +// payBefore.setServicemoney(serviceMoney); +// payBefore.setMtmoney(BigDecimal.ZERO); +// payBefore.setYemoney(BigDecimal.ZERO); +// payBefore.setCouponmoney(BigDecimal.ZERO); +// payBefore.setServicetype(serviceId); +// payBefore.setMembermoney(memberMoney); +// payBefore.setType(orderType); +// payBefore.setSku(sku != null ? sku : ""); +// payBefore.setServiceid(serviceId); +// payBefore.setGrouporderid(grouporderid != null ? grouporderid : ""); +// payBefore.setAddressid(addressid); +// payBefore.setMaketime(maketime != null ? maketime : ""); +// payBefore.setAttachments(attachments != null ? attachments : ""); +// payBefore.setStatus(1L); // 1待支付 +// payBefore.setPaytype(1L); // 默认微信支付 +// int result = usersPayBeforService.insertUsersPayBefor(payBefore); +// if (result > 0) { +// return payBefore.getId(); +// } +// return null; +// } catch (Exception e) { +// e.printStackTrace(); +// return null; +// } +// } + + + /** + * 创建预支付记录(简化版) + * + * @param user 用户信息 + * @param amount 支付金额 + * @return 预支付记录ID,失败返回null + */ + public String createPayBefore(Users user, BigDecimal amount) { + return createPayBefore(user, amount, null, null, 0L, 0L, null, null, null, null, null,null); + } + + /** + * 创建预支付记录(基础版) + * + * @param user 用户信息 + * @param amount 支付金额 + * @param orderId 订单号 + * @param oid 订单ID + * @param serviceId 服务ID + * @param orderType 订单类型 + * @return 预支付记录ID,失败返回null + */ + public String createPayBefore(Users user, BigDecimal amount, String orderId, Long oid, + Long serviceId, Long orderType) { + return createPayBefore(user, amount, orderId, oid, serviceId, orderType, null, null, null, null, null,null); + } + + /** + * 更新预支付记录 + * + * @param payBeforeId 预支付记录ID + * @param amount 新的支付金额 + * @return 是否更新成功 + */ + public boolean updatePayBefore(Long payBeforeId, BigDecimal amount) { + try { + UsersPayBefor payBefore = usersPayBeforService.selectUsersPayBeforById(payBeforeId); + if (payBefore == null) { + return false; + } + payBefore.setAllmoney(amount); + payBefore.setWxmoney(amount); + payBefore.setUpdateTime(new Date()); + int result = usersPayBeforService.updateUsersPayBefor(payBefore); + return result > 0; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 更新预支付记录状态 + * + * @param payBeforeId 预支付记录ID + * @param status 新状态 + * @return 是否更新成功 + */ + public boolean updatePayBeforeStatus(Long payBeforeId, Long status) { + try { + UsersPayBefor payBefore = usersPayBeforService.selectUsersPayBeforById(payBeforeId); + if (payBefore == null) { + return false; + } + payBefore.setStatus(status); + if (status == 2L) { // 支付成功 + payBefore.setPaytime(new Date()); + } + payBefore.setUpdateTime(new Date()); + int result = usersPayBeforService.updateUsersPayBefor(payBefore); + return result > 0; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 根据订单号查询预支付记录 + * + * @param orderId 订单号 + * @return 预支付记录,不存在返回null + */ + public UsersPayBefor getPayBeforeByOrderId(String orderId) { + try { + return usersPayBeforService.selectUsersPayBeforByOrderId(orderId); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + /** + * 删除预支付记录 + * + * @param payBeforeId 预支付记录ID + * @return 是否删除成功 + */ + public boolean deletePayBefore(Long payBeforeId) { + try { + int result = usersPayBeforService.deleteUsersPayBeforById(payBeforeId); + return result > 0; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppleDoMain/OrderApple.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppleDoMain/OrderApple.java index 027ad77..2a0c580 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppleDoMain/OrderApple.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/AppleDoMain/OrderApple.java @@ -24,7 +24,8 @@ public class OrderApple extends BaseEntity { private Integer type;// 1 private Integer odertype;// 1 private Integer reamk;// 1 - + private Integer cartid; + private Integer bigtype; private String fileData; private Long uid;// : 302 @@ -171,4 +172,21 @@ public class OrderApple extends BaseEntity { public void setReamk(Integer reamk) { this.reamk = reamk; } + + + public Integer getBigtype() { + return bigtype; + } + + public void setBigtype(Integer bigtype) { + this.bigtype = bigtype; + } + + public Integer getCartid() { + return cartid; + } + + public void setCartid(Integer cartid) { + this.cartid = cartid; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsCart.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsCart.java index 8cd7a7f..888e275 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsCart.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsCart.java @@ -57,6 +57,9 @@ public class GoodsCart extends BaseEntity @Excel(name = "类别") private Long ordertype; + + + /** $column.columnComment */ @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private Date createdAt; @@ -160,6 +163,14 @@ public class GoodsCart extends BaseEntity this.ordertype = ordertype; } + public Long getGoodstype() { + return goodstype; + } + + public void setGoodstype(Long goodstype) { + this.goodstype = goodstype; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java index 4b1789e..7d8b3e2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/GoodsOrder.java @@ -105,6 +105,16 @@ public class GoodsOrder extends BaseEntity @Excel(name = "邮费") private BigDecimal postage; + /** 排序 */ + @Excel(name = "是否跳转服务") + private Integer isforservice; + + + /** 排序 */ + @Excel(name = "跳转服务id") + private Integer forserviceid; + + /** 支付时间 */ @JsonFormat(pattern = "yyyy-MM-dd") @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd") @@ -531,6 +541,23 @@ public class GoodsOrder extends BaseEntity this.shopadresssid = shopadresssid; } + + public Integer getForserviceid() { + return forserviceid; + } + + public void setForserviceid(Integer forserviceid) { + this.forserviceid = forserviceid; + } + + public Integer getIsforservice() { + return isforservice; + } + + public void setIsforservice(Integer isforservice) { + this.isforservice = isforservice; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java index 1181dab..5125fb0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/Order.java @@ -192,6 +192,10 @@ public class Order extends BaseEntity @Excel(name = "服务评价") private int fwpj; + /** 通知记录 */ + @Excel(name = "大分类") + private Integer bigtype; + /** 订单附件 */ @Excel(name = "订单附件") @@ -875,6 +879,14 @@ public class Order extends BaseEntity this.cartid = cartid; } + public Integer getBigtype() { + return bigtype; + } + + public void setBigtype(Integer bigtype) { + this.bigtype = bigtype; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java index ccdee0c..660eb32 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java @@ -115,7 +115,21 @@ private String cateName; @Excel(name = "排序") private Integer sort; + /** 排序 */ + @Excel(name = "是否跳转服务") + private Integer isforservice; + + + /** 排序 */ + @Excel(name = "跳转服务id") + private Integer forserviceid; + + + + /** 物料费用 */ + + @Excel(name = "物料费用") private String material; @@ -650,6 +664,22 @@ private String cateName; this.questions = questions; } + public Integer getIsforservice() { + return isforservice; + } + + public void setIsforservice(Integer isforservice) { + this.isforservice = isforservice; + } + + public Integer getForserviceid() { + return forserviceid; + } + + public void setForserviceid(Integer forserviceid) { + this.forserviceid = forserviceid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml b/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml index 5c58315..1100584 100644 --- a/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml @@ -13,6 +13,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + @@ -42,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, type, main_order_id, order_id, transaction_id,isself,coupon_id,shopadresssid, uid, product_id, name, phone, address, num, total_price, good_price, service_price, pay_price, deduction, postage, pay_time, status, delivery_id, delivery_num, send_time, mark, address_id, sku, created_at, updated_at, deleted_at from goods_order + select id, type, main_order_id, order_id, transaction_id,forserviceid,isforservice,isself,coupon_id,shopadresssid, uid, product_id, name, phone, address, num, total_price, good_price, service_price, pay_price, deduction, postage, pay_time, status, delivery_id, delivery_num, send_time, mark, address_id, sku, created_at, updated_at, deleted_at from goods_order @@ -162,7 +168,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" groupnum, servicetype, questions, - + isforservice, + forserviceid, created_at, updated_at @@ -208,6 +215,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{groupnum}, #{servicetype}, #{questions}, + #{isforservice}, + #{forserviceid}, NOW(), NOW() @@ -250,7 +259,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" onceprice = #{onceprice}, servicetype = #{servicetype}, questions = #{questions}, - + isforservice = #{isforservice}, + forserviceid = #{forserviceid}, commissiontype = #{commissiontype}, commission = #{commission}, dispatchtype = #{dispatchtype}, diff --git a/ruoyi-ui/src/api/system/ServiceGoods.js b/ruoyi-ui/src/api/system/ServiceGoods.js index c2783c7..ec335d8 100644 --- a/ruoyi-ui/src/api/system/ServiceGoods.js +++ b/ruoyi-ui/src/api/system/ServiceGoods.js @@ -22,6 +22,17 @@ export function getServiceGoods(id) { method: 'get' }) } + +// 查询服务内容详细 +export function getselectTypeList(type) { + return request({ + url: '/system/ServiceGoods/selectTypeList/' + type, + method: 'get' + }) +} + + + // 查询服务内容详细 export function selectServiceCateList(id) { return request({ diff --git a/ruoyi-ui/src/views/system/GoodsShangPin/index.vue b/ruoyi-ui/src/views/system/GoodsShangPin/index.vue index 2be5cec..3f0a7da 100644 --- a/ruoyi-ui/src/views/system/GoodsShangPin/index.vue +++ b/ruoyi-ui/src/views/system/GoodsShangPin/index.vue @@ -95,7 +95,7 @@ v-hasPermi="['system:ServiceGoods:remove']" >删除 - + @@ -267,6 +267,23 @@ inactive-value="0" /> + + + + + + + + + + + + @@ -287,7 +304,7 @@ - + @@ -356,7 +373,7 @@