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

View File

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

View File

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

View File

@ -203,4 +203,9 @@ public class DataSummaryServiceImpl implements DataSummaryService {
data.setCountPayType(total); data.setCountPayType(total);
return data; 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.setStaffId(0L);
param.setSeatNum(0); param.setSeatNum(0);
param.setOriginAmount(amount); param.setOriginAmount(amount);
param.setOrderAmount(amount);
param.setTableCode(""); param.setTableCode("");
param.setOrderType("cash"); param.setOrderType("cash");
param.setPlatformType("H5"); param.setPlatformType("H5");
@ -834,7 +835,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setTableCode(param.getTableCode()); orderInfo.setTableCode(param.getTableCode());
orderInfo.setPlaceNum(param.getPlaceNum()); orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setOriginAmount(param.getOriginAmount()); 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.setPackFee(orderInfo.getPackFee().add(param.getPackFee()));
orderInfo.setRoundAmount(BigDecimal.ZERO); orderInfo.setRoundAmount(BigDecimal.ZERO);
orderInfo.setPointsNum(0); orderInfo.setPointsNum(0);

View File

@ -279,6 +279,9 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空"); AssertUtil.isBlank(payParam.getOpenId(), "用户小程序ID不能为空");
OrderInfo orderInfo; OrderInfo orderInfo;
if (payParam.getCheckOrderPay().getOrderId() == null) { 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(), orderInfo = orderInfoService.createPayOrder(payParam.getShopId(), payParam.getCheckOrderPay().getOrderAmount(),
payParam.getCheckOrderPay().getRemark()); payParam.getCheckOrderPay().getRemark());
} else { } else {

View File

@ -1,33 +1,20 @@
package com.czg.service.order.service.impl; package com.czg.service.order.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; 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.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.order.service.ShopOrderStatisticService;
import com.czg.service.order.mapper.ShopOrderStatisticMapper; import com.czg.service.order.mapper.ShopOrderStatisticMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 服务层实现 * 服务层实现
@ -38,11 +25,7 @@ import java.util.stream.Collectors;
@Service @Service
public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService { public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisticMapper, ShopOrderStatistic> implements ShopOrderStatisticService {
@Resource @Resource
private OrderInfoService orderInfoService; private DataSummaryService dataSummaryService;
@DubboReference
private ShopUserFlowService shopUserFlowService;
@DubboReference
private ShopTableService shopTableService;
@Override @Override
@ -53,108 +36,21 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
DateTime startOfDay = DateUtil.beginOfDay(yesterday); DateTime startOfDay = DateUtil.beginOfDay(yesterday);
// 获取前一天的结束时间23:59:59 // 获取前一天的结束时间23:59:59
DateTime endOfDay = DateUtil.endOfDay(yesterday); DateTime endOfDay = DateUtil.endOfDay(yesterday);
List<OrderInfo> orderInfos = orderInfoService.list(new QueryWrapper() List<Long> shopIdList = dataSummaryService.getShopIdList();
.ge(OrderInfo::getPaidTime, startOfDay) if (CollUtil.isEmpty(shopIdList)) {
.le(OrderInfo::getPaidTime, endOfDay) return;
.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);
}
} }
shopIdList.parallelStream().forEach(shopId -> {
countInfo.forEach((shopId, info) -> { DataSummaryTradeParam param = new DataSummaryTradeParam();
ShopOrderStatistic statistic = getOne(new QueryWrapper().eq(ShopOrderStatistic::getShopId, shopId).eq(ShopOrderStatistic::getCreateDay, yesterday.toSqlDate())); param.setShopId(shopId);
if (statistic == null) { param.setBeginDate(startOfDay.toStringDefaultTimeZone());
statistic = new ShopOrderStatistic(); param.setEndDate(endOfDay.toStringDefaultTimeZone());
statistic.setShopId(shopId); ShopOrderStatistic statistic = dataSummaryService.getTradeData(param);
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);
statistic.setShopId(shopId); statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now()); statistic.setCreateDay(LocalDate.now());
statistic.setUpdateTime(LocalDateTime.now());
saveOrUpdate(statistic); saveOrUpdate(statistic);
}); });
} }
} }

View File

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

View File

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

View File

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

View File

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