feat: 修改DemoController和IndexController类,优化了查询逻辑和数据统计方式,增加了对门店统计和商品数量统计的查询功能。
This commit is contained in:
parent
e7cf36928f
commit
82a2bf0fa5
@ -4,6 +4,8 @@ namespace app\statistics\controller;
|
|||||||
|
|
||||||
use app\admin\logic\statistic\TradeStatisticLogic;
|
use app\admin\logic\statistic\TradeStatisticLogic;
|
||||||
use app\common\controller\BaseLikeController;
|
use app\common\controller\BaseLikeController;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\system_store\SystemStore;
|
use app\common\model\system_store\SystemStore;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -15,36 +17,52 @@ class DemoController extends BaseLikeController
|
|||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$store_id = $this->request->get('store_id', 0);
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$res = Db::name('demo_order_money')->whereDay('dates', $time)->sum('money');
|
$where = [];
|
||||||
$res = $res ? $res : 0;
|
if ($store_id) {
|
||||||
switch ($store_id) {
|
$where['store_id'] = $store_id;
|
||||||
case 1:
|
$name = SystemStore::where('id', $store_id)->value('name');
|
||||||
$title = '喻寺镇农(特)产品交易大数据';
|
$title = $name . '农(特)产品交易大数据';
|
||||||
break;
|
} else {
|
||||||
case 2:
|
|
||||||
$title = '立石镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$title = '百和镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$title = '得胜镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
$title = '玄滩镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
$title = '牛滩镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
$title = '云锦镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$title = '泸县农(特)产品交易大数据';
|
$title = '泸县农(特)产品交易大数据';
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
$res = Db::name('demo_order_money')->where($where)->whereDay('dates', $time)->sum('money');
|
||||||
|
$res = $res ? $res : 0;
|
||||||
return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
|
return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 门店统计
|
||||||
|
*/
|
||||||
|
public function sotre_count()
|
||||||
|
{
|
||||||
|
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()->each(function ($item) use (&$data) {
|
||||||
|
$item['merchant_count'] = 1;
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地方商品数量统计
|
||||||
|
*/
|
||||||
|
public function product_count_sotre_count()
|
||||||
|
{
|
||||||
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
|
$data=SystemStore::where('is_show', 1)->field('id,introduction street_name')->select()->each(function ($item) {
|
||||||
|
$item['product_count'] = StoreBranchProduct::where('store_id', $item['id'])->count();
|
||||||
|
return $item;
|
||||||
|
});
|
||||||
|
//总商品
|
||||||
|
$townProductCount = StoreProduct::where('create_time','<=',strtotime($time))->count();
|
||||||
|
//商品销量
|
||||||
|
$product_count = StoreBranchProduct::where('create_time','<=',strtotime($time))->group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
|
||||||
|
//总销量
|
||||||
|
$productRankingTotal = 0;
|
||||||
|
foreach ($product_count as $item) {
|
||||||
|
$productRankingTotal += $item['total_sales'];
|
||||||
|
}
|
||||||
|
return $this->success('ok', ['townProductCountList' => $data, 'productRankingList' => $product_count, 'townProductCount' => $townProductCount, 'productRankingTotal' => $productRankingTotal]);
|
||||||
|
}
|
||||||
public function bottomLeft()
|
public function bottomLeft()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m'));
|
$time = $this->request->get('date', date('Y-m'));
|
||||||
@ -53,7 +71,7 @@ class DemoController extends BaseLikeController
|
|||||||
if ($store_id) {
|
if ($store_id) {
|
||||||
$where['store_id'] = $store_id;
|
$where['store_id'] = $store_id;
|
||||||
}
|
}
|
||||||
$arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
|
$arr = SystemStore::where('is_show', 1)->field('id,abbreviation street_name')->select()
|
||||||
->each(function ($item) use ($time) {
|
->each(function ($item) use ($time) {
|
||||||
$day = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', $time)->sum('money');
|
$day = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', $time)->sum('money');
|
||||||
$yester = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', date('Y-m', strtotime('-1 month')))->sum('money');
|
$yester = Db::name('demo_order_money')->where('store_id', $item['id'])->whereMonth('dates', date('Y-m', strtotime('-1 month')))->sum('money');
|
||||||
@ -67,10 +85,10 @@ class DemoController extends BaseLikeController
|
|||||||
public function store_order_day_two()
|
public function store_order_day_two()
|
||||||
{
|
{
|
||||||
$time = $this->request->get('date', date('Y-m-d'));
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
$arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
|
$arr = SystemStore::where('is_show', 1)->field('id,abbreviation street_name')->select()
|
||||||
->each(function ($item) use ($time) {
|
->each(function ($item) use ($time) {
|
||||||
$today_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', $time)->sum('money');
|
$today_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', $time)->sum('money');
|
||||||
$yesterday_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', date('Y-m-d', strtotime($time.'-1 day')))->sum('money');
|
$yesterday_order_amount = Db::name('demo_order_money')->where('store_id', $item['id'])->whereDay('dates', date('Y-m-d', strtotime($time . '-1 day')))->sum('money');
|
||||||
$item['today_order_amount'] = $today_order_amount;
|
$item['today_order_amount'] = $today_order_amount;
|
||||||
$item['yesterday_order_amount'] = $yesterday_order_amount;
|
$item['yesterday_order_amount'] = $yesterday_order_amount;
|
||||||
return $item;
|
return $item;
|
||||||
@ -85,32 +103,26 @@ class DemoController extends BaseLikeController
|
|||||||
{
|
{
|
||||||
$store_id = $this->request->get('store_id', 0);
|
$store_id = $this->request->get('store_id', 0);
|
||||||
$date = $this->request->get('date', '');
|
$date = $this->request->get('date', '');
|
||||||
|
$a = new TradeStatisticLogic();
|
||||||
|
|
||||||
if ($date != '') {
|
if ($date != '') {
|
||||||
$where = ['create_time' => ['start_time' => $date, 'end_time' => $date . ' 23:59:59']];
|
$time['start_time'] = $date;
|
||||||
$where2 = ['create_time' => ['start_time' => $date, 'end_time' => $date . ' 23:59:59']];
|
$time['end_time'] = date('Y-m-d', strtotime($date . '-1 month'));
|
||||||
|
$aa = $a->TimeConvert($time);
|
||||||
|
$time['start_time'] = $aa['end_time'];
|
||||||
|
$time['end_time'] = $aa['start_time'];
|
||||||
|
$time['days'] = 30;
|
||||||
} else {
|
} else {
|
||||||
$where = ['create_time' => 'today'];
|
|
||||||
$where2 = ['create_time' => 'yestoday'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($store_id) {
|
|
||||||
$where['store_id'] = $store_id;
|
|
||||||
$where2['store_id'] = $store_id;
|
|
||||||
}
|
|
||||||
$left = [];
|
|
||||||
|
|
||||||
// foreach ($totalleft as $k => $v) {
|
|
||||||
// $left['name'] = "当日订单金额";
|
|
||||||
// $left['x'] = $v['curve']['x'];
|
|
||||||
// $left['series'][$k]['money'] = round($v['total_money'], 2);
|
|
||||||
// $left['series'][$k]['value'] = array_values($v['curve']['y']);
|
|
||||||
// }
|
|
||||||
$time['start_time'] = date('Y-01-01 00:00:00', time());
|
$time['start_time'] = date('Y-01-01 00:00:00', time());
|
||||||
$time['end_time'] = date('Y-12-t 23:59:59', time());
|
$time['end_time'] = date('Y-12-t 23:59:59', time());
|
||||||
$time['days'] = 365;
|
$time['days'] = 365;
|
||||||
$left = $this->getCurveData([], $time, 'sum(money)', 'dates');
|
}
|
||||||
$a = new TradeStatisticLogic();
|
$where = [];
|
||||||
|
if ($store_id) {
|
||||||
|
$where['store_id'] = $store_id;
|
||||||
|
}
|
||||||
|
$left = $this->getCurveData($where, $time, 'sum(money)', 'dates');
|
||||||
|
|
||||||
$totalMoney = $a->trendYdata($left, $time);
|
$totalMoney = $a->trendYdata($left, $time);
|
||||||
|
|
||||||
$datas['name'] = "门店订单金额曲线";
|
$datas['name'] = "门店订单金额曲线";
|
||||||
@ -143,4 +155,42 @@ class DemoController extends BaseLikeController
|
|||||||
})
|
})
|
||||||
->order("$group ASC")->select()->toArray();
|
->order("$group ASC")->select()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当日订单金额
|
||||||
|
*/
|
||||||
|
public function street_currday_order_count()
|
||||||
|
{
|
||||||
|
$time = $this->request->get('date', date('Y-m-d'));
|
||||||
|
$store_id = $this->request->get('store_id', 0);
|
||||||
|
$where = [];
|
||||||
|
if ($store_id) {
|
||||||
|
$where['store_id'] = $store_id;
|
||||||
|
}
|
||||||
|
$startTime = strtotime($time . ' 00:00:00'); // 当天的开始时间戳
|
||||||
|
$endTime = strtotime($time . ' 23:59:59'); // 当天的结束时间戳
|
||||||
|
|
||||||
|
$interval = 4 * 60 * 60; // 4小时的秒数
|
||||||
|
$data = [];
|
||||||
|
for ($time = $startTime; $time < $endTime; $time += $interval) {
|
||||||
|
|
||||||
|
$endTimeSegment = $time + $interval;
|
||||||
|
$startTimeSegment = date('Y-m-d H:i:s', $time);
|
||||||
|
$yesterendTimeSegment = date('Y-m-d H:i:s', $endTimeSegment - 86400);
|
||||||
|
$endTimeSegment = date('Y-m-d H:i:s', $endTimeSegment);
|
||||||
|
$yesterstartTimeSegment = date('Y-m-d H:i:s', $time - 86400);
|
||||||
|
// 统计当前时间段的订单
|
||||||
|
$todayAmount = Db::name('demo_order_money')->where($where)
|
||||||
|
->whereBetween('dates', [strtotime($startTimeSegment), strtotime($endTimeSegment)])
|
||||||
|
->sum('money');
|
||||||
|
$yesterdayAmount = Db::name('demo_order_money')->where($where)
|
||||||
|
->whereBetween('dates', [strtotime($yesterstartTimeSegment), strtotime($yesterendTimeSegment)])
|
||||||
|
->sum('money');
|
||||||
|
$data[] = [
|
||||||
|
'todayAmount' => $todayAmount,
|
||||||
|
'yesterdayAmount' => $yesterdayAmount,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->success('ok', $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use app\statistics\logic\OrderLogic;
|
|||||||
use app\statistics\logic\ProductLogic;
|
use app\statistics\logic\ProductLogic;
|
||||||
use app\statistics\logic\UserLogic;
|
use app\statistics\logic\UserLogic;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use think\facade\Db;
|
||||||
|
|
||||||
class IndexController extends BaseLikeController
|
class IndexController extends BaseLikeController
|
||||||
{
|
{
|
||||||
@ -33,50 +34,15 @@ class IndexController extends BaseLikeController
|
|||||||
if (OrderLogic::hasError()) {
|
if (OrderLogic::hasError()) {
|
||||||
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
|
return $this->fail(OrderLogic::getError()); //获取错误信息并返回错误信息
|
||||||
}
|
}
|
||||||
switch ($store_id) {
|
if ($store_id) {
|
||||||
case 1:
|
$name = SystemStore::where('id', $store_id)->value('name');
|
||||||
$title = '喻寺镇农(特)产品交易大数据';
|
$title = $name . '农(特)产品交易大数据';
|
||||||
break;
|
} else {
|
||||||
case 2:
|
|
||||||
$title = '立石镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$title = '百和镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$title = '得胜镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
$title = '玄滩镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
$title = '牛滩镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
$title = '云锦镇农(特)产品交易大数据';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$title = '泸县农(特)产品交易大数据';
|
$title = '泸县农(特)产品交易大数据';
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
|
return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 门店统计
|
|
||||||
*/
|
|
||||||
public function sotre_count()
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
['street_name' => '喻寺镇', 'merchant_count' => 1],
|
|
||||||
['street_name' => '立石镇', 'merchant_count' => 1],
|
|
||||||
['street_name' => '百和镇', 'merchant_count' => 1],
|
|
||||||
['street_name' => '得胜镇', 'merchant_count' => 1],
|
|
||||||
['street_name' => '玄滩镇', 'merchant_count' => 1],
|
|
||||||
['street_name' => '云锦镇', 'merchant_count' => 1],
|
|
||||||
];
|
|
||||||
return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地方商品数量统计
|
* 地方商品数量统计
|
||||||
@ -126,6 +92,7 @@ class IndexController extends BaseLikeController
|
|||||||
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
|
return $this->fail(UserLogic::getError()); //获取错误信息并返回错误信息
|
||||||
}
|
}
|
||||||
$res['date']=$dates_two;
|
$res['date']=$dates_two;
|
||||||
|
$res['dayPayPrice']=Db::name('demo_order_money')->where($where)->sum('money');
|
||||||
return $this->success('ok', $res);
|
return $this->success('ok', $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ class ProductLogic extends BaseLogic
|
|||||||
$yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count();
|
$yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count();
|
||||||
$todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count();
|
$todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count();
|
||||||
$yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
$yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count();
|
||||||
|
$where['id']=$where['store_id'];
|
||||||
|
unset($where['store_id']);
|
||||||
} else {
|
} else {
|
||||||
$todayProductCount = StoreProduct::whereDay('create_time', $time)->count();
|
$todayProductCount = StoreProduct::whereDay('create_time', $time)->count();
|
||||||
$yestertodayProductCount = StoreProduct::count();
|
$yestertodayProductCount = StoreProduct::count();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user