|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.applet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
|
|
|
import dev.langchain4j.service.AiServices; |
|
|
@ -40,9 +41,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
@ -99,6 +98,7 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
.lambdaQuery() |
|
|
|
.eq(AppletOrder::getUserId, userId) |
|
|
|
.eq(StringUtils.isNotEmpty(status), AppletOrder::getOrderStatus, status) |
|
|
|
.orderByDesc(AppletOrder::getCreateTime) |
|
|
|
.page(page); |
|
|
|
|
|
|
|
for (AppletOrder record : page1.getRecords()) { |
|
|
@ -107,7 +107,10 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
.eq(AppletOrderProduct::getOrderId, record.getId()) |
|
|
|
.list()); |
|
|
|
|
|
|
|
record.setAfterSales(appletOrderAfterSaleService.getById(record.getId())); |
|
|
|
record.setAfterSales(appletOrderAfterSaleService |
|
|
|
.lambdaQuery() |
|
|
|
.eq(AppletOrderAfterSale::getOrderId, record.getId()) |
|
|
|
.one()); |
|
|
|
} |
|
|
|
|
|
|
|
log.info("订单列表查询完成,返回 {} 条记录", page1.getRecords().size()); |
|
|
@ -141,7 +144,10 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
.orderByDesc(AppletOrderAfterSaleProcess::getCreateTime) |
|
|
|
.list()); |
|
|
|
|
|
|
|
order.setAfterSales(appletOrderAfterSaleService.getById(order.getId())); |
|
|
|
order.setAfterSales(appletOrderAfterSaleService |
|
|
|
.lambdaQuery() |
|
|
|
.eq(AppletOrderAfterSale::getOrderId, order.getId()) |
|
|
|
.one()); |
|
|
|
|
|
|
|
log.info("订单详情查询完成,订单号: {}", order.getOrderNo()); |
|
|
|
return order; |
|
|
@ -150,15 +156,21 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
@Override |
|
|
|
public Object create(CreateOrderBo bo) { |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
log.info("开始创建订单,用户ID: {}, 商品数量: {}", userId, bo != null && bo.getList() != null ? bo.getList().size() : 0); |
|
|
|
|
|
|
|
if (bo == null || bo.getList() == null || bo.getList().isEmpty()) { |
|
|
|
if (bo == null || StringUtils.isBlank(bo.getList())) { |
|
|
|
log.error("创建订单失败,订单商品不能为空,用户ID: {}", userId); |
|
|
|
throw new JeecgBootException("订单商品不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
List<CreateOrderItemBo> list = JSON.parseArray(bo.getList(), CreateOrderItemBo.class); |
|
|
|
|
|
|
|
log.info("开始创建订单,用户ID: {}, 商品数量: {}", userId, list.size()); |
|
|
|
|
|
|
|
if (list.isEmpty()) { |
|
|
|
log.error("创建订单失败,订单商品不能为空,用户ID: {}", userId); |
|
|
|
throw new JeecgBootException("订单商品不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
List<CreateOrderItemBo> list = bo.getList(); |
|
|
|
|
|
|
|
// 获取地址信息 |
|
|
|
AppletShippingAddress address = null; |
|
|
|
if (StringUtils.isNotEmpty(bo.getAddressId())) { |
|
|
@ -197,10 +209,9 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
// 获取规格信息(如果有规格ID) |
|
|
|
AppletProductSpec spec = null; |
|
|
|
if (StringUtils.isNotEmpty(item.getSpecId())) { |
|
|
|
// 这里需要注入规格服务,暂时先设置为null |
|
|
|
spec = appletProductSpecService.getById(item.getSpecId()); |
|
|
|
AppletProductSpec spec = appletProductSpecService.getById(item.getSpecId()); |
|
|
|
if (spec == null) { |
|
|
|
throw new JeecgBootException("规格不存在:" + item.getProductId()); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(order.getTitle())){ |
|
|
@ -212,16 +223,16 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
orderProduct.setUserId(userId); |
|
|
|
orderProduct.setProductId(product.getId()); |
|
|
|
orderProduct.setProductName(product.getName()); |
|
|
|
orderProduct.setPrice(product.getCurrentPrice()); |
|
|
|
orderProduct.setImage(product.getImage()); |
|
|
|
orderProduct.setPrice(spec.getPrice() == null ? product.getCurrentPrice() : spec.getPrice()); |
|
|
|
orderProduct.setQuantity(item.getNum()); |
|
|
|
orderProduct.setType(product.getType()); |
|
|
|
orderProduct.setUnit(product.getUnit()); |
|
|
|
orderProduct.setStatus("0"); |
|
|
|
orderProduct.setSubscribeType(product.getSubscribeType()); |
|
|
|
|
|
|
|
if (spec != null) { |
|
|
|
orderProduct.setSpecId(spec.getId()); |
|
|
|
} |
|
|
|
orderProduct.setSpecId(spec.getId()); |
|
|
|
orderProduct.setSpecName(spec.getSpecName()); |
|
|
|
|
|
|
|
orderProductList.add(orderProduct); |
|
|
|
|
|
|
@ -338,7 +349,7 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
if (order.getOrderStatus() == 0) { |
|
|
|
// 更新订单状态为已支付 |
|
|
|
order.setOrderStatus(1); // 1表示已支付待发货 |
|
|
|
order.setPaymentTime(LocalTime.now()); |
|
|
|
order.setPaymentTime(new Date()); |
|
|
|
appletOrderService.updateById(order); |
|
|
|
|
|
|
|
handleSpecialProducts(order.getId(), order); |
|
|
@ -385,9 +396,10 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
detection.setProductId(orderProduct.getProductId()); |
|
|
|
detection.setPrice(orderProduct.getPrice()); |
|
|
|
detection.setSkuId(orderProduct.getSpecId()); |
|
|
|
detection.setSubscribeType(orderProduct.getSpecId()); |
|
|
|
detection.setUserId(orderProduct.getUserId()); |
|
|
|
detection.setType(orderProduct.getSubscribeType()); |
|
|
|
detection.setSubscribeType(orderProduct.getSubscribeType()); |
|
|
|
detection.setOrderProductId(orderProduct.getId()); |
|
|
|
|
|
|
|
//地址 |
|
|
|
detection.setSendAddress(order.getDeliveryAddress()); |
|
|
@ -472,7 +484,10 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
.list(); |
|
|
|
|
|
|
|
evaluate.setUserId(userId); |
|
|
|
evaluate.setProductId(list.stream().map(n -> n.getProductId()).collect(Collectors.joining(","))); |
|
|
|
|
|
|
|
String p = list.stream().map(n -> n.getProductId()).collect(Collectors.joining(",")); |
|
|
|
|
|
|
|
evaluate.setProductId(p); |
|
|
|
|
|
|
|
order.setOrderStatus(4); |
|
|
|
appletOrderService.updateById(order); |
|
|
@ -485,7 +500,7 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
@Override |
|
|
|
public void confirm(String id) { |
|
|
|
log.info("开始确认收货,订单ID: {}", id); |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(id)){ |
|
|
|
log.error("确认收货失败,订单ID不能为空"); |
|
|
|
throw new JeecgBootException("订单ID不能为空"); |
|
|
@ -502,4 +517,62 @@ public class AppletApiOrderServiceImpl implements AppletApiOrderService { |
|
|
|
log.info("确认收货成功,订单状态更新为已完成,订单ID: {}", id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object statistics() { |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
log.info("开始统计订单状态,用户ID: {}", userId); |
|
|
|
|
|
|
|
// 查询当前用户的所有订单,按状态分组统计 |
|
|
|
List<AppletOrder> orders = appletOrderService.lambdaQuery() |
|
|
|
.eq(AppletOrder::getUserId, userId) |
|
|
|
.select(AppletOrder::getOrderStatus) |
|
|
|
.list(); |
|
|
|
|
|
|
|
long count = appletOrderAfterSaleService.lambdaQuery() |
|
|
|
.eq(AppletOrderAfterSale::getUserId, userId).count(); |
|
|
|
|
|
|
|
// 使用Stream API进行分组统计 |
|
|
|
Map<Integer, Long> statusCountMap = orders.stream() |
|
|
|
.collect(java.util.stream.Collectors.groupingBy( |
|
|
|
AppletOrder::getOrderStatus, |
|
|
|
java.util.stream.Collectors.counting() |
|
|
|
)); |
|
|
|
|
|
|
|
// 转换为Map<String, Integer>格式,确保所有状态都有值 |
|
|
|
Map<String, Integer> result = new java.util.HashMap<>(); |
|
|
|
result.put("0", statusCountMap.getOrDefault(0, 0L).intValue()); // 待支付 |
|
|
|
result.put("1", statusCountMap.getOrDefault(1, 0L).intValue()); // 待发货 |
|
|
|
result.put("2", statusCountMap.getOrDefault(2, 0L).intValue()); // 待收货 |
|
|
|
result.put("3", statusCountMap.getOrDefault(3, 0L).intValue()); // 待评价 |
|
|
|
result.put("4", statusCountMap.getOrDefault(4, 0L).intValue()); // 已完成 |
|
|
|
result.put("afterSales", (int) count); // 售后 |
|
|
|
|
|
|
|
log.info("订单状态统计完成,用户ID: {}, 统计结果: {}", userId, result); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteEvaluate(String id) { |
|
|
|
appletOrderEvaluateService.removeBatchByIds(Arrays.asList(id.split(","))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<AppletOrderEvaluate> productEvaluate(String productId) { |
|
|
|
return appletOrderEvaluateService.lambdaQuery() |
|
|
|
.like(AppletOrderEvaluate::getProductId, productId) |
|
|
|
.orderByDesc(AppletOrderEvaluate::getCreateTime) |
|
|
|
.list(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<AppletOrderEvaluate> myEvaluate(String type) { |
|
|
|
String userId = AppletUserUtil.getCurrentAppletUserId(); |
|
|
|
|
|
|
|
return appletOrderEvaluateService.lambdaQuery() |
|
|
|
.eq(AppletOrderEvaluate::getUserId, userId) |
|
|
|
.isNotNull("0".equals(type), AppletOrderEvaluate::getImage) |
|
|
|
.orderByDesc(AppletOrderEvaluate::getCreateTime) |
|
|
|
.list(); |
|
|
|
} |
|
|
|
|
|
|
|
} |