Merge remote-tracking branch 'origin/prod' into prod

This commit is contained in:
张松 2025-03-26 12:54:25 +08:00
commit e386ef9ea7
12 changed files with 47 additions and 119 deletions

View File

@ -56,6 +56,9 @@ public class UserAuthorizationController {
@GetMapping("/openId")
public CzgResult<Map<String, String>> getOpenId(@RequestParam String code, @RequestParam String source, @RequestParam Long shopId) {
String openId = userAuthorizationService.getOpenId(code, source);
if (openId == null){
return CzgResult.failure("获取openId失败");
}
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo == null){
return CzgResult.failure("店铺信息不存在");

View File

@ -44,6 +44,7 @@ public class OrderInfoAddDTO implements Serializable {
* 订单原金额包含打包费+餐位费 不含折扣价格
*/
private BigDecimal originAmount;
private BigDecimal orderAmount;
/**
* 台桌Id

View File

@ -8,6 +8,8 @@ import com.czg.order.vo.DataSummaryPayTypeVo;
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
import com.mybatisflex.core.paginate.Page;
import java.util.List;
/**
* 数据统计Service接口
*
@ -24,4 +26,5 @@ public interface DataSummaryService {
DataSummaryPayTypeVo getSummaryPayTypeData(Long shopId, Integer day);
List<Long> getShopIdList();
}

View File

@ -28,4 +28,6 @@ public interface ShopOrderStatisticMapper extends BaseMapper<ShopOrderStatistic>
BigDecimal getCustomerUnitPrice(DataSummaryTradeParam param);
BigDecimal getTableTurnoverRate(DataSummaryTradeParam param);
List<Long> getShopIdList();
}

View File

@ -203,4 +203,9 @@ public class DataSummaryServiceImpl implements DataSummaryService {
data.setCountPayType(total);
return data;
}
@Override
public List<Long> getShopIdList() {
return shopOrderStatisticMapper.getShopIdList();
}
}

View File

@ -776,6 +776,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
param.setStaffId(0L);
param.setSeatNum(0);
param.setOriginAmount(amount);
param.setOrderAmount(amount);
param.setTableCode("");
param.setOrderType("cash");
param.setPlatformType("H5");
@ -834,7 +835,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setTableCode(param.getTableCode());
orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setOriginAmount(param.getOriginAmount());
orderInfo.setOrderAmount(BigDecimal.ZERO);
if (param.getOrderAmount() != null && param.getOrderAmount().compareTo(BigDecimal.ZERO) >= 0) {
orderInfo.setOrderAmount(param.getOrderAmount());
}else {
orderInfo.setOrderAmount(BigDecimal.ZERO);
}
orderInfo.setPackFee(orderInfo.getPackFee().add(param.getPackFee()));
orderInfo.setRoundAmount(BigDecimal.ZERO);
orderInfo.setPointsNum(0);

View File

@ -279,6 +279,9 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
OrderInfo orderInfo;
if (payParam.getCheckOrderPay().getOrderId() == null) {
if (payParam.getCheckOrderPay().getOrderAmount() == null || payParam.getCheckOrderPay().getOrderAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new CzgException("支付金额不合法");
}
orderInfo = orderInfoService.createPayOrder(payParam.getShopId(), payParam.getCheckOrderPay().getOrderAmount(),
payParam.getCheckOrderPay().getRemark());
} else {

View File

@ -1,33 +1,20 @@
package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import com.czg.account.entity.ShopTable;
import com.czg.account.entity.ShopUserFlow;
import com.czg.account.service.ShopTableService;
import com.czg.account.service.ShopUserFlowService;
import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.ShopOrderStatistic;
import com.czg.order.service.OrderInfoService;
import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.service.DataSummaryService;
import com.czg.order.service.ShopOrderStatisticService;
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 服务层实现
@ -38,11 +25,7 @@ import java.util.stream.Collectors;
@Service
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
@Resource
private OrderInfoService orderInfoService;
@DubboReference
private ShopUserFlowService shopUserFlowService;
@DubboReference
private ShopTableService shopTableService;
private DataSummaryService dataSummaryService;
@Override
@ -53,108 +36,21 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
DateTime startOfDay = DateUtil.beginOfDay(yesterday);
// 获取前一天的结束时间23:59:59
DateTime endOfDay = DateUtil.endOfDay(yesterday);
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper()
.ge(OrderInfo::getPaidTime, startOfDay)
.le(OrderInfo::getPaidTime, endOfDay)
.ne(OrderInfo::getStatus, "unpaid").ne(OrderInfo::getStatus, "cancelled"));
// 统计充值记录
Map<Long, BigDecimal> flowMap = shopUserFlowService.list(new QueryWrapper()
.ge(ShopUserFlow::getCreateTime, startOfDay.toLocalDateTime())
.le(ShopUserFlow::getCreateTime, endOfDay.toLocalDateTime())
.in(ShopUserFlow::getBizCode, CollUtil.newArrayList("cashIn", "wechatIn", "alipayIn", "awardIn"))).stream()
.collect(Collectors.groupingBy(
ShopUserFlow::getShopId,
Collectors.reducing(
BigDecimal.ZERO,
ShopUserFlow::getAmount,
BigDecimal::add
)
));
HashMap<Long, ShopOrderStatistic> countInfo = new HashMap<>();
for (OrderInfo item : orderInfos) {
ShopOrderStatistic statisticTask = countInfo.get(item.getShopId());
if (statisticTask == null) {
countInfo.put(item.getShopId(), statisticTask = new ShopOrderStatistic());
}
BigDecimal bigDecimal = flowMap.get(item.getShopId());
if (bigDecimal != null) {
statisticTask.setRechargeAmount(bigDecimal);
}
if ("refunding".equals(item.getStatus()) || "refund".equals(item.getStatus()) || "part-refund".equals(item.getStatus())) {
statisticTask.setRefundAmount(statisticTask.getRefundAmount().add(item.getRefundAmount()));
statisticTask.setRefundCount(statisticTask.getRefundCount() + 1);
if (item.getRefundAmount().compareTo(item.getPayAmount()) < 0) {
statisticTask.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount().subtract(item.getRefundAmount())));
}
} else {
statisticTask.setSaleCount(statisticTask.getSaleCount() + 1);
statisticTask.setSaleAmount(statisticTask.getSaleAmount().add(item.getPayAmount()));
}
switch (item.getPayType()) {
case "wechat-mini":
statisticTask.setWechatPayAmount(statisticTask.getWechatPayAmount().add(item.getPayAmount()));
statisticTask.setWechatPayCount(statisticTask.getWechatPayCount() + 1);
break;
case "main-scan", "back-scan":
statisticTask.setScanPayAmount(statisticTask.getScanPayAmount().add(item.getPayAmount()));
statisticTask.setScanPayCount(statisticTask.getScanPayCount() + 1);
break;
case "alipay-mini":
statisticTask.setAliPayAmount(statisticTask.getAliPayAmount().add(item.getPayAmount()));
statisticTask.setAliPayCount(statisticTask.getAliPayCount() + 1);
break;
case "vip-pay":
statisticTask.setMemberPayAmount(statisticTask.getMemberPayAmount().add(item.getPayAmount()));
statisticTask.setMemberPayCount(statisticTask.getMemberPayCount() + 1);
break;
case "credit-pay":
statisticTask.setCreditPayAmount(statisticTask.getCreditPayAmount().add(item.getPayAmount()));
statisticTask.setCreditPayCount(statisticTask.getCreditPayCount() + 1);
break;
case "cash-pay":
statisticTask.setCashPayAmount(statisticTask.getCashPayAmount().add(item.getPayAmount()));
statisticTask.setCashPayCount(statisticTask.getCashPayCount() + 1);
}
List<Long> shopIdList = dataSummaryService.getShopIdList();
if (CollUtil.isEmpty(shopIdList)) {
return;
}
countInfo.forEach((shopId, info) -> {
ShopOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, yesterday.toSqlDate()));
if (statistic == null) {
statistic = new ShopOrderStatistic();
statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now());
}
BigDecimal totalAmount = statistic.getSaleAmount().add(statistic.getRefundAmount());
BigDecimal totalCount = BigDecimal.valueOf(statistic.getSaleCount() + statistic.getRefundCount());
// 充值金额
// statistic.setRechargeAmount(BigDecimal.ZERO);
//客单价
if (totalAmount.compareTo(BigDecimal.ZERO) != 0) {
statistic.setCustomerUnitPrice(totalAmount.divide(totalCount, 2, RoundingMode.DOWN));
}
// 查询台桌数量
long count = shopTableService.count(new QueryWrapper().eq(ShopTable::getShopId, shopId));
//翻台率
if (count > 0) {
statistic.setTableTurnoverRate(totalCount.subtract(BigDecimal.valueOf(count)).divide(BigDecimal.valueOf(count), 2, RoundingMode.DOWN).multiply(BigDecimal.valueOf(100)));
}
statistic.setUpdateTime(LocalDateTime.now());
BeanUtil.copyProperties(info, statistic);
shopIdList.parallelStream().forEach(shopId -> {
DataSummaryTradeParam param = new DataSummaryTradeParam();
param.setShopId(shopId);
param.setBeginDate(startOfDay.toStringDefaultTimeZone());
param.setEndDate(endOfDay.toStringDefaultTimeZone());
ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now());
statistic.setUpdateTime(LocalDateTime.now());
saveOrUpdate(statistic);
});
}
}

View File

@ -120,4 +120,7 @@
]]>
</if>
</select>
<select id="getShopIdList" resultType="java.lang.Long">
select id from tb_shop_info order by id
</select>
</mapper>

View File

@ -93,6 +93,7 @@
GROUP BY x1.order_id
) t2 on t1.id = t2.order_id
where t1.shop_id = #{shopId}
and t1.status in ('part-refund','refund','done')
<if test="productName != null and productName != ''">
and t2.product_name like concat('%', #{productName}, '%')
</if>
@ -122,6 +123,7 @@
left join tb_product t2 on t1.product_id = t2.id
left join tb_shop_prod_category t3 on t2.category_id = t3.id
where t1.shop_id = #{shopId}
and t1.status in ('part-refund','refund','done')
<if test="productName != null and productName != ''">
and t1.product_name like concat('%', #{productName}, '%')
</if>
@ -147,6 +149,7 @@
sum(t1.pay_amount) as amount
from tb_order_detail t1
where t1.shop_id = #{shopId}
and t1.status = 'done'
<if test="beginDate != null and beginDate != ''">
and t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
</if>

View File

@ -64,6 +64,7 @@
where t1.shop_id = #{shopId}
and t1.table_code is not null
and t2.name is not null
and t1.paid_time is not null
<if test="beginDate != null and beginDate != ''">
AND t1.create_time >= str_to_date(#{beginDate}, '%Y-%m-%d %H:%i:%s')
</if>

View File

@ -203,6 +203,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
param.setId(id);
QueryWrapper queryWrapper = buildFullQueryWrapper(param);
ProductDTO dto = super.getOneAs(queryWrapper, ProductDTO.class);
if(dto == null) {
return null;
}
List<ProdSkuDTO> skuList = prodSkuMapper.selectListByQueryAs(query().eq(ProdSku::getProductId, id).eq(ProdSku::getIsDel, DeleteEnum.NORMAL.value()), ProdSkuDTO.class);
dto.setSkuList(skuList);
List<ProdConsRelationDTO> consList = prodConsRelationMapper.selectListByProdId(dto.getId());