diff --git a/AppletController统一响应处理说明.md b/AppletController统一响应处理说明.md index 575e268..e12204a 100644 --- a/AppletController统一响应处理说明.md +++ b/AppletController统一响应处理说明.md @@ -157,4 +157,175 @@ return AppletControllerUtil.appletWarning("积分不足"); ## 下一步工作 -需要继续对剩余的方法进行统一响应格式处理,确保所有小程序接口都使用统一的响应格式。 \ No newline at end of file +需要继续对剩余的方法进行统一响应格式处理,确保所有小程序接口都使用统一的响应格式。 + +# AppletController 接口说明 + +## 修改的接口 + +### `/api/paybefor/info/{id}` - 预支付记录查询和金额计算 + +**请求方式**: POST +**接口描述**: 根据预支付记录ID查询详情,并根据传递的参数计算支付金额 + +**请求参数**: +- `id` (路径参数): 预支付记录ID +- `paytype` (可选): 支付方式,1=微信支付,2=余额支付,3=组合支付,默认为1 +- `coupon_id` (可选): 优惠券ID +- `mtcode` (可选): 美团优惠码 + +**请求示例**: +```json +{ + "paytype": 1, + "coupon_id": 123, + "mtcode": "MT123456" +} +``` + +**响应示例**: + +**微信支付示例**: +```json +{ + "code": 200, + "msg": "操作成功", + "data": { + "id": 1, + "orderId": "ORDER20250101001", + "paycode": "PAY20250101001", + "allmoney": 100.00, + "finalAmount": 85.10, + "wxmoney": 85.10, + "yemoney": 0.00, + "membermoney": 5.00, + "shopmoney": 2.00, + "servicemoney": 3.00, + "couponmoney": 10.00, + "mtmoney": 9.90, + "type": 1, + "paytype": 1, + "usersBalance": 50.00, + "couponId": 123, + "mtcode": "MT123456", + "calculationDetail": { + "originalAmount": 100.00, + "memberDiscount": 5.00, + "serviceDiscount": 3.00, + "shopDiscount": 2.00, + "couponDiscount": 10.00, + "mtDiscount": 9.90, + "finalAmount": 85.10 + } + } +} +``` + +**组合支付示例**(用户余额30元,实际应付85.10元): +```json +{ + "code": 200, + "msg": "操作成功", + "data": { + "id": 1, + "orderId": "ORDER20250101001", + "paycode": "PAY20250101001", + "allmoney": 100.00, + "finalAmount": 85.10, + "wxmoney": 55.10, + "yemoney": 30.00, + "membermoney": 5.00, + "shopmoney": 2.00, + "servicemoney": 3.00, + "couponmoney": 10.00, + "mtmoney": 9.90, + "type": 1, + "paytype": 3, + "usersBalance": 30.00, + "couponId": 123, + "mtcode": "MT123456", + "calculationDetail": { + "originalAmount": 100.00, + "memberDiscount": 5.00, + "serviceDiscount": 3.00, + "shopDiscount": 2.00, + "couponDiscount": 10.00, + "mtDiscount": 9.90, + "finalAmount": 85.10 + } + } +} +``` + +**响应参数**: +- `id`: 预支付记录ID +- `orderId`: 订单ID +- `paycode`: 支付订单号 +- `allmoney`: 原始总金额(固定不变,这是您最初存储的金额) +- `finalAmount`: 实际应付金额(基于allmoney计算得出) +- `wxmoney`: 微信支付金额 +- `yemoney`: 余额支付金额 +- `membermoney`: 会员优惠金额(固定不变) +- `shopmoney`: 购物金抵扣金额(固定不变) +- `servicemoney`: 服务金抵扣金额(固定不变) +- `couponmoney`: 优惠券金额(实时计算) +- `mtmoney`: 美团优惠金额(实时计算) +- `type`: 订单类型 +- `paytype`: 支付方式 +- `usersBalance`: 用户余额 +- `couponId`: 优惠券ID +- `mtcode`: 美团优惠码 +- `calculationDetail`: 计算明细 + - `originalAmount`: 原始金额(allmoney) + - `memberDiscount`: 会员优惠 + - `serviceDiscount`: 服务金抵扣 + - `shopDiscount`: 购物金抵扣 + - `couponDiscount`: 优惠券金额 + - `mtDiscount`: 美团优惠 + - `finalAmount`: 最终应付金额 + +**业务逻辑**: +1. 验证用户登录状态和权限 +2. 获取 `allmoney`(原始总金额,固定不变)和固定优惠金额(会员优惠、服务金抵扣、购物金抵扣) +3. 根据优惠券ID查询优惠券信息并验证有效性,计算优惠券优惠金额 +4. 计算美团优惠金额(每次调用生成2至15的随机整数) +5. 基于 `allmoney` 减去所有优惠,计算实际应付金额: + ``` + 实际应付金额 = allmoney - 会员优惠 - 服务金抵扣 - 购物金抵扣 - 优惠券金额 - 美团优惠 + ``` +6. 根据支付方式计算各支付渠道金额: + - 微信支付:全部用微信支付 + - 余额支付:验证余额是否足够,全部用余额支付 + - 组合支付: + - 余额足够:全部用余额支付 + - 余额不足:优先扣除用户所有余额,剩余部分用微信支付 + - 无余额:全部用微信支付 +7. 更新预支付记录到数据库(注意:`allmoney` 保持不变) +8. 返回计算后的支付信息,包含计算明细 + +**错误处理**: +- 用户未登录或token无效 +- 预支付记录不存在 +- 无权查看该预支付记录 +- 优惠券无效或已被使用 +- 优惠券不属于当前用户 +- 优惠券已过期 +- 订单金额未达到优惠券使用条件 +- 余额不足 +- 无效的支付方式 +- 更新预支付记录失败 + +**注意事项**: +- `allmoney` 是您最初存储的总金额,永远不会改变,所有计算都基于这个金额 +- 每次调用都会基于 `allmoney` 重新计算,确保前端能实时获取最新的支付信息 +- 会员优惠、服务金抵扣、购物金抵扣金额在每次计算中保持不变 +- 优惠券金额和美团优惠金额根据用户选择实时计算 +- 美团优惠功能每次调用生成2至15的随机整数作为优惠金额(用于测试) +- 优惠券验证包括状态、归属权、过期时间、最低消费等 +- 组合支付逻辑: + - 余额足够:全部用余额支付(wxmoney=0, yemoney=实际金额) + - 余额不足:优先扣除用户所有余额,剩余部分用微信支付(wxmoney=差额, yemoney=用户余额) + - 无余额:全部用微信支付(wxmoney=实际金额, yemoney=0) +- 所有金额计算都使用BigDecimal确保精度 +- 返回的calculationDetail字段方便前端理解金额构成和计算过程 +- 更新数据库时,`allmoney` 字段保持不变 \ No newline at end of file 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 113288a..a79809b 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 @@ -360,43 +360,43 @@ public class AppleMemberController extends BaseController { // ==================== 余额支付相关接口 ==================== - /** - * 余额支付测试接口 - * - * 测试用户余额支付功能 - * 模拟购买99.99元商品的余额支付流程 - * - * @param request HTTP请求对象(需要包含token) - * @return 支付结果 - */ - @GetMapping("/balance/payment") - public AjaxResult apibalancepayment(HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 调用余额支付工具类 - Map rmap = BalancePayUtil.processBalancePayment( - user.getId(), - new BigDecimal("99.99"), - "购买一般商品单价99.99"); - return AppletControllerUtil.appletSuccess(rmap.get("message")); - - } catch (Exception e) { - System.err.println("余额支付异常:" + e.getMessage()); - return AppletControllerUtil.appletError("余额支付失败:" + e.getMessage()); - } - } +// /** +// * 余额支付测试接口 +// * +// * 测试用户余额支付功能 +// * 模拟购买99.99元商品的余额支付流程 +// * +// * @param request HTTP请求对象(需要包含token) +// * @return 支付结果 +// */ +// @GetMapping("/balance/payment") +// public AjaxResult apibalancepayment(HttpServletRequest request) { +// try { +// // 1. 验证用户登录状态 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletWarning("用户未登录或token无效"); +// } +// +// // 2. 获取用户信息 +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// +//// // 3. 调用余额支付工具类 +//// Map rmap = BalancePayUtil.processBalancePayment( +//// user.getId(), +//// new BigDecimal("99.99"), +//// "购买一般商品单价99.99"); +//// return AppletControllerUtil.appletSuccess(rmap.get("message")); +// +// } catch (Exception e) { +// System.err.println("余额支付异常:" + e.getMessage()); +// return AppletControllerUtil.appletError("余额支付失败:" + e.getMessage()); +// } +// } // ==================== 记录查询相关接口 ==================== 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 f67287f..a80c48e 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 @@ -1,15 +1,16 @@ package com.ruoyi.system.controller; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.annotation.Log; 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.AppletControllerUtil; -import com.ruoyi.system.ControllerUtil.AppletLoginUtil; -import com.ruoyi.system.ControllerUtil.GenerateCustomCode; +import com.ruoyi.system.ControllerUtil.*; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -17,11 +18,11 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import com.ruoyi.system.service.IShopAddressService; +import com.ruoyi.system.domain.ShopAddress; /** * 苹果订单控制器 @@ -48,7 +49,10 @@ public class AppleOrderController extends BaseController { @Autowired private IOrderService orderService; - + + @Autowired + private IUserUseSecondaryCardService userUseSecondaryCardService; + @Autowired @@ -61,8 +65,99 @@ public class AppleOrderController extends BaseController { private IOrderLogService orderLogService; @Autowired - private IUserUseSecondaryCardService userUseSecondaryCardService; + private IUserSecondaryCardService userSecondaryCardService; + @Autowired + private ISiteConfigService siteConfigService; + + @Autowired + private ICouponsService couponsService; + + + @Autowired + private IServiceCateService serviceCateService; + + @Autowired + private IShopAddressService shopAddressService; + + @Autowired + private IGoodsOrderService goodsOrderService; + + + + /** + * 查询用户优惠券列表 + * + * @param request HTTP请求对象 + * @return 返回用户优惠券列表 + */ + @PostMapping("/api/coupon/mypay/lst/{id}") + public AjaxResult getMyCouponList(@PathVariable("id") String id, HttpServletRequest request) { + + // 3. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 4. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + UsersPayBefor usersPayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(id); + if(usersPayBefor==null){ + return AppletControllerUtil.appletWarning("订单不存在"); + } + + Long userId = user.getId(); // 获取当前用户id + int status = 1; + + String productId = ""; + if (usersPayBefor.getServiceid()==null){ + GoodsOrder goodsOrder = new GoodsOrder(); + goodsOrder.setMainOrderId( usersPayBefor.getOrderid()); + List GoodsOrderList = goodsOrderService.selectGoodsOrderList(goodsOrder); + if (!GoodsOrderList.isEmpty()){ + productId = GoodsOrderList.getFirst().getProductId().toString(); + } + }else{ + productId = usersPayBefor.getServiceid().toString(); + } + + BigDecimal totalPrice = usersPayBefor.getAllmoney(); + // 过期的优惠券标记为已过期 + CouponUser couponUser = new CouponUser(); + couponUser.setStatus(1L); + couponUser.setUid(user.getId()); + List couponUserList = couponUserService.selectCouponUserNoList(couponUser); + for (CouponUser c: couponUserList){ + c.setStatus(3L); + couponUserService.updateCouponUser(c); + } + //安状态进行赋值 + //待领取优惠券 + if (status==4){ +// Coupons coupons = new Coupons(); +// coupons.setSearchValue("12"); + List couponsList = CouponUtil.iscoupon(userId,couponsService,couponUserService); + if (!couponsList.isEmpty()){ + return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponDataList(couponsList,serviceCateService,serviceGoodsService)); + } + }else{ + CouponUser couponUserData = new CouponUser(); + couponUserData.setStatus(Long.valueOf(status)); + couponUserData.setUid(user.getId()); + List couponUserDataList = couponUserService.selectCouponUserList(couponUserData); + if (couponUserDataList!=null){ + return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponUserList(couponUserDataList,serviceCateService,serviceGoodsService,productId,totalPrice)); + } + } + // 按is_use排序 + return AjaxResult.success(); + } /** * 通用订单预支接口 * @@ -71,7 +166,7 @@ public class AppleOrderController extends BaseController { * @param params 预支付参数 * @param request HTTP请求对象 * @return 预支付结果 - * + * 1=拼团 2一口价 3=秒杀 4=报价 0=普通预约(必填) * 请求参数说明: * - id: 产品或次卡主键ID(必填) * - sku: 购买的规格(可选) @@ -113,39 +208,87 @@ public class AppleOrderController extends BaseController { // 3. 解析参数 Long productId = Long.valueOf(params.get("id").toString()); Integer ordertype = Integer.valueOf(params.get("ordertype").toString()); - String sku = params.get("sku") != null ? params.get("sku").toString() : ""; - Long addressId = params.get("address_id") != null ? Long.valueOf(params.get("address_id").toString()) : null; + + // 处理sku参数 - 可能是JSON对象或字符串 + String sku = ""; + if (params.get("sku") != null) { + Object skuObj = params.get("sku"); + if (skuObj instanceof String) { + sku = (String) skuObj; + } else { + // 如果是JSON对象,转换为JSON字符串 + sku = JSONObject.toJSONString(skuObj); + } + } + + // 处理address_id参数 - 避免空字符串导致的NumberFormatException + Long addressId = null; + if (params.get("address_id") != null) { + String addressIdStr = params.get("address_id").toString(); + if (!addressIdStr.trim().isEmpty()) { + try { + addressId = Long.valueOf(addressIdStr); + } catch (NumberFormatException e) { + logger.warn("地址ID格式错误: " + addressIdStr); + addressId = null; + } + } + } Integer num = params.get("num") != null ? Integer.valueOf(params.get("num").toString()) : 1; String makeTime = params.get("make_time") != null ? params.get("make_time").toString() : ""; - - // 处理附件数组 - String attachments = ""; - if (params.get("attachments") != null) { - try { - @SuppressWarnings("unchecked") - List attachmentList = (List) params.get("attachments"); - if (attachmentList != null && !attachmentList.isEmpty()) { - // 限制最多9个附件 - if (attachmentList.size() > 9) { - return AppletControllerUtil.appletWarning("附件数量不能超过9个"); + String grouporderid = params.get("grouporderid") != null ? params.get("grouporderid").toString() : ""; + String reamk = params.get("reamk") != null ? params.get("reamk").toString() : ""; + String cikaid = params.get("cikaid") != null ? params.get("cikaid").toString() : ""; + if (grouporderid==""){ + grouporderid=GenerateCustomCode.generCreateOrder("pt"); + } + if (StringUtils.isNotBlank(cikaid)){ + UserUseSecondaryCard userUseSecondaryCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(cikaid); + if (userUseSecondaryCard == null){ + return AjaxResult.error("此卡不存在"); + } + if (userUseSecondaryCard.getStatus() != 1){ + return AjaxResult.error("此卡不是使用状态"); + } + } + String ptcode=GenerateCustomCode.generCreateOrder("PT"); + // 处理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); } - attachments = String.join(",", attachmentList); + } catch (Exception e) { + logger.warn("附件参数解析失败: " + e.getMessage()); + fileData = ""; } - } catch (Exception e) { - logger.warn("附件参数解析失败: " + e.getMessage()); - attachments = ""; + } else { + // 其他类型,尝试转换为字符串 + fileData = fileDataObj.toString(); } } // 4. 验证订单类型 if (ordertype < 0 || ordertype > 4) { - return AppletControllerUtil.appletWarning("订单类别无效:0=普通预约 1=拼团 2=次卡 3=秒杀 4=报价"); + return AppletControllerUtil.appletWarning("订单类别无效:0=普通预约 1=拼团 2=一口价 3=秒杀 4=报价"); } // 5. 查询商品信息 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); if (serviceGoods == null) { - return AppletControllerUtil.appletWarning("商品不存在"); + return AppletControllerUtil.appletWarning("服务不存在"); } // 6. 查询地址信息(如果提供了地址ID) @@ -156,34 +299,145 @@ public class AppleOrderController extends BaseController { return AppletControllerUtil.appletWarning("地址不存在"); } } - + // 根据订单类型确定是否一口价和订单类型 + int isyikoujia = 2; // 默认非一口价 + int priceType = ordertype; // 价格类型与订单类型一致 + // 根据订单类型调整参数 + switch (ordertype) { + case 0: // 普通预约 - 非一口价 + isyikoujia = 2; + priceType = 1; // 使用普通价格 + break; + case 1: // 拼团 - 非一口价 + isyikoujia = 2; + priceType = 1; // 拼团价格 + break; + case 2: // 一口价 - 一口价 + isyikoujia = 1; + priceType = 2; // 一口价价格 + break; + case 3: // 秒杀 - 非一口价 + isyikoujia = 2; + priceType = 3; // 秒杀价格 + break; + case 4: // 报价 - 非一口价 + isyikoujia = 2; + priceType = 1; // 普通价格 + break; + } + BigDecimal totalAmount=new BigDecimal(0); + if (ordertype != 0) { + BigDecimal money=OrderUtil.confirmOrderPrice(productId, sku, priceType); + if (money == null){ + if (serviceGoods.getFixedprice() != null){ + money = serviceGoods.getFixedprice(); + }else{ + money = serviceGoods.getPrice(); + } + } + totalAmount =money.multiply(BigDecimal.valueOf(num)); + } + // 7. 根据订单类型创建相应的订单 + +// Integer ordertype, Users user, Long productId, +// UserAddress userAddress, String sku, Integer num, String makeTime, +// String fileData,String grouporderid,String reamk,String cikaid + +// BigDecimal allprice= OrderUtil.confirmOrderPrice(productId, sku, ordertype); + + Map orderResult = createOrderByType( - ordertype, user, serviceGoods, userAddress, sku, num, - makeTime, null, BigDecimal.ZERO, BigDecimal.ZERO, "", "", attachments + ordertype, user, productId, userAddress, sku, num, + makeTime,fileData, grouporderid,reamk,cikaid,totalAmount,ptcode ); if (!(Boolean) orderResult.get("success")) { return AppletControllerUtil.appletWarning((String) orderResult.get("message")); } - // 8. 获取订单信息 String orderId = (String) orderResult.get("orderId"); Long oid = (Long) orderResult.get("oid"); - BigDecimal totalAmount = (BigDecimal) orderResult.get("totalAmount"); - + // 如果是报价订单,直接返回结果,不插入UsersPayBefor - if (ordertype == 4) { + //次卡订单不用支付直接走 + if (ordertype == 2&&StringUtils.isNotBlank(cikaid)) { + //次卡订单需要处理的数据 + UserUseSecondaryCard userUseSecondaryCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(cikaid); + if(userUseSecondaryCard!=null){ + userUseSecondaryCard.setUsenum(userUseSecondaryCard.getUsenum()+1); + userUseSecondaryCardService.updateUserUseSecondaryCard(userUseSecondaryCard); + if (userUseSecondaryCard.getUsenum().intValue() >= userUseSecondaryCard.getNum().intValue()){ + userUseSecondaryCard.setStatus(2L);//设置不可用 + userUseSecondaryCardService.updateUserUseSecondaryCard(userUseSecondaryCard); + } + } + Map result = new HashMap<>(); - result.put("orderId", orderId); - result.put("oid", oid); - result.put("totalAmount", totalAmount); - result.put("orderType", ordertype); - result.put("attachments", attachments); + result.put("trpe", "1"); + result.put("orderid", orderId); + return AppletControllerUtil.appletSuccess(result); + } + if (ordertype == 0) { + Map result = new HashMap<>(); + result.put("trpe", "1"); + result.put("orderid", orderId); +// result.put("orderId", orderId); +// result.put("oid", oid); +// result.put("totalAmount", totalAmount); +// result.put("orderType", ordertype); +// result.put("attachments", attachments); return AppletControllerUtil.appletSuccess(result); } - // 9. 创建预支付记录 + // 9. 计算会员优惠和服务金抵扣 + BigDecimal memberMoney = BigDecimal.ZERO; + BigDecimal serviceMoney = BigDecimal.ZERO; + + try { + // 查询config_one配置 + 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()) { + JSONObject configJson = JSONObject.parseObject(configValue); + + // 计算会员优惠金额 + if (user.getIsmember() != null && user.getIsmember() == 1) { + // 用户是包年会员,计算会员优惠 + Integer memberDiscount = configJson.getInteger("member_discount"); + if (memberDiscount != null && memberDiscount > 0) { + // 会员优惠金额 = 订单金额 * (100 - 会员折扣) / 100 + BigDecimal discountRate = BigDecimal.valueOf(memberDiscount).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); + if (totalAmount != null) { + memberMoney = totalAmount.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) { + // 服务金抵扣金额 = 用户服务金 * 服务金比例 / 100 + BigDecimal serviceRate = BigDecimal.valueOf(serviceFee).divide(BigDecimal.valueOf(100), 4, BigDecimal.ROUND_HALF_UP); + serviceMoney = userDb.getServicefee().multiply(serviceRate); + } + } + } + } + } catch (Exception e) { + logger.warn("计算会员优惠和服务金抵扣失败: " + e.getMessage()); + memberMoney = BigDecimal.ZERO; + serviceMoney = BigDecimal.ZERO; + } + + // 10. 创建预支付记录 UsersPayBefor usersPayBefor = new UsersPayBefor(); usersPayBefor.setUid(user.getId()); usersPayBefor.setOrderid(orderId); @@ -191,10 +445,20 @@ public class AppleOrderController extends BaseController { usersPayBefor.setPaycode(GenerateCustomCode.generCreateOrder("PAY")); usersPayBefor.setAllmoney(totalAmount); usersPayBefor.setWxmoney(totalAmount); + usersPayBefor.setShopmoney(BigDecimal.ZERO); + usersPayBefor.setServicemoney(serviceMoney); + usersPayBefor.setMtmoney(BigDecimal.ZERO); usersPayBefor.setYemoney(BigDecimal.ZERO); usersPayBefor.setCouponmoney(BigDecimal.ZERO); - usersPayBefor.setMembermoney(BigDecimal.ZERO); + usersPayBefor.setServicetype(Long.valueOf(serviceGoods.getType())); + usersPayBefor.setMembermoney(memberMoney); usersPayBefor.setType(Long.valueOf(ordertype)); + usersPayBefor.setSku(sku); + usersPayBefor.setServiceid(productId); + usersPayBefor.setGrouporderid(grouporderid); + usersPayBefor.setAddressid(addressId); + usersPayBefor.setMaketime(makeTime); + usersPayBefor.setAttachments(fileData); usersPayBefor.setStatus(1L); // 1=待支付 usersPayBefor.setPaytype(1L); // 默认微信支付 @@ -204,48 +468,731 @@ public class AppleOrderController extends BaseController { } // 10. 返回预支付信息 - Map result = new HashMap<>(); - result.put("orderId", orderId); - result.put("oid", oid); - result.put("payBeforId", usersPayBefor.getId()); - result.put("paycode", usersPayBefor.getPaycode()); - result.put("totalAmount", totalAmount); - result.put("wxMoney", totalAmount); - result.put("yeMoney", BigDecimal.ZERO); - result.put("couponMoney", BigDecimal.ZERO); - result.put("memberMoney", BigDecimal.ZERO); - result.put("orderType", ordertype); - result.put("attachments", attachments); - - return AppletControllerUtil.appletSuccess(result); +// Map result = new HashMap<>(); +// result.put("orderId", orderId); +// result.put("oid", oid); +// result.put("payBeforId", usersPayBefor.getId()); +// result.put("paycode", usersPayBefor.getPaycode()); +// result.put("totalAmount", totalAmount); +// result.put("wxMoney", totalAmount); +// result.put("yeMoney", BigDecimal.ZERO); +// result.put("couponMoney", BigDecimal.ZERO); +// result.put("memberMoney", BigDecimal.ZERO); +// result.put("orderType", ordertype); +// result.put("attachments", attachments); + Map result1 = new HashMap<>(); + if (ordertype == 4){ + result1.put("type", "1"); + }else{ + result1.put("type", "2"); + } + + result1.put("orderid", usersPayBefor.getOrderid()); + return AppletControllerUtil.appletSuccess(result1); } catch (Exception e) { logger.error("订单预支付创建失败:", e); return AppletControllerUtil.appletError("订单预支付创建失败:" + e.getMessage()); } } - + + + + + /** + * 创建服务订单(支持多商品批量下单) + * + * @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); +// } + } 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()); + } + } + + + + + + + + + + /** + * 次卡购买接口 + * @param params {"id":次卡id, "goodsids":["1","2",...]} + * @param request HTTP请求对象 + * @return 预支付orderid + */ + @PostMapping("/api/secondary/card/buy") + public AjaxResult buySecondaryCard(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验参数 + if (params == null || params.get("id") == null || params.get("goodsids") == null) { + return AppletControllerUtil.appletWarning("参数id和goodsids不能为空"); + } + Long cardId = Long.valueOf(params.get("id").toString()); + List goodsids; + try { + goodsids = (List) params.get("goodsids"); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("goodsids参数格式错误,必须为字符串数组"); + } + // 2. 获取用户 + 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("用户信息获取失败"); + } + // 3. 查询次卡基本信息 + UserSecondaryCard card = userSecondaryCardService.selectUserSecondaryCardById(cardId); + if (card == null) { + return AppletControllerUtil.appletWarning("次卡不存在"); + } + // 4. 保存用户次卡购买记录 + UserUseSecondaryCard useCard = new UserUseSecondaryCard(); + useCard.setUid(user.getId()); + useCard.setCarid(cardId.toString()); + // goodsids存为JSON数组字符串 + useCard.setGoodsids(JSONObject.toJSONString(goodsids)); + useCard.setNum(card.getNum()); + useCard.setUsenum(0L); + String orderid = GenerateCustomCode.generCreateOrder("CIKA"); + useCard.setOrderid(orderid); + useCard.setTransactionId(""); + useCard.setPaymoney(card.getRealMoney()); + useCard.setStatus(4L); // 4=未支付 + useCard.setRemark(""); + int insertResult = userUseSecondaryCardService.insertUserUseSecondaryCard(useCard); + if (insertResult <= 0) { + return AppletControllerUtil.appletWarning("次卡购买记录保存失败"); + } + // 5. 计算会员优惠和服务金抵扣 + BigDecimal allMoney = card.getRealMoney(); + 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()) { + JSONObject configJson = 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); + if (allMoney != null) { + memberMoney = allMoney.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) { + logger.warn("计算会员优惠和服务金抵扣失败: " + e.getMessage()); + memberMoney = BigDecimal.ZERO; + serviceMoney = BigDecimal.ZERO; + } + // 6. 保存预支付信息,金额字段参考预支接口 + UsersPayBefor payBefor = new UsersPayBefor(); + payBefor.setUid(user.getId()); + payBefor.setOrderid(orderid); + payBefor.setOid(useCard.getId()); + payBefor.setPaycode(GenerateCustomCode.generCreateOrder("PAY")); + payBefor.setAllmoney(allMoney); + payBefor.setWxmoney(allMoney.subtract(memberMoney).subtract(serviceMoney)); + payBefor.setShopmoney(BigDecimal.ZERO); + payBefor.setServicemoney(serviceMoney); + payBefor.setMtmoney(BigDecimal.ZERO); + payBefor.setYemoney(BigDecimal.ZERO); + payBefor.setCouponmoney(BigDecimal.ZERO); + payBefor.setServicetype(1L); // 2=次卡 + payBefor.setMembermoney(memberMoney); + payBefor.setType(2L); // 2=次卡 + payBefor.setSku(""); + payBefor.setServiceid(cardId); + payBefor.setGrouporderid(""); + payBefor.setAddressid(null); + payBefor.setMaketime(""); + payBefor.setAttachments(""); + payBefor.setStatus(1L); // 1=待支付 + payBefor.setPaytype(1L); // 默认微信支付 + int payBeforResult = usersPayBeforService.insertUsersPayBefor(payBefor); + if (payBeforResult <= 0) { + return AppletControllerUtil.appletWarning("预支付记录创建失败"); + } + // 7. 返回orderid + Map result = new HashMap<>(); + result.put("orderid", payBefor.getOrderid()); + result.put("type", "2"); + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + logger.error("次卡购买失败:", e); + return AppletControllerUtil.appletError("次卡购买失败:" + e.getMessage()); + } + } + + /** + * 查询我的次卡列表(分页) + * @param pageNum 页码 + * @param pageSize 每页数量 + * @param request HTTP请求对象 + * @return 我的次卡列表 + */ + @GetMapping("/api/secondary/card/mylist") + public AjaxResult getMySecondaryCardList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, + @RequestParam(value = "pageSize", defaultValue = "10") int pageSize, + HttpServletRequest request) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 校验用户登录 + 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("用户信息获取失败"); + } + // 查询用户全部次卡 + UserUseSecondaryCard queryCard = new UserUseSecondaryCard(); + queryCard.setUid(user.getId()); + queryCard.setStatus(1L); + List allCardList = userUseSecondaryCardService.selectUserUseSecondaryCardList(queryCard); + int total = allCardList.size(); + int fromIndex = Math.max(0, (pageNum - 1) * pageSize); + int toIndex = Math.min(fromIndex + pageSize, total); + List cardList = fromIndex < toIndex ? allCardList.subList(fromIndex, toIndex) : new ArrayList<>(); + List> resultList = new ArrayList<>(); + for (UserUseSecondaryCard card : cardList) { + Map map = new HashMap<>(); + // 查询次卡基本信息 + UserSecondaryCard cardInfo = userSecondaryCardService.selectUserSecondaryCardById(Long.valueOf(card.getCarid())); + if (cardInfo != null) { + map.put("icon", AppletControllerUtil.buildImageUrl(cardInfo.getShowimage())); + map.put("price", cardInfo.getRealMoney()); + map.put("title", cardInfo.getTitle()); + if (Objects.equals(card.getNum(), cardInfo.getNum())){ + map.put("iscanback", "1"); + }else{ + map.put("iscanback", "2"); + } + } else { + map.put("icon", ""); + map.put("price", ""); + map.put("title", ""); + } + + map.put("num", "1"); + map.put("id", card.getId()); + map.put("canusenum", card.getNum()); + map.put("buyTime",sdf.format(card.getCreatedAt())); + map.put("status", card.getStatus()); + resultList.add(map); + } + Map pageData = new HashMap<>(); + pageData.put("total", total); + pageData.put("data", resultList); + pageData.put("pageNum", pageNum); + pageData.put("pageSize", pageSize); + return AppletControllerUtil.appletSuccess(pageData); + } catch (Exception e) { + logger.error("查询我的次卡失败:", e); + return AppletControllerUtil.appletError("查询我的次卡失败:" + e.getMessage()); + } + } + + /** + * 查询我的次卡详情 + * @param cardid 次卡使用记录ID + * @param request HTTP请求对象 + * @return 次卡详情(卡片信息、服务预约情况、订单信息) + */ + @GetMapping("/api/secondary/card/detail") + public AjaxResult getMySecondaryCardDetail(@RequestParam("cardid") Long cardid, HttpServletRequest request) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 校验用户登录 + 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("用户信息获取失败"); + } + // 1. 查次卡使用记录 + UserUseSecondaryCard card = userUseSecondaryCardService.selectUserUseSecondaryCardById(cardid); + if (card == null || !user.getId().equals(card.getUid())) { + return AppletControllerUtil.appletWarning("次卡不存在或无权查看"); + } + // 2. 查次卡基本信息 + UserSecondaryCard cardInfo = userSecondaryCardService.selectUserSecondaryCardById(Long.valueOf(card.getCarid())); + // 3. 解析服务ID列表 + List goodsIds = new ArrayList<>(); + try { + List goodsIdStrs = com.alibaba.fastjson2.JSONArray.parseArray(card.getGoodsids(), String.class); + for (String gid : goodsIdStrs) { + goodsIds.add(Long.valueOf(gid)); + } + } catch (Exception e) { + return AppletControllerUtil.appletWarning("次卡服务ID解析失败"); + } + // 4. 查该次卡下所有订单(通过cartid过滤) + Order orderQuery = new Order(); + orderQuery.setCartid(card.getOrderid()); + List orderList = orderService.selectOrderList(orderQuery); + List> serviceOrderMap = new ArrayList<>(); + // 5. 先处理已预约的服务(有订单的) + for (Order o : orderList) { + if (o.getProductId() != null && goodsIds.contains(o.getProductId())) { + ServiceGoods goods = serviceGoodsService.selectServiceGoodsById(o.getProductId()); + Map map = new HashMap<>(); + map.put("type", "order"); + map.put("serviceid", o.getProductId()); + map.put("serviceName", goods != null ? goods.getTitle() : ""); + map.put("status",o.getStatus()); + map.put("orderid", o.getOrderId()); + map.put("oid", o.getId()); + + serviceOrderMap.add(map); + goodsIds.remove(o.getProductId()); // 剔除已预约的服务 + } + } + // 6. 再处理未预约的服务 + for (Long gid : goodsIds) { + ServiceGoods goods = serviceGoodsService.selectServiceGoodsById(gid); + Map map = new HashMap<>(); + map.put("type", "service"); + map.put("serviceid", gid); + map.put("serviceName", goods != null ? goods.getTitle() : ""); + serviceOrderMap.add(map); + } + // 7. 组装返回 + Map result = new HashMap<>(); + if (Objects.equals(card.getNum(), cardInfo.getNum())) { + result.put("iscanback", "1"); + }else{ + result.put("iscanback", "2"); + } + result.put("icon", cardInfo != null ? AppletControllerUtil.buildImageUrl(cardInfo.getShowimage()) : ""); + result.put("title", cardInfo != null ? cardInfo.getTitle() : ""); + result.put("num", "1"); + result.put("orderNo", card.getOrderid()); + result.put("status", card.getStatus()); + result.put("buyTime",sdf.format(card.getCreatedAt())); + result.put("serviceList", serviceOrderMap); + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + logger.error("查询我的次卡详情失败:", e); + return AppletControllerUtil.appletError("查询我的次卡详情失败:" + e.getMessage()); + } + } + + + /** + * 查询所有状态为1的店铺地址 + */ + @GetMapping("/api/shopAddress/activeData") + public AjaxResult getActiveShopAddressList() { + ShopAddress query = new ShopAddress(); + query.setAddressStatus(1L); + List list = shopAddressService.selectShopAddressList(query); + if (list == null || list.isEmpty()) { + return AppletControllerUtil.appletWarning("暂无可用店铺地址"); + } + ShopAddress shopAddress = list.get(0); + Map result = new HashMap<>(); + result.put("id", shopAddress.getId()); + result.put("shopName", shopAddress.getShopName()); + result.put("shopAddress", shopAddress.getShopAddress()); + result.put("contactPhone", shopAddress.getContactPhone()); + result.put("longitude", shopAddress.getLongitude()); + result.put("latitude", shopAddress.getLatitude()); + result.put("contactPerson", shopAddress.getContactPerson()); + result.put("addressStatus", shopAddress.getAddressStatus()); + return AppletControllerUtil.appletSuccess(result); + } + + + // 工具方法:订单状态转中文 + private String getOrderStatusStr(Long status) { + if (status == null) return ""; + switch (status.intValue()) { + case 1: return "服务中"; + case 2: return "已完成"; + case 3: return "已取消"; + case 4: return "待支付"; + default: return "待预约"; + } + } + + /** + * 随机获取6个一口价服务或商城商品 + * @param type 1服务,2商品 + * @return 图片、价格、一口价价格、标题 + */ + @GetMapping("/api/goods/random/list") + public AjaxResult getRandomGoodsList(@RequestParam("type") int type) { + try { + ServiceGoods query = new ServiceGoods(); + query.setStatus("1"); // 只查启用 + if (type == 1) { + // 一口价服务商品(type=2,一口价 isfixed=1) + query.setType(1); + query.setIsfixed(1); + } else if (type == 2) { + // 商城商品(type=3) + query.setType(2); + } else { + return AppletControllerUtil.appletWarning("type参数无效"); + } + List goodsList = serviceGoodsService.selectServiceGoodsList(query); + Collections.shuffle(goodsList); + List resultList = goodsList.size() > 6 ? goodsList.subList(0, 6) : goodsList; + List> result = new ArrayList<>(); + for (ServiceGoods g : resultList) { + Map map = new HashMap<>(); + map.put("img", AppletControllerUtil.buildImageUrl(g.getIcon())); + map.put("price", g.getPrice()); + map.put("id", g.getId()); + map.put("fixedprice", g.getFixedprice()); + map.put("title", g.getTitle()); + result.add(map); + } + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + logger.error("随机获取商品失败:", e); + return AppletControllerUtil.appletError("随机获取商品失败:" + e.getMessage()); + } + } + /** * 根据订单类型创建相应的订单 */ - private Map createOrderByType(Integer ordertype, Users user, ServiceGoods serviceGoods, + private Map createOrderByType(Integer ordertype, Users user, Long productId, UserAddress userAddress, String sku, Integer num, String makeTime, - CouponUser couponUser, BigDecimal couponDiscount, - BigDecimal memberMoney, String mtcode, String ptcode, String attachments) { + String fileData,String grouporderid,String reamk,String cikaid ,BigDecimal totalAmount,String ptcode) { Map result = new HashMap<>(); try { switch (ordertype) { case 0: // 普通预约 - return createNormalOrder(user, serviceGoods, userAddress, sku, num, makeTime, couponUser, couponDiscount, memberMoney, mtcode, attachments); + return createNormalOrder(user, productId, userAddress, sku, num, makeTime,fileData,reamk); case 1: // 拼团 - return createGroupBuyingOrder(user, serviceGoods, sku, num, couponUser, couponDiscount, memberMoney, mtcode, ptcode, attachments); - case 2: // 次卡 - return createCardOrder(user, serviceGoods, userAddress, sku, num, makeTime, couponUser, couponDiscount, memberMoney, mtcode, attachments); + return createGroupBuyingOrder(user, productId,fileData,grouporderid,ptcode); + case 2: // 一口价 + return createCardOrder(user, productId, userAddress, sku, num, makeTime, fileData,cikaid,totalAmount); case 3: // 秒杀 - return createSeckillOrder(user, serviceGoods, userAddress, sku, num, makeTime, couponUser, couponDiscount, memberMoney, mtcode, attachments); + return createSeckillOrder(user, productId, userAddress, sku, num, makeTime,fileData,totalAmount); case 4: // 报价 - return createQuoteOrder(user, serviceGoods, userAddress, sku, num, makeTime, couponUser, couponDiscount, memberMoney, mtcode, attachments); + return createQuoteOrder(user, productId, userAddress, sku, num, makeTime,fileData); default: result.put("success", false); result.put("message", "不支持的订单类型"); @@ -263,12 +1210,18 @@ public class AppleOrderController extends BaseController { * 创建普通预约订单 * 1预约 2报价 3一口价 4拼团 5普通订单 */ - private Map createNormalOrder(Users user, ServiceGoods serviceGoods, UserAddress userAddress, - String sku, Integer num, String makeTime, CouponUser couponUser, - BigDecimal couponDiscount, BigDecimal memberMoney, String mtcode, String attachments) { + private Map createNormalOrder(Users user, Long productId, UserAddress userAddress, + String sku, Integer num, String makeTime, + String attachments,String reamk) { Map result = new HashMap<>(); try { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + //派单模式 + Integer dispatchtype=serviceGoods.getDispatchtype(); + if (dispatchtype==null){ + dispatchtype=1; + } // 计算订单金额 BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); @@ -285,8 +1238,8 @@ public class AppleOrderController extends BaseController { order.setUname(user.getName()); order.setProductId(serviceGoods.getId()); order.setProductName(serviceGoods.getTitle()); + order.setReamk(reamk); order.setSku(sku); - if (userAddress != null) { order.setAddressId(userAddress.getId()); order.setName(userAddress.getName()); @@ -314,11 +1267,12 @@ public class AppleOrderController extends BaseController { order.setServicePrice(BigDecimal.ZERO); order.setPayPrice(itemPrice); order.setStatus(1L); // 待支付 - order.setReceiveType(1L); // 自由抢单 + order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 order.setIsAccept(0); order.setIsComment(0); order.setIsPause(1); - order.setDeduction(couponDiscount.add(memberMoney)); + order.setOdertype(0); + order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 order.setType(1); int insertResult = orderService.insertOrder(order); @@ -337,9 +1291,7 @@ public class AppleOrderController extends BaseController { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", "订单创建成功"); orderLog.setContent(jsonObject.toJSONString()); - orderLog.setRemark("订单预支付创建"); orderLogService.insertOrderLog(orderLog); - result.put("success", true); result.put("orderId", orderId); result.put("oid", order.getId()); @@ -356,13 +1308,13 @@ public class AppleOrderController extends BaseController { } /** - * 创建拼团订单 + * 创建拼团订单user, productId,fileData,grouporderid */ - private Map createGroupBuyingOrder(Users user, ServiceGoods serviceGoods, String sku, Integer num, - CouponUser couponUser, BigDecimal couponDiscount, - BigDecimal memberMoney, String mtcode, String ptcode, String attachments) { + private Map createGroupBuyingOrder(Users user, Long productId,String fileData, + String grouporderid,String ptcode) { Map result = new HashMap<>(); - + + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); try { // 验证拼团价格 if (serviceGoods.getGroupprice() == null) { @@ -370,29 +1322,29 @@ public class AppleOrderController extends BaseController { result.put("message", "该商品不支持拼团"); return result; } - // 计算订单金额 - BigDecimal itemPrice = serviceGoods.getGroupprice().multiply(BigDecimal.valueOf(num)); + BigDecimal itemPrice = serviceGoods.getGroupprice().multiply(BigDecimal.valueOf(1)); - // 处理拼团单号 - String finalPtcode = ptcode; - if (finalPtcode == null || finalPtcode.trim().isEmpty()) { - // 如果没有提供拼团单号,生成新的拼团单号 - finalPtcode = GenerateCustomCode.generCreateOrder("PT"); - } +// // 处理拼团单号 +// String finalPtcode = ptcode; +// if (finalPtcode == null || finalPtcode.trim().isEmpty()) { +// // 如果没有提供拼团单号,生成新的拼团单号 +// finalPtcode = GenerateCustomCode.generCreateOrder("PT"); +// } // 创建拼团订单(预支付状态) UserGroupBuying userGroupBuying = new UserGroupBuying(); - userGroupBuying.setOrderid(finalPtcode); // 使用拼团单号作为订单号 + userGroupBuying.setOrderid(grouporderid); // 使用拼团单号作为订单号 + userGroupBuying.setPtorderid(ptcode); userGroupBuying.setUid(user.getId()); + userGroupBuying.setImage(user.getAvatar()); userGroupBuying.setUname(user.getName()); userGroupBuying.setProductId(serviceGoods.getId()); userGroupBuying.setMoney(itemPrice); - userGroupBuying.setStatus(1L); // 待支付 - userGroupBuying.setPaystatus(1L); // 待支付 + userGroupBuying.setStatus(4L); // 待支付 + userGroupBuying.setPaystatus(2L); // 待支付 userGroupBuying.setPaytype(1L); // 默认微信支付 - userGroupBuying.setDeduction(couponDiscount.add(memberMoney)); - + userGroupBuying.setDeduction(new BigDecimal(0)); int insertResult = userGroupBuyingService.insertUserGroupBuying(userGroupBuying); if (insertResult <= 0) { result.put("success", false); @@ -403,7 +1355,7 @@ public class AppleOrderController extends BaseController { // 预支付接口不需要检查拼团人数,只需要记录预支付信息 result.put("success", true); - result.put("orderId", finalPtcode); + result.put("orderId", ptcode); result.put("oid", userGroupBuying.getId()); result.put("totalAmount", itemPrice); @@ -416,58 +1368,193 @@ public class AppleOrderController extends BaseController { return result; } } - + + + /** - * 创建次卡订单 + * 创建一口价次卡 + * 1预约 2报价 3一口价 4拼团 5普通订单 */ - private Map createCardOrder(Users user, ServiceGoods serviceGoods, UserAddress userAddress, - String sku, Integer num, String makeTime, CouponUser couponUser, - BigDecimal couponDiscount, BigDecimal memberMoney, String mtcode, String attachments) { + private Map createCardOrder(Users user, Long productId, UserAddress userAddress, + String sku, Integer num, String makeTime, + String attachments,String cikaid,BigDecimal totalAmount) { Map result = new HashMap<>(); + try { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + //派单模式 + Integer dispatchtype=serviceGoods.getDispatchtype(); + if (dispatchtype==null){ + dispatchtype=1; + } // 计算订单金额 - BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); + BigDecimal itemPrice = totalAmount; // 生成订单号 - String orderId = GenerateCustomCode.generCreateOrder("C"); - // 创建次卡使用记录 - UserUseSecondaryCard card = new UserUseSecondaryCard(); - card.setUid(user.getId()); - card.setCarid(String.valueOf(serviceGoods.getId())); // 假设商品ID即为次卡ID - card.setGoodsids(String.valueOf(serviceGoods.getId())); // 如有多个服务ID可调整 - card.setNum(Long.valueOf(num)); - card.setUsenum(0L); - card.setOrderid(orderId); - card.setTransactionId(""); - card.setPaymoney(itemPrice); - card.setStatus(4L); // 1可用 2已用完 3已退款 4未支付 - card.setRemark(attachments); // 附件信息存remark - int insertResult = userUseSecondaryCardService.insertUserUseSecondaryCard(card); + String orderId = GenerateCustomCode.generCreateOrder("N"); + + // 创建普通预约订单(统一使用服务订单表) + Order order = new Order(); + order.setNum(Long.valueOf(num)); + order.setType(1); // 普通预约订单 + order.setCreateType(1); // 用户自主下单 + order.setOrderId(orderId); + order.setUid(user.getId()); + order.setUname(user.getName()); + order.setProductId(serviceGoods.getId()); + order.setProductName(serviceGoods.getTitle()); + order.setSku(sku); + order.setCartid(cikaid); + // order.setc + if (userAddress != null) { + 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); + //有次卡直接形成订单 + if (StringUtils.isNotBlank(cikaid)){ + order.setStatus(1L); // 待接单 + }else{ + order.setStatus(11L); // 待支付 + } + + order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 + order.setIsAccept(0); + order.setIsComment(0); + order.setIsPause(1); + order.setOdertype(2); + order.setDeduction(new BigDecimal(0)); + order.setFileData(attachments); // 设置附件数据 + order.setType(1); + order.setTotalPrice(itemPrice); + int insertResult = orderService.insertOrder(order); if (insertResult <= 0) { result.put("success", false); - result.put("message", "次卡订单创建失败"); + result.put("message", "普通预约订单创建失败"); return result; } + + // 添加订单日志 + OrderLog orderLog = new OrderLog(); + if (StringUtils.isNotBlank(cikaid)){ + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + orderLog.setType(BigDecimal.valueOf(1.0)); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "订单创建成功,待派单"); + orderLog.setContent(jsonObject.toJSONString()); + + }else{ + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + orderLog.setType(BigDecimal.valueOf(1.0)); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "订单创建成功,待支付"); + orderLog.setContent(jsonObject.toJSONString()); + + } + + orderLogService.insertOrderLog(orderLog); + result.put("success", true); result.put("orderId", orderId); - result.put("oid", card.getId()); + result.put("oid", order.getId()); result.put("totalAmount", itemPrice); + return result; + } catch (Exception e) { - logger.error("创建次卡订单失败:", e); + logger.error("创建普通预约订单失败:", e); result.put("success", false); - result.put("message", "创建次卡订单失败:" + e.getMessage()); + result.put("message", "创建普通预约订单失败:" + e.getMessage()); return result; } } + + + +// /** +// * 创建次卡订单 +// */ +// private Map createCardOrder(Users user, Long productId, UserAddress userAddress, +// String sku, Integer num, String makeTime, CouponUser couponUser, +// BigDecimal couponDiscount, BigDecimal memberMoney, String mtcode, String attachments,String goodsids) { +// Map result = new HashMap<>(); +// try { +// +// UserSecondaryCard userSecondaryCard = userSecondaryCardService.selectUserSecondaryCardById(productId); +// +// // 计算订单金额 +// BigDecimal itemPrice = userSecondaryCard.getRealMoney(); +// // 生成订单号 +// String orderId = GenerateCustomCode.generCreateOrder("C"); +// // 创建次卡使用记录 +// UserUseSecondaryCard card = new UserUseSecondaryCard(); +// card.setUid(user.getId()); +// card.setCarid(String.valueOf(userSecondaryCard.getId())); // 假设商品ID即为次卡ID +// card.setGoodsids(goodsids); // 如有多个服务ID可调整 +// card.setNum(Long.valueOf(num)); +// card.setUsenum(0L); +// card.setOrderid(orderId); +// card.setTransactionId(""); +// card.setPaymoney(itemPrice); +// card.setStatus(4L); // 1可用 2已用完 3已退款 4未支付 +// card.setRemark(attachments); // 附件信息存remark +// int insertResult = userUseSecondaryCardService.insertUserUseSecondaryCard(card); +// if (insertResult <= 0) { +// result.put("success", false); +// result.put("message", "次卡订单创建失败"); +// return result; +// } +// result.put("success", true); +// result.put("orderId", orderId); +// result.put("oid", card.getId()); +// result.put("totalAmount", itemPrice); +// return result; +// } catch (Exception e) { +// logger.error("创建次卡订单失败:", e); +// result.put("success", false); +// result.put("message", "创建次卡订单失败:" + e.getMessage()); +// return result; +// } +// } /** * 创建秒杀订单 */ - private Map createSeckillOrder(Users user, ServiceGoods serviceGoods, UserAddress userAddress, - String sku, Integer num, String makeTime, CouponUser couponUser, - BigDecimal couponDiscount, BigDecimal memberMoney, String mtcode, String attachments) { + private Map createSeckillOrder(Users user, Long productId, UserAddress userAddress, + String sku, Integer num, String makeTime, + String attachments,BigDecimal totalAmount) { Map result = new HashMap<>(); - + + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + //派单模式 + Integer dispatchtype=serviceGoods.getDispatchtype(); + if (dispatchtype==null){ + dispatchtype=1; + } try { // 验证秒杀价格 if (serviceGoods.getFixedprice() == null) { @@ -519,14 +1606,15 @@ public class AppleOrderController extends BaseController { order.setGoodPrice(serviceGoods.getFixedprice()); order.setServicePrice(BigDecimal.ZERO); order.setPayPrice(itemPrice); - order.setStatus(1L); // 待支付 - order.setReceiveType(1L); // 自由抢单 + order.setStatus(11L); // 待待接单 + order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 order.setIsAccept(0); order.setIsComment(0); + order.setOdertype(3); order.setIsPause(1); - order.setDeduction(couponDiscount.add(memberMoney)); + order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 - order.setType(1); + order.setTotalPrice(totalAmount); int insertResult = orderService.insertOrder(order); if (insertResult <= 0) { result.put("success", false); @@ -538,11 +1626,12 @@ public class AppleOrderController extends BaseController { OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("秒杀订单生成"); - orderLog.setContent("用户创建秒杀订单"); - orderLog.setRemark("订单预支付创建"); + orderLog.setType(BigDecimal.valueOf(1)); + orderLog.setTitle("订单生成"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "用户创建秒杀订单,待支付"); + orderLog.setContent(jsonObject.toJSONString()); orderLogService.insertOrderLog(orderLog); - result.put("success", true); result.put("orderId", orderId); result.put("oid", order.getId()); @@ -561,11 +1650,18 @@ public class AppleOrderController extends BaseController { /** * 创建报价订单 */ - private Map createQuoteOrder(Users user, ServiceGoods serviceGoods, UserAddress userAddress, - String sku, Integer num, String makeTime, CouponUser couponUser, - BigDecimal couponDiscount, BigDecimal memberMoney, String mtcode, String attachments) { + private Map createQuoteOrder(Users user, Long productId, UserAddress userAddress, + String sku, Integer num, String makeTime, + String attachments) { Map result = new HashMap<>(); - + + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + + Integer dispatchtype=serviceGoods.getDispatchtype(); + if (dispatchtype==null){ + dispatchtype=1; + } + try { // 计算订单金额 BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); @@ -612,12 +1708,13 @@ public class AppleOrderController extends BaseController { order.setGoodPrice(serviceGoods.getPrice()); order.setServicePrice(BigDecimal.ZERO); order.setPayPrice(itemPrice); - order.setStatus(1L); // 待支付 - order.setReceiveType(1L); // 自由抢单 + order.setStatus(8L); // 待待报价 + order.setReceiveType(Long.valueOf(dispatchtype)); // 自由抢单 order.setIsAccept(0); order.setIsComment(0); order.setIsPause(1); - order.setDeduction(couponDiscount.add(memberMoney)); + order.setOdertype(4); + order.setDeduction(new BigDecimal(0)); order.setFileData(attachments); // 设置附件数据 int insertResult = orderService.insertOrder(order); @@ -631,9 +1728,12 @@ public class AppleOrderController extends BaseController { OrderLog orderLog = new OrderLog(); orderLog.setOid(order.getId()); orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("报价订单生成"); - orderLog.setContent("用户创建报价订单"); - orderLog.setRemark("订单预支付创建"); + orderLog.setType(BigDecimal.valueOf(1)); + orderLog.setTitle("订单生成"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "用户创建报价订单,待报价"); + orderLog.setContent(jsonObject.toJSONString()); + orderLogService.insertOrderLog(orderLog); result.put("success", true); @@ -650,6 +1750,7 @@ public class AppleOrderController extends BaseController { return result; } } - + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java index 1a4dcf1..b13ce5d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ApplePayController.java @@ -68,6 +68,12 @@ public class ApplePayController extends BaseController { private IGoodsOrderService goodsOrderService; @Autowired private WechatPayV3Util wechatPayV3Util; + @Autowired + private IUsersPayBeforService usersPayBeforService; + @Autowired + private IUserSecondaryCardService userSecondaryCardService; + @Autowired + private IUserUseSecondaryCardService userUseSecondaryCardService; // ==================== 支付下单相关接口 ==================== @PostMapping("/api/quick-refund") @@ -550,269 +556,7 @@ public class ApplePayController 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无效"); - } - // 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 = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); - totalAmount = totalAmount.add(itemPrice); - - // 判断商品类型并创建相应订单 - BigDecimal DeductionPrice = new BigDecimal("0"); - if (serviceGoods.getType() == 2) { - // 创建服务订单 - String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; - 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); - 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) { - // 使用工具类简化微信支付参数组装 - 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()); - } - } @@ -1379,796 +1123,247 @@ public class ApplePayController extends BaseController { } } -// /** -// * 通用订单支付接口 -// * -// * 支持多种订单类型和支付方式的统一支付接口 -// * -// * @param params 支付参数 -// * @param request HTTP请求对象 -// * @return 支付结果 -// * -// * 请求参数说明: -// * - id: 产品或次卡主键ID(必填) -// * - sku: 购买的规格(可选) -// * - paytype: 支付类型 1=微信支付 2=余额支付 3=组合支付(必填) -// * - ordertype: 订单类别 1=拼团 2=次卡 3=秒杀 4=报价 0=普通预约(必填) -// * - coupon_id: 优惠券ID(可选) -// * - address_id: 地址ID(可选) -// * - mtcode: 美团核销码(可选) -// * - membermoney: 会员优惠金额(可选) -// * - num: 购买数量(可选,默认1) -// * - make_time: 预约时间(可选,格式:yyyy-MM-dd HH:mm) -// * - wechat_pay_amount: 微信支付金额(组合支付时必填) -// * - balance_pay_amount: 余额支付金额(组合支付时必填) -// */ -// @PostMapping("/api/universal/order/pay") -// public AjaxResult universalOrderPay(@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无效"); -// } -// -// // 2. 获取用户信息 -// Users user = (Users) userValidation.get("user"); -// if (user == null) { -// return AppletControllerUtil.appletWarning("用户信息获取失败"); -// } -// -// // 3. 验证必要参数 -// if (params == null || params.get("id") == null || params.get("paytype") == null || params.get("ordertype") == null) { -// return AppletControllerUtil.appletWarning("必要参数不能为空:id、paytype、ordertype"); -// } -// -// // 4. 解析参数 -// Long productId = Long.valueOf(params.get("id").toString()); -// Integer paytype = Integer.valueOf(params.get("paytype").toString()); -// Integer ordertype = Integer.valueOf(params.get("ordertype").toString()); -// String sku = params.get("sku") != null ? params.get("sku").toString() : ""; -// Long couponId = params.get("coupon_id") != null ? Long.valueOf(params.get("coupon_id").toString()) : null; -// Long addressId = params.get("address_id") != null ? Long.valueOf(params.get("address_id").toString()) : null; -// String mtcode = params.get("mtcode") != null ? params.get("mtcode").toString() : ""; -// BigDecimal memberMoney = params.get("membermoney") != null ? new BigDecimal(params.get("membermoney").toString()) : BigDecimal.ZERO; -// Integer num = params.get("num") != null ? Integer.valueOf(params.get("num").toString()) : 1; -// String makeTime = params.get("make_time") != null ? params.get("make_time").toString() : ""; -// -// // 5. 验证支付类型 -// if (paytype < 1 || paytype > 3) { -// return AppletControllerUtil.appletWarning("支付类型无效:1=微信支付 2=余额支付 3=组合支付"); -// } -// -// // 6. 验证订单类型 -// if (ordertype < 0 || ordertype > 4) { -// return AppletControllerUtil.appletWarning("订单类型无效:0=普通预约 1=拼团 2=次卡 3=秒杀 4=报价"); -// } -// -// // 7. 根据订单类型处理不同的业务逻辑 -// Map orderResult = null; -// switch (ordertype) { -// case 0: // 普通预约 -// orderResult = handleNormalOrder(user, productId, sku, addressId, couponId, memberMoney, num, makeTime, mtcode); -// break; -// case 1: // 拼团 -// orderResult = handleGroupBuyingOrder(user, productId, sku, couponId, memberMoney, num); -// break; -// case 2: // 次卡 -// orderResult = handleCardOrder(user, productId, sku, couponId, memberMoney, num); -// break; -// case 3: // 秒杀 -// orderResult = handleSeckillOrder(user, productId, sku, addressId, couponId, memberMoney, num); -// break; -// case 4: // 报价 -// orderResult = handleQuoteOrder(user, productId, sku, addressId, couponId, memberMoney, num); -// break; -// default: -// return AppletControllerUtil.appletWarning("不支持的订单类型"); -// } -// -// if (orderResult == null || !(Boolean) orderResult.get("success")) { -// String errorMsg = orderResult != null ? (String) orderResult.get("message") : "订单创建失败"; -// return AppletControllerUtil.appletWarning(errorMsg); -// } -// -// // 8. 获取订单信息 -// String orderId = (String) orderResult.get("orderId"); -// BigDecimal totalAmount = (BigDecimal) orderResult.get("totalAmount"); -// String orderDescription = (String) orderResult.get("description"); -// -// // 9. 根据支付类型处理支付 -// Map paymentResult = null; -// switch (paytype) { -// case 1: // 微信支付 -// paymentResult = handleWechatPayment(user, orderId, totalAmount, orderDescription, ordertype); -// break; -// case 2: // 余额支付 -// paymentResult = handleBalancePayment(user, orderId, totalAmount, orderDescription); -// break; -// case 3: // 组合支付 -// paymentResult = handleCombinedPayment(user, orderId, totalAmount, orderDescription, params, ordertype); -// break; -// default: -// return AppletControllerUtil.appletWarning("不支持的支付类型"); -// } -// -// if (paymentResult == null || !(Boolean) paymentResult.get("success")) { -// String errorMsg = paymentResult != null ? (String) paymentResult.get("message") : "支付处理失败"; -// return AppletControllerUtil.appletWarning(errorMsg); -// } -// -// // 10. 返回支付结果 -// Map responseData = new HashMap<>(); -// responseData.put("orderId", orderId); -// responseData.put("totalAmount", totalAmount); -// responseData.put("paytype", paytype); -// responseData.put("ordertype", ordertype); -// responseData.putAll(paymentResult); -// -// return AppletControllerUtil.appletSuccess(responseData); -// -// } catch (Exception e) { -// logger.error("通用订单支付异常:", e); -// return AppletControllerUtil.appletError("订单支付失败:" + e.getMessage()); -// } -// } -// -// /** -// * 处理普通预约订单 -// */ -// private Map handleNormalOrder(Users user, Long productId, String sku, Long addressId, -// Long couponId, BigDecimal memberMoney, Integer num, -// String makeTime, String mtcode) { -// Map result = new HashMap<>(); -// try { -// // 1. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// result.put("success", false); -// result.put("message", "商品不存在"); -// return result; -// } -// -// // 2. 验证地址信息(如果需要) -// UserAddress userAddress = null; -// if (addressId != null) { -// userAddress = userAddressService.selectUserAddressById(addressId); -// if (userAddress == null) { -// result.put("success", false); -// result.put("message", "地址不存在"); -// return result; -// } -// } -// -// // 3. 计算订单金额 -// BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); -// BigDecimal totalAmount = itemPrice.subtract(memberMoney); -// -// // 4. 处理优惠券 -// BigDecimal couponDiscount = BigDecimal.ZERO; -// if (couponId != null) { -// CouponUser coupon = couponUserService.selectCouponUserById(couponId); -// if (coupon != null && coupon.getStatus() == 1) { -// couponDiscount = new BigDecimal(coupon.getCouponPrice()); -// totalAmount = totalAmount.subtract(couponDiscount); -// // 标记优惠券为已使用 -// coupon.setStatus(2L); -// couponUserService.updateCouponUser(coupon); -// } -// } -// -// // 5. 创建订单 -// String orderId = GenerateCustomCode.generCreateOrder("B"); -// -// if (serviceGoods.getType() == 2) { -// // 创建商品订单 -// GoodsOrder goodsOrder = new GoodsOrder(); -// goodsOrder.setType(1); -// goodsOrder.setOrderId(orderId); -// goodsOrder.setUid(user.getId()); -// goodsOrder.setProductId(productId); -// goodsOrder.setNum(Long.valueOf(num)); -// goodsOrder.setTotalPrice(itemPrice); -// goodsOrder.setGoodPrice(serviceGoods.getPrice()); -// goodsOrder.setPayPrice(totalAmount); -// goodsOrder.setDeduction(couponDiscount.add(memberMoney)); -// goodsOrder.setStatus(1L); // 待支付 -// goodsOrder.setSku(sku); -// goodsOrder.setMtcode(mtcode); -// if (addressId != null) { -// goodsOrder.setAddressId(addressId); -// goodsOrder.setName(userAddress.getName()); -// goodsOrder.setPhone(userAddress.getPhone()); -// goodsOrder.setAddress(userAddress.getAddressName()); -// } -// if (couponId != null) { -// goodsOrder.setCouponId(couponId); -// } -// -// int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "订单创建失败"); -// return result; -// } -// } else { -// // 创建服务订单 -// Order order = new Order(); -// order.setType(1); -// order.setCreateType(1); -// order.setOrderId(orderId); -// order.setUid(user.getId()); -// order.setUname(user.getName()); -// order.setProductId(productId); -// order.setProductName(serviceGoods.getTitle()); -// order.setNum(Long.valueOf(num)); -// order.setTotalPrice(itemPrice); -// order.setGoodPrice(serviceGoods.getPrice()); -// order.setPayPrice(totalAmount); -// order.setDeduction(couponDiscount.add(memberMoney)); -// order.setStatus(1L); // 待接单 -// order.setReceiveType(1L); // 自由抢单 -// order.setSku(sku); -// order.setMtcode(mtcode); -// if (addressId != null) { -// order.setAddressId(addressId); -// order.setName(userAddress.getName()); -// order.setPhone(userAddress.getPhone()); -// order.setAddress(userAddress.getAddressInfo()); -// } -// if (couponId != null) { -// order.setCouponId(couponId); -// } -// -// // 处理预约时间 -// 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); -// } -// } -// } -// -// int insertResult = orderService.insertOrder(order); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "订单创建失败"); -// return result; -// } -// } -// -// result.put("success", true); -// result.put("orderId", orderId); -// result.put("totalAmount", totalAmount); -// result.put("description", "普通预约-" + serviceGoods.getTitle()); -// return result; -// -// } catch (Exception e) { -// logger.error("处理普通预约订单异常:", e); -// result.put("success", false); -// result.put("message", "订单处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理拼团订单 -// */ -// private Map handleGroupBuyingOrder(Users user, Long productId, String sku, -// Long couponId, BigDecimal memberMoney, Integer num) { -// Map result = new HashMap<>(); -// try { -// // 1. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// result.put("success", false); -// result.put("message", "商品不存在"); -// return result; -// } -// -// // 2. 验证拼团价格 -// if (serviceGoods.getGroupprice() == null) { -// result.put("success", false); -// result.put("message", "该商品不支持拼团"); -// return result; -// } -// -// // 3. 计算订单金额 -// BigDecimal itemPrice = serviceGoods.getGroupprice().multiply(BigDecimal.valueOf(num)); -// BigDecimal totalAmount = itemPrice.subtract(memberMoney); -// -// // 4. 处理优惠券 -// if (couponId != null) { -// CouponUser coupon = couponUserService.selectCouponUserById(couponId); -// if (coupon != null && coupon.getStatus() == 1) { -// BigDecimal couponDiscount = new BigDecimal(coupon.getCouponPrice()); -// totalAmount = totalAmount.subtract(couponDiscount); -// coupon.setStatus(2L); -// couponUserService.updateCouponUser(coupon); -// } -// } -// -// // 5. 创建拼团订单 -// String orderId = GenerateCustomCode.generCreateOrder("G"); -// UserGroupBuying userGroupBuying = new UserGroupBuying(); -// userGroupBuying.setUid(user.getId()); -// userGroupBuying.setStatus(4L); // 待支付 -// userGroupBuying.setUname(user.getName()); -// userGroupBuying.setProductId(productId); -// userGroupBuying.setPaytype(1L); // 微信支付 -// userGroupBuying.setMoney(totalAmount); -// userGroupBuying.setOrderid(orderId); -// userGroupBuying.setSku(sku); -// if (couponId != null) { -// userGroupBuying.setCouponId(couponId); -// } -// -// int insertResult = userGroupBuyingService.insertUserGroupBuying(userGroupBuying); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "拼团订单创建失败"); -// return result; -// } -// -// result.put("success", true); -// result.put("orderId", orderId); -// result.put("totalAmount", totalAmount); -// result.put("description", "拼团-" + serviceGoods.getTitle()); -// return result; -// -// } catch (Exception e) { -// logger.error("处理拼团订单异常:", e); -// result.put("success", false); -// result.put("message", "拼团订单处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理次卡订单 -// */ -// private Map handleCardOrder(Users user, Long productId, String sku, -// Long couponId, BigDecimal memberMoney, Integer num) { -// Map result = new HashMap<>(); -// try { -// // 1. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// result.put("success", false); -// result.put("message", "商品不存在"); -// return result; -// } -// -// // 2. 验证次卡类型 -// if (serviceGoods.getType() != 3) { // 假设type=3表示次卡 -// result.put("success", false); -// result.put("message", "该商品不是次卡类型"); -// return result; -// } -// -// // 3. 计算订单金额 -// BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); -// BigDecimal totalAmount = itemPrice.subtract(memberMoney); -// -// // 4. 处理优惠券 -// if (couponId != null) { -// CouponUser coupon = couponUserService.selectCouponUserById(couponId); -// if (coupon != null && coupon.getStatus() == 1) { -// BigDecimal couponDiscount = new BigDecimal(coupon.getCouponPrice()); -// totalAmount = totalAmount.subtract(couponDiscount); -// coupon.setStatus(2L); -// couponUserService.updateCouponUser(coupon); -// } -// } -// -// // 5. 创建次卡订单(使用商品订单表) -// String orderId = GenerateCustomCode.generCreateOrder("C"); -// GoodsOrder goodsOrder = new GoodsOrder(); -// goodsOrder.setType(3); // 次卡类型 -// goodsOrder.setOrderId(orderId); -// goodsOrder.setUid(user.getId()); -// goodsOrder.setProductId(productId); -// goodsOrder.setNum(Long.valueOf(num)); -// goodsOrder.setTotalPrice(itemPrice); -// goodsOrder.setGoodPrice(serviceGoods.getPrice()); -// goodsOrder.setPayPrice(totalAmount); -// goodsOrder.setDeduction(memberMoney); -// goodsOrder.setStatus(1L); // 待支付 -// goodsOrder.setSku(sku); -// if (couponId != null) { -// goodsOrder.setCouponId(couponId); -// } -// -// int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "次卡订单创建失败"); -// return result; -// } -// -// result.put("success", true); -// result.put("orderId", orderId); -// result.put("totalAmount", totalAmount); -// result.put("description", "次卡-" + serviceGoods.getTitle()); -// return result; -// -// } catch (Exception e) { -// logger.error("处理次卡订单异常:", e); -// result.put("success", false); -// result.put("message", "次卡订单处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理秒杀订单 -// */ -// private Map handleSeckillOrder(Users user, Long productId, String sku, Long addressId, -// Long couponId, BigDecimal memberMoney, Integer num) { -// Map result = new HashMap<>(); -// try { -// // 1. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// result.put("success", false); -// result.put("message", "商品不存在"); -// return result; -// } -// -// // 2. 验证秒杀价格 -// if (serviceGoods.getSeckillprice() == null) { -// result.put("success", false); -// result.put("message", "该商品不支持秒杀"); -// return result; -// } -// -// // 3. 验证库存 -// if (serviceGoods.getStock() != null && serviceGoods.getStock() < num) { -// result.put("success", false); -// result.put("message", "库存不足"); -// return result; -// } -// -// // 4. 计算订单金额 -// BigDecimal itemPrice = serviceGoods.getSeckillprice().multiply(BigDecimal.valueOf(num)); -// BigDecimal totalAmount = itemPrice.subtract(memberMoney); -// -// // 5. 处理优惠券 -// if (couponId != null) { -// CouponUser coupon = couponUserService.selectCouponUserById(couponId); -// if (coupon != null && coupon.getStatus() == 1) { -// BigDecimal couponDiscount = new BigDecimal(coupon.getCouponPrice()); -// totalAmount = totalAmount.subtract(couponDiscount); -// coupon.setStatus(2L); -// couponUserService.updateCouponUser(coupon); -// } -// } -// -// // 6. 验证地址信息 -// UserAddress userAddress = null; -// if (addressId != null) { -// userAddress = userAddressService.selectUserAddressById(addressId); -// if (userAddress == null) { -// result.put("success", false); -// result.put("message", "地址不存在"); -// return result; -// } -// } -// -// // 7. 创建秒杀订单 -// String orderId = GenerateCustomCode.generCreateOrder("S"); -// GoodsOrder goodsOrder = new GoodsOrder(); -// goodsOrder.setType(4); // 秒杀类型 -// goodsOrder.setOrderId(orderId); -// goodsOrder.setUid(user.getId()); -// goodsOrder.setProductId(productId); -// goodsOrder.setNum(Long.valueOf(num)); -// goodsOrder.setTotalPrice(itemPrice); -// goodsOrder.setGoodPrice(serviceGoods.getSeckillprice()); -// goodsOrder.setPayPrice(totalAmount); -// goodsOrder.setDeduction(memberMoney); -// goodsOrder.setStatus(1L); // 待支付 -// goodsOrder.setSku(sku); -// if (addressId != null) { -// goodsOrder.setAddressId(addressId); -// goodsOrder.setName(userAddress.getName()); -// goodsOrder.setPhone(userAddress.getPhone()); -// goodsOrder.setAddress(userAddress.getAddressName()); -// } -// if (couponId != null) { -// goodsOrder.setCouponId(couponId); -// } -// -// int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "秒杀订单创建失败"); -// return result; -// } -// -// result.put("success", true); -// result.put("orderId", orderId); -// result.put("totalAmount", totalAmount); -// result.put("description", "秒杀-" + serviceGoods.getTitle()); -// return result; -// -// } catch (Exception e) { -// logger.error("处理秒杀订单异常:", e); -// result.put("success", false); -// result.put("message", "秒杀订单处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理报价订单 -// */ -// private Map handleQuoteOrder(Users user, Long productId, String sku, Long addressId, -// Long couponId, BigDecimal memberMoney, Integer num) { -// Map result = new HashMap<>(); -// try { -// // 报价订单通常是先创建订单,后续师傅报价后再支付 -// // 这里创建一个待报价的订单 -// -// // 1. 查询商品信息 -// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); -// if (serviceGoods == null) { -// result.put("success", false); -// result.put("message", "商品不存在"); -// return result; -// } -// -// // 2. 验证地址信息 -// UserAddress userAddress = null; -// if (addressId != null) { -// userAddress = userAddressService.selectUserAddressById(addressId); -// if (userAddress == null) { -// result.put("success", false); -// result.put("message", "地址不存在"); -// return result; -// } -// } -// -// // 3. 创建报价订单(初始金额为0,等待师傅报价) -// String orderId = GenerateCustomCode.generCreateOrder("Q"); -// Order order = new Order(); -// order.setType(1); -// order.setCreateType(1); -// order.setOrderId(orderId); -// order.setUid(user.getId()); -// order.setUname(user.getName()); -// order.setProductId(productId); -// order.setProductName(serviceGoods.getTitle()); -// order.setNum(Long.valueOf(num)); -// order.setTotalPrice(BigDecimal.ZERO); // 待报价 -// order.setGoodPrice(serviceGoods.getPrice()); -// order.setPayPrice(BigDecimal.ZERO); // 待报价 -// order.setDeduction(memberMoney); -// order.setStatus(1L); // 待接单 -// order.setReceiveType(1L); // 自由抢单 -// order.setSku(sku); -// if (addressId != null) { -// order.setAddressId(addressId); -// order.setName(userAddress.getName()); -// order.setPhone(userAddress.getPhone()); -// order.setAddress(userAddress.getAddressInfo()); -// } -// if (couponId != null) { -// order.setCouponId(couponId); -// } -// -// int insertResult = orderService.insertOrder(order); -// if (insertResult <= 0) { -// result.put("success", false); -// result.put("message", "报价订单创建失败"); -// return result; -// } -// -// result.put("success", true); -// result.put("orderId", orderId); -// result.put("totalAmount", BigDecimal.ZERO); // 报价订单暂时为0 -// result.put("description", "报价订单-" + serviceGoods.getTitle()); -// return result; -// -// } catch (Exception e) { -// logger.error("处理报价订单异常:", e); -// result.put("success", false); -// result.put("message", "报价订单处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理微信支付 -// */ -// private Map handleWechatPayment(Users user, String orderId, BigDecimal totalAmount, -// String description, Integer ordertype) { -// Map result = new HashMap<>(); -// try { -// if (totalAmount.compareTo(BigDecimal.ZERO) <= 0) { -// result.put("success", false); -// result.put("message", "支付金额必须大于0"); -// return result; -// } -// -// // 根据订单类型选择不同的回调地址 -// String notifyUrl = getNotifyUrlByOrderType(ordertype); -// -// // 调用微信支付 -// Map payResult = wechatPayUtil.createBatchOrderAndPay( -// user.getOpenid(), -// orderId, -// new BigDecimal("0.01"), // 测试环境使用0.01元 -// 1, -// notifyUrl); -// -// if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { -// result.put("success", true); -// result.put("paytype", "wechat"); -// result.put("prepayId", payResult.get("prepayId")); -// result.putAll(payResult); -// } else { -// String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; -// result.put("success", false); -// result.put("message", errorMsg); -// } -// -// return result; -// -// } catch (Exception e) { -// logger.error("处理微信支付异常:", e); -// result.put("success", false); -// result.put("message", "微信支付处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理余额支付 -// */ -// private Map handleBalancePayment(Users user, String orderId, BigDecimal totalAmount, -// String description) { -// Map result = new HashMap<>(); -// try { -// if (totalAmount.compareTo(BigDecimal.ZERO) <= 0) { -// result.put("success", false); -// result.put("message", "支付金额必须大于0"); -// return result; -// } -// -// // 调用余额支付工具类 -// Map balanceResult = BalancePayUtil.processBalancePayment( -// user.getId(), -// totalAmount, -// description); -// -// if (balanceResult != null && Boolean.TRUE.equals(balanceResult.get("success"))) { -// result.put("success", true); -// result.put("paytype", "balance"); -// result.put("message", "余额支付成功"); -// result.put("beforeBalance", balanceResult.get("beforeBalance")); -// result.put("afterBalance", balanceResult.get("afterBalance")); -// } else { -// result.put("success", false); -// result.put("message", balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"); -// if (balanceResult != null && balanceResult.containsKey("insufficientAmount")) { -// result.put("insufficientAmount", balanceResult.get("insufficientAmount")); -// } -// } -// -// return result; -// -// } catch (Exception e) { -// logger.error("处理余额支付异常:", e); -// result.put("success", false); -// result.put("message", "余额支付处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 处理组合支付 -// */ -// private Map handleCombinedPayment(Users user, String orderId, BigDecimal totalAmount, -// String description, Map params, -// Integer ordertype) { -// Map result = new HashMap<>(); -// try { -// if (totalAmount.compareTo(BigDecimal.ZERO) <= 0) { -// result.put("success", false); -// result.put("message", "支付金额必须大于0"); -// return result; -// } -// -// // 获取组合支付参数 -// BigDecimal wechatAmount = params.get("wechat_pay_amount") != null ? -// new BigDecimal(params.get("wechat_pay_amount").toString()) : BigDecimal.ZERO; -// BigDecimal balanceAmount = params.get("balance_pay_amount") != null ? -// new BigDecimal(params.get("balance_pay_amount").toString()) : BigDecimal.ZERO; -// -// // 验证金额 -// if (wechatAmount.add(balanceAmount).compareTo(totalAmount) != 0) { -// result.put("success", false); -// result.put("message", "组合支付金额不匹配"); -// return result; -// } -// -// // 先处理余额支付部分 -// if (balanceAmount.compareTo(BigDecimal.ZERO) > 0) { -// Map balanceResult = BalancePayUtil.processBalancePayment( -// user.getId(), -// balanceAmount, -// description + "-余额支付部分"); -// -// if (balanceResult == null || !Boolean.TRUE.equals(balanceResult.get("success"))) { -// result.put("success", false); -// result.put("message", balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"); -// return result; -// } -// } -// -// // 再处理微信支付部分 -// if (wechatAmount.compareTo(BigDecimal.ZERO) > 0) { -// String notifyUrl = getNotifyUrlByOrderType(ordertype); -// Map wechatResult = wechatPayUtil.createBatchOrderAndPay( -// user.getOpenid(), -// orderId, -// new BigDecimal("0.01"), // 测试环境使用0.01元 -// 1, -// notifyUrl); -// -// if (wechatResult == null || !Boolean.TRUE.equals(wechatResult.get("success"))) { -// result.put("success", false); -// result.put("message", wechatResult != null ? (String) wechatResult.get("message") : "微信支付失败"); -// return result; -// } -// -// result.put("prepayId", wechatResult.get("prepayId")); -// result.putAll(wechatResult); -// } -// -// result.put("success", true); -// result.put("paytype", "combined"); -// result.put("wechatAmount", wechatAmount); -// result.put("balanceAmount", balanceAmount); -// result.put("message", "组合支付处理成功"); -// -// return result; -// -// } catch (Exception e) { -// logger.error("处理组合支付异常:", e); -// result.put("success", false); -// result.put("message", "组合支付处理异常:" + e.getMessage()); -// return result; -// } -// } -// -// /** -// * 根据订单类型获取回调地址 -// */ -// private String getNotifyUrlByOrderType(Integer ordertype) { -// switch (ordertype) { -// case 0: // 普通预约 -// return WechatPayUtil.PAY_FH + "api/goods/pay/notify"; -// case 1: // 拼团 -// return WechatPayUtil.PAY_FH + "api/group/pay/notify"; -// case 2: // 次卡 -// return WechatPayUtil.PAY_FH + "api/card/pay/notify"; -// case 3: // 秒杀 -// return WechatPayUtil.PAY_FH + "api/seckill/pay/notify"; -// case 4: // 报价 -// return WechatPayUtil.PAY_FH + "api/quote/pay/notify"; -// default: -// return WechatPayUtil.PAY_FH + "api/goods/pay/notify"; -// } -// } + /** + * 订单支付接口 + * 根据订单号查询预支付信息,并根据预支付信息中的支付方式和金额进行支付 + * + * @param params orderNo(订单号) + * @param request HTTP请求对象 + * @return 支付结果 + */ + @PostMapping("/order/pay") + public AjaxResult orderPay(@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("orderNo") == null) { + return AppletControllerUtil.appletWarning("订单号不能为空"); + } + String orderNo = params.get("orderNo").toString(); + + // 3. 查询预支付记录 + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(orderNo); + if (payBefor == null) { + return AppletControllerUtil.appletWarning("预支付记录不存在"); + } + if (!payBefor.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权操作该预支付记录"); + } + if (payBefor.getStatus() != null && payBefor.getStatus() != 1) { + return AppletControllerUtil.appletWarning("该订单已支付或已失效"); + } + + // 4. 获取支付方式和金额 + Integer paytype = payBefor.getPaytype() != null ? payBefor.getPaytype().intValue() : 1; + BigDecimal wxMoney = payBefor.getWxmoney() != null ? payBefor.getWxmoney() : BigDecimal.ZERO; + BigDecimal yeMoney = payBefor.getYemoney() != null ? payBefor.getYemoney() : BigDecimal.ZERO; + + // 5. 处理支付 + Map payResult = new HashMap<>(); + + if (paytype == 1) { + // 微信支付 + if (wxMoney.compareTo(BigDecimal.ZERO) <= 0) { + return AppletControllerUtil.appletWarning("微信支付金额不能为0"); + } + payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + payBefor.getOrderid(), + new BigDecimal("0.01"), + 1, + WechatPayUtil.PAY_FH + "api/order/amount/paydata/notify" + ); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + payResult.put("istowx", 1); + return AppletControllerUtil.appletSuccess(payResult); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } else if (paytype == 2) { + // 余额支付 + if (yeMoney.compareTo(BigDecimal.ZERO) <= 0) { + return AppletControllerUtil.appletWarning("余额支付金额不能为0"); + } + Map balanceResult = BalancePayUtil.processBalancePayment( + user.getId(), + yeMoney, + "订单支付"+payBefor.getYemoney()+"元", + payBefor.getOrderid() + ); + if (balanceResult != null && Boolean.TRUE.equals(balanceResult.get("success"))) { + // 更新预支付记录状态 + payBefor.setStatus(2L); // 已支付 + payBefor.setPaytime(new Date()); + usersPayBeforService.updateUsersPayBefor(payBefor); + OrderUtil.prepayCallback(payBefor, user); + payResult.put("istowx", 2); + return AppletControllerUtil.appletSuccess(payResult); + } else { + String errorMsg = balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"; + return AppletControllerUtil.appletWarning(errorMsg); + } + } else if (paytype == 3) { + // 组合支付 + if (wxMoney.compareTo(BigDecimal.ZERO) > 0 && yeMoney.compareTo(BigDecimal.ZERO) > 0) { +// // 先扣余额 +// Map balanceResult = BalancePayUtil.processBalancePayment( +// user.getId(), +// yeMoney, +// "订单组合支付-余额部分"+payBefor.getYemoney()+"元", +// payBefor.getOrderid() +// ); +// if (balanceResult == null || !Boolean.TRUE.equals(balanceResult.get("success"))) { +// String errorMsg = balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"; +// return AppletControllerUtil.appletWarning(errorMsg); +// } + + // 再微信支付 + payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + payBefor.getPaycode(), + new BigDecimal("0.01"), + 1, + WechatPayUtil.PAY_FH + "api/order/amount/paydata/zuhenotify" + ); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + payResult.put("istowx", 1); + return AppletControllerUtil.appletSuccess(payResult); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } else if (yeMoney.compareTo(BigDecimal.ZERO) > 0) { + // 全部余额支付 + Map balanceResult = BalancePayUtil.processBalancePayment( + user.getId(), + yeMoney, + "订单支付"+payBefor.getYemoney()+"元", + payBefor.getOrderid() + ); + if (balanceResult != null && Boolean.TRUE.equals(balanceResult.get("success"))) { + payBefor.setStatus(2L); // 已支付 + usersPayBeforService.updateUsersPayBefor(payBefor); + OrderUtil.prepayCallback(payBefor, user); + payResult.put("istowx", 2); + return AppletControllerUtil.appletSuccess("余额支付成功"); + } else { + String errorMsg = balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"; + return AppletControllerUtil.appletWarning(errorMsg); + } + } else if (wxMoney.compareTo(BigDecimal.ZERO) > 0) { + // 全部微信支付 + payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + payBefor.getOrderid(), + new BigDecimal("0.01"), + 1, + WechatPayUtil.PAY_FH + "api/order/amount/paydata/zuhenotify" + ); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + payResult.put("istowx", 1); + return AppletControllerUtil.appletSuccess(payResult); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } else { + return AppletControllerUtil.appletWarning("支付金额不能为0"); + } + } else { + return AppletControllerUtil.appletWarning("不支持的支付类型"); + } + } catch (Exception e) { + logger.error("订单支付异常:", e); + return AppletControllerUtil.appletError("订单支付失败:" + e.getMessage()); + } + } + + /** + * 次卡微信支付接口 + * @param params {"id":次卡id, "goodsids":["161","160",...]} + * @param request HTTP请求对象 + * @return 微信支付参数 + */ + @PostMapping("/secondary/card/wxpay") + public AjaxResult secondaryCardWxPay(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验参数 + if (params == null || params.get("id") == null || params.get("goodsids") == null) { + return AppletControllerUtil.appletWarning("参数id和goodsids不能为空"); + } + Long cardId = Long.valueOf(params.get("id").toString()); + List goodsids; + try { + goodsids = (List) params.get("goodsids"); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("goodsids参数格式错误,必须为字符串数组"); + } + // 2. 获取用户 + 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("用户信息获取失败"); + } + // 3. 查询次卡基本信息 + UserSecondaryCard card = userSecondaryCardService.selectUserSecondaryCardById(cardId); + if (card == null) { + return AppletControllerUtil.appletWarning("次卡不存在"); + } + // 4. 插入未支付的次卡使用记录 + UserUseSecondaryCard useCard = new UserUseSecondaryCard(); + useCard.setUid(user.getId()); + useCard.setCarid(cardId.toString()); + useCard.setGoodsids(com.alibaba.fastjson2.JSONObject.toJSONString(goodsids)); + useCard.setNum(card.getNum()); + useCard.setUsenum(0L); + String orderid = GenerateCustomCode.generCreateOrder("CIKA"); + useCard.setOrderid(orderid); + useCard.setTransactionId(""); + useCard.setPaymoney(card.getRealMoney()); + useCard.setStatus(4L); // 4=未支付 + useCard.setRemark(""); + int insertResult = userUseSecondaryCardService.insertUserUseSecondaryCard(useCard); + if (insertResult <= 0) { + return AppletControllerUtil.appletWarning("次卡购买记录保存失败"); + } + // 5. 调用微信支付 + Map payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + orderid, + new BigDecimal("0.01"), + 1, + WechatPayUtil.PAY_FH + "api/secondary/card/paydata/notify" + ); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("orderid", orderid); + responseData.put("totalAmount", card.getRealMoney()); + 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); + } + } 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 60702cd..37fb124 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 @@ -11,6 +11,8 @@ import com.ruoyi.system.domain.AppleDoMain.OrderApple; import com.ruoyi.system.domain.AppleDoMain.AddressApple; import com.ruoyi.system.service.*; import com.winnerlook.model.VoiceResponseResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -40,6 +42,8 @@ import com.ruoyi.system.domain.QuoteMaterial; @RestController public class AppletController extends BaseController { + private static final Logger logger = LoggerFactory.getLogger(AppletController.class); + @Autowired private IServiceCateService serviceCateService; @Autowired @@ -115,7 +119,8 @@ public class AppletController extends BaseController { private IUserSecondaryCardService userSecondaryCardService; @Autowired private IUserGroupBuyingService userGroupBuyingService; - + @Autowired + private IUsersPayBeforService usersPayBeforService; @@ -961,6 +966,7 @@ public class AppletController extends BaseController { if (type != null && type == 2) { UserSecondaryCard goods = userSecondaryCardService.selectUserSecondaryCardById(id); Map map = new HashMap<>(); + map.put("isyikoujia", 1); map.put("id", goods.getId()); map.put("allsellnum", 10); map.put("orderid", goods.getOrderid()); @@ -1010,15 +1016,18 @@ public class AppletController extends BaseController { //拼团独有数据 if (type == 1) { // 拼团服务详情 + goodsData.put("isyikoujia", 1); goodsData.put("allsellnum", 10); goodsData.put("isgroup", serviceGoodsData.getIsgroup()); + goodsData.put("groupnum", serviceGoodsData.getGroupnum()); goodsData.put("groupprice", serviceGoodsData.getGroupprice()); List> groupBuyingList = userGroupBuyingService.selectGroupBuyingGroupByProductAndOrder(Math.toIntExact(serviceGoodsData.getId())); for (Map groupBuying : groupBuyingList) { //还差几人成团 - JSONArray groupBuyingArray = JSONArray.parseArray(groupBuying.get("name").toString()); - groupBuying.put("neednum", serviceGoodsData.getGroupnum() - groupBuyingArray.size()); - groupBuying.put("image", AppletControllerUtil.parseImagesStringToArray(groupBuying.get("image").toString())); + JSONArray groupBuyingArray = JSONArray.parseArray(groupBuying.get("name").toString()); + // JSONArray groupBuyingArray =new JSONArray(); + groupBuying.put("neednum", serviceGoodsData.getGroupnum() - groupBuyingArray.size()); + groupBuying.put("image", AppletControllerUtil.parseImagesStringToArray(groupBuying.get("image").toString())); //parseImagesStringToArray(goods.getImgs()) //groupBuying.put("neednum", AppletControllerUtil.buildImageUrl(groupBuying.get("image").toString())); } @@ -1026,20 +1035,54 @@ public class AppletController extends BaseController { } //秒杀独有数据 if (type == 3) { + + // 获取秒杀相关数据 + long msdata = 0L; + try { + // 获取config_one配置中的秒杀结束时间 + 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()) { + JSONObject configJson = JSONObject.parseObject(configValue); + String mstime = configJson.getString("mstime"); + + if (mstime != null && !mstime.trim().isEmpty()) { + // 解析秒杀结束时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date endTime = sdf.parse(mstime); + msdata = endTime.getTime(); // 返回结束时间的毫秒数 + } + } + } + } catch (Exception e) { + // 解析异常时设置为0 + msdata = 0L; + } + + // 秒杀服务详情 + goodsData.put("isyikoujia", 1); + goodsData.put("msdata", msdata); goodsData.put("allsellnum", 10); goodsData.put("isfixed", serviceGoodsData.getIsfixed()); goodsData.put("fixedprice", serviceGoodsData.getFixedprice()); } //报价数据下师傅的报价详情 - if (type == 3) { + if (type == 4) { + goodsData.put("isyikoujia", 2); // 秒杀服务详情 // List> quoteList = new List>() ; // // goodsData.put("isfixed", serviceGoodsData.getIsfixed()); // goodsData.put("fixedprice", serviceGoodsData.getFixedprice()); } - } + }else{ + goodsData.put("isyikoujia", 2); + } return AppletControllerUtil.appletSuccess(goodsData); } } catch (Exception e) { @@ -1667,7 +1710,6 @@ public class AppletController extends BaseController { userInfo.put("status", user.getStatus() != null ? user.getStatus() : 1); userInfo.put("tpd", 0); // 默认值 // userInfo.put("total_comm","0.00"); - // userInfo.put("total_comm", user.getTotalComm().toString() != null ? user.getTotalComm().toString() : "0.00"); userInfo.put("total_integral", user.getTotalIntegral() != null ? user.getTotalIntegral() : 100); userInfo.put("type", user.getType() != null ? user.getType().toString() : "1"); userInfo.put("worker_time", user.getWorkerTime()); @@ -3130,30 +3172,52 @@ public class AppletController extends BaseController { } else { sku = null; } - // 5. 查询商品信息并验证 + + // 5. 获取新增的三个参数:ordertype、fileData、remark + Long ordertype = null; + if (params.get("ordertype") != null) { + try { + ordertype = Long.valueOf(params.get("ordertype").toString()); + } catch (NumberFormatException e) { + // 如果转换失败,保持为null + ordertype = null; + } + } + + String fileData = null; + if (params.get("fileData") != null) { + fileData = params.get("fileData").toString(); + } + + String remark = null; + if (params.get("remark") != null) { + remark = params.get("remark").toString(); + } + + // 6. 查询商品信息并验证 ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); if (serviceGoods == null) { return AppletControllerUtil.appletWarning("商品不存在"); } - // 6. 验证商品状态 + // 7. 验证商品状态 // if (serviceGoods.getStatus() == null || !serviceGoods.getStatus().equals(1L)) { // return AppletControllerUtil.appletWarning("商品已下架或不可用"); // } - // 7. 检查商品库存(如果有库存管理) + // 8. 检查商品库存(如果有库存管理) // if (serviceGoods.getStock() != null && serviceGoods.getStock() <= 0L) { // return AppletControllerUtil.appletWarning("商品库存不足"); // } - // 8. 检查购物车中是否已存在该商品 + // 9. 检查购物车中是否已存在该商品 GoodsCart existingCartItem = AppletControllerUtil.findExistingCartItem(user.getId(), goodId, sku, goodsCartService); if (existingCartItem != null) { - // 如果已存在,更新数量 - return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService); + // 如果已存在,更新数量和新参数 + return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService, ordertype, fileData, remark); } else { // 如果不存在,新增购物车记录 - return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService); + return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService, ordertype, fileData, remark); } } catch (Exception e) { @@ -3161,6 +3225,94 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("添加购物车失败:" + e.getMessage()); } } + + + + /** + * 查询用户购物车数据,按商品类型分为商城类和服务类(不分页) + * + * @param request HTTP请求对象 + * @return { mallList: [...], serviceList: [...] } + *

+ * 接口说明: + * - 查询当前登录用户的全部购物车数据(不分页) + * - 根据商品的 type 字段分为商城类(type=2)和服务类(type=1) + * - 每个列表的封装方式参考 /api/cart/lst + * - 需要用户登录验证 + *

+ */ + @GetMapping("/api/cart/pluslst") + public AjaxResult getCartPlusList(HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 3. 查询全部购物车数据(不分页) + GoodsCart queryCart = new GoodsCart(); + queryCart.setUid(user.getId()); + List cartList = goodsCartService.selectGoodsCartList(queryCart); + + // 4. 按商品类型分组 + List> goodsList = new ArrayList<>(); + List> serviceList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (GoodsCart cart : cartList) { + Map cartData = new HashMap<>(); + cartData.put("id", cart.getId()); + cartData.put("uid", cart.getUid()); + cartData.put("good_id", cart.getGoodId()); + cartData.put("good_num", cart.getGoodNum()); + if (cart.getSku() != null && !cart.getSku().isEmpty()) { + try { + cartData.put("sku", com.alibaba.fastjson2.JSONObject.parseObject(cart.getSku())); + } catch (Exception e) { + cartData.put("sku", cart.getSku()); + } + } else { + cartData.put("sku", null); + } + cartData.put("ordertype", cart.getOrdertype()); + cartData.put("fileData", cart.getFileData()); + cartData.put("remark", cart.getReamk()); + cartData.put("created_at", cart.getCreatedAt() != null ? sdf.format(cart.getCreatedAt()) : null); + cartData.put("updated_at", cart.getUpdatedAt() != null ? sdf.format(cart.getUpdatedAt()) : null); + + // 查询商品详细信息 + Map goodInfo = AppletControllerUtil.getGoodDetailForCart(cart.getGoodId(), serviceGoodsService); + cartData.put("good", goodInfo); + + // 判断商品类型 + Integer type = null; + if (goodInfo.get("type") != null) { + try { + type = Integer.valueOf(goodInfo.get("type").toString()); + } catch (Exception ignore) {} + } + if (type != null && type == 2) { + goodsList.add(cartData); + } else { + // 默认都归为服务类(type=1) + serviceList.add(cartData); + } + } + // 5. 返回结构 + Map result = new HashMap<>(); + result.put("goodsList", goodsList); + result.put("serviceList", serviceList); + return AppletControllerUtil.appletSuccess(result); + } catch (Exception e) { + System.err.println("查询购物车plus列表异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询购物车plus列表失败:" + e.getMessage()); + } + } /** * 查询购物车列表接口 * @@ -6735,6 +6887,7 @@ public class AppletController extends BaseController { map.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); map.put("title", goods.getTitle()); map.put("price", goods.getPrice()); + map.put("id", goods.getId()); map.put("groupprice", goods.getGroupprice()); map.put("groupnum", goods.getGroupnum()); resultList.add(map); @@ -6815,6 +6968,7 @@ public class AppletController extends BaseController { List> resultList = new ArrayList<>(); for (ServiceGoods goods : goodsList) { Map map = new HashMap<>(); + map.put("id", goods.getId()); map.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); map.put("title", goods.getTitle()); map.put("price", goods.getPrice()); @@ -6826,7 +6980,38 @@ public class AppletController extends BaseController { TableDataInfo tableDataInfo = getDataTable(goodsList); tableDataInfo.setRows(resultList); // 只返回精简字段 Map pageData = PageUtil.buildSimplePageResponse(tableDataInfo, page, limit); - return AppletControllerUtil.appletSuccess(pageData); + + // 获取秒杀相关数据 + long msdata = 0L; + try { + // 获取config_one配置中的秒杀结束时间 + 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()) { + JSONObject configJson = JSONObject.parseObject(configValue); + String mstime = configJson.getString("mstime"); + + if (mstime != null && !mstime.trim().isEmpty()) { + // 解析秒杀结束时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date endTime = sdf.parse(mstime); + msdata = endTime.getTime(); // 返回结束时间的毫秒数 + } + } + } + } catch (Exception e) { + // 解析异常时设置为0 + msdata = 0L; + } + + Map reData = new HashMap<>(); + reData.put("listData", pageData); + reData.put("msdata", msdata); + return AppletControllerUtil.appletSuccess(reData); } //报价数据 @@ -6846,6 +7031,7 @@ public class AppletController extends BaseController { List> resultList = new ArrayList<>(); for (ServiceGoods goods : goodsList) { Map map = new HashMap<>(); + map.put("id", goods.getId()); map.put("icon", AppletControllerUtil.buildImageUrl(goods.getIcon())); map.put("title", goods.getTitle()); resultList.add(map); @@ -6863,7 +7049,273 @@ public class AppletController extends BaseController { } return null; } + /** + * 根据ID查询预支付记录并计算支付金额 + * + * @param id 预支付记录ID + * @param params 请求参数,包含paytype、coupon_id、mtcode + * @param request HTTP请求对象 + * @return 预支付记录详情和计算后的支付金额 + */ + @PostMapping("/api/paybefor/info/{id}") + public AjaxResult getPayBeforInfo(@PathVariable("id") String id, @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 (StringUtils.isBlank(id)) { + return AppletControllerUtil.appletWarning("预支付记录ID不能为空"); + } + + // 3. 获取请求参数 + Integer paytype = params.get("paytype") != null ? Integer.parseInt(params.get("paytype").toString()) : 1; + Long couponId = params.get("coupon_id") != null ? Long.parseLong(params.get("coupon_id").toString()) : null; + String mtcode = params.get("mtcode") != null ? params.get("mtcode").toString() : null; + + // 4. 查询预支付记录 + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforByOrderId(id); + if (payBefor == null) { + return AppletControllerUtil.appletWarning("预支付记录不存在"); + } + + // 5. 验证记录归属权(只能查看自己的记录) + if (!payBefor.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权查看该预支付记录"); + } + + // 6. 获取原始总金额(allmoney是固定的,永远不会改变) + BigDecimal originalAmount = payBefor.getAllmoney(); + if (originalAmount == null) { + originalAmount = BigDecimal.ZERO; + } + + // 获取会员优惠金额(固定不变) + BigDecimal memberMoney = payBefor.getMembermoney(); + if (memberMoney == null) { + memberMoney = BigDecimal.ZERO; + } + + // 获取服务金抵扣金额(固定不变) + BigDecimal serviceMoney = payBefor.getServicemoney(); + if (serviceMoney == null) { + serviceMoney = BigDecimal.ZERO; + } + + // 获取购物金抵扣金额(固定不变) + BigDecimal shopMoney = payBefor.getShopmoney(); + if (shopMoney == null) { + shopMoney = BigDecimal.ZERO; + } + + // 7. 计算优惠券金额(每次重新计算) + BigDecimal couponMoney = BigDecimal.ZERO; + if (couponId != null) { + CouponUser couponUser = couponUserService.selectCouponUserById(couponId); + if (couponUser != null && couponUser.getStatus() != null && couponUser.getStatus() == 1L) { + // 验证优惠券是否属于当前用户 + if (!couponUser.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("优惠券不属于当前用户"); + } + + // 验证优惠券是否过期 + if (couponUser.getLoseTime() != null && !"永久有效".equals(couponUser.getLoseTime())) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date loseTime = sdf.parse(couponUser.getLoseTime()); + if (new Date().after(loseTime)) { + return AppletControllerUtil.appletWarning("优惠券已过期"); + } + } catch (Exception e) { + logger.warn("解析优惠券过期时间失败: " + e.getMessage()); + } + } + + // 验证最低消费(基于原始金额) + if (couponUser.getMinPrice() != null && originalAmount.compareTo(BigDecimal.valueOf(couponUser.getMinPrice())) < 0) { + return AppletControllerUtil.appletWarning("订单金额未达到优惠券使用条件"); + } + + couponMoney = BigDecimal.valueOf(couponUser.getCouponPrice()); + } else { + return AppletControllerUtil.appletWarning("优惠券无效或已被使用"); + } + } + + // 8. 计算美团优惠金额(每次重新计算,2至15的随机整数用于测试) + BigDecimal mtMoney = BigDecimal.ZERO; + if (mtcode != null && !mtcode.trim().isEmpty()) { + // 生成2至15的随机整数 + Random random = new Random(); + int randomDiscount = random.nextInt(14) + 2; // 2到15的随机数 + mtMoney = new BigDecimal(randomDiscount); + } + + // 9. 计算实际应付金额(基于allmoney减去所有优惠) + BigDecimal actualAmount = originalAmount + .subtract(memberMoney) // 减去会员优惠 + .subtract(serviceMoney) // 减去服务金抵扣 + .subtract(shopMoney) // 减去购物金抵扣 + .subtract(couponMoney) // 减去优惠券金额 + .subtract(mtMoney); // 减去美团优惠 + + if (actualAmount.compareTo(BigDecimal.ZERO) < 0) { + actualAmount = BigDecimal.ZERO; + } + + // 10. 根据支付方式计算各支付渠道金额 + BigDecimal wxMoney = BigDecimal.ZERO; + BigDecimal yeMoney = BigDecimal.ZERO; + + if (paytype == 1) { + // 微信支付 + wxMoney = actualAmount; + yeMoney = BigDecimal.ZERO; + } else if (paytype == 2) { + // 余额支付 + if (user.getBalance() != null && user.getBalance().compareTo(actualAmount) >= 0) { + wxMoney = BigDecimal.ZERO; + yeMoney = actualAmount; + } else { + // 13. 构建返回数据 + Map result = new HashMap<>(); + result.put("id", payBefor.getId()); + result.put("orderId", payBefor.getOrderid()); + result.put("paycode", payBefor.getPaycode()); + result.put("allmoney", originalAmount); // 原始总金额(固定不变,这是您最初存储的金额) + result.put("finalAmount", actualAmount); // 实际应付金额(基于allmoney计算得出) + result.put("wxmoney", wxMoney); // 微信支付金额 + result.put("yemoney", yeMoney); // 余额支付金额 + result.put("membermoney", memberMoney); // 会员优惠金额(固定不变) + result.put("shopmoney", shopMoney); // 购物金抵扣金额(固定不变) + result.put("servicemoney", serviceMoney); // 服务金抵扣金额(固定不变) + result.put("couponmoney", couponMoney); // 优惠券金额(实时计算) + result.put("mtmoney", mtMoney); // 美团优惠金额(实时计算) + result.put("type", payBefor.getType()); + result.put("servicetype", payBefor.getServicetype()); + result.put("paytype", paytype); + result.put("usersBalance", user.getBalance()); + result.put("couponId", couponId); + result.put("mtcode", mtcode); + return AppletControllerUtil.appletSuccess(result); + } + } else if (paytype == 3) { + // 组合支付:优先使用余额,不足部分用微信支付 + if (user.getBalance() != null && user.getBalance().compareTo(actualAmount) >= 0) { + // 余额足够,全部用余额支付 + wxMoney = BigDecimal.ZERO; + yeMoney = actualAmount; + } else if (user.getBalance() != null && user.getBalance().compareTo(BigDecimal.ZERO) > 0) { + // 余额不足,优先扣除用户所有余额,剩余部分用微信支付 + yeMoney = user.getBalance(); + wxMoney = actualAmount.subtract(yeMoney); + } else { + // 无余额,全部微信支付 + wxMoney = actualAmount; + yeMoney = BigDecimal.ZERO; + } + } else { + return AppletControllerUtil.appletWarning("无效的支付方式"); + } + + // 11. 更新预支付记录(注意:allmoney保持不变,只更新其他字段) + payBefor.setPaytype(Long.valueOf(paytype)); + payBefor.setCouponid(couponId); + payBefor.setCouponmoney(couponMoney); + payBefor.setMtcode(mtcode); + payBefor.setMtmoney(mtMoney); + payBefor.setWxmoney(wxMoney); + payBefor.setYemoney(yeMoney); + // 注意:allmoney保持不变,这是原始总金额 + + int updateResult = usersPayBeforService.updateUsersPayBefor(payBefor); + if (updateResult <= 0) { + return AppletControllerUtil.appletWarning("更新预支付记录失败"); + } + + // 12. 构建支付公式 + StringBuilder paymentFormula = new StringBuilder(); + paymentFormula.append("总金额(").append(originalAmount).append(")"); + + // 添加各种优惠项 + if (memberMoney.compareTo(BigDecimal.ZERO) > 0) { + paymentFormula.append("-会员优惠(").append(memberMoney).append(")"); + } + if (serviceMoney.compareTo(BigDecimal.ZERO) > 0) { + paymentFormula.append("-服务金抵扣(").append(serviceMoney).append(")"); + } + if (shopMoney.compareTo(BigDecimal.ZERO) > 0) { + paymentFormula.append("-购物金抵扣(").append(shopMoney).append(")"); + } + if (couponMoney.compareTo(BigDecimal.ZERO) > 0) { + paymentFormula.append("-优惠券(").append(couponMoney).append(")"); + } + if (mtMoney.compareTo(BigDecimal.ZERO) > 0) { + paymentFormula.append("-美团优惠(").append(mtMoney).append(")"); + } + + paymentFormula.append("=").append(actualAmount).append("="); + + // 添加支付方式 + if (wxMoney.compareTo(BigDecimal.ZERO) > 0 && yeMoney.compareTo(BigDecimal.ZERO) > 0) { + // 组合支付 + paymentFormula.append("微信支付(").append(wxMoney).append(")+余额支付(").append(yeMoney).append(")"); + } else if (wxMoney.compareTo(BigDecimal.ZERO) > 0) { + // 纯微信支付 + paymentFormula.append("微信支付(").append(wxMoney).append(")"); + } else if (yeMoney.compareTo(BigDecimal.ZERO) > 0) { + // 纯余额支付 + paymentFormula.append("余额支付(").append(yeMoney).append(")"); + } + + // 13. 构建返回数据 + Map result = new HashMap<>(); + result.put("id", payBefor.getId()); + result.put("orderId", payBefor.getOrderid()); + result.put("paycode", payBefor.getPaycode()); + result.put("allmoney", originalAmount); // 原始总金额(固定不变,这是您最初存储的金额) + result.put("finalAmount", actualAmount); // 实际应付金额(基于allmoney计算得出) + result.put("wxmoney", wxMoney); // 微信支付金额 + result.put("yemoney", yeMoney); // 余额支付金额 + result.put("membermoney", memberMoney); // 会员优惠金额(固定不变) + result.put("shopmoney", shopMoney); // 购物金抵扣金额(固定不变) + result.put("servicemoney", serviceMoney); // 服务金抵扣金额(固定不变) + result.put("couponmoney", couponMoney); // 优惠券金额(实时计算) + result.put("mtmoney", mtMoney); // 美团优惠金额(实时计算) + result.put("type", payBefor.getType()); + result.put("paytype", paytype); + result.put("usersBalance", user.getBalance()); + result.put("couponId", couponId); + result.put("mtcode", mtcode); + result.put("servicetype", payBefor.getServicetype()); + result.put("paymentFormula", paymentFormula.toString()); // 支付公式 + +// // 添加计算明细,方便前端理解金额构成 +// Map calculationDetail = new HashMap<>(); +// calculationDetail.put("originalAmount", originalAmount); +// calculationDetail.put("memberDiscount", memberMoney); +// calculationDetail.put("serviceDiscount", serviceMoney); +// calculationDetail.put("shopDiscount", shopMoney); +// calculationDetail.put("couponDiscount", couponMoney); +// calculationDetail.put("mtDiscount", mtMoney); +// calculationDetail.put("finalAmount", actualAmount); +// result.put("calculationDetail", calculationDetail); + + return AppletControllerUtil.appletSuccess(result); + + } catch (Exception e) { + logger.error("查询预支付记录失败:", e); + return AppletControllerUtil.appletError("查询预支付记录失败:" + e.getMessage()); + } + } // /** // * 获取次卡列表(支持分页) // * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java index 5f14bdf..a101d87 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java @@ -5,7 +5,9 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.ControllerUtil.BalancePayUtil; import com.ruoyi.system.ControllerUtil.GenerateCustomCode; +import com.ruoyi.system.ControllerUtil.OrderUtil; import com.ruoyi.system.ControllerUtil.WXsendMsgUtil; import com.ruoyi.system.ControllerUtil.WechatPayUtil; import com.ruoyi.system.domain.*; @@ -91,6 +93,13 @@ public class PayNotifyController extends BaseController { @Autowired private IUserGroupBuyingService userGroupBuyingService; + @Autowired + private IUsersPayBeforService usersPayBeforService; + + @Autowired + private IUserUseSecondaryCardService userUseSecondaryCardService; + + /** * 商品支付回调接口 * @@ -258,6 +267,177 @@ public class PayNotifyController extends BaseController { + /** + * 拼团支付的回调接口 + * + * @param request HTTP请求对象 + * @return XML格式响应给微信服务器 + *IUserGroupBuyingService userGroupBuyingService; + * 处理商品订单的支付成功回调: + * 1. 验证支付签名 + * 2. 更新商品订单支付状态 + * 3. 更新订单支付时间和交易号 + * 4. 处理库存扣减等业务逻辑 + */ + @PostMapping(value = "/api/order/amount/paydata/notify") + public String apiorderamountpaydatanotify(HttpServletRequest request) { + try { + logger.info("收到商品支付回调通知,开始处理..."); + + // 1. 使用WechatPayUtil处理支付回调 + Map notifyResult = wechatPayUtil.handlePayNotify(request); + + // 2. 检查处理结果 + boolean success = (Boolean) notifyResult.get("success"); + String message = (String) notifyResult.get("message"); + + if (!success) { + logger.error("商品支付回调处理失败:{}", message); + return buildFailResponse("商品支付回调处理失败"); + } + + // 3. 获取支付信息 + Map paymentInfo = (Map) notifyResult.get("paymentInfo"); + String outTradeNo = (String) paymentInfo.get("outTradeNo"); + String transactionId = (String) paymentInfo.get("transactionId"); + String totalFee = (String) paymentInfo.get("totalFee"); + UsersPayBefor usersPayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(outTradeNo); + + if (usersPayBefor!=null){ + usersPayBefor.setStatus(2L); + usersPayBefor.setPaytime(new Date()); + usersPayBefor.setPaycode(transactionId); + usersPayBeforService.updateUsersPayBefor(usersPayBefor); + } + Users users = null; + if (usersPayBefor != null) { + users = usersService.selectUsersById(usersPayBefor.getUid()); + } + //订单回调处理,拼团创建订单,其他订单修改状态 + OrderUtil.prepayCallback(usersPayBefor, users); + +// //最后无论如何平台流水需要添加,让平台看到流水和账目 + PayMoneyLog payMoneyLog = new PayMoneyLog(); + if (usersPayBefor != null) { + payMoneyLog.setOid(usersPayBefor.getId()); + } + payMoneyLog.setOrderId(usersPayBefor.getOrderid()); + payMoneyLog.setUid(usersPayBefor.getUid()); + if (users != null) { + payMoneyLog.setUname(users.getName()); + } + payMoneyLog.setPrice(usersPayBefor.getWxmoney()); + payMoneyLog.setMark("订单支付"); + payMoneyLog.setPayTime(new Date()); + payMoneyLogService.insertPayMoneyLog(payMoneyLog); + //sendWechatMessage(users,outTradeNo); + logger.info("商品支付回调处理成功,订单号:{}", outTradeNo); + return buildSuccessResponse(); + + } catch (Exception e) { + logger.error("商品支付回调处理异常:", e); + return buildFailResponse("商品支付回调处理异常"); + } + } + + + + + /** + * 拼团支付的回调接口 + * + * @param request HTTP请求对象 + * @return XML格式响应给微信服务器 + *IUserGroupBuyingService userGroupBuyingService; + * 处理商品订单的支付成功回调: + * 1. 验证支付签名 + * 2. 更新商品订单支付状态 + * 3. 更新订单支付时间和交易号 + * 4. 处理库存扣减等业务逻辑 + */ + @PostMapping(value = "/api/order/amount/paydata/zuhenotify") + public String apiorderamountpaydatazuhenotify(HttpServletRequest request) { + try { + logger.info("收到商品支付回调通知,开始处理..."); + + // 1. 使用WechatPayUtil处理支付回调 + Map notifyResult = wechatPayUtil.handlePayNotify(request); + + // 2. 检查处理结果 + boolean success = (Boolean) notifyResult.get("success"); + String message = (String) notifyResult.get("message"); + + if (!success) { + logger.error("商品支付回调处理失败:{}", message); + return buildFailResponse("商品支付回调处理失败"); + } + + // 3. 获取支付信息 + Map paymentInfo = (Map) notifyResult.get("paymentInfo"); + String outTradeNo = (String) paymentInfo.get("outTradeNo"); + String transactionId = (String) paymentInfo.get("transactionId"); + String totalFee = (String) paymentInfo.get("totalFee"); + UsersPayBefor usersPayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(outTradeNo); + + // 组合支付:微信支付回调后自动扣余额 + if (usersPayBefor != null && usersPayBefor.getYemoney() != null && usersPayBefor.getYemoney().compareTo(BigDecimal.ZERO) > 0) { + Users user = usersService.selectUsersById(usersPayBefor.getUid()); + Map balanceResult = BalancePayUtil.processBalancePayment( + user.getId(), + usersPayBefor.getYemoney(), + "订单组合支付-余额部分" + usersPayBefor.getYemoney() + "元", + usersPayBefor.getOrderid() + ); + if (balanceResult == null || !Boolean.TRUE.equals(balanceResult.get("success"))) { + OrderUtil.prepayCallback(usersPayBefor, user); + String errorMsg = balanceResult != null ? (String) balanceResult.get("message") : "余额支付失败"; + logger.error("组合支付余额部分扣款失败:{}", errorMsg); + return buildFailResponse("组合支付余额部分扣款失败: " + errorMsg); + } + } + + if (usersPayBefor!=null){ + usersPayBefor.setStatus(2L); + usersPayBefor.setPaytime(new Date()); + usersPayBefor.setPaycode(transactionId); + usersPayBeforService.updateUsersPayBefor(usersPayBefor); + + } + Users users = null; + if (usersPayBefor != null) { + users = usersService.selectUsersById(usersPayBefor.getUid()); + } + //订单回调处理,拼团创建订单,其他订单修改状态 + OrderUtil.prepayCallback(usersPayBefor, users); + +// //最后无论如何平台流水需要添加,让平台看到流水和账目 + PayMoneyLog payMoneyLog = new PayMoneyLog(); + if (usersPayBefor != null) { + payMoneyLog.setOid(usersPayBefor.getId()); + } + payMoneyLog.setOrderId(usersPayBefor.getOrderid()); + payMoneyLog.setUid(usersPayBefor.getUid()); + if (users != null) { + payMoneyLog.setUname(users.getName()); + } + payMoneyLog.setPrice(usersPayBefor.getWxmoney()); + payMoneyLog.setMark("订单支付"); + payMoneyLog.setPayTime(new Date()); + payMoneyLogService.insertPayMoneyLog(payMoneyLog); + //sendWechatMessage(users,outTradeNo); + logger.info("商品支付回调处理成功,订单号:{}", outTradeNo); + return buildSuccessResponse(); + + } catch (Exception e) { + logger.error("商品支付回调处理异常:", e); + return buildFailResponse("商品支付回调处理异常"); + } + } + + + + + /** @@ -1347,4 +1527,57 @@ public class PayNotifyController extends BaseController { return "商品"; } } + + /** + * 次卡微信支付回调接口 + * @param request HTTP请求对象 + * @return XML格式响应给微信服务器 + * 逻辑: + * 1. 验证支付签名 + * 2. 查询次卡使用记录(orderId) + * 3. 修改为可用状态 + */ + @PostMapping("/api/secondary/card/paydata/notify") + public String secondaryCardPayDataNotify(HttpServletRequest request) { + try { + logger.info("收到次卡微信支付回调通知,开始处理..."); + + // 1. 使用WechatPayUtil处理支付回调 + Map notifyResult = wechatPayUtil.handlePayNotify(request); + + // 2. 检查处理结果 + boolean success = (Boolean) notifyResult.get("success"); + String message = (String) notifyResult.get("message"); + + if (!success) { + logger.error("次卡支付回调处理失败:{}", message); + return buildFailResponse("次卡支付回调处理失败"); + } + + // 3. 获取支付信息 + Map paymentInfo = (Map) notifyResult.get("paymentInfo"); + String outTradeNo = (String) paymentInfo.get("outTradeNo"); // 订单号 + String transactionId = (String) paymentInfo.get("transactionId"); + String totalFee = (String) paymentInfo.get("totalFee"); + + // 4. 查询次卡使用记录 + UserUseSecondaryCard useCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(outTradeNo); + if (useCard == null) { + logger.error("未找到次卡使用记录,订单号:{}", outTradeNo); + return buildFailResponse("未找到次卡使用记录"); + } + + // 5. 修改为可用状态(假设status=1为可用) + useCard.setStatus(1L); + useCard.setUpdatedAt(new Date()); + useCard.setTransactionId(transactionId); + userUseSecondaryCardService.updateUserUseSecondaryCard(useCard); + + logger.info("次卡支付回调处理成功,订单号:{}", outTradeNo); + return buildSuccessResponse(); + } catch (Exception e) { + logger.error("次卡支付回调处理异常:", e); + return buildFailResponse("次卡支付回调处理异常"); + } + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/ShopAddressController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ShopAddressController.java new file mode 100644 index 0000000..c07756e --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/ShopAddressController.java @@ -0,0 +1,104 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.ShopAddress; +import com.ruoyi.system.service.IShopAddressService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 店铺地址Controller + * + * @author ruoyi + * @date 2025-07-17 + */ +@RestController +@RequestMapping("/system/address") +public class ShopAddressController extends BaseController +{ + @Autowired + private IShopAddressService shopAddressService; + + /** + * 查询店铺地址列表 + */ + @PreAuthorize("@ss.hasPermi('system:address:list')") + @GetMapping("/list") + public TableDataInfo list(ShopAddress shopAddress) + { + startPage(); + List list = shopAddressService.selectShopAddressList(shopAddress); + return getDataTable(list); + } + + /** + * 导出店铺地址列表 + */ + @PreAuthorize("@ss.hasPermi('system:address:export')") + @Log(title = "店铺地址", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, ShopAddress shopAddress) + { + List list = shopAddressService.selectShopAddressList(shopAddress); + ExcelUtil util = new ExcelUtil(ShopAddress.class); + util.exportExcel(response, list, "店铺地址数据"); + } + + /** + * 获取店铺地址详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:address:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(shopAddressService.selectShopAddressById(id)); + } + + /** + * 新增店铺地址 + */ + @PreAuthorize("@ss.hasPermi('system:address:add')") + @Log(title = "店铺地址", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody ShopAddress shopAddress) + { + return toAjax(shopAddressService.insertShopAddress(shopAddress)); + } + + /** + * 修改店铺地址 + */ + @PreAuthorize("@ss.hasPermi('system:address:edit')") + @Log(title = "店铺地址", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody ShopAddress shopAddress) + { + return toAjax(shopAddressService.updateShopAddress(shopAddress)); + } + + /** + * 删除店铺地址 + */ + @PreAuthorize("@ss.hasPermi('system:address:remove')") + @Log(title = "店铺地址", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(shopAddressService.deleteShopAddressByIds(ids)); + } +} 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 1d652f9..29430a8 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 @@ -7,7 +7,6 @@ import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.*; -import com.ruoyi.system.domain.AppleDoMain.OrderApple; import com.ruoyi.system.service.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -1685,6 +1684,8 @@ public class AppletControllerUtil { List> resultList = new ArrayList<>(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (CouponUser couponUser : couponUserList) { Map couponData = new HashMap<>(); ServiceGoods serviceGoods = null; @@ -2779,7 +2780,7 @@ public class AppletControllerUtil { } /** - * 更新购物车商品数量 + * 更新购物车商品数量(向后兼容版本) * * @param cartItem 购物车商品记录 * @param serviceGoods 商品信息 @@ -2790,6 +2791,27 @@ public class AppletControllerUtil { GoodsCart cartItem, ServiceGoods serviceGoods, IGoodsCartService goodsCartService) { + return updateCartItemQuantity(cartItem, serviceGoods, goodsCartService, null, null, null); + } + + /** + * 更新购物车商品数量 + * + * @param cartItem 购物车商品记录 + * @param serviceGoods 商品信息 + * @param goodsCartService 购物车服务 + * @param ordertype 订单类别 + * @param fileData 附件 + * @param remark 备注 + * @return 更新结果 + */ + public static AjaxResult updateCartItemQuantity( + GoodsCart cartItem, + ServiceGoods serviceGoods, + IGoodsCartService goodsCartService, + Long ordertype, + String fileData, + String remark) { try { // 数量加1 Long newQuantity = (cartItem.getGoodNum() != null ? cartItem.getGoodNum() : 0L) + 1L; @@ -2803,6 +2825,9 @@ public class AppletControllerUtil { GoodsCart updateCart = new GoodsCart(); updateCart.setId(cartItem.getId()); updateCart.setGoodNum(newQuantity); + updateCart.setOrdertype(ordertype); + updateCart.setFileData(fileData); + updateCart.setReamk(remark); updateCart.setUpdatedAt(new Date()); int updateResult = goodsCartService.updateGoodsCart(updateCart); @@ -2819,7 +2844,7 @@ public class AppletControllerUtil { } /** - * 新增购物车商品记录 + * 新增购物车商品记录(向后兼容版本) * * @param user 用户信息 * @param serviceGoods 商品信息 @@ -2832,6 +2857,29 @@ public class AppletControllerUtil { ServiceGoods serviceGoods, String sku, IGoodsCartService goodsCartService) { + return addNewCartItem(user, serviceGoods, sku, goodsCartService, null, null, null); + } + + /** + * 新增购物车商品记录 + * + * @param user 用户信息 + * @param serviceGoods 商品信息 + * @param sku 商品规格 + * @param goodsCartService 购物车服务 + * @param ordertype 订单类别 + * @param fileData 附件 + * @param remark 备注 + * @return 添加结果 + */ + public static AjaxResult addNewCartItem( + Users user, + ServiceGoods serviceGoods, + String sku, + IGoodsCartService goodsCartService, + Long ordertype, + String fileData, + String remark) { try { // 构建购物车记录 GoodsCart newCartItem = new GoodsCart(); @@ -2839,6 +2887,9 @@ public class AppletControllerUtil { newCartItem.setGoodId(serviceGoods.getId()); newCartItem.setSku(sku); newCartItem.setGoodNum(1L); // 默认数量为1 + newCartItem.setOrdertype(ordertype); + newCartItem.setFileData(fileData); + newCartItem.setReamk(remark); newCartItem.setCreatedAt(new Date()); newCartItem.setUpdatedAt(new Date()); @@ -3143,7 +3194,7 @@ public class AppletControllerUtil { data.put("icon", buildImageUrl(goods.getIcon())); data.put("sub_title", goods.getSubTitle()); data.put("info", goods.getInfo()); - data.put("price", goods.getPrice() != null ? goods.getPrice().toString() : "0.00"); + data.put("price_zn", goods.getPriceZn()); data.put("sales", goods.getSales() != null ? goods.getSales().intValue() : 0); data.put("stock", goods.getStock() != null ? goods.getStock().intValue() : 0); @@ -3160,6 +3211,12 @@ public class AppletControllerUtil { // 处理SKU数据 // data.put("sku", parseSkuStringToObject(goods.getSku())); data.put("latitude", goods.getLatitude()); + + data.put("groupprice", goods.getGroupprice() != null ? goods.getGroupprice().toString() : "0.00"); + data.put("fixedprice", goods.getFixedprice() != null ? goods.getFixedprice().toString() : "0.00"); + data.put("price", goods.getPrice() != null ? goods.getPrice().toString() : "0.00"); + + data.put("longitude", goods.getLongitude()); data.put("type", goods.getType() != null ? goods.getType() : 2); data.put("cate_id", goods.getCateId()); @@ -3170,6 +3227,7 @@ public class AppletControllerUtil { data.put("basic", parseBasicStringToArray(goods.getBasic())); data.put("margin", goods.getMargin() != null ? goods.getMargin().toString() : null); data.put("skill_ids", goods.getSkillIds()); + data.put("servicetype", goods.getServicetype()); // 处理图片数组 data.put("imgs", parseImagesStringToArray(goods.getImgs())); // 时间字段 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/BalancePayUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/BalancePayUtil.java index 4f8cdd5..39dae5c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/BalancePayUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/BalancePayUtil.java @@ -93,7 +93,7 @@ public class BalancePayUtil { * - afterBalance: 支付后余额 * - consumptionLogId: 消费记录ID */ - public static Map processBalancePayment(Long userId, BigDecimal money, String remark) { + public static Map processBalancePayment(Long userId, BigDecimal money, String remark,String orderid) { Map result = new HashMap<>(); try { @@ -163,6 +163,7 @@ public class BalancePayUtil { consumptionLog.setConsumptiontype(1); // 1=余额支付消费 consumptionLog.setConsumptiontime(new Date()); consumptionLog.setConsumptionmoney(money); + consumptionLog.setOrderid(orderid); consumptionLog.setReamk(remark); consumptionLog.setBeformoney(currentBalance); consumptionLog.setAftermoney(afterBalance); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java index eb17b98..7f791d1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/OrderUtil.java @@ -4,19 +4,17 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.utils.AmapUtils; import com.ruoyi.common.utils.spring.SpringUtils; -import com.ruoyi.system.domain.Order; -import com.ruoyi.system.domain.OrderLog; -import com.ruoyi.system.domain.UserAddress; -import com.ruoyi.system.domain.Users; -import com.ruoyi.system.service.IOrderLogService; -import com.ruoyi.system.service.IUserAddressService; -import com.ruoyi.system.service.IUsersService; +import com.ruoyi.system.domain.*; +import com.ruoyi.system.service.*; import org.springframework.stereotype.Controller; +import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; + /** * 服务订单Controller工具类 * 专注于订单编号生成、状态验证和用户地址处理等核心功能 @@ -25,6 +23,8 @@ import java.util.*; public class OrderUtil { private static IUsersService usersService = SpringUtils.getBean(IUsersService.class); private static IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); + private static IGoodsOrderService goodsOrderService = SpringUtils.getBean(IGoodsOrderService.class); + private static OrderLogHandler orderLogHandler = SpringUtils.getBean(OrderLogHandler.class); // 订单编号生成相关常量 @@ -338,4 +338,450 @@ public class OrderUtil { } } } + + /** + * 拼团订单创建(参考AppleOrderController标准流程) + * @param id 预支付记录ID + * @return 新创建的订单对象,若未找到预支付记录则返回null + */ + public Order createGroupOrderByPayBeforId(Long id) { + IUsersPayBeforService usersPayBeforService = SpringUtils.getBean(IUsersPayBeforService.class); + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); + IUserAddressService userAddressService = SpringUtils.getBean(IUserAddressService.class); + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); + + // 1. 查询预支付记录 + UsersPayBefor payBefor = usersPayBeforService.selectUsersPayBeforById(id); + if (payBefor == null) { + return null; // 未找到预支付记录 + } + + // 2. 查询商品信息 + Long productId = null; + try { + productId = Long.valueOf(payBefor.getSku()); // 假设sku字段存储商品ID + } catch (Exception e) { + // 若sku不是商品ID,则尝试orderid等其它方式 + } + if (productId == null) { + // 若无法获取商品ID,直接返回 + return null; + } + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + if (serviceGoods == null) { + return null; + } + + // 3. 查询地址信息 + UserAddress userAddress = null; + if (payBefor.getAddressid() != null) { + userAddress = userAddressService.selectUserAddressById(payBefor.getAddressid()); + } + // GenerateCustomCode. + // 4. 生成订单号 + //com.ruoyi.system.ControllerUtil.GenerateCustomCode GenerateCustomCode = null; + String orderId = payBefor.getOrderid() != null ? payBefor.getOrderid() : GenerateCustomCode.generCreateOrder("PT"); + + // 5. 创建订单 + Order order = new Order(); + order.setOdertype(4); // 拼团 + order.setStatus(9L); // 状态9 + order.setOrderId(orderId); + order.setUid(payBefor.getUid()); + order.setNum(1L); // 默认1,可根据业务调整 + order.setProductId(serviceGoods.getId()); + order.setProductName(serviceGoods.getTitle()); + order.setSku(payBefor.getSku()); + order.setTotalPrice(payBefor.getAllmoney()); + order.setPayPrice(payBefor.getWxmoney()); + order.setCreateTime(new Date()); + order.setType(1); // 服务订单 + order.setCreateType(1); // 用户自主下单 + order.setUname(""); // 可补充用户名称 + if (userAddress != null) { + order.setAddressId(userAddress.getId()); + order.setName(userAddress.getName()); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + } + // 可补充其它字段,如拼团价、优惠券、备注等 + + // 6. 保存订单 + orderService.insertOrder(order); + + // 7. 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("拼团订单创建"); + orderLog.setType(new BigDecimal("1.0")); + orderLog.setContent("拼团订单创建成功"); + orderLog.setRemark("拼团订单自动创建"); + orderLogService.insertOrderLog(orderLog); + + return order; + } + + /** + * 订单价格确认工具方法 + * 根据服务ID、SKU、是否一口价和订单类型计算最终价格 + * + * @param serviceId 服务ID + * @param sku SKU信息,格式:{"精细擦玻璃":"20㎡全屋精细擦窗","pic":"","price":"236","groupprice":"100","seckillprice":"99","stock":"1000"} + * @param type 订单类别 1=拼团 2=次卡 3=秒杀 + * @return 计算后的价格,如果计算失败返回null + * + * 使用示例: + * // 一口价订单(单规格) + * BigDecimal price1 = OrderUtil.confirmOrderPrice(1L, null, 1, 1); + * + * // 一口价订单(多规格) + * String sku = "{\"精细擦玻璃\":\"20㎡全屋精细擦窗\",\"pic\":\"\",\"price\":\"236\",\"groupprice\":\"100\",\"seckillprice\":\"99\",\"stock\":\"1000\"}"; + * BigDecimal price2 = OrderUtil.confirmOrderPrice(1L, sku, 1, 1); + * + * // 拼团订单(单规格) + * BigDecimal price3 = OrderUtil.confirmOrderPrice(1L, null, 2, 1); + * + * // 秒杀订单(多规格) + * BigDecimal price4 = OrderUtil.confirmOrderPrice(1L, sku, 2, 3); + */ + public static BigDecimal confirmOrderPrice(Long serviceId, String sku, Integer type) { + try { +// // 参数验证 +// if (serviceId == null || isyikoujia == null || type == null) { +// return null; +// } + + // 获取服务商品信息 + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(serviceId); + + if (serviceGoods == null) { + return null; + } + + // 获取sku_type,默认为单规格 + Integer skuType = serviceGoods.getSkuType(); + if (skuType == null) { + skuType = 1; // 默认为单规格 + } + +// // 如果是一口价 +// if (isyikoujia == 1) { +// // 如果是多规格商品,从SKU中获取price +// if (skuType == 2 && sku != null && !sku.trim().isEmpty()) { +// return handleMultiSkuPrice(sku, null); // 传入null表示获取基础价格 +// } +// // 单规格商品直接返回商品的基础价格 +// return serviceGoods.getPrice(); +// } + + // 如果不是一口价,需要根据sku_type和订单类型判断 + + // 单规格商品 (sku_type = 1) + if (skuType == 1) { + return handleSingleSkuPrice(serviceGoods, type); + } + // 多规格商品 (sku_type = 2) + else if (skuType == 2) { + return handleMultiSkuPrice(sku, type); + } + + return null; + + } catch (Exception e) { + // 记录异常信息(这里可以添加日志记录) + System.err.println("订单价格确认失败: " + e.getMessage()); + return null; + } + } + + /** + * 处理单规格商品价格计算 + * + * @param serviceGoods 服务商品对象 + * @param type 订单类型 1=拼团 2=次卡 3=秒杀 + * @return 计算后的价格 + */ + private static BigDecimal handleSingleSkuPrice(ServiceGoods serviceGoods, Integer type) { + switch (type) { + case 1: // 拼团 + return serviceGoods.getGroupprice(); + case 3: // 秒杀 + return serviceGoods.getFixedprice(); + case 2: // 一口价 + return serviceGoods.getPrice(); + default: + return serviceGoods.getPrice(); // 默认返回基础价格 + } + } + + /** + * 处理多规格商品价格计算 + * + * @param sku SKU信息JSON字符串 + * @param type 订单类型 1=拼团 2=次卡 3=秒杀,null表示获取基础价格 + * @return 计算后的价格 + */ + private static BigDecimal handleMultiSkuPrice(String sku, Integer type) { + try { + if (sku == null || sku.trim().isEmpty()) { + return null; + } + + // 解析SKU JSON + JSONObject skuJson = JSONObject.parseObject(sku); + + // 如果type为null,获取基础价格 + if (type == null) { + String priceStr = skuJson.getString("price"); + return parsePrice(priceStr); + } + + switch (type) { + case 1: // 拼团 + String groupPriceStr = skuJson.getString("groupprice"); + return parsePrice(groupPriceStr); + case 3: // 秒杀 + String seckillPriceStr = skuJson.getString("seckillprice"); + return parsePrice(seckillPriceStr); + case 2: // 一口价 + String priceStr = skuJson.getString("price"); + return parsePrice(priceStr); + default: + String defaultPriceStr = skuJson.getString("price"); + return parsePrice(defaultPriceStr); + } + + } catch (Exception e) { + System.err.println("解析多规格SKU价格失败: " + e.getMessage()); + return null; + } + } + + /** + * 解析价格字符串为BigDecimal + * + * @param priceStr 价格字符串 + * @return BigDecimal价格,解析失败返回null + */ + private static BigDecimal parsePrice(String priceStr) { + try { + if (priceStr == null || priceStr.trim().isEmpty()) { + return null; + } + return new BigDecimal(priceStr.trim()); + } catch (NumberFormatException e) { + System.err.println("价格格式解析失败: " + priceStr); + return null; + } + } + + /** + * 预支付回调处理方法 + * @param payBefor 预支付记录 + * @param user 用户实体 + * @return 新建的订单对象(仅拼团),或处理结果Map + */ + public static Object prepayCallback(UsersPayBefor payBefor, Users user) { + if (payBefor == null || user == null) { + return null; + } + int type = payBefor.getType() != null ? payBefor.getType().intValue() : 0; + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + // 拼团 + if (payBefor.getServicetype()==2){ + GoodsOrder gorder = new GoodsOrder(); + gorder.setMainOrderId(payBefor.getOrderid()); + List orderslist =goodsOrderService.selectGoodsOrderList(gorder); + if (!orderslist.isEmpty()){ + for (GoodsOrder goodsOrder : orderslist){ + goodsOrder.setStatus(2L); + goodsOrder.setTransactionId(payBefor.getPaycode()); + goodsOrderService.updateGoodsOrder(goodsOrder); + } + } + return payBefor.getOrderid(); + } + if (type == 1) { + String ptorderid= payBefor.getOrderid(); + //第一步创建订单状态为待成团 + Order order = new Order(); + order.setOdertype(1); // 拼团 + order.setStatus(9L); // 9=待成团 + order.setOrderId(ptorderid); + order.setUid(payBefor.getUid()); + order.setNum(1L); // 默认1,可根据业务调整 + //order.setProductId(payBefor.getSku() != null ? Long.valueOf(payBefor.getSku()) : null); // 假设sku字段存储商品ID + order.setProductId(payBefor.getServiceid()); // 假设sku字段存储商品ID + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(payBefor.getServiceid()); + // 商品名、图片、类型、价格等 + String productName = ""; + + if (serviceGoods != null) { + productName = serviceGoods.getTitle(); + } + order.setProductName(productName); + order.setSku(payBefor.getSku()); + order.setTotalPrice(payBefor.getAllmoney()); + order.setPayPrice(payBefor.getWxmoney()); + order.setCreateTime(new Date()); + order.setType(1); // 服务订单 + order.setCreateType(1); // 用户自主下单 + order.setUname(user.getName()); + // 预约时间 + if (payBefor.getMaketime() != null && !payBefor.getMaketime().isEmpty()) { + String[] makeTimeArr = payBefor.getMaketime().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) { + // 忽略解析异常 + } + } + } + if (payBefor.getAddressid() != null) { + IUserAddressService userAddressService = SpringUtils.getBean(IUserAddressService.class); + UserAddress userAddress = userAddressService.selectUserAddressById(payBefor.getAddressid()); + if (userAddress != null) { + order.setAddressId(userAddress.getId()); + order.setName(userAddress.getName()); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + } + } + // 可补充其它字段,如拼团价、优惠券、备注等 + orderService.insertOrder(order); + // 添加订单日志 + IOrderLogService orderLogService = SpringUtils.getBean(IOrderLogService.class); + //IOrderService orderService = SpringUtils.getBean(IOrderService.class); + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + orderLog.setType(new BigDecimal("1.0")); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "订单创建成功,待成团"); + orderLog.setContent(jsonObject.toJSONString()); + orderLogService.insertOrderLog(orderLog); + //第二步修改拼团时候的状态 + IUserGroupBuyingService userGroupBuyingService = SpringUtils.getBean(IUserGroupBuyingService.class); + UserGroupBuying userGroupBuying = userGroupBuyingService.selectUserGroupBuyingByptorderid(ptorderid); + if (userGroupBuying != null){ + userGroupBuying.setStatus(1L); + userGroupBuying.setPaystatus(1L); + userGroupBuyingService.updateUserGroupBuying(userGroupBuying); + } + //第三步核验团数据,如果满足条件都修改为待预约 + UserGroupBuying userGroupBuyingData = new UserGroupBuying(); + userGroupBuyingData.setOrderid(payBefor.getGrouporderid()); + userGroupBuyingData.setPaystatus(1L); + List userGroupBuyingList = userGroupBuyingService.selectUserGroupBuyingList(userGroupBuyingData); + if (userGroupBuyingList.size() >= serviceGoods.getGroupnum()) { + for (UserGroupBuying groupBuying1 : userGroupBuyingList){ + groupBuying1.setStatus(1L); + groupBuying1.setPaystatus(1L); + userGroupBuyingService.updateUserGroupBuying(groupBuying1); + Order orderdata = orderService.selectOrderByOrderId(groupBuying1.getPtorderid()); + if (orderdata != null){ + orderdata.setStatus(10L);//已成团待预约 + orderService.updateOrder(orderdata); + } + + } + + } + return order; + } else { // 其他类型 + // 只更新订单状态为待预约(假设为1) + if (payBefor.getOrderid() != null) { + if (type == 2){ + IUserUseSecondaryCardService userUseSecondaryCardService = SpringUtils.getBean(IUserUseSecondaryCardService.class); + UserUseSecondaryCard userUseSecondaryCard = userUseSecondaryCardService.selectUserUseSecondaryCardByorderId(payBefor.getOrderid()); + if (userUseSecondaryCard != null){ + userUseSecondaryCard.setStatus(1L); + userUseSecondaryCardService.updateUserUseSecondaryCard(userUseSecondaryCard); + } + return userUseSecondaryCard; + }else{ + Order order = orderService.selectOrderByOrderId(payBefor.getOrderid()); + if (order != null) { + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单支付"); + orderLog.setType(new BigDecimal("1.1")); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "订单支付成功,待派单"); + orderLog.setContent(jsonObject.toJSONString()); + orderLogService.insertOrderLog(orderLog); + order.setStatus(1L); // 1=待预约 + orderService.updateOrder(order); + return order; + } + + } + } + return null; + } + } + + /** + * 核验拼团订单 + * @param orderId 主订单号 + * @param uid 用户ID + * @return 处理结果 true=拼团成功 false=未成团 + */ + public static boolean verifyGroupOrder(String orderId, Long uid) { + IUserGroupBuyingService userGroupBuyingService = SpringUtils.getBean(IUserGroupBuyingService.class); + IServiceGoodsService serviceGoodsService = SpringUtils.getBean(IServiceGoodsService.class); + IOrderService orderService = SpringUtils.getBean(IOrderService.class); + // 1. 查询拼团记录 + UserGroupBuying query = new UserGroupBuying(); + query.setOrderid(orderId); + query.setUid(uid); + List groupList = userGroupBuyingService.selectUserGroupBuyingList(query); + if (groupList == null || groupList.isEmpty()) { + return false; + } + UserGroupBuying group = groupList.get(0); + // 2. 设置paystatus=1 + group.setPaystatus(1L); + userGroupBuyingService.updateUserGroupBuying(group); + // 3. 查询服务详情 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(group.getProductId()); + if (serviceGoods == null) { + return false; + } + Integer groupNum = serviceGoods.getGroupnum(); + if (groupNum == null || groupNum <= 0) { + return false; + } + // 4. 统计已支付人数 + UserGroupBuying paidQuery = new UserGroupBuying(); + paidQuery.setOrderid(orderId); + paidQuery.setPaystatus(1L); + List paidList = userGroupBuyingService.selectUserGroupBuyingList(paidQuery); + int paidCount = paidList != null ? paidList.size() : 0; + // 5. 如果已支付人数达到拼团人数,更新订单状态 + if (paidCount >= groupNum) { + // 查询所有mainOrderId=orderId的订单 + Order orderQuery = new Order(); + orderQuery.setMainOrderId(orderId); + List orderList = orderService.selectOrderList(orderQuery); + if (orderList != null) { + for (Order o : orderList) { + o.setStatus(1L); // 1=待预约 + orderService.updateOrder(o); + } + } + return true; + } + return false; + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java index 9213dbc..dedb232 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/WechatPayUtil.java @@ -81,7 +81,7 @@ public class WechatPayUtil { private static final String WECHAT_TRANSFER_URL = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; // 企业付款 - public static final String PAY_FH = "https://1571276c.r3.cpolar.top/"; + public static final String PAY_FH = "https://c5ed8e7.r3.cpolar.top/"; /** * 其他配置常量 */ 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 80f1683..027ad77 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 @@ -22,6 +22,9 @@ public class OrderApple extends BaseEntity { private Long status;// 4 private String total_price;// "68.00" private Integer type;// 1 + private Integer odertype;// 1 + private Integer reamk;// 1 + private String fileData; private Long uid;// : 302 @@ -152,4 +155,20 @@ public class OrderApple extends BaseEntity { public void setFileData(String fileData) { this.fileData = fileData; } + + public Integer getOdertype() { + return odertype; + } + + public void setOdertype(Integer odertype) { + this.odertype = odertype; + } + + public Integer getReamk() { + return reamk; + } + + public void setReamk(Integer reamk) { + this.reamk = reamk; + } } 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 c2c371d..8cd7a7f 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 @@ -28,6 +28,15 @@ public class GoodsCart extends BaseEntity @Excel(name = "商品id") private Long goodId; + + /** 商品id */ + @Excel(name = "商品分类") + private Long goodstype; + + + + + /** 商品数量 */ @Excel(name = "商品数量") private Long goodNum; @@ -36,6 +45,18 @@ public class GoodsCart extends BaseEntity @Excel(name = "规格") private String sku; + /** 规格 */ + @Excel(name = "备注") + private String reamk; + + /** 规格 */ + @Excel(name = "附件") + private String fileData; + + /** 规格 */ + @Excel(name = "类别") + private Long ordertype; + /** $column.columnComment */ @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private Date createdAt; @@ -114,6 +135,31 @@ public class GoodsCart extends BaseEntity return updatedAt; } + + public String getReamk() { + return reamk; + } + + public void setReamk(String reamk) { + this.reamk = reamk; + } + + public String getFileData() { + return fileData; + } + + public void setFileData(String fileData) { + this.fileData = fileData; + } + + public Long getOrdertype() { + return ordertype; + } + + public void setOrdertype(Long ordertype) { + this.ordertype = ordertype; + } + @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 47fd1a4..4b1789e 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 @@ -89,7 +89,13 @@ public class GoodsOrder extends BaseEntity @Excel(name = "优惠券id") private Long couponId; + /** 支付金额 */ + @Excel(name = "是否自提 1是 2不是") + private Long isself; + /** 支付金额 */ + @Excel(name = "自提店铺地址id") + private Long shopadresssid; /** 抵扣金额 */ @Excel(name = "抵扣金额") @@ -508,6 +514,23 @@ public class GoodsOrder extends BaseEntity this.couponId = couponId; } + + public Long getIsself() { + return isself; + } + + public void setIsself(Long isself) { + this.isself = isself; + } + + public Long getShopadresssid() { + return shopadresssid; + } + + public void setShopadresssid(Long shopadresssid) { + this.shopadresssid = shopadresssid; + } + @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 ed47249..1181dab 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 @@ -196,10 +196,12 @@ public class Order extends BaseEntity /** 订单附件 */ @Excel(name = "订单附件") private String fileData; - - + /** 录音文件 */ + @Excel(name = "订单类别 1预约 2报价 3一口价 4拼团 5普通订单") + private int odertype; + private String reamk; private OrderLog orderLog; - + private String cartid; private BigDecimal totalPriceMin; private BigDecimal totalPriceMax; private BigDecimal payPriceMin; @@ -848,6 +850,31 @@ public class Order extends BaseEntity this.fileData = fileData; } + + public int getOdertype() { + return odertype; + } + + public void setOdertype(int odertype) { + this.odertype = odertype; + } + + public String getReamk() { + return reamk; + } + + public void setReamk(String reamk) { + this.reamk = reamk; + } + + public String getCartid() { + return cartid; + } + + public void setCartid(String cartid) { + this.cartid = cartid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/ShopAddress.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ShopAddress.java new file mode 100644 index 0000000..fcedf70 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ShopAddress.java @@ -0,0 +1,186 @@ +package com.ruoyi.system.domain; + +import java.util.Date; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 店铺地址对象 shop_address + * + * @author ruoyi + * @date 2025-07-17 + */ +public class ShopAddress extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 店铺名称 */ + @Excel(name = "店铺名称") + private String shopName; + + /** 店铺地址 */ + @Excel(name = "店铺地址") + private String shopAddress; + + /** 联系电话 */ + @Excel(name = "联系电话") + private String contactPhone; + + /** 经度 */ + @Excel(name = "经度") + private String longitude; + + /** 纬度 */ + @Excel(name = "纬度") + private String latitude; + + /** 联系人 */ + @Excel(name = "联系人") + private String contactPerson; + + /** 地址状态 */ + @Excel(name = " 地址状态") + private Long addressStatus; + + /** $column.columnComment */ + private Date createdAt; + + /** $column.columnComment */ + private Date updatedAt; + + /** $column.columnComment */ + private Date deletedAt; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setShopName(String shopName) + { + this.shopName = shopName; + } + + public String getShopName() + { + return shopName; + } + + public void setShopAddress(String shopAddress) + { + this.shopAddress = shopAddress; + } + + public String getShopAddress() + { + return shopAddress; + } + + public void setContactPhone(String contactPhone) + { + this.contactPhone = contactPhone; + } + + public String getContactPhone() + { + return contactPhone; + } + + public void setLongitude(String longitude) + { + this.longitude = longitude; + } + + public String getLongitude() + { + return longitude; + } + + public void setLatitude(String latitude) + { + this.latitude = latitude; + } + + public String getLatitude() + { + return latitude; + } + + public void setContactPerson(String contactPerson) + { + this.contactPerson = contactPerson; + } + + public String getContactPerson() + { + return contactPerson; + } + + public void setAddressStatus(Long addressStatus) + { + this.addressStatus = addressStatus; + } + + public Long getAddressStatus() + { + return addressStatus; + } + + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } + + public Date getCreatedAt() + { + return createdAt; + } + + public void setUpdatedAt(Date updatedAt) + { + this.updatedAt = updatedAt; + } + + public Date getUpdatedAt() + { + return updatedAt; + } + + public void setDeletedAt(Date deletedAt) + { + this.deletedAt = deletedAt; + } + + public Date getDeletedAt() + { + return deletedAt; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("shopName", getShopName()) + .append("shopAddress", getShopAddress()) + .append("contactPhone", getContactPhone()) + .append("longitude", getLongitude()) + .append("latitude", getLatitude()) + .append("contactPerson", getContactPerson()) + .append("addressStatus", getAddressStatus()) + .append("createdAt", getCreatedAt()) + .append("updatedAt", getUpdatedAt()) + .append("deletedAt", getDeletedAt()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java index a3a6b06..42d142c 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java @@ -53,6 +53,11 @@ public class UserGroupBuying extends BaseEntity @Excel(name = "支付订单号") private String transactionId; + /** 支付订单号 */ + @Excel(name = "拼团订单号") + private String ptorderid; + + /** 支付订单号 */ @Excel(name = "头像") private String image; @@ -220,6 +225,14 @@ public class UserGroupBuying extends BaseEntity this.paystatus = paystatus; } + public String getPtorderid() { + return ptorderid; + } + + public void setPtorderid(String ptorderid) { + this.ptorderid = ptorderid; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java index 3b91f68..c174c43 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersPayBefor.java @@ -74,6 +74,10 @@ public class UsersPayBefor extends BaseEntity @Excel(name = "订类别 1=拼团 2=次卡 3=秒杀 4=报价 0=普通预约", readConverterExp = "必=填") private Long type; + + private Long serviceid; + + /** 订单号码 */ @Excel(name = "订单号码") private String orderid; @@ -91,6 +95,16 @@ public class UsersPayBefor extends BaseEntity @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd") private Date paytime; + + private Long servicetype; + + private String sku; + private Long addressid; + private String maketime; + private String attachments; + private String grouporderid; + + /** 支付订单号 */ @Excel(name = "支付订单号") private String paycode; @@ -283,6 +297,64 @@ public class UsersPayBefor extends BaseEntity this.allmoney = allmoney; } + + public String getAttachments() { + return attachments; + } + + public void setAttachments(String attachments) { + this.attachments = attachments; + } + + public String getMaketime() { + return maketime; + } + + public void setMaketime(String maketime) { + this.maketime = maketime; + } + + public Long getAddressid() { + return addressid; + } + + public void setAddressid(Long addressid) { + this.addressid = addressid; + } + + public String getSku() { + return sku; + } + + public void setSku(String sku) { + this.sku = sku; + } + + public String getGrouporderid() { + return grouporderid; + } + + public void setGrouporderid(String grouporderid) { + this.grouporderid = grouporderid; + } + + public Long getServiceid() { + return serviceid; + } + + public void setServiceid(Long serviceid) { + this.serviceid = serviceid; + } + + + public Long getServicetype() { + return servicetype; + } + + public void setServicetype(Long servicetype) { + this.servicetype = servicetype; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopAddressMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopAddressMapper.java new file mode 100644 index 0000000..bbf08e3 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/ShopAddressMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.ShopAddress; + +/** + * 店铺地址Mapper接口 + * + * @author ruoyi + * @date 2025-07-17 + */ +public interface ShopAddressMapper +{ + /** + * 查询店铺地址 + * + * @param id 店铺地址主键 + * @return 店铺地址 + */ + public ShopAddress selectShopAddressById(Long id); + + /** + * 查询店铺地址列表 + * + * @param shopAddress 店铺地址 + * @return 店铺地址集合 + */ + public List selectShopAddressList(ShopAddress shopAddress); + + /** + * 新增店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + public int insertShopAddress(ShopAddress shopAddress); + + /** + * 修改店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + public int updateShopAddress(ShopAddress shopAddress); + + /** + * 删除店铺地址 + * + * @param id 店铺地址主键 + * @return 结果 + */ + public int deleteShopAddressById(Long id); + + /** + * 批量删除店铺地址 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteShopAddressByIds(Long[] ids); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java index 22828d9..653d4c9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java @@ -22,6 +22,10 @@ public interface UserGroupBuyingMapper */ public UserGroupBuying selectUserGroupBuyingById(Long id); + public UserGroupBuying selectUserGroupBuyingByptorderid(String ptorderid); + + + /** * 查询拼团专区管理列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserUseSecondaryCardMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserUseSecondaryCardMapper.java index e7ca608..ad269cc 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserUseSecondaryCardMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserUseSecondaryCardMapper.java @@ -19,6 +19,11 @@ public interface UserUseSecondaryCardMapper */ public UserUseSecondaryCard selectUserUseSecondaryCardById(Long id); + + public UserUseSecondaryCard selectUserUseSecondaryCardByorderId(String orderid); + + + /** * 查询次卡使用列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersPayBeforMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersPayBeforMapper.java index 8e66ff0..4f9f6a6 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersPayBeforMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UsersPayBeforMapper.java @@ -19,6 +19,11 @@ public interface UsersPayBeforMapper */ public UsersPayBefor selectUsersPayBeforById(Long id); + + + public UsersPayBefor selectUsersPayBeforByOrderId(String orderid); + + /** * 查询预支付列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopAddressService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopAddressService.java new file mode 100644 index 0000000..5c48181 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IShopAddressService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.ShopAddress; + +/** + * 店铺地址Service接口 + * + * @author ruoyi + * @date 2025-07-17 + */ +public interface IShopAddressService +{ + /** + * 查询店铺地址 + * + * @param id 店铺地址主键 + * @return 店铺地址 + */ + public ShopAddress selectShopAddressById(Long id); + + /** + * 查询店铺地址列表 + * + * @param shopAddress 店铺地址 + * @return 店铺地址集合 + */ + public List selectShopAddressList(ShopAddress shopAddress); + + /** + * 新增店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + public int insertShopAddress(ShopAddress shopAddress); + + /** + * 修改店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + public int updateShopAddress(ShopAddress shopAddress); + + /** + * 批量删除店铺地址 + * + * @param ids 需要删除的店铺地址主键集合 + * @return 结果 + */ + public int deleteShopAddressByIds(Long[] ids); + + /** + * 删除店铺地址信息 + * + * @param id 店铺地址主键 + * @return 结果 + */ + public int deleteShopAddressById(Long id); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java index 6b461ef..fecec49 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java @@ -21,6 +21,8 @@ public interface IUserGroupBuyingService */ public UserGroupBuying selectUserGroupBuyingById(Long id); + + public UserGroupBuying selectUserGroupBuyingByptorderid(String ptorderid); /** * 查询拼团专区管理列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserUseSecondaryCardService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserUseSecondaryCardService.java index 8c07bfa..1954493 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserUseSecondaryCardService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserUseSecondaryCardService.java @@ -19,6 +19,11 @@ public interface IUserUseSecondaryCardService */ public UserUseSecondaryCard selectUserUseSecondaryCardById(Long id); + + + public UserUseSecondaryCard selectUserUseSecondaryCardByorderId(String orderid); + + /** * 查询次卡使用列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersPayBeforService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersPayBeforService.java index 3181cb1..2a88b81 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersPayBeforService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUsersPayBeforService.java @@ -19,6 +19,10 @@ public interface IUsersPayBeforService */ public UsersPayBefor selectUsersPayBeforById(Long id); + + + public UsersPayBefor selectUsersPayBeforByOrderId(String orderid); + /** * 查询预支付列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopAddressServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopAddressServiceImpl.java new file mode 100644 index 0000000..c907ba7 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/ShopAddressServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.ShopAddressMapper; +import com.ruoyi.system.domain.ShopAddress; +import com.ruoyi.system.service.IShopAddressService; + +/** + * 店铺地址Service业务层处理 + * + * @author ruoyi + * @date 2025-07-17 + */ +@Service +public class ShopAddressServiceImpl implements IShopAddressService +{ + @Autowired + private ShopAddressMapper shopAddressMapper; + + /** + * 查询店铺地址 + * + * @param id 店铺地址主键 + * @return 店铺地址 + */ + @Override + public ShopAddress selectShopAddressById(Long id) + { + return shopAddressMapper.selectShopAddressById(id); + } + + /** + * 查询店铺地址列表 + * + * @param shopAddress 店铺地址 + * @return 店铺地址 + */ + @Override + public List selectShopAddressList(ShopAddress shopAddress) + { + return shopAddressMapper.selectShopAddressList(shopAddress); + } + + /** + * 新增店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + @Override + public int insertShopAddress(ShopAddress shopAddress) + { + return shopAddressMapper.insertShopAddress(shopAddress); + } + + /** + * 修改店铺地址 + * + * @param shopAddress 店铺地址 + * @return 结果 + */ + @Override + public int updateShopAddress(ShopAddress shopAddress) + { + return shopAddressMapper.updateShopAddress(shopAddress); + } + + /** + * 批量删除店铺地址 + * + * @param ids 需要删除的店铺地址主键 + * @return 结果 + */ + @Override + public int deleteShopAddressByIds(Long[] ids) + { + return shopAddressMapper.deleteShopAddressByIds(ids); + } + + /** + * 删除店铺地址信息 + * + * @param id 店铺地址主键 + * @return 结果 + */ + @Override + public int deleteShopAddressById(Long id) + { + return shopAddressMapper.deleteShopAddressById(id); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java index a75b896..1789648 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java @@ -69,6 +69,12 @@ public class UserGroupBuyingServiceImpl implements IUserGroupBuyingService return userGroupBuyingMapper.updateUserGroupBuying(userGroupBuying); } + + + public UserGroupBuying selectUserGroupBuyingByptorderid(String ptorderid) { + + return userGroupBuyingMapper.selectUserGroupBuyingByptorderid(ptorderid); + } /** * 批量删除拼团专区管理 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserUseSecondaryCardServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserUseSecondaryCardServiceImpl.java index f36cca7..7225d30 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserUseSecondaryCardServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserUseSecondaryCardServiceImpl.java @@ -19,6 +19,13 @@ public class UserUseSecondaryCardServiceImpl implements IUserUseSecondaryCardSer @Autowired private UserUseSecondaryCardMapper userUseSecondaryCardMapper; + + + public UserUseSecondaryCard selectUserUseSecondaryCardByorderId(String orderid){ + return userUseSecondaryCardMapper.selectUserUseSecondaryCardByorderId(orderid); + } + + /** * 查询次卡使用 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersPayBeforServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersPayBeforServiceImpl.java index 64a289f..01ca84a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersPayBeforServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UsersPayBeforServiceImpl.java @@ -31,6 +31,11 @@ public class UsersPayBeforServiceImpl implements IUsersPayBeforService return usersPayBeforMapper.selectUsersPayBeforById(id); } + + public UsersPayBefor selectUsersPayBeforByOrderId(String orderid){ + return usersPayBeforMapper.selectUsersPayBeforByOrderId(orderid); + } + /** * 查询预支付列表 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/utils/QiniuUploadUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/utils/QiniuUploadUtil.java index 217b7a8..de8489d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/utils/QiniuUploadUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/utils/QiniuUploadUtil.java @@ -101,7 +101,7 @@ public class QiniuUploadUtil { DefaultPutRet putRet = JSON.parseObject(response.bodyString(), DefaultPutRet.class); // 返回完整的访问URL - return putRet.key; + return "https://" + config.getDomain() + "/" + putRet.key; } catch (QiniuException ex) { Response r = ex.response; diff --git a/ruoyi-system/src/main/resources/mapper/system/GoodsCartMapper.xml b/ruoyi-system/src/main/resources/mapper/system/GoodsCartMapper.xml index 0696144..c4d4448 100644 --- a/ruoyi-system/src/main/resources/mapper/system/GoodsCartMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/GoodsCartMapper.xml @@ -10,12 +10,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - select id, uid, good_id, good_num, sku, created_at, updated_at from goods_cart + select id, uid, good_id, good_num, sku,goodstype,ordertype,reamk,file_data, created_at, updated_at from goods_cart @@ -43,6 +44,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" good_id, good_num, sku, + file_data, + reamk, + ordertype, + goodstype, created_at, updated_at @@ -51,6 +56,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{goodId}, #{goodNum}, #{sku}, + #{fileData}, + #{reamk}, + #{ordertype}, + #{goodstype}, NOW(), NOW() @@ -63,6 +72,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" good_id = #{goodId}, good_num = #{goodNum}, sku = #{sku}, + file_data = #{fileData}, + reamk = #{reamk}, + ordertype = #{ordertype}, + goodstype = #{goodstype}, + + updated_at=NOW() where id = #{id} diff --git a/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml b/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml index 0d87eae..5c58315 100644 --- a/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/GoodsOrderMapper.xml @@ -34,10 +34,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + - select id, type, main_order_id, order_id, transaction_id, 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,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 @@ -344,6 +361,16 @@ file_data, + + odertype, + + + reamk, + + + cartid, + + created_at, updated_at @@ -480,6 +507,16 @@ #{fileData}, + + #{odertype}, + + + #{reamk}, + + + #{cartid}, + + NOW(), NOW() @@ -517,6 +554,10 @@ product_id = #{productId}, + + odertype = #{odertype}, + + name = #{name}, @@ -622,6 +663,12 @@ deleted_at = #{deletedAt}, + + reamk = #{reamk}, + + + cartid = #{cartid}, + updated_at = NOW() where id = #{id} diff --git a/ruoyi-system/src/main/resources/mapper/system/ShopAddressMapper.xml b/ruoyi-system/src/main/resources/mapper/system/ShopAddressMapper.xml new file mode 100644 index 0000000..00bf3d8 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/ShopAddressMapper.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + select id, shop_name, shop_address, contact_phone, longitude, latitude, contact_person, address_status, created_at, updated_at, deleted_at from shop_address + + + + + + + + insert into shop_address + + id, + shop_name, + shop_address, + contact_phone, + longitude, + latitude, + contact_person, + address_status, + created_at, + updated_at, + deleted_at, + + + #{id}, + #{shopName}, + #{shopAddress}, + #{contactPhone}, + #{longitude}, + #{latitude}, + #{contactPerson}, + #{addressStatus}, + #{createdAt}, + #{updatedAt}, + #{deletedAt}, + + + + + update shop_address + + shop_name = #{shopName}, + shop_address = #{shopAddress}, + contact_phone = #{contactPhone}, + longitude = #{longitude}, + latitude = #{latitude}, + contact_person = #{contactPerson}, + address_status = #{addressStatus}, + created_at = #{createdAt}, + updated_at = #{updatedAt}, + deleted_at = #{deletedAt}, + + where id = #{id} + + + + delete from shop_address where id = #{id} + + + + delete from shop_address where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml index 26e63f8..85c31a3 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml @@ -20,10 +20,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + - select id, orderid, uid, money, status, deduction, paystatus,image,uname, paytime, transaction_id, paytype, product_id, created_at, updated_at from user_group_buying + select id, orderid, uid, money, status, ptorderid,deduction, paystatus,image,uname, paytime, transaction_id, paytype, product_id, created_at, updated_at from user_group_buying @@ -41,6 +47,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + insert into user_group_buying @@ -57,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" product_id, image, paystatus, + ptorderid, created_at, updated_at @@ -75,6 +87,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{productId}, #{image}, #{paystatus}, + #{ptorderid}, + NOW(), NOW() @@ -95,6 +109,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" paytype = #{paytype}, product_id = #{productId}, paystatus = #{paystatus}, + ptorderid = #{ptorderid}, + updated_at = NOW(), where id = #{id} diff --git a/ruoyi-system/src/main/resources/mapper/system/UserUseSecondaryCardMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UserUseSecondaryCardMapper.xml index 30bd7ab..345de88 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UserUseSecondaryCardMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UserUseSecondaryCardMapper.xml @@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, uid, carid, goodsids, num, usenum, orderid, introduction,transaction_id, paymoney, status, created_at, updated_at from user_use_secondary_card + select id, uid, carid, goodsids, num, usenum, orderid,transaction_id, paymoney, status, created_at, updated_at from user_use_secondary_card @@ -45,6 +42,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + + + + insert into user_use_secondary_card diff --git a/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml index ecc551d..0be7e06 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UsersPayBeforMapper.xml @@ -18,6 +18,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + @@ -28,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select id, uid, paytype, wxmoney, yemoney, allmoney,membermoney, shopmoney, servicemoney, couponid, couponmoney, mtcode, mtmoney, type, orderid, oid, status, paytime, paycode from users_pay_befor + select id, uid, paytype,grouporderid, wxmoney,serviceid,servicetype,sku,addressid,maketime,attachments, yemoney, allmoney,membermoney, shopmoney, servicemoney, couponid, couponmoney, mtcode, mtmoney, type, orderid, oid, status, paytime, paycode from users_pay_befor @@ -59,6 +71,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + + insert into users_pay_befor @@ -81,6 +99,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" paycode, allmoney, + sku, + addressid, + maketime, + attachments, + grouporderid, + serviceid, + servicetype, + + @@ -103,6 +130,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{paycode}, #{allmoney}, + #{sku}, + #{addressid}, + #{maketime}, + #{attachments}, + #{grouporderid}, + #{serviceid}, + #{servicetype}, + @@ -127,6 +162,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" paytime = #{paytime}, paycode = #{paycode}, allmoney = #{allmoney}, + serviceid = #{serviceid}, + + sku = #{sku}, + addressid = #{addressid}, + maketime = #{maketime}, + attachments = #{attachments}, + grouporderid = #{grouporderid}, + servicetype = #{servicetype}, where id = #{id} diff --git a/ruoyi-ui/src/api/system/address.js b/ruoyi-ui/src/api/system/address.js new file mode 100644 index 0000000..75f1fbb --- /dev/null +++ b/ruoyi-ui/src/api/system/address.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询店铺地址列表 +export function listAddress(query) { + return request({ + url: '/system/address/list', + method: 'get', + params: query + }) +} + +// 查询店铺地址详细 +export function getAddress(id) { + return request({ + url: '/system/address/' + id, + method: 'get' + }) +} + +// 新增店铺地址 +export function addAddress(data) { + return request({ + url: '/system/address', + method: 'post', + data: data + }) +} + +// 修改店铺地址 +export function updateAddress(data) { + return request({ + url: '/system/address', + method: 'put', + data: data + }) +} + +// 删除店铺地址 +export function delAddress(id) { + return request({ + url: '/system/address/' + id, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/components/ShopSku/sku.vue b/ruoyi-ui/src/components/ShopSku/sku.vue new file mode 100644 index 0000000..bd0b906 --- /dev/null +++ b/ruoyi-ui/src/components/ShopSku/sku.vue @@ -0,0 +1,298 @@ + + + + diff --git a/ruoyi-ui/src/components/ShopSku/skufrom.vue b/ruoyi-ui/src/components/ShopSku/skufrom.vue new file mode 100644 index 0000000..e07b746 --- /dev/null +++ b/ruoyi-ui/src/components/ShopSku/skufrom.vue @@ -0,0 +1,1017 @@ + + + + + diff --git a/ruoyi-ui/src/components/Sku/sku.vue b/ruoyi-ui/src/components/Sku/sku.vue index bd0b906..e719cf9 100644 --- a/ruoyi-ui/src/components/Sku/sku.vue +++ b/ruoyi-ui/src/components/Sku/sku.vue @@ -18,7 +18,11 @@ @@ -66,7 +70,9 @@ export default { name: 'pic', type: 'slot', label: '图片', - batch:false + batch:false, + required: true + }, { @@ -77,6 +83,23 @@ export default { required: true }, + { + name: 'groupprice', + type: 'input', + label: '拼团价', + batch:false, + required: true + + }, + { + name: 'seckillprice', + type: 'input', + label: '秒杀价', + batch:false, + required: true + + }, + { name: 'stock', type: 'input', @@ -102,8 +125,9 @@ export default { }; } const attrs = data.attrs || {}; - const attrArr = Object.keys(attrs).map(name => ({ + const attrArr = Object.keys(attrs).map((name,index) => ({ name, + desc:data.desc[index] || '', item: attrs[name] })); // 生成sku字段 @@ -129,6 +153,7 @@ export default { this.attribute = parsed.attribute; this.sku = parsed.sku; this.$refs.skuForm.init() + } }, TodoData(){ @@ -137,9 +162,11 @@ export default { // 取规格名和规格值(数组) this.$refs.skuForm.getArray().forEach(attr => { if(attr.name && Array.isArray(attr.item)){ + attrs[attr.name] = attr.item.map(r => r.name || r); } }); + console.log(this.$refs.skuForm.getArray()) // 2. 组装 sku // 取所有规格名 const specNames = Object.keys(attrs); @@ -160,10 +187,11 @@ export default { }); return result; }); - + console.log(attrs) return { type: 'many', attrs, + desc:this.$refs.skuForm.getArray().map(r=>r.desc), sku: skuList }; }, @@ -186,10 +214,12 @@ export default { this.sourceAttribute.push({ "name": "", "item": [], + // "desc": "", "input":"" }) this.attribute.push({ "name": "", + // "desc": "", "item": [] }) this.$refs.skuForm.init() @@ -211,6 +241,7 @@ export default { let specs = this.sourceAttribute.map(attr => { return { name: attr.name, + // desc: attr.desc, items: attr.item }; }).filter(spec => spec.name && spec.items.length > 0); @@ -255,6 +286,7 @@ export default { // 更新attribute数据 this.attribute = specs.map(spec => ({ name: spec.name, + // desc: spec.desc, item: spec.items })); }, diff --git a/ruoyi-ui/src/components/Sku/skufrom.vue b/ruoyi-ui/src/components/Sku/skufrom.vue index e07b746..02f9242 100644 --- a/ruoyi-ui/src/components/Sku/skufrom.vue +++ b/ruoyi-ui/src/components/Sku/skufrom.vue @@ -47,6 +47,14 @@ @change="onAttributeNameChange(index, $event, item.name)" > + + - + @@ -251,6 +271,10 @@ 批量设置价格 批量设置库存 + + 批量设置拼团价 + + 批量设置秒杀价

@@ -341,6 +365,8 @@ export default { form: { skuData: [], }, + batchSetGroupPrice: '', + batchSetSeckillPrice: '', batch: {}, attributeNameMap: {}, batchSetPrice: '', @@ -397,6 +423,7 @@ export default { this.myAttribute.forEach((v1) => { const obj = { name: v1.name, + desc: v1.desc, item: [], }; v1.item.forEach((v2) => { @@ -418,6 +445,7 @@ export default { this.myAttribute.forEach((attr, idx) => { if (!Object.prototype.hasOwnProperty.call(attr, '_oldName')) { this.$set(this.myAttribute[idx], '_oldName', attr.name); + this.$set(this.myAttribute[idx], '_oldDesc', attr.desc); } }); if (!this.isInit) { @@ -557,6 +585,7 @@ export default { this.myAttribute.push({ name: this.inputname.trim(), + desc:"", item: [], canAddAttribute: true, addAttribute: "", @@ -582,12 +611,14 @@ export default { ? v.canAddAttribute : true, addAttribute: "", + desc: v.desc, item: [], }; v.item.forEach((itemName) => { temp.item.push({ name: itemName, checked: false, + desc: v.desc, }); }); myAttribute.push(temp); @@ -607,6 +638,7 @@ export default { ) { myAttrVal.item.push({ name: attrName, + desc: attr.desc, checked: true, }); } @@ -738,18 +770,24 @@ export default { v.price = this.batchSetPrice; }); this.batchSetPrice = ''; - } else if (type === 'stock' && this.batchSetStock !== '') { + } + if (type === 'stock' && this.batchSetStock !== '') { this.form.skuData.forEach((v) => { v.stock = this.batchSetStock; }); this.batchSetStock = ''; - } else if (this.batch[type] != "") { + } + if (type === 'groupprice' && this.batchSetGroupPrice !== '') { this.form.skuData.forEach((v) => { - v[type] = this.batch[type]; + v.groupprice = this.batchSetGroupPrice; }); - this.batch[type] = ""; - // 批量设置完成后,触发一次当前列的验证 - this.validateFieldByColumns([type], () => {}); + this.batchSetGroupPrice = ''; + } + if (type === 'seckillprice' && this.batchSetSeckillPrice !== '') { + this.form.skuData.forEach((v) => { + v.seckillprice = this.batchSetSeckillPrice; + }); + this.batchSetSeckillPrice = ''; } }, // 自定义输入框验证,通过调用 structure 里的 validate 方法实现,重点是 callback 要带过去 @@ -866,8 +904,10 @@ export default { this.myAttribute[index].name = newName; this.$set(this.myAttribute[index], '_oldName', newName); this.$forceUpdate(); - }, - }, + } + } + + }; diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index 249f7f3..a4fb04d 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -43,7 +43,7 @@ import BeautyWrapper from '@/components/BeautyWrapper' import UserSelect from '@/components/UserSelect' import sku from '@/components/Sku/sku' - +import shopSku from '@/components/ShopSku/sku' // 全局方法挂载 Vue.prototype.getDicts = getDicts Vue.prototype.getConfigKey = getConfigKey @@ -66,6 +66,7 @@ Vue.component('ImagePreview', ImagePreview) Vue.component('BeautyWrapper', BeautyWrapper) Vue.component('UserSelect', UserSelect) Vue.component('Sku', sku) +Vue.component('ShopSku', shopSku) Vue.use(directive) Vue.use(plugins) diff --git a/ruoyi-ui/src/views/system/GoodsShangPin/index.vue b/ruoyi-ui/src/views/system/GoodsShangPin/index.vue index cd3322a..2be5cec 100644 --- a/ruoyi-ui/src/views/system/GoodsShangPin/index.vue +++ b/ruoyi-ui/src/views/system/GoodsShangPin/index.vue @@ -284,7 +284,7 @@ -->
- +
diff --git a/ruoyi-ui/src/views/system/Order/index.vue b/ruoyi-ui/src/views/system/Order/index.vue index 8220ebb..ad6a164 100644 --- a/ruoyi-ui/src/views/system/Order/index.vue +++ b/ruoyi-ui/src/views/system/Order/index.vue @@ -221,11 +221,20 @@ + + + + + + + - +