fix(订单中心):首页统计优化,优惠券创建逻辑完善
This commit is contained in:
+77
-3
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -1236,10 +1237,83 @@ public class CouponController {
|
|||||||
return buildErrorResponse(request, "0003", "订单项为空");
|
return buildErrorResponse(request, "0003", "订单项为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建优惠券(这里需要根据实际的优惠券创建逻辑来调整)
|
// 创建优惠券
|
||||||
String otaOrderId = "CTRIP_" + System.currentTimeMillis();
|
String otaOrderId = "CTRIP_" + System.currentTimeMillis();
|
||||||
// TODO: 实现具体的优惠券创建逻辑
|
|
||||||
boolean success = true; // 临时设置为true,实际需要实现具体的创建逻辑
|
// 从订单信息中提取优惠券创建所需的数据
|
||||||
|
boolean success = false;
|
||||||
|
String userPhone = null;
|
||||||
|
String ctripCouponId = null;
|
||||||
|
String couponName = null;
|
||||||
|
BigDecimal amount = null;
|
||||||
|
BigDecimal minAmount = null;
|
||||||
|
Integer discountRate = null;
|
||||||
|
Date validStartTime = null;
|
||||||
|
Date validEndTime = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 从订单项中提取用户信息
|
||||||
|
if (body.getItems() != null && !body.getItems().isEmpty()) {
|
||||||
|
CtripOrderItem item = body.getItems().get(0);
|
||||||
|
|
||||||
|
// 提取乘客信息作为用户信息
|
||||||
|
if (item.getPassengers() != null && !item.getPassengers().isEmpty()) {
|
||||||
|
CtripPassenger passenger = item.getPassengers().get(0);
|
||||||
|
userPhone = passenger.getMobile();
|
||||||
|
log.info("从乘客信息中提取到用户手机号: {}", userPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取联系人信息作为备选
|
||||||
|
if (userPhone == null && body.getContacts() != null && !body.getContacts().isEmpty()) {
|
||||||
|
CtripContact contact = body.getContacts().get(0);
|
||||||
|
userPhone = contact.getMobile();
|
||||||
|
log.info("从联系人信息中提取到用户手机号: {}", userPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成携程优惠券ID
|
||||||
|
ctripCouponId = "CTRIP_COUPON_" + System.currentTimeMillis() + "_" + (userPhone != null ? userPhone.hashCode() : "UNKNOWN");
|
||||||
|
|
||||||
|
// 设置优惠券基本信息
|
||||||
|
couponName = "携程优惠券";
|
||||||
|
amount = new BigDecimal("10.00"); // 默认优惠券面额10元
|
||||||
|
minAmount = new BigDecimal("50.00"); // 默认使用门槛50元
|
||||||
|
discountRate = null; // 满减券不使用折扣率
|
||||||
|
|
||||||
|
// 设置有效期(默认30天)
|
||||||
|
Date now = new Date();
|
||||||
|
validStartTime = now;
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(now);
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, 30);
|
||||||
|
validEndTime = calendar.getTime();
|
||||||
|
|
||||||
|
log.info("准备创建携程优惠券 - userPhone: {}, ctripCouponId: {}, couponName: {}, amount: {}, minAmount: {}",
|
||||||
|
userPhone, ctripCouponId, couponName, amount, minAmount);
|
||||||
|
|
||||||
|
// 调用优惠券服务创建优惠券
|
||||||
|
if (userPhone != null) {
|
||||||
|
success = couponService.createCouponFromCtrip(
|
||||||
|
ctripCouponId, userPhone, couponName, 1, // 1表示满减券
|
||||||
|
amount, minAmount, discountRate, validStartTime, validEndTime
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
log.info("携程优惠券创建成功 - ctripCouponId: {}, userPhone: {}", ctripCouponId, userPhone);
|
||||||
|
} else {
|
||||||
|
log.error("携程优惠券创建失败 - ctripCouponId: {}, userPhone: {}", ctripCouponId, userPhone);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("无法提取用户手机号,无法创建优惠券");
|
||||||
|
return buildErrorResponse(request, "0006", "无法提取用户手机号");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("订单项为空,无法创建优惠券");
|
||||||
|
return buildErrorResponse(request, "0007", "订单项为空");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建携程优惠券时发生异常: {}", e.getMessage(), e);
|
||||||
|
return buildErrorResponse(request, "0008", "创建优惠券时发生异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
log.info("携程优惠券创建成功,OTA订单ID: {}", otaOrderId);
|
log.info("携程优惠券创建成功,OTA订单ID: {}", otaOrderId);
|
||||||
|
|||||||
+11
-2
@@ -897,8 +897,17 @@ public class OrderController {
|
|||||||
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
videoMap.put("url", url.replace(cdnOssUrl, cdnUrl));
|
||||||
videoMap.put("contentType", orderFile.getFileType());
|
videoMap.put("contentType", orderFile.getFileType());
|
||||||
videoMap.put("path", orderFile.getFilePath());
|
videoMap.put("path", orderFile.getFilePath());
|
||||||
fileMap.put("path",orderFile.getFilePath());
|
|
||||||
videoMap.put("viewUrl", fileCenterService.getViewUrlByPathStyle(fileMap));
|
// 视频缩略图使用图片的缩略图
|
||||||
|
if (!imgList.isEmpty()) {
|
||||||
|
// 使用第一张图片的缩略图作为视频缩略图
|
||||||
|
String thumbnailUrl = imgList.get(0).get("viewUrl");
|
||||||
|
videoMap.put("viewUrl", thumbnailUrl);
|
||||||
|
} else {
|
||||||
|
// 如果没有图片,则使用默认缩略图或空值
|
||||||
|
videoMap.put("viewUrl", null);
|
||||||
|
}
|
||||||
|
|
||||||
videoList.add(videoMap);
|
videoList.add(videoMap);
|
||||||
}
|
}
|
||||||
orderFileMap.put("videoList", videoList);
|
orderFileMap.put("videoList", videoList);
|
||||||
|
|||||||
+5
-3
@@ -21,6 +21,7 @@ public interface DashboardMapper {
|
|||||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
" AND q.is_test = 0",
|
" AND q.is_test = 0",
|
||||||
"</if>",
|
"</if>",
|
||||||
|
"AND o.order_status IN (1, 3, 4, 5, 7, 8)",
|
||||||
"<if test='p.tourismId != null'>",
|
"<if test='p.tourismId != null'>",
|
||||||
" AND o.tourism_id = #{p.tourismId}",
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
"</if>",
|
"</if>",
|
||||||
@@ -50,6 +51,7 @@ public interface DashboardMapper {
|
|||||||
" AND q.is_test = 0",
|
" AND q.is_test = 0",
|
||||||
"</if>",
|
"</if>",
|
||||||
"AND DATE(o.create_time) = CURDATE()",
|
"AND DATE(o.create_time) = CURDATE()",
|
||||||
|
"AND o.order_status IN (1, 3, 4, 5, 7, 8)",
|
||||||
"<if test='p.tourismId != null'>",
|
"<if test='p.tourismId != null'>",
|
||||||
" AND o.tourism_id = #{p.tourismId}",
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
"</if>",
|
"</if>",
|
||||||
@@ -177,7 +179,7 @@ public interface DashboardMapper {
|
|||||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
" AND q.is_test = 0",
|
" AND q.is_test = 0",
|
||||||
"</if>",
|
"</if>",
|
||||||
"AND o.order_status IN (1, 4, 3, 5)",
|
"AND o.order_status IN (1, 3, 4, 7, 5)",
|
||||||
"<if test='p.tourismId != null'>",
|
"<if test='p.tourismId != null'>",
|
||||||
" AND o.tourism_id = #{p.tourismId}",
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
"</if>",
|
"</if>",
|
||||||
@@ -206,7 +208,7 @@ public interface DashboardMapper {
|
|||||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
" AND q.is_test = 0",
|
" AND q.is_test = 0",
|
||||||
"</if>",
|
"</if>",
|
||||||
"AND o.order_status IN (1, 4, 3, 5)",
|
"AND o.order_status IN (1, 3, 4, 7, 5)",
|
||||||
"AND DATE(o.create_time) = CURDATE()",
|
"AND DATE(o.create_time) = CURDATE()",
|
||||||
"<if test='p.tourismId != null'>",
|
"<if test='p.tourismId != null'>",
|
||||||
" AND o.tourism_id = #{p.tourismId}",
|
" AND o.tourism_id = #{p.tourismId}",
|
||||||
@@ -551,7 +553,7 @@ public interface DashboardMapper {
|
|||||||
" q.code_id as qrcodeId,",
|
" q.code_id as qrcodeId,",
|
||||||
" COUNT(o.id) as orderCount",
|
" COUNT(o.id) as orderCount",
|
||||||
"FROM qrcodes q",
|
"FROM qrcodes q",
|
||||||
"LEFT JOIN orders o ON q.code_id = o.code_id",
|
"LEFT JOIN orders o ON q.code_id = o.code_id AND o.order_status = 3",
|
||||||
"WHERE q.is_del = 0",
|
"WHERE q.is_del = 0",
|
||||||
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
|
||||||
" AND q.is_test = 0",
|
" AND q.is_test = 0",
|
||||||
|
|||||||
@@ -55,6 +55,8 @@
|
|||||||
"@umijs/route-utils": "^2.0.0",
|
"@umijs/route-utils": "^2.0.0",
|
||||||
"antd": "^4.20.0",
|
"antd": "^4.20.0",
|
||||||
"classnames": "^2.3.0",
|
"classnames": "^2.3.0",
|
||||||
|
"echarts": "^5.6.0",
|
||||||
|
"echarts-for-react": "^3.0.2",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moment": "^2.29.0",
|
"moment": "^2.29.0",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Sp
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { dashboard, getQrcodeOptions, getDashboardOrders } from '@/services/orders/api';
|
import { dashboard, getQrcodeOptions, getDashboardOrders } from '@/services/orders/api';
|
||||||
import { Line, Column, Pie } from '@ant-design/plots';
|
import { Line, Column, Pie } from '@ant-design/plots';
|
||||||
|
import ReactECharts from 'echarts-for-react';
|
||||||
import {
|
import {
|
||||||
ShoppingCartOutlined,
|
ShoppingCartOutlined,
|
||||||
PayCircleOutlined,
|
PayCircleOutlined,
|
||||||
@@ -262,6 +263,37 @@ const Welcome: React.FC = () => {
|
|||||||
return statusMap[status] || '未知状态';
|
return statusMap[status] || '未知状态';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 时间快捷选择处理函数
|
||||||
|
const handleQuickTimeSelect = (type: 'today' | 'week' | 'month') => {
|
||||||
|
const now = new Date();
|
||||||
|
let startDate: Date;
|
||||||
|
let endDate: Date;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'today':
|
||||||
|
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||||
|
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
|
||||||
|
break;
|
||||||
|
case 'week':
|
||||||
|
const dayOfWeek = now.getDay();
|
||||||
|
const daysToSubtract = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 周一到周日
|
||||||
|
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToSubtract);
|
||||||
|
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - dayOfWeek), 23, 59, 59);
|
||||||
|
break;
|
||||||
|
case 'month':
|
||||||
|
startDate = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||||
|
endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeRange([
|
||||||
|
startDate.toISOString().slice(0, 19).replace('T', ' '),
|
||||||
|
endDate.toISOString().slice(0, 19).replace('T', ' ')
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
// 动态分账金额计算(基于净收入和分账比例)
|
// 动态分账金额计算(基于净收入和分账比例)
|
||||||
const platformAmount = Math.round(netIncome * platformRate);
|
const platformAmount = Math.round(netIncome * platformRate);
|
||||||
const tourismAmount = netIncome - platformAmount;
|
const tourismAmount = netIncome - platformAmount;
|
||||||
@@ -304,42 +336,87 @@ const Welcome: React.FC = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 二维码订单数量配置 - 横向柱状图
|
// 二维码订单数量配置 - ECharts 横向柱状图(按数量降序排列)
|
||||||
|
const qrcodeOrderData = (chartStats.qrcodeOrderCount || []).sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||||
|
|
||||||
|
// 确保数据按订单数量从多到少排列,最多的显示在最上面
|
||||||
|
const sortedData = [...qrcodeOrderData].sort((a: any, b: any) => b.orderCount - a.orderCount);
|
||||||
|
|
||||||
const qrcodeOrderConfig = {
|
const qrcodeOrderConfig = {
|
||||||
data: chartStats.qrcodeOrderCount || [],
|
tooltip: {
|
||||||
xField: 'orderCount',
|
trigger: 'axis',
|
||||||
yField: 'qrcodeName',
|
axisPointer: {
|
||||||
seriesField: 'qrcodeName',
|
type: 'shadow'
|
||||||
bar: {
|
|
||||||
style: {
|
|
||||||
fill: '#1890ff',
|
|
||||||
},
|
},
|
||||||
|
formatter: function(params: any) {
|
||||||
|
const data = params[0];
|
||||||
|
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||||
|
const percentage = ((data.value / total) * 100).toFixed(2);
|
||||||
|
return `${data.name}<br/>订单数量: ${data.value}单<br/>占比: ${percentage}%`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
label: {
|
grid: {
|
||||||
position: 'right' as const,
|
left: '15%',
|
||||||
style: {
|
right: '15%',
|
||||||
fill: '#666',
|
bottom: '3%',
|
||||||
fontSize: 12,
|
top: '3%',
|
||||||
},
|
containLabel: true
|
||||||
},
|
},
|
||||||
xAxis: {
|
xAxis: {
|
||||||
title: {
|
type: 'value',
|
||||||
text: '订单数量',
|
name: '订单数量',
|
||||||
|
axisLabel: {
|
||||||
|
formatter: '{value}单',
|
||||||
|
fontSize: 12
|
||||||
},
|
},
|
||||||
|
nameTextStyle: {
|
||||||
|
fontSize: 12
|
||||||
|
}
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
title: {
|
type: 'category',
|
||||||
text: '二维码',
|
name: '二维码',
|
||||||
},
|
data: sortedData.map((item: any) => item.qrcodeName),
|
||||||
},
|
axisLabel: {
|
||||||
tooltip: {
|
width: 120,
|
||||||
formatter: (datum: any) => {
|
overflow: 'truncate',
|
||||||
return {
|
fontSize: 12
|
||||||
name: '订单数量',
|
|
||||||
value: datum.orderCount,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
nameTextStyle: {
|
||||||
|
fontSize: 12
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: '订单数量',
|
||||||
|
type: 'bar',
|
||||||
|
data: sortedData.map((item: any) => {
|
||||||
|
const total = sortedData.reduce((sum: number, dataItem: any) => sum + dataItem.orderCount, 0);
|
||||||
|
const percentage = ((item.orderCount / total) * 100).toFixed(2);
|
||||||
|
return {
|
||||||
|
value: item.orderCount,
|
||||||
|
itemStyle: {
|
||||||
|
color: '#52c41a' // 绿色,与图片中的颜色一致
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
itemStyle: {
|
||||||
|
color: '#52c41a'
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
show: true,
|
||||||
|
position: 'right',
|
||||||
|
formatter: function(params: any) {
|
||||||
|
const total = sortedData.reduce((sum: number, item: any) => sum + item.orderCount, 0);
|
||||||
|
const percentage = ((params.value / total) * 100).toFixed(2);
|
||||||
|
return `${params.value}单 (${percentage}%)`;
|
||||||
|
},
|
||||||
|
fontSize: 11,
|
||||||
|
color: '#666'
|
||||||
|
},
|
||||||
|
barWidth: '60%'
|
||||||
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -393,18 +470,22 @@ const Welcome: React.FC = () => {
|
|||||||
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
(当前:平台{Math.round(platformRate * 100)}% | 景区{Math.round((1 - platformRate) * 100)}%)
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
{/* 快速选择常用分账比例 */}
|
{/* 时间快捷选择 */}
|
||||||
<Space size="small">
|
<Space size="small">
|
||||||
<span style={{ color: '#666', fontSize: '12px' }}>快速选择:</span>
|
<span style={{ color: '#666', fontSize: '12px' }}>时间快捷选择:</span>
|
||||||
{[0.7, 0.6, 0.5, 0.4, 0.3].map(rate => (
|
{[
|
||||||
|
{ key: 'today', label: '今日' },
|
||||||
|
{ key: 'week', label: '本周' },
|
||||||
|
{ key: 'month', label: '本月' }
|
||||||
|
].map(item => (
|
||||||
<Button
|
<Button
|
||||||
key={rate}
|
key={item.key}
|
||||||
size="small"
|
size="small"
|
||||||
type={platformRate === rate ? 'primary' : 'default'}
|
type={timeRange[0] && timeRange[1] ? 'primary' : 'default'}
|
||||||
onClick={() => setPlatformRate(rate)}
|
onClick={() => handleQuickTimeSelect(item.key as 'today' | 'week' | 'month')}
|
||||||
style={{ fontSize: '11px', padding: '0 6px' }}
|
style={{ fontSize: '11px', padding: '0 6px' }}
|
||||||
>
|
>
|
||||||
{Math.round(rate * 100)}%
|
{item.label}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
</Space>
|
</Space>
|
||||||
@@ -450,17 +531,10 @@ const Welcome: React.FC = () => {
|
|||||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||||
<span>订单总览</span>
|
<span>订单总览</span>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }}>
|
<div className="subStats___2WPW1">
|
||||||
<Statistic
|
<Statistic
|
||||||
title={getOrderTitle()}
|
title={getOrderTitle()}
|
||||||
value={orderStats.totalOrders || 0}
|
value={orderStats.totalOrders || 0}
|
||||||
suffix={
|
|
||||||
!hasTimeRange && (
|
|
||||||
<span className={styles.trend}>
|
|
||||||
<RiseOutlined /> {orderStats.orderGrowth || 0}%
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<Statistic
|
<Statistic
|
||||||
title="总收款数量"
|
title="总收款数量"
|
||||||
@@ -554,13 +628,17 @@ const Welcome: React.FC = () => {
|
|||||||
</Col>
|
</Col>
|
||||||
<Col xs={24} lg={8}>
|
<Col xs={24} lg={8}>
|
||||||
<Card title="二维码订单数量" loading={loading}>
|
<Card title="二维码订单数量" loading={loading}>
|
||||||
<Column {...qrcodeOrderConfig} height={300} />
|
<ReactECharts
|
||||||
|
option={qrcodeOrderConfig}
|
||||||
|
style={{ height: '300px' }}
|
||||||
|
notMerge={true}
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/* 订单列表 */}
|
{/* 订单列表 */}
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]} style={{ marginTop: 24 }}>
|
||||||
<Col xs={24}>
|
<Col xs={24}>
|
||||||
<Card title="最新订单列表" loading={loading}>
|
<Card title="最新订单列表" loading={loading}>
|
||||||
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
<div style={{ maxHeight: '400px', overflowY: 'auto' }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user