Merge remote-tracking branch 'origin/master'

This commit is contained in:
GYJ
2025-03-12 14:57:26 +08:00
43 changed files with 452 additions and 193 deletions

View File

@@ -1,7 +1,14 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.ShopProdStatistic;
import com.czg.order.param.DataSummaryProductSaleParam;
import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.order.vo.SaleSummaryInfoVo;
import com.mybatisflex.core.BaseMapper;
import java.util.List;
/**
* 映射层。
@@ -11,4 +18,10 @@ import com.czg.order.entity.ShopProdStatistic;
*/
public interface ShopProdStatisticMapper extends BaseMapper<ShopProdStatistic> {
List<DataSummaryProductSaleRankingVo> findProdRandingSummaryPage(DataSummaryProductSaleParam param);
SaleSummaryCountVo getSaleSummaryCount(SaleSummaryCountParam param);
List<SaleSummaryInfoVo> findSaleSummaryList(SaleSummaryCountParam param);
}

View File

@@ -1,7 +1,9 @@
package com.czg.service.order.mapper;
import com.mybatisflex.core.BaseMapper;
import com.czg.order.entity.ShopTableOrderStatistic;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.vo.TableSummaryInfoVo;
import com.mybatisflex.core.BaseMapper;
import java.math.BigDecimal;
import java.util.List;
@@ -18,4 +20,5 @@ public interface ShopTableOrderStatisticMapper extends BaseMapper<ShopTableOrder
boolean incrInfo(long shopId, long tableId, long count, BigDecimal amount, String dateStr);
List<TableSummaryInfoVo> findSummaryList(TableSummaryParam param);
}

View File

@@ -5,12 +5,14 @@ import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.czg.order.entity.OrderDetail;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
@@ -87,7 +89,7 @@ public interface PrinterImpl {
price = addSpace(price, b2);
num = addSpace(num, b3);
total = addSpace(total, b4);
String otherStr = " %s%s %s".formatted(price, num, total);
String otherStr = " %s%s%s".formatted(price, num, total);
int titleByteLen = StrUtil.bytes(title, CharsetUtil.CHARSET_GBK).length;
StringBuilder sb = new StringBuilder();
@@ -171,7 +173,7 @@ public interface PrinterImpl {
// data.append("<OUT:15>");
// data.append("<BR>");
// 18个空格 12
data.append(getFormatLabel("品名 数量 小计", signLabelInfo.s))
data.append(getFormatLabel("品名 数量 小计 ", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>品名 数量 小计</S><BR>");
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
@@ -180,7 +182,7 @@ public interface PrinterImpl {
for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString();
String row = getRow(detail.getProductName(), "", number,
toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 23, 0, 5, 4);
toPlainStr(detail.getPayAmount().stripTrailingZeros().toPlainString()), 21, 0, 5, 6);
data.append(row);
if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
@@ -194,12 +196,15 @@ public interface PrinterImpl {
if (!JSONUtil.isTypeJSONArray(proGroupInfo)) {
continue;
}
JSONArray subItems = JSONUtil.parseArray(proGroupInfo);
for (int i = 0; i < subItems.size(); i++) {
String proName = subItems.getJSONObject(i).getStr("proName");
int qty = subItems.getJSONObject(i).getInt("number");
String subRow = getRow(" - " + proName, "", qty + ".00", "0.00", 20, 0, 3, 6);
data.append(subRow);
JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number");
String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6);
data.append(subRow);
});
}
}
if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) {
@@ -319,12 +324,16 @@ public interface PrinterImpl {
// builder.append("<S><L>备注: ").append(note).append(" </L></S><BR>");
}
if (!StrUtil.isBlank(proGroupInfo) && JSONUtil.isTypeJSONArray(proGroupInfo)) {
JSONArray subItems = JSONUtil.parseArray(proGroupInfo);
for (int i = 0; i < subItems.size(); i++) {
String proName = subItems.getJSONObject(i).getStr("proName");
int qty = subItems.getJSONObject(i).getInt("number");
builder.append(StrUtil.format("({}) x {}", proName, qty))
.append(signLabelInfo.br);
JSONArray subItems = JSONArray.parseArray(proGroupInfo);
for (Object subItem : subItems) {
JSONObject jsonObject = (JSONObject) subItem;
jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number -> 1");
builder.append(StrUtil.format("({}) x {}", proName, qty))
.append(signLabelInfo.br);
});
// builder.append("<CS:32>(").append(i + 1).append(")").append(proName).append(" x ").append(qty).append("</CS><BR>");
}
}
@@ -390,7 +399,11 @@ public interface PrinterImpl {
* @return 填充之后的字符串
*/
default String addSpace(String str, int size) {
return StrUtil.fillAfter(str, ' ', size);
int len = str.length();
if (len < size) {
str = str + " ".repeat(size - len);
}
return str;
}
/**
@@ -427,8 +440,20 @@ public interface PrinterImpl {
* @return 添加间距的字符串
*/
default String titleAddSpace(String str, int b1) {
int byteLen = StrUtil.bytes(str, CharsetUtil.CHARSET_GBK).length;
return StrUtil.fillAfter(str, ' ', b1 - byteLen);
int k = 0;
try {
k = str.getBytes("GBK").length;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
str = str + " ".repeat(Math.max(0, b1 - k));
return str;
}
public static void main(String[] args) {
System.out.println("水煮肉片".length());
System.out.println( StrUtil.repeat(' ', 8));
System.out.println(StrUtil.fillAfter("水煮肉片", ' ', 21));
}
/**

View File

@@ -10,9 +10,14 @@ import com.czg.order.param.DataSummaryTradeParam;
import com.czg.order.service.DataSummaryService;
import com.czg.order.vo.DataSummaryDateAmountVo;
import com.czg.order.vo.DataSummaryPayTypeVo;
import com.czg.order.vo.DataSummaryProductSaleVo;
import com.czg.order.vo.DataSummaryProductSaleRankingVo;
import com.czg.service.order.mapper.OrderInfoMapper;
import com.czg.service.order.mapper.ShopOrderStatisticMapper;
import com.czg.service.order.mapper.ShopProdStatisticMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@@ -34,6 +39,8 @@ public class DataSummaryServiceImpl implements DataSummaryService {
private ShopOrderStatisticMapper shopOrderStatisticMapper;
@Resource
private OrderInfoMapper orderInfoMapper;
@Resource
private ShopProdStatisticMapper shopProdStatisticMapper;
@Override
public ShopOrderStatistic getTradeData(DataSummaryTradeParam param) {
@@ -41,14 +48,25 @@ public class DataSummaryServiceImpl implements DataSummaryService {
if (shopOrderStatistic == null) {
shopOrderStatistic = new ShopOrderStatistic();
}
shopOrderStatistic.setCustomerUnitPrice(shopOrderStatistic.getCustomerUnitPrice().setScale(2, java.math.RoundingMode.HALF_UP));
shopOrderStatistic.setTableTurnoverRate(shopOrderStatistic.getTableTurnoverRate().setScale(2, java.math.RoundingMode.HALF_UP));
return shopOrderStatistic;
}
@Override
public DataSummaryProductSaleVo getProductSaleData(DataSummaryProductSaleParam param) {
DataSummaryProductSaleVo data = new DataSummaryProductSaleVo();
System.out.println(1);
return data;
public Page<DataSummaryProductSaleRankingVo> getProductSaleRankingPage(DataSummaryProductSaleParam param) {
LocalDate now = LocalDate.now();
Integer day = param.getDay();
LocalDate beginDate = now.plusDays(-day);
List<String> days = new ArrayList<>();
for (int i = 1; i <= day; i++) {
String thisDay = beginDate.plusDays(i).format(DatePattern.NORM_DATE_FORMATTER);
days.add(thisDay);
}
param.setDays(days);
PageHelper.startPage(PageUtil.buildPageHelp());
PageInfo<DataSummaryProductSaleRankingVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findProdRandingSummaryPage(param));
return PageUtil.convert(pageInfo);
}
@Override

View File

@@ -706,6 +706,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setSeatAmount(shopInfo.getTableFee().multiply(new BigDecimal(param.getSeatNum())));
orderInfo.setSeatNum(param.getSeatNum());
}
orderInfo.setTableCode(param.getTableCode());
orderInfo.setPlaceNum(param.getPlaceNum());
orderInfo.setOriginAmount(param.getOriginAmount());
orderInfo.setOrderAmount(BigDecimal.ZERO);

View File

@@ -13,6 +13,7 @@ import com.czg.config.RedisCst;
import com.czg.entity.req.*;
import com.czg.entity.resp.*;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
import com.czg.exception.PaySuccessException;
import com.czg.order.dto.BigDecimalDTO;
import com.czg.order.dto.CheckOrderPay;
@@ -551,16 +552,20 @@ public class PayServiceImpl implements PayService {
orderInfo.setStatus(OrderStatusEnums.REFUND.getCode());
// ssss
List<OrderDetail> orderDetails = orderDetailService.queryChain()
.select(OrderDetail::getId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getReturnNum)
.select(OrderDetail::getId, OrderDetail::getProductId, OrderDetail::getNum, OrderDetail::getReturnNum, OrderDetail::getReturnNum)
.eq(OrderDetail::getOrderId, orderInfo.getId())
.list();
for (OrderDetail orderDetail : orderDetails) {
if (isPay) {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum()));
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum()));
}
orderDetail.setRefundNum(orderDetail.getNum().subtract(orderDetail.getReturnNum()));
orderDetail.setStatus(OrderStatusEnums.REFUND.getCode());
} else {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()));
if (orderDetail.getProductId() != null && orderDetail.getProductId() > 0) {
returnProMap.put(Convert.toStr(orderDetail.getProductId()), orderDetail.getNum().subtract(orderDetail.getReturnNum()));
}
orderDetail.setReturnNum(orderDetail.getNum());
orderDetail.setStatus(OrderStatusEnums.CANCELLED.getCode());
}
@@ -639,14 +644,14 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
return czgPayService.queryPayOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
}
@Override
@Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
return czgPayService.queryRefundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
}
@@ -666,7 +671,7 @@ public class PayServiceImpl implements PayService {
private CzgResult<Map<String, Object>> h5Pay(@NonNull Long shopId, CzgH5PayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
CzgResult<CzgH5PayResp> h5PayRespCzgResult = czgPayService.h5Pay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
@@ -674,7 +679,7 @@ public class PayServiceImpl implements PayService {
}
private CzgResult<Map<String, Object>> jsPay(@NonNull Long shopId, @NonNull String payType, CzgJsPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
@@ -685,7 +690,7 @@ public class PayServiceImpl implements PayService {
}
private CzgResult<Map<String, Object>> ltPay(@NonNull Long shopId, String payType, CzgLtPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setSubAppid("aliPay".equals(payType) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(payType) ? "支付宝" : "微信") + "小程序");
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
@@ -695,7 +700,7 @@ public class PayServiceImpl implements PayService {
}
private CzgResult<Map<String, Object>> scanPay(@NonNull Long shopId, CzgScanPayReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
CzgResult<CzgScanPayResp> scanPayRespCzgResult = czgPayService.scanPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
@@ -704,7 +709,7 @@ public class PayServiceImpl implements PayService {
private CzgResult<Map<String, Object>> microPay(@NonNull Long shopId, CzgMicroPayReq bizData) {
AssertUtil.isBlank(bizData.getAuthCode(), "扫码失败,请重试");
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.assignMerchant(shopMerchant.getStoreId(), shopMerchant.getMerchantName(),
sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_NOTIFY_URL.getCode()));
String firstTwoDigitsStr = bizData.getAuthCode().substring(0, 2);
@@ -728,11 +733,19 @@ public class PayServiceImpl implements PayService {
}
private CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData) {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
ShopMerchant shopMerchant = getMerchant(shopId);
bizData.setNotifyUrl(sysParamsService.getSysParamValue(SysParamCodeEnum.PAY_CZG_REFUND_NOTIFY_URL.getCode()));
return czgPayService.refundOrder(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private ShopMerchant getMerchant(Long shopId) {
try {
return shopMerchantService.getById(shopId);
} catch (Exception e) {
throw new CzgException("暂未开通支付");
}
}
private CzgResult<Map<String, Object>> execPayResult(CzgResult<? extends CzgBaseResp> res) {
CzgResult<Map<String, Object>> result = CzgResult.success();
if (res.getCode() != 200 || res.getData() == null) {

View File

@@ -4,10 +4,14 @@ import com.czg.order.param.SaleSummaryCountParam;
import com.czg.order.service.SaleSummaryService;
import com.czg.order.vo.SaleSummaryCountVo;
import com.czg.order.vo.SaleSummaryInfoVo;
import com.czg.service.order.mapper.ShopProdStatisticMapper;
import com.czg.utils.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@@ -18,21 +22,27 @@ import java.util.List;
*/
@Service
public class SaleSummaryServiceImpl implements SaleSummaryService {
@Resource
private ShopProdStatisticMapper shopProdStatisticMapper;
@Override
public SaleSummaryCountVo summaryCount(SaleSummaryCountParam param) {
return new SaleSummaryCountVo();
SaleSummaryCountVo saleSummaryCount = shopProdStatisticMapper.getSaleSummaryCount(param);
if (saleSummaryCount == null) {
saleSummaryCount = new SaleSummaryCountVo();
}
return saleSummaryCount;
}
@Override
public Page<SaleSummaryInfoVo> summaryPage(SaleSummaryCountParam param) {
Page<SaleSummaryInfoVo> page = new Page<>();
page.setRecords(new ArrayList<SaleSummaryInfoVo>());
return page;
PageHelper.startPage(PageUtil.buildPageHelp());
PageInfo<SaleSummaryInfoVo> pageInfo = new PageInfo<>(shopProdStatisticMapper.findSaleSummaryList(param));
return PageUtil.convert(pageInfo);
}
@Override
public List<SaleSummaryInfoVo> summaryList(SaleSummaryCountParam param) {
return List.of();
return shopProdStatisticMapper.findSaleSummaryList(param);
}
}

View File

@@ -13,6 +13,7 @@ import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashMap;
@@ -93,8 +94,14 @@ public class ShopOrderStatisticServiceImpl extends ServiceImpl<ShopOrderStatisti
statistic = new ShopOrderStatistic();
statistic.setShopId(shopId);
statistic.setCreateDay(LocalDate.now());
statistic.setUpdateTime(LocalDateTime.now());
}
//TODO 充值金额
statistic.setRechargeAmount(BigDecimal.ZERO);
//TODO 客单价
statistic.setCustomerUnitPrice(BigDecimal.ZERO);
//TODO 翻台率
statistic.setTableTurnoverRate(BigDecimal.ZERO);
statistic.setUpdateTime(LocalDateTime.now());
BeanUtil.copyProperties(info, statistic);
saveOrUpdate(statistic);
});

View File

@@ -2,8 +2,9 @@ package com.czg.service.order.service.impl;
import com.czg.order.param.TableSummaryParam;
import com.czg.order.service.TableSummaryService;
import com.czg.order.vo.TableSummaryExportVo;
import com.czg.order.vo.TableSummaryInfoVo;
import com.czg.service.order.mapper.ShopTableOrderStatisticMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
@@ -17,14 +18,12 @@ import java.util.List;
@Service
public class TableSummaryServiceImpl implements TableSummaryService {
@Resource
private ShopTableOrderStatisticMapper shopTableOrderStatisticMapper;
@Override
public List<TableSummaryInfoVo> summaryList(TableSummaryParam param) {
return List.of();
return shopTableOrderStatisticMapper.findSummaryList(param);
}
@Override
public List<TableSummaryExportVo> summaryExport(TableSummaryParam param) {
return List.of();
}
}

View File

@@ -7,22 +7,22 @@
<select id="getTradeData" resultType="com.czg.order.entity.ShopOrderStatistic">
select
sum(sale_amount) as sale_amount,
count(sale_count) as sale_count,
sum(sale_count) as sale_count,
sum(discount_amount) as discount_amount,
count(discount_count) as discount_count,
sum(discount_count) as discount_count,
sum(refund_amount) as refund_amount,
count(refund_count) as refund_count,
count(wechat_pay_count) as wechat_pay_count,
sum(refund_count) as refund_count,
sum(wechat_pay_count) as wechat_pay_count,
sum(wechat_pay_amount) as wechat_pay_amount,
count(ali_pay_count) as ali_pay_count,
sum(ali_pay_count) as ali_pay_count,
sum(ali_pay_amount) as ali_pay_amount,
count(credit_pay_count) as credit_pay_count,
sum(credit_pay_count) as credit_pay_count,
sum(credit_pay_amount) as credit_pay_amount,
count(member_pay_count) as member_pay_count,
sum(member_pay_count) as member_pay_count,
sum(member_pay_amount) as member_pay_amount,
count(scan_pay_count) as scan_pay_count,
sum(scan_pay_count) as scan_pay_count,
sum(scan_pay_amount) as scan_pay_amount,
count(cash_pay_count) as cash_pay_count,
sum(cash_pay_count) as cash_pay_count,
sum(cash_pay_amount) as cash_pay_amount,
sum(recharge_amount) as recharge_amount,
avg(customer_unit_price) as customer_unit_price,
@@ -30,12 +30,12 @@
max(update_time) as update_time
from tb_shop_order_statistic
where shop_id = #{shopId}
<if test="beginTime != null">
and create_day >= str_to_date(#{beginTime}, '%Y-%m-%d')
<if test="beginDate != null and endDate != ''">
and create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
</if>
<if test="endTime != null">
<if test="endDate != null and endDate != ''">
<![CDATA[
and create_day <= str_to_date(#{endTime}, '%Y-%m-%d')
and create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
]]>
</if>
group by shop_id

View File

@@ -4,4 +4,74 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.czg.service.order.mapper.ShopProdStatisticMapper">
<select id="findProdRandingSummaryPage" resultType="com.czg.order.vo.DataSummaryProductSaleRankingVo">
select
t1.prod_id,
t2.name as product_name,
sum(t1.sale_count) as number,
sum(t1.sale_amount) as amount
from tb_shop_prod_statistic t1
left join tb_product t2 on t1.prod_id = t2.id
where t1.shop_id = #{shopId}
and t1.create_day in
<foreach item="day" collection="days" open="(" separator="," close=")">
#{day}
</foreach>
group by t1.prod_id
</select>
<select id="getSaleSummaryCount" resultType="com.czg.order.vo.SaleSummaryCountVo">
select
sum(t1.sale_count) as sale_count,
sum(t1.sale_amount) as total_amount,
sum(t1.refund_count) as refund_count,
sum(t1.refund_amount) as refund_amount
from tb_shop_prod_statistic t1
left join tb_product t2 on t1.prod_id = t2.id
where t1.shop_id = #{shopId}
<if test="productName != null and productName != ''">
and t2.name like concat('%', #{productName}, '%')
</if>
<if test="prodCategoryId != null">
and t2.category_id = #{prodCategoryId}
</if>
<if test="beginDate != null and beginDate != ''">
and t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
]]>
</if>
</select>
<select id="findSaleSummaryList" resultType="com.czg.order.vo.SaleSummaryInfoVo">
select
t1.prod_id,
max(t1.id) as id,
t2.NAME AS product_name,
t3.name as category_name,
sum(t1.sale_count) as sale_count,
sum(t1.sale_amount) as sale_amount,
sum(t1.refund_count) as refund_count,
sum(t1.refund_amount) as refund_amount
from tb_shop_prod_statistic t1
left join tb_product t2 on t1.prod_id = t2.id
left join tb_shop_prod_category t3 on t2.category_id = t3.id
where t1.shop_id = #{shopId}
<if test="productName != null and productName != ''">
and t2.name like concat('%', #{productName}, '%')
</if>
<if test="prodCategoryId != null">
and t2.category_id = #{prodCategoryId}
</if>
<if test="beginDate != null and beginDate != ''">
and t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
</if>
<if test="endDate != null and endDate != ''">
<![CDATA[
and t1.create_day <= str_to_date(#{endDate}, '%Y-%m-%d')
]]>
</if>
group by t1.prod_id
ORDER BY sum( t1.sale_count ) DESC,max(t1.id) DESC
</select>
</mapper>

View File

@@ -26,4 +26,26 @@
a.table_id
order by a.id desc
</select>
<select id="findSummaryList" resultType="com.czg.order.vo.TableSummaryInfoVo">
select
t1.table_id,
ifnull(t3.name,'N/A') as area_name,
ifnull(t2.name,'N/A') as table_name,
sum(t1.order_count) as order_count,
sum(t1.order_amount) as order_amount,
ifnull(sum(t1.refund_count),0) as refund_count,
ifnull(sum(t1.refund_amount),0) as refund_amount
from tb_shop_table_order_statistic t1
left join tb_shop_table t2 on t1.table_id = t2.id
left join tb_shop_table_area t3 on t2.area_id = t3.id
where t1.shop_id = #{shopId}
<if test="beginDate != null and beginDate != ''">
AND t1.create_day >= str_to_date(#{beginDate}, '%Y-%m-%d')
</if>
<if test="endDate != null and endDate != ''">
and t2.create_day &lt;= str_to_date(#{endDate}, '%Y-%m-%d')
</if>
group by t1.table_id
order by sum(t1.order_count) desc,max(t1.id) desc
</select>
</mapper>