链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

136 lines
4.9 KiB

<?php
namespace App\Admin\Controllers\v3;
use App\Admin\Actions\Grid\v3\DataReportOption;
use App\Admin\Actions\Tools\GoodsReportExport;
use App\Admin\Common\Auth;
use App\Admin\Repositories\v3\GoodsReport;
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\Grid\Filter;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
class GoodsReportController 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()
{
$this->marketId = Auth::getMarket();
if($this->marketId){
$this->newParams = ['market_id'=>$this->marketId];
$builder = new GoodsReport($this->newParams);
$this->marketList = MarketModel::getMarketArray([['id','=',$this->marketId]]);
$this->storeList = StoreModel::getStoreArray([['market_id','=',$this->marketId]]);
}else{
$builder = new GoodsReport();
$this->marketList = MarketModel::getMarketArray();
$this->storeList = StoreModel::getStoreArray();
}
return Grid::make($builder, 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('number');
$grid->column('created_at')->display(function($createdAt){
return date('Y-m-d H:I:s',$createdAt) ?? '';
});
$grid->column('global_order_id')->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('goods_id','商品ID')->width(2);
$filter->equal('name','商品名称')->width(2);
if(!$this->marketId){
$filter->equal('market_id','市场')->select($marketList)->width(2);
}
$filter->equal('store_id','店铺')->select($storeList)->width(2);
});
$grid->tools([
new DataReportOption('today','goods_report','今日'),
new DataReportOption('yesterday','goods_report','昨日'),
new DataReportOption('this_week','goods_report','本周'),
new DataReportOption('last_week','goods_report','上周'),
new DataReportOption('this_month','goods_report','本月'),
new DataReportOption('last_month','goods_report','上月'),
new GoodsReportExport()
]);
// 每页1条
$grid->paginate(10);
$grid->disableCreateButton();
$grid->disableBatchActions();
$grid->disableBatchDelete();
$grid->toolsWithOutline();
$grid->disableDeleteButton();
$grid->disableEditButton();
$grid->disableQuickEditButton();
$grid->disableViewButton();
$grid->disableActions();
$grid->disableRowSelector();
});
}
/**
* 数据导出
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
*/
public function export(Request $request)
{
$this->marketId = Auth::getMarket();
$params = [
'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\GoodsSales($params);
if(empty($data)){
return $this->error('没有数据!');
}
return Excel::download($data, $name.'.xlsx');
}
}