Browse Source
Merge branch 'goods_activity_1020'
Merge branch 'goods_activity_1020'
# Conflicts: # app/Admin/Actions/Exporter/GoodsActivitySales.phpmaster
16 changed files with 1324 additions and 4 deletions
-
65app/Admin/Actions/Exporter/GoodsActivitySales.php
-
113app/Admin/Actions/Grid/v3/DataReportOption.php
-
84app/Admin/Actions/Tools/GoodsActivityExport.php
-
1app/Admin/Controllers/v3/GoodsActivityController.php
-
180app/Admin/Controllers/v3/GoodsActivityReportController.php
-
6app/Admin/Controllers/v3/OrderReportController.php
-
128app/Admin/Repositories/v3/GoodsActivityReport.php
-
194app/Admin/Widgets/Charts/OrderGoodsActivityColumnChart.php
-
182app/Admin/Widgets/Charts/OrderGoodsActivityCountChart.php
-
160app/Admin/Widgets/Charts/OrderGoodsActivityMarketChart.php
-
179app/Admin/Widgets/Charts/OrderGoodsActivityTotalChart.php
-
3app/Admin/routes.php
-
6app/Models/ImsCjdcOrder.php
-
7app/Models/LanzuOrderGoods.php
-
19resources/lang/zh-CN/goods-activity-report.php
-
1resources/lang/zh-CN/goods-activity.php
@ -0,0 +1,65 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Exporter; |
||||
|
|
||||
|
use Maatwebsite\Excel\Concerns\FromArray; |
||||
|
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; |
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
|
||||
|
class GoodsActivitySales implements FromArray, WithStrictNullComparison |
||||
|
{ |
||||
|
protected $params = []; |
||||
|
public function __construct($params) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
public function array(): array |
||||
|
{ |
||||
|
$result = [[ |
||||
|
'商品ID', |
||||
|
'商品名称', |
||||
|
'市场', |
||||
|
'店铺', |
||||
|
'售价(元)', |
||||
|
'原价(元)', |
||||
|
'销量(单)', |
||||
|
'补贴(元)', |
||||
|
]]; |
||||
|
$data = $this->getData($this->params); |
||||
|
$markets = MarketModel::getMarketArray(); |
||||
|
$stores = StoreModel::getStoreArray(); |
||||
|
foreach ($data as $value){ |
||||
|
$item = [ |
||||
|
$value['goods_id'], |
||||
|
$value['name']??'', |
||||
|
$markets[$value['market_id']]??'', |
||||
|
$stores[$value['store_id']]??'', |
||||
|
$value['price']??0, |
||||
|
$value['original_price']??0, |
||||
|
$value['total']??0, |
||||
|
$value['subsidy_total']??0 |
||||
|
]; |
||||
|
|
||||
|
$result[] = $item; |
||||
|
} |
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取数据 |
||||
|
*/ |
||||
|
public function getData($option = []) |
||||
|
{ |
||||
|
$params = $option; |
||||
|
$repository = new GoodsActivityReport(); |
||||
|
$selects = 'SUM(number) as total,SUM((original_price-price)*number) as subsidy_total,price,original_price,lanzu_order_goods.goods_id,lanzu_order_goods.name,lanzu_order_goods.cover_img,lanzu_order_main.market_id,lanzu_order.store_id'; |
||||
|
$orderGoodsActivity = $repository->getDataModel($selects,$params); |
||||
|
$list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id','price','original_price')->get()->toArray(); |
||||
|
|
||||
|
return $list; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,113 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Tree\AbstractTool; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class DataReportOption extends AbstractTool |
||||
|
{ |
||||
|
protected $url; |
||||
|
protected $option; |
||||
|
protected $title = ''; |
||||
|
|
||||
|
public function __construct($option = '', $url = '', $title = '') |
||||
|
{ |
||||
|
$this->option = $option; |
||||
|
$this->url = $url; |
||||
|
$this->title = $title; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// $date = $this->getDataByOption($this->option);
|
||||
|
// $startTime = $date['start'] ?? '';
|
||||
|
// $endTime = $date['end'] ?? '';
|
||||
|
return $this->response() |
||||
|
->success('查询中~'); |
||||
|
// ->redirect('/'.$this->url.'?start_time='.$startTime.'&end_time='.$endTime);
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected function html() |
||||
|
{ |
||||
|
$date = $this->getDataByOption($this->option); |
||||
|
$startTime = $date['start'] ?? ''; |
||||
|
$endTime = $date['end'] ?? ''; |
||||
|
$url = 'admin/'.$this->url.'?start_time='.$startTime.'&end_time='.$endTime; |
||||
|
$this->defaultHtmlAttribute('href', url($url)); |
||||
|
|
||||
|
return <<<HTML |
||||
|
<a {$this->formatHtmlAttributes()}>{$this->title()}</a> |
||||
|
HTML; |
||||
|
} |
||||
|
|
||||
|
public function getDataByOption($option) |
||||
|
{ |
||||
|
$date = ['start','end']; |
||||
|
$today = date('Y-m-d'); |
||||
|
switch($option){ |
||||
|
case 'today': |
||||
|
$date['start'] = $today; |
||||
|
$date['end'] = $today; |
||||
|
break; |
||||
|
case 'yesterday': |
||||
|
$yesterday = date("Y-m-d",strtotime("-1 days",time())); |
||||
|
$date['start'] = $yesterday; |
||||
|
$date['end'] = $yesterday; |
||||
|
break; |
||||
|
case 'this_week': |
||||
|
$first=1; |
||||
|
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
|
||||
|
$w=date('w',strtotime($today)); |
||||
|
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
|
||||
|
$week_start=date('Y-m-d',strtotime("$today -".($w ? $w - $first : 6).' days')); |
||||
|
//本周结束日期
|
||||
|
$week_end=date('Y-m-d',strtotime("$week_start +6 days")); |
||||
|
$date['start'] = $week_start; |
||||
|
$date['end'] = $week_end; |
||||
|
break; |
||||
|
case 'last_week': |
||||
|
// 上周日
|
||||
|
$lastSunday = date('Y-m-d', strtotime('-1 sunday', time())); |
||||
|
// 上周一
|
||||
|
$lastMonday = date('Y-m-d', strtotime('-1 monday', strtotime($lastSunday))); |
||||
|
|
||||
|
$date['start'] = $lastMonday; |
||||
|
$date['end'] = $lastSunday; |
||||
|
break; |
||||
|
case 'this_month': |
||||
|
$thisMonthStart = date('Y-m-01', strtotime($today)); |
||||
|
$thisMonthEnd = date('Y-m-d', strtotime($today)); |
||||
|
|
||||
|
$date['start'] = $thisMonthStart; |
||||
|
$date['end'] = $thisMonthEnd; |
||||
|
break; |
||||
|
case 'last_month': |
||||
|
//上月初
|
||||
|
$lastMonthStart = date('Y-m-d', strtotime('-1 month', strtotime(date('Y-m', time()) . '-01'))); |
||||
|
// 上月底
|
||||
|
$lastMonthEnd = date('Y-m-d', strtotime(date('Y-m', time()) . '-01') - 86400); |
||||
|
|
||||
|
$date['start'] = $lastMonthStart; |
||||
|
$date['end'] = $lastMonthEnd; |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
return $date; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Tools; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Dcat\Admin\Tree\AbstractTool; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class GoodsActivityExport extends AbstractTool |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = '<span class="feather icon-download">导出<span>'; |
||||
|
|
||||
|
/** |
||||
|
* Handle the action request. |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
$url = '/goods_activity_export?'; |
||||
|
$name = $request->get('name', ''); |
||||
|
$marketId = $request->get('market_id',0); |
||||
|
$storeId = $request->get('store_id',0); |
||||
|
$startTime = $request->get('start_time',''); |
||||
|
$endTime = $request->get('end_time',''); |
||||
|
|
||||
|
if(!empty($name)){ |
||||
|
$url .= '&name='.$name; |
||||
|
} |
||||
|
if(!empty($marketId)){ |
||||
|
$url .= '&market_id='.$marketId; |
||||
|
} |
||||
|
if(!empty($storeId)){ |
||||
|
$url .= '&store_id='.$storeId; |
||||
|
} |
||||
|
if(!empty($startTime)){ |
||||
|
$url .= '&start_time='.$startTime; |
||||
|
} |
||||
|
|
||||
|
if(!empty($endTime)){ |
||||
|
$url .= '&end_time='.$endTime; |
||||
|
} |
||||
|
return $this->response() |
||||
|
->success('导出中~') |
||||
|
->redirect($url); |
||||
|
} |
||||
|
public function parameters() |
||||
|
{ |
||||
|
return [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* @return string|array|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '确定导出数据吗?'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @param Model|Authenticatable|HasPermissions|null $user |
||||
|
* |
||||
|
* @return bool |
||||
|
*/ |
||||
|
protected function authorize($user): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,180 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers\v3; |
||||
|
|
||||
|
use App\Admin\Actions\Grid\v3\DataReportOption; |
||||
|
use App\Admin\Actions\Tools\GoodsActivityExport; |
||||
|
use App\Admin\Common\Auth; |
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use App\Admin\Widgets\Charts\OrderGoodsActivityCountChart; |
||||
|
use App\Admin\Widgets\Charts\OrderGoodsActivityMarketChart; |
||||
|
use App\Admin\Widgets\Charts\OrderGoodsActivityTotalChart; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Controllers\AdminController; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
use App\Models\v3\Store as StoreModel; |
||||
|
use Dcat\Admin\Layout\Column; |
||||
|
use Dcat\Admin\Grid\Filter; |
||||
|
use Dcat\Admin\Layout\Content; |
||||
|
use Dcat\Admin\Layout\Row; |
||||
|
use Dcat\Admin\Widgets\Card; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Maatwebsite\Excel\Facades\Excel; |
||||
|
|
||||
|
class GoodsActivityReportController extends AdminController |
||||
|
{ |
||||
|
protected $GoodsActivityReport = null; |
||||
|
public $marketId = 0; |
||||
|
public $newParams = []; |
||||
|
public $marketList = []; |
||||
|
public $storeList = []; |
||||
|
public function __construct() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
|
||||
|
return Grid::make($this->GoodsActivityReport, function (Grid $grid) { |
||||
|
$marketList = $this->marketList; |
||||
|
$storeList = $this->storeList; |
||||
|
$grid->column('goods_id')->sortable(); |
||||
|
$grid->column('cover_img')->image('',50); |
||||
|
$grid->column('name','商品名称'); |
||||
|
|
||||
|
$grid->column('market_id')->display(function($marketId){ |
||||
|
$item = MarketModel::getMarketInfo($marketId,'name'); |
||||
|
return $item->name ?? ''; |
||||
|
}); |
||||
|
$grid->column('store_id')->display(function($storeId){ |
||||
|
$item = StoreModel::getStoreInfo($storeId,'name'); |
||||
|
return $item->name ?? ''; |
||||
|
})->width('12%'); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('original_price'); |
||||
|
$grid->column('total','销量'); |
||||
|
$grid->column('subsidy_total','补贴')->help('(原价-售价)* 销量'); |
||||
|
|
||||
|
$grid->filter(function (Filter $filter) use($marketList,$storeList) { |
||||
|
// 更改为 panel 布局
|
||||
|
$filter->panel(); |
||||
|
$filter->equal('start_time','开始时间')->date()->width(2); |
||||
|
$filter->equal('end_time','结束时间')->date()->width(2); |
||||
|
$filter->equal('name','商品名称')->width(3); |
||||
|
if(!$this->marketId){ |
||||
|
$filter->equal('market_id','市场')->select($marketList)->width(2); |
||||
|
} |
||||
|
$filter->equal('store_id','店铺')->select($storeList)->width(3); |
||||
|
}); |
||||
|
|
||||
|
$grid->tools([ |
||||
|
new DataReportOption('today','goods_activity_report','今日'), |
||||
|
new DataReportOption('yesterday','goods_activity_report','昨日'), |
||||
|
new DataReportOption('this_week','goods_activity_report','本周'), |
||||
|
new DataReportOption('last_week','goods_activity_report','上周'), |
||||
|
new DataReportOption('this_month','goods_activity_report','本月'), |
||||
|
new DataReportOption('last_month','goods_activity_report','上月'), |
||||
|
new GoodsActivityExport() |
||||
|
]); |
||||
|
|
||||
|
// 每页1条
|
||||
|
$grid->paginate(10); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableBatchActions(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
|
||||
|
$grid->toolsWithOutline(); |
||||
|
|
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableEditButton(); |
||||
|
$grid->disableQuickEditButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableActions(); |
||||
|
|
||||
|
$grid->disableRowSelector(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 页面 |
||||
|
*/ |
||||
|
public function index(Content $content) |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
|
||||
|
if($this->marketId){ |
||||
|
$this->newParams = ['market_id'=>$this->marketId]; |
||||
|
$this->GoodsActivityReport = new GoodsActivityReport($this->newParams); |
||||
|
$this->marketList = MarketModel::getMarketArray([['id','=',$this->marketId]]); |
||||
|
$this->storeList = StoreModel::getStoreArray([['market_id','=',$this->marketId]]); |
||||
|
}else{ |
||||
|
$this->GoodsActivityReport = new GoodsActivityReport(); |
||||
|
$this->marketList = MarketModel::getMarketArray(); |
||||
|
$this->storeList = StoreModel::getStoreArray(); |
||||
|
} |
||||
|
|
||||
|
return $content->title('活动商品统计') |
||||
|
->body(function(Row $row){ |
||||
|
// $row->column(2,function (Column $column){
|
||||
|
// $title = "销售总数量(单)";
|
||||
|
// $value = 123;
|
||||
|
// $card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
||||
|
// $card->style('background-color:#4e9876');
|
||||
|
// $column->row($card);
|
||||
|
// });
|
||||
|
// $row->column(2,function (Column $column){
|
||||
|
// $title = "总补贴金额(元)";
|
||||
|
// $value = 56.23;
|
||||
|
// $card = Card::make("<span style='color: #ffffff'>{$title}</span>","<span style='color: #ffffff'>{$value}</span>");
|
||||
|
// $card->style('background-color:#4e9876');
|
||||
|
// $column->row($card);
|
||||
|
// });
|
||||
|
$marketData = $this->GoodsActivityReport->getMarketData($this->newParams); |
||||
|
$totalData = $this->GoodsActivityReport->getCountData($this->newParams); |
||||
|
|
||||
|
$totalParams = [ |
||||
|
'list' => $totalData, |
||||
|
]; |
||||
|
$marketParams = [ |
||||
|
'list' => $marketData, |
||||
|
'markets' => $this->marketList |
||||
|
]; |
||||
|
|
||||
|
$row->column(4,new OrderGoodsActivityTotalChart($totalParams)); |
||||
|
$row->column(4,new OrderGoodsActivityCountChart($totalParams)); |
||||
|
$row->column(4,new OrderGoodsActivityMarketChart($marketParams)); |
||||
|
}) |
||||
|
->body(function(Row $row){ |
||||
|
$row->column(12,$this->grid()); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 数据导出 |
||||
|
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||||
|
*/ |
||||
|
public function export(Request $request) |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
$params = [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
|
||||
|
$name = date('Y-m-d-His',time()); |
||||
|
$data = new \App\Admin\Actions\Exporter\GoodsActivitySales($params); |
||||
|
if(empty($data)){ |
||||
|
return $this->error('没有数据!'); |
||||
|
} |
||||
|
return Excel::download($data, $name.'.xlsx'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,128 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories\v3; |
||||
|
|
||||
|
use App\Models\LanzuOrderGoods as Model; |
||||
|
use Dcat\Admin\Grid\Model as GridModel; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class GoodsActivityReport extends EloquentRepository |
||||
|
{ |
||||
|
public $params = []; |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
|
||||
|
public function __construct($params = []) |
||||
|
{ |
||||
|
$this->params = $params; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取统计列表数据 |
||||
|
*/ |
||||
|
public function get(GridModel $model) |
||||
|
{ |
||||
|
// 获取当前页数
|
||||
|
$currentPage = $model->getCurrentPage(); |
||||
|
// 获取每页显示行数
|
||||
|
$perPage = $model->getPerPage(); |
||||
|
|
||||
|
$where = []; |
||||
|
if(!empty($this->params) && isset($this->params['market_id']) && !empty($this->params['market_id'])){ |
||||
|
$where = ['market_id'=>$this->params['market_id']]; |
||||
|
} |
||||
|
|
||||
|
$selects = 'SUM(number) as total,SUM((original_price-price)*number) as subsidy_total,price,original_price,lanzu_order_goods.goods_id,lanzu_order_goods.name,lanzu_order_goods.cover_img,lanzu_order_main.market_id,lanzu_order.store_id'; |
||||
|
$orderGoodsActivity = $this->getDataModel($selects,$where); |
||||
|
$list = $orderGoodsActivity->orderBy('total','desc')->groupBy('goods_id','lanzu_order_goods.name','cover_img','market_id','store_id','price','original_price')->paginate($perPage); |
||||
|
$list = $list->toArray(); |
||||
|
|
||||
|
return $model->makePaginator( |
||||
|
$list['total'] ?? 0,$list['data'] ?? [] |
||||
|
); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public function getDataModel($selects,$params = []) |
||||
|
{ |
||||
|
$time = date('Y-m-d',time()); |
||||
|
// 获取筛选参数
|
||||
|
$name = $params['name'] ?? request()->input('name', ''); |
||||
|
$marketId = $params['market_id'] ?? request()->input('market_id',0); |
||||
|
$storeId = $params['store_id'] ?? request()->input('store_id',0); |
||||
|
|
||||
|
$startTime = $params['start_time'] ?? request()->input('start_time',''); |
||||
|
$endTime = $params['end_time'] ?? request()->input('end_time',''); |
||||
|
|
||||
|
$orderGoodsActivity = Model::select(DB::raw($selects)) |
||||
|
->join('lanzu_order','lanzu_order_goods.order_id','=','lanzu_order.id') |
||||
|
->join('lanzu_order_main','lanzu_order.order_main_id','=','lanzu_order_main.global_order_id') |
||||
|
->where('lanzu_order_goods.activity_type',2) |
||||
|
->where('lanzu_order_goods.status',1) |
||||
|
->whereIn('lanzu_order_main.state',[4,5,10,11]); |
||||
|
|
||||
|
if($name){ |
||||
|
$orderGoodsActivity->where('lanzu_order_goods.name','like',"%$name%"); |
||||
|
} |
||||
|
if($marketId){ |
||||
|
$orderGoodsActivity->where('market_id',$marketId); |
||||
|
} |
||||
|
if($storeId){ |
||||
|
$orderGoodsActivity->where('store_id',$storeId); |
||||
|
} |
||||
|
if($startTime){ |
||||
|
$date = $startTime; |
||||
|
$startTime = $startTime.' 00:00:00'; |
||||
|
|
||||
|
$orderGoodsActivity->where('lanzu_order_goods.created_at','>=',strtotime($startTime)); |
||||
|
}else{ |
||||
|
$date = '2020-06-01'; |
||||
|
} |
||||
|
if($endTime){ |
||||
|
$date = $date.' 至 '.$endTime; |
||||
|
$endTime = $endTime.' 23:59:59'; |
||||
|
|
||||
|
$orderGoodsActivity->where('lanzu_order_goods.created_at','<=',strtotime($endTime)); |
||||
|
}else{ |
||||
|
$date .= ' 至 '.$time; |
||||
|
} |
||||
|
// if(empty($startTime) && empty($endTime)){
|
||||
|
// $date = $time;
|
||||
|
// $todayStart = $time.' 00:00:00';
|
||||
|
// $todayEnd = $time.' 23:59:59';
|
||||
|
// $orderGoodsActivity->where([['lanzu_order_goods.created_at','>=',strtotime($todayStart)]]);
|
||||
|
// $orderGoodsActivity->where([['lanzu_order_goods.created_at','<=',strtotime($todayEnd)]]);
|
||||
|
// }
|
||||
|
|
||||
|
return $orderGoodsActivity; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取总数 |
||||
|
*/ |
||||
|
public function getCountData($params = []) |
||||
|
{ |
||||
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,FROM_UNIXTIME(lanzu_order_goods.created_at,'%Y-%m-%d') as dtime"; |
||||
|
$orderGoodsActivity = $this->getDataModel($selects,$params); |
||||
|
$total = $orderGoodsActivity->orderBy('dtime','asc')->groupBy('dtime')->get()->toArray(); |
||||
|
|
||||
|
return $total ?? []; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 分市场获取 |
||||
|
*/ |
||||
|
public function getMarketData($params = []) |
||||
|
{ |
||||
|
$selects = "SUM(lanzu_order_goods.number) as total,SUM((original_price-price)*number) as subsidy_total,market_id"; |
||||
|
$orderGoodsActivity = $this->getDataModel($selects,$params); |
||||
|
$total = $orderGoodsActivity->groupBy('market_id')->get()->toArray(); |
||||
|
|
||||
|
return $total ?? []; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,194 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Widgets\Charts; |
||||
|
|
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Support\JavaScript; |
||||
|
use Dcat\Admin\Widgets\ApexCharts\Chart; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class OrderGoodsActivityColumnChart extends Chart |
||||
|
{ |
||||
|
protected $categories = [ |
||||
|
'商品1', '商品2', '商品3', '商品4', '商品5', '商品6', '商品7', '商品8', '商品9', '商品10' |
||||
|
// ,'商品11', '商品12', '商品13', '商品14', '商品15', '商品16', '商品17', '商品18', '商品19', '商品20'
|
||||
|
]; |
||||
|
protected $data = []; |
||||
|
protected $id; |
||||
|
protected $option; |
||||
|
|
||||
|
public function __construct($data = [], $containerSelector = null, $options = []) |
||||
|
{ |
||||
|
$this->option = $this->id = 7; |
||||
|
$this->data = $data; |
||||
|
parent::__construct($containerSelector, $options); |
||||
|
|
||||
|
$this->setUpOptions(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 初始化图表配置 |
||||
|
*/ |
||||
|
protected function setUpOptions() |
||||
|
{ |
||||
|
$color = Admin::color(); |
||||
|
|
||||
|
$this->options([ |
||||
|
'chart' => [ |
||||
|
'type' => 'bar', |
||||
|
'height'=> 350, |
||||
|
], |
||||
|
'colors' => [ |
||||
|
'#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B', '#2b908f', '#f9a3a4', '#90ee7e', '#f48024', '#69d2e7' |
||||
|
,'#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B', '#2b908f', '#f9a3a4', '#90ee7e', '#f48024', '#69d2e7' |
||||
|
], |
||||
|
'plotOptions'=> [ |
||||
|
'bar'=> [ |
||||
|
'distributed' =>false, // 柱状图颜色
|
||||
|
'horizontal' => false, // 竖直
|
||||
|
'columnWidth' => '50%', // 柱状宽
|
||||
|
'dataLabels' => [ |
||||
|
'position' => 'bottom' |
||||
|
] |
||||
|
] |
||||
|
], |
||||
|
'dataLabels' => [ |
||||
|
'enabled'=> true, |
||||
|
], |
||||
|
'xaxis' => [ |
||||
|
'categories' => $this->categories, |
||||
|
], |
||||
|
'yaxis' => [ |
||||
|
'axisBorder' => [ |
||||
|
'show' => true, |
||||
|
'color' => $color->primary() |
||||
|
], |
||||
|
'labels' => [ |
||||
|
'show' => true, |
||||
|
'style' => [ |
||||
|
'colors' => $color->primary() |
||||
|
] |
||||
|
], |
||||
|
'title' => [ |
||||
|
'text' => "销量", |
||||
|
'align' => 'center', |
||||
|
'style' => [ |
||||
|
'color' => $color->primary() |
||||
|
] |
||||
|
] |
||||
|
], |
||||
|
// 'tooltip' => [
|
||||
|
// 'x' => [
|
||||
|
// 'show' => true
|
||||
|
// ]
|
||||
|
// ]
|
||||
|
]); |
||||
|
$number = 10; |
||||
|
// $this->chartOption(
|
||||
|
// 'tooltip.y.formatter',
|
||||
|
// // 这个值最后段代码会作为JS代码执行
|
||||
|
// JavaScript::make("function (params, index) {
|
||||
|
// return params +'-'+ index;
|
||||
|
// }")
|
||||
|
// );
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* @return mixed|void |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
|
||||
|
switch ((int) $request->get('option')) { |
||||
|
case 30: |
||||
|
// 你的数据查询逻辑
|
||||
|
$data = [ |
||||
|
[ |
||||
|
'name' => '活动商品', |
||||
|
'data' => [54, 45, 41, 64, 22, 46, 52, 10, 9, 11, 54, 45, 41, 64, 22, 46, 52, 10, 9, 11] |
||||
|
] |
||||
|
]; |
||||
|
break; |
||||
|
case 28: |
||||
|
// 你的数据查询逻辑
|
||||
|
$data = [ |
||||
|
[ |
||||
|
'name' => '活动商品', |
||||
|
'data' => [44, 55, 41, 64, 22, 56, 52, 12, 52, 12, 44, 55, 41, 64, 22, 56, 52, 12, 52, 12] |
||||
|
] |
||||
|
]; |
||||
|
break; |
||||
|
case 7: |
||||
|
default: |
||||
|
// 你的数据查询逻辑
|
||||
|
$data = [ |
||||
|
[ |
||||
|
'name' => '活动商品', |
||||
|
'data' => [54, 45, 41, 64, 22, 46, 52, 10, 9, 11] |
||||
|
] |
||||
|
]; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
$this->withData($data); |
||||
|
} |
||||
|
/** |
||||
|
* 处理图表数据 |
||||
|
*/ |
||||
|
protected function buildData() |
||||
|
{ |
||||
|
// 执行你的数据查询逻辑
|
||||
|
$data = [ |
||||
|
[ |
||||
|
'name' => '活动商品', |
||||
|
'data' => [44, 55, 41, 64, 22, 56, 52, 12, 52, 12] |
||||
|
] |
||||
|
]; |
||||
|
$categories = $this->categories; |
||||
|
|
||||
|
$this->withData($data); |
||||
|
$this->withCategories($categories); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 这里返回需要异步传递到 handler 方法的参数 |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function parameters(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'id' => $this->id, |
||||
|
'option' => $this->option, |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置图表数据 |
||||
|
* |
||||
|
* @param array $data |
||||
|
* |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function withData(array $data) |
||||
|
{ |
||||
|
return $this->option('series', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染图表 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function render() |
||||
|
{ |
||||
|
$this->buildData(); |
||||
|
|
||||
|
return parent::render(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,182 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Widgets\Charts; |
||||
|
|
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Support\JavaScript; |
||||
|
use Dcat\Admin\Widgets\Metrics\Line; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Admin\Common\Auth; |
||||
|
|
||||
|
class OrderGoodsActivityCountChart extends Line |
||||
|
{ |
||||
|
/** |
||||
|
* 活动商品总数 |
||||
|
*/ |
||||
|
protected $categories = []; |
||||
|
protected $data = []; |
||||
|
protected $total = []; |
||||
|
protected $valueData = []; |
||||
|
protected $chartData = []; |
||||
|
protected $GoodsActivityReport = null; |
||||
|
protected $showNumber = 7; |
||||
|
|
||||
|
public function __construct($params = []) |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
|
||||
|
$data = $params['list'] ?? []; |
||||
|
|
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$subsidyTotal = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
|
||||
|
if($key < $this->showNumber){ |
||||
|
$this->data[] = $value['subsidy_total']; |
||||
|
$this->categories[] = $value['dtime']; |
||||
|
} |
||||
|
$subsidyTotal += $value['subsidy_total']; |
||||
|
} |
||||
|
$this->total['subsidy_total'] = $subsidyTotal; |
||||
|
} |
||||
|
|
||||
|
$this->chartData = [ |
||||
|
[ |
||||
|
'name' => '金额', |
||||
|
'data' => $this->data, |
||||
|
] |
||||
|
]; |
||||
|
|
||||
|
$color = Admin::color(); |
||||
|
// 设置标题
|
||||
|
$this->title('总补贴金额(元)'); |
||||
|
$this->subTitle('其中'.$this->showNumber.'天每天总补贴金额'); |
||||
|
$this->chartHeight(140); |
||||
|
|
||||
|
// 设置图表颜色
|
||||
|
$this->chartColors([$color->primary()]); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'tooltip.x', |
||||
|
['show' => true] |
||||
|
); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'tooltip.y.formatter', |
||||
|
JavaScript::make("function (params,index) {
|
||||
|
return params ; |
||||
|
}")
|
||||
|
); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'xaxis.type', |
||||
|
'category' |
||||
|
); |
||||
|
$this->chartOption( |
||||
|
'xaxis.categories', |
||||
|
$this->categories |
||||
|
); |
||||
|
$this->withContent($this->total); |
||||
|
$this->withChart($this->chartData); |
||||
|
$this->withCategories($this->categories); |
||||
|
} |
||||
|
|
||||
|
protected function init() |
||||
|
{ |
||||
|
parent::init(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* @return mixed|void |
||||
|
*/ |
||||
|
public function handleBar(Request $request) |
||||
|
{ |
||||
|
// $this->GoodsActivityReport = new GoodsActivityReport($data);
|
||||
|
|
||||
|
// 数据查询逻辑
|
||||
|
// 分页的时候不重复查询数据
|
||||
|
$currentPage = request()->input('page', 1); |
||||
|
if($currentPage == 1){ |
||||
|
$params = $this->parameters(); |
||||
|
$data = $this->GoodsActivityReport->getCountData($params); |
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$subsidyTotal = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
if($key < $this->showNumber){ |
||||
|
$this->data[] = $value['subsidy_total']; |
||||
|
$this->categories[] = $value['dtime']; |
||||
|
} |
||||
|
$subsidyTotal += $value['subsidy_total']; |
||||
|
} |
||||
|
$this->total['subsidy_total'] = $subsidyTotal; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
$data = $this->data; |
||||
|
$categories = $this->categories; |
||||
|
$chartData = [ |
||||
|
[ |
||||
|
'name' => '金额', |
||||
|
'data' => $data, |
||||
|
] |
||||
|
]; |
||||
|
$this->withContent($this->total); |
||||
|
$this->withChart($chartData); |
||||
|
$this->withCategories($categories); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 这里返回需要异步传递到 handler 方法的参数 |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function parameters(): array |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
return [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* 设置图表数据. |
||||
|
* |
||||
|
* @param array $data |
||||
|
* |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function withChart(array $data) |
||||
|
{ |
||||
|
return $this->chart([ |
||||
|
'series' => $data, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染卡片内容. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function withContent($total = []) |
||||
|
{ |
||||
|
$content = $total['subsidy_total'] ??0; |
||||
|
return $this->content( |
||||
|
<<<HTML |
||||
|
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> |
||||
|
<h2 class="ml-1 font-lg-1">{$content}</h2> |
||||
|
<!-- <span class="mb-0 mr-1 text-80">{$this->title}</span> --> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,160 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Widgets\Charts; |
||||
|
|
||||
|
use App\Admin\Common\Auth; |
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use Dcat\Admin\Widgets\Metrics\Donut; |
||||
|
use Illuminate\Http\Request; |
||||
|
use App\Models\v3\Market as MarketModel; |
||||
|
|
||||
|
class OrderGoodsActivityMarketChart extends Donut |
||||
|
{ |
||||
|
/** |
||||
|
* 活动商品总数 |
||||
|
*/ |
||||
|
protected $labels = []; |
||||
|
protected $data = []; |
||||
|
protected $total = []; |
||||
|
protected $colors = []; |
||||
|
|
||||
|
protected $GoodsActivityReport = null; |
||||
|
protected $color = ['#33b2df', '#546E7A', '#d4526e', '#13d8aa', '#A5978B', '#2b908f', '#f9a3a4', '#90ee7e', '#f48024', '#69d2e7']; |
||||
|
|
||||
|
public function __construct($params = []) |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
|
||||
|
// $params = $this->parameters($params);
|
||||
|
|
||||
|
$data = $params['list'] ?? []; |
||||
|
$market = $params['markets'] ?? []; |
||||
|
|
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$total = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
$this->data[] = (int)$value['total']; |
||||
|
$this->labels[] = $market[$value['market_id']]??'未知'; |
||||
|
$this->colors[] = $this->color[$key]; |
||||
|
$total += $value['total']; |
||||
|
} |
||||
|
$this->total['number_total'] = $total; |
||||
|
} |
||||
|
|
||||
|
$this->chartLabels($this->labels); |
||||
|
$this->chartColors($this->colors); |
||||
|
// 数据查询逻辑
|
||||
|
$data = $this->data; |
||||
|
$this->withContent($data); |
||||
|
$this->withChart($data); |
||||
|
} |
||||
|
|
||||
|
protected function init() |
||||
|
{ |
||||
|
parent::init(); |
||||
|
// 设置标题
|
||||
|
$this->title('各市场销售量(单)'); |
||||
|
$this->subTitle('各市场销售量的占比图'); |
||||
|
$this->chartHeight(170); |
||||
|
$this->chartMarginTop(20); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* @return mixed|void |
||||
|
*/ |
||||
|
public function handleBar(Request $request) |
||||
|
{ |
||||
|
// $this->GoodsActivityReport = new GoodsActivityReport($params);
|
||||
|
// 分页的时候不重复查询数据
|
||||
|
// $currentPage = $params['page'] ?? 1;
|
||||
|
// if($currentPage == 1){
|
||||
|
// $data = $this->GoodsActivityReport->getMarketData($params);
|
||||
|
// $market = MarketModel::getMarketArray();
|
||||
|
// }else{
|
||||
|
// }
|
||||
|
// 分页的时候不重复查询数据
|
||||
|
$currentPage = $request->get('page'); |
||||
|
if($currentPage == 1){ |
||||
|
$params = $this->parameters(); |
||||
|
$data = $this->GoodsActivityReport->getMarketData($params); |
||||
|
$market = MarketModel::getMarketArray(); |
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$total = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
$this->data[] = (int)$value['total']; |
||||
|
$this->labels[] = $market[$value['market_id']]??'未知'; |
||||
|
$this->colors[] = $this->color[$key]; |
||||
|
$total += $value['total']; |
||||
|
} |
||||
|
$this->total['number_total'] = $total; |
||||
|
} |
||||
|
} |
||||
|
$this->chartLabels($this->labels); |
||||
|
$this->chartColors($this->colors); |
||||
|
// 数据查询逻辑
|
||||
|
$data = $this->data; |
||||
|
$this->withContent($data); |
||||
|
$this->withChart($data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 这里返回需要异步传递到 handler 方法的参数 |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function parameters($data = []): array |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
return [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
'data' => $data |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置图表数据. |
||||
|
* |
||||
|
* @param array $data |
||||
|
* |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function withChart(array $data) |
||||
|
{ |
||||
|
return $this->chart([ |
||||
|
'series' => $data, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染卡片内容. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function withContent($data = []) |
||||
|
{ |
||||
|
$div = ''; |
||||
|
$style = 'margin-bottom: 8px'; |
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
foreach($data as $key => $value){ |
||||
|
$div .= '<div class="d-flex pl-1 pr-1 pt-1" style="'.$style.'"><div style="width: 120px">
|
||||
|
<i class="fa fa-circle" style="color:'.$this->colors[$key].'"></i> '.$this->labels[$key].' |
||||
|
</div><div>'.$value.'</div></div>'; |
||||
|
} |
||||
|
} |
||||
|
return $this->content( |
||||
|
<<<HTML |
||||
|
{$div} |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,179 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Widgets\Charts; |
||||
|
|
||||
|
use App\Admin\Common\Auth; |
||||
|
use App\Admin\Repositories\v3\GoodsActivityReport; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Support\JavaScript; |
||||
|
use Dcat\Admin\Widgets\Metrics\Bar; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class OrderGoodsActivityTotalChart extends Bar |
||||
|
{ |
||||
|
/** |
||||
|
* 活动商品总数 |
||||
|
*/ |
||||
|
protected $categories = []; |
||||
|
protected $data = []; |
||||
|
protected $total = []; |
||||
|
protected $valueData = []; |
||||
|
protected $GoodsActivityReport = null; |
||||
|
protected $showNumber = 7; |
||||
|
|
||||
|
public function __construct($params = []) |
||||
|
{ |
||||
|
parent::__construct(); |
||||
|
|
||||
|
$data = $params['list'] ?? []; |
||||
|
|
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$total = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
if($key < $this->showNumber){ |
||||
|
$this->data[] = $value['total']; |
||||
|
$this->categories[] = $value['dtime']; |
||||
|
} |
||||
|
$total += $value['total']; |
||||
|
} |
||||
|
$this->total['number_total'] = $total; |
||||
|
} |
||||
|
|
||||
|
$categories = $this->categories; |
||||
|
$chartData = [ |
||||
|
[ |
||||
|
'name' => '销量', |
||||
|
'data' => $this->data, |
||||
|
] |
||||
|
]; |
||||
|
|
||||
|
$color = Admin::color(); |
||||
|
// 设置标题
|
||||
|
$this->title('销售总数量(单)'); |
||||
|
$this->subTitle('其中'.$this->showNumber.'天每天的销量'); |
||||
|
// 设置图表颜色
|
||||
|
$this->chartColors([$color->primary()]); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'tooltip.x', |
||||
|
['show' => true] |
||||
|
); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'tooltip.y.formatter', |
||||
|
JavaScript::make("function (params,index) {
|
||||
|
return params ; |
||||
|
}")
|
||||
|
); |
||||
|
|
||||
|
$this->chartOption( |
||||
|
'xaxis.type', |
||||
|
'category' |
||||
|
); |
||||
|
$this->chartOption( |
||||
|
'xaxis.categories', |
||||
|
$this->categories |
||||
|
); |
||||
|
|
||||
|
$this->withContent($this->total); |
||||
|
$this->withChart($chartData); |
||||
|
$this->withCategories($categories); |
||||
|
} |
||||
|
|
||||
|
protected function init() |
||||
|
{ |
||||
|
parent::init(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* @return mixed|void |
||||
|
*/ |
||||
|
public function handleBar(Request $request) |
||||
|
{ |
||||
|
// $this->GoodsActivityReport = new GoodsActivityReport($data);
|
||||
|
// 数据查询逻辑
|
||||
|
// 分页的时候不重复查询数据
|
||||
|
$currentPage = request()->input('page', 1); |
||||
|
if($currentPage == 1){ |
||||
|
$params = $this->parameters(); |
||||
|
$data = $this->GoodsActivityReport->getCountData($params); |
||||
|
if(!empty($data) && is_array($data)){ |
||||
|
$total = 0; |
||||
|
foreach($data as $key => $value){ |
||||
|
if($key < $this->showNumber){ |
||||
|
$this->data[] = $value['total']; |
||||
|
$this->categories[] = $value['dtime']; |
||||
|
} |
||||
|
$total += $value['total']; |
||||
|
} |
||||
|
$this->total['number_total'] = $total; |
||||
|
} |
||||
|
} |
||||
|
$categories = $this->categories; |
||||
|
$chartData = [ |
||||
|
[ |
||||
|
'name' => '销量', |
||||
|
'data' => $this->data, |
||||
|
] |
||||
|
]; |
||||
|
$this->withContent($this->total); |
||||
|
$this->withChart($chartData); |
||||
|
$this->withCategories($categories); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 这里返回需要异步传递到 handler 方法的参数 |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function parameters(): array |
||||
|
{ |
||||
|
$this->marketId = Auth::getMarket(); |
||||
|
return [ |
||||
|
'page' => request()->input('page', 1), |
||||
|
'name' => request()->input('name', ''), |
||||
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0), |
||||
|
'store_id' => request()->input('store_id',0), |
||||
|
'start_time' => request()->input('start_time',''), |
||||
|
'end_time' => request()->input('end_time',''), |
||||
|
]; |
||||
|
} |
||||
|
/** |
||||
|
* 设置图表数据. |
||||
|
* |
||||
|
* @param array $data |
||||
|
* |
||||
|
* @return $this |
||||
|
*/ |
||||
|
public function withChart(array $data) |
||||
|
{ |
||||
|
return $this->chart([ |
||||
|
'series' => $data, |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 渲染卡片内容. |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function withContent($total = []) |
||||
|
{ |
||||
|
$value = $total['number_total'] ?? 0; |
||||
|
$minHeight = '113px'; |
||||
|
return $this->content( |
||||
|
<<<HTML |
||||
|
<div class="d-flex p-1 flex-column justify-content-between" style="padding-top: 0;width: 100%;height: 100%;min-height: {$minHeight}"> |
||||
|
<div class="text-left"> |
||||
|
<h2 class="ml-1 font-lg-1">{$value}</h2> |
||||
|
</div> |
||||
|
</div> |
||||
|
HTML |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'GoodsActivityReport' => '活动商品统计报表', |
||||
|
'goods_activity_report' => '活动商品统计报表', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'goods_id' => 'ID', |
||||
|
'name' => '统计名称', |
||||
|
'cover_img' => '封面图', |
||||
|
'market_id' => '市场', |
||||
|
'store_id' => '店铺', |
||||
|
'price' => '售价', |
||||
|
'original_price' => '原价', |
||||
|
'total' => '统计数量', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue