支付方式
@@ -250,6 +252,28 @@
+
+
+
+
+
+
+
订单地域分布
+
+ {{if !empty($time_data)}}
+
+ {{foreach $time_data as $k=>$v}}
+ {{$v.name}}
+ {{/foreach}}
+ 全部
+
+ {{/if}}
+ {{include file="/index/stats_time" /}}
+
+
+
+
+
{{/if}}
diff --git a/app/service/StatisticalService.php b/app/service/StatisticalService.php
index 789bf6a8d..132526554 100755
--- a/app/service/StatisticalService.php
+++ b/app/service/StatisticalService.php
@@ -35,6 +35,14 @@ class StatisticalService
public static $today_time_start;
public static $today_time_end;
+ // 近365天
+ public static $year_time_start;
+ public static $year_time_end;
+
+ // 近180天
+ public static $half_year_time_start;
+ public static $half_year_time_end;
+
// 近30天
public static $thirty_time_start;
public static $thirty_time_end;
@@ -92,6 +100,14 @@ class StatisticalService
self::$today_time_start = strtotime(date('Y-m-d 00:00:00'));
self::$today_time_end = time();
+ // 近365天日期
+ self::$year_time_start = strtotime(date('Y-m-d 00:00:00', strtotime('-365 day')));
+ self::$year_time_end = time();
+
+ // 近180天日期
+ self::$half_year_time_start = strtotime(date('Y-m-d 00:00:00', strtotime('-180 day')));
+ self::$half_year_time_end = time();
+
// 近30天日期
self::$thirty_time_start = strtotime(date('Y-m-d 00:00:00', strtotime('-29 day')));
self::$thirty_time_end = time();
@@ -185,6 +201,16 @@ class StatisticalService
'start' => date('Y-m-d H:i:s', StatisticalService::$thirty_time_start),
'end' => date('Y-m-d H:i:s', StatisticalService::$thirty_time_end),
],
+ '180-day' => [
+ 'name' => '近半年',
+ 'start' => date('Y-m-d H:i:s', StatisticalService::$half_year_time_start),
+ 'end' => date('Y-m-d H:i:s', StatisticalService::$half_year_time_end),
+ ],
+ '365-day' => [
+ 'name' => '近1年',
+ 'start' => date('Y-m-d H:i:s', StatisticalService::$year_time_start),
+ 'end' => date('Y-m-d H:i:s', StatisticalService::$year_time_end),
+ ],
'this-month' => [
'name' => '当月',
'start' => date('Y-m-d H:i:s', StatisticalService::$this_month_time_start),
@@ -653,6 +679,60 @@ class StatisticalService
return DataReturn('处理成功', 0, $result);
}
+ /**
+ * 热销商品
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 0.0.1
+ * @datetime 2016-12-06T21:31:53+0800
+ * @param [array] $params [输入参数]
+ */
+ public static function GoodsHotTotal($params = [])
+ {
+ // 获取订单id
+ $where = [
+ ['status', '<=', 4],
+ ];
+ if(!empty($params['start']))
+ {
+ $where[] = ['add_time', '>=', $params['start']];
+ }
+ if(!empty($params['end']))
+ {
+ $where[] = ['add_time', '<=', $params['end']];
+ }
+ $order_ids = Db::name('Order')->where($where)->column('id');
+
+ // 获取订单详情热销商品
+ if(empty($order_ids))
+ {
+ $data = [];
+ } else {
+ $data = Db::name('OrderDetail')->field('goods_id, sum(buy_number) AS value')->where('order_id', 'IN', $order_ids)->group('goods_id')->order('value desc')->limit(30)->select()->toArray();
+ }
+
+ if(!empty($data))
+ {
+ foreach($data as &$v)
+ {
+ // 获取商品名称(这里不一次性读取、为了兼容 mysql 5.7+版本)
+ $v['name'] = Db::name('OrderDetail')->where('goods_id', $v['goods_id'])->value('title');
+ if(mb_strlen($v['name'], 'utf-8') > 12)
+ {
+ $v['name'] = mb_substr($v['name'], 0, 12, 'utf-8').'...';
+ }
+ unset($v['goods_id']);
+ }
+ }
+
+ // 数据组装
+ $result = [
+ 'name_arr' => array_column($data, 'name'),
+ 'data' => $data,
+ ];
+ return DataReturn('处理成功', 0, $result);
+ }
+
/**
* 支付方式
* @author Devil
@@ -663,9 +743,6 @@ class StatisticalService
*/
public static function PayTypeTotal($params = [])
{
- // 初始化
- self::Init($params);
-
// 获取支付方式名称
$where = [
['business_type', '<>', ''],
@@ -722,18 +799,19 @@ class StatisticalService
}
/**
- * 热销商品
+ * 订单地域分布
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-06T21:31:53+0800
* @param [array] $params [输入参数]
*/
- public static function GoodsHotTotal($params = [])
- {
+ public static function OrderWholeCountryTotal($params = [])
+ {
// 获取订单id
$where = [
['status', '<=', 4],
+ ['order_model', 'in', [0,2]],
];
if(!empty($params['start']))
{
@@ -750,27 +828,13 @@ class StatisticalService
{
$data = [];
} else {
- $data = Db::name('OrderDetail')->field('goods_id, sum(buy_number) AS value')->where('order_id', 'IN', $order_ids)->group('goods_id')->order('value desc')->limit(30)->select()->toArray();
- }
-
- if(!empty($data))
- {
- foreach($data as &$v)
- {
- // 获取商品名称(这里不一次性读取、为了兼容 mysql 5.7+版本)
- $v['name'] = Db::name('OrderDetail')->where('goods_id', $v['goods_id'])->value('title');
- if(mb_strlen($v['name'], 'utf-8') > 12)
- {
- $v['name'] = mb_substr($v['name'], 0, 12, 'utf-8').'...';
- }
- unset($v['goods_id']);
- }
+ $data = Db::name('OrderAddress')->field('province_name as name, count(*) AS value')->where('order_id', 'IN', $order_ids)->group('province_name')->order('value asc')->select()->toArray();
}
// 数据组装
$result = [
'name_arr' => array_column($data, 'name'),
- 'data' => $data,
+ 'data' => array_column($data, 'value'),
];
return DataReturn('处理成功', 0, $result);
}
@@ -849,6 +913,11 @@ class StatisticalService
$ret = self::PayTypeTotal($params);
break;
+ // 订单地域分布
+ case 'order-whole-country' :
+ $ret = self:: OrderWholeCountryTotal($params);
+ break;
+
default :
$ret = DataReturn('类型有误', -1);
}
diff --git a/public/static/admin/default/css/index.init.css b/public/static/admin/default/css/index.init.css
index 24ae4ec26..70ae96786 100755
--- a/public/static/admin/default/css/index.init.css
+++ b/public/static/admin/default/css/index.init.css
@@ -191,26 +191,13 @@ html, body {
}
/**
- * 支付方式
- */
-#echarts-pay-type {
- margin-top: 10px;
- height: 400px;
-}
-
-/**
- * 热销商品
- */
-#echarts-goods-hot {
- margin-top: 10px;
- height: 400px;
-}
-
-/**
- * 订单交易
+ * 图表容器
*/
#echarts-order-profit,
-#echarts-order-trading {
+#echarts-order-trading,
+#echarts-goods-hot,
+#echarts-pay-type,
+#echarts-map-whole-country {
margin-top: 10px;
height: 400px;
}
diff --git a/public/static/admin/default/js/index.init.js b/public/static/admin/default/js/index.init.js
index 79d4a4ae9..bd5db3386 100644
--- a/public/static/admin/default/js/index.init.js
+++ b/public/static/admin/default/js/index.init.js
@@ -327,6 +327,75 @@ function EchartsPayType(title_arr, name_arr, data)
return chart;
}
+/**
+ * 订单地域分布
+ * @author Devil
+ * @blog http://gong.gg/
+ * @version 1.0.0
+ * @date 2021-08-30
+ * @desc description
+ * @param {[array]} name_arr [名称]
+ * @param {[array]} data [数据]
+ */
+function EchartsOrderMapWholeCountry(name_arr, data)
+{
+ var chart = echarts.init(document.getElementById('echarts-map-whole-country'), 'macarons');
+ var option = {
+ title: {
+ text: '',
+ subtext: ''
+ },
+ tooltip: {
+ trigger: 'axis',
+ axisPointer: {
+ type: 'shadow'
+ }
+ },
+ legend: {
+ data: []
+ },
+ grid: {
+ top: '5%',
+ left: '3%',
+ right: '4%',
+ bottom: '3%',
+ containLabel: true
+ },
+ xAxis: {
+ type: 'value',
+ boundaryGap: [0, 0.01]
+ },
+ yAxis: {
+ type: 'category',
+ data: name_arr
+ },
+ series: [
+ {
+ name: '',
+ type: 'bar',
+ data: data,
+ itemStyle: {
+ normal: {
+ // 定制颜色显示(按顺序)
+ // 超出定制颜色则返回随机
+ color: function(params) {
+ var colorList = ['#C33531','#EFE42A','#64BD3D','#EE9201','#29AAE3', '#B74AE5','#0AAF9F','#E89589','#16A085','#4A235A','#C39BD3 ','#F9E79F','#BA4A00','#ECF0F1','#616A6B','#EAF2F8','#4A235A','#3498DB', '#00BCD4', '#FF9800', '#E63A75', '#3F51B5'];
+ if(colorList[params.dataIndex] == undefined)
+ {
+ return "#"+Math.floor(Math.random()*(256*256*256-1)).toString(16);
+ } else {
+ return colorList[params.dataIndex];
+ }
+ }
+ }
+ }
+ }
+ ]
+ };
+ chart.setOption(option);
+ return chart;
+}
+
/**
* 图表更新
* @author Devil
@@ -391,6 +460,11 @@ function EchartsInit(e)
var chart = EchartsPayType(res.data.title_arr, res.data.name_arr, res.data.data);
break;
+ // 订单地域分布
+ case 'order-whole-country' :
+ var chart = EchartsOrderMapWholeCountry(res.data.name_arr, res.data.data);
+ break;
+
default :
console.info('操作类型未定义['+type+']')
}