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('purchase_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('goods_id','活动商品ID')->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("{$title}","{$value}"); // $card->style('background-color:#4e9876'); // $column->row($card); // }); // $row->column(2,function (Column $column){ // $title = "总补贴金额(元)"; // $value = 56.23; // $card = Card::make("{$title}","{$value}"); // $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'); } }