链街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.

123 lines
4.2 KiB

  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Actions\Grid\v3\DataReportOption;
  4. use App\Admin\Actions\Tools\GoodsReportExport;
  5. use App\Admin\Common\Auth;
  6. use App\Admin\Repositories\v3\GoodsReport;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Controllers\AdminController;
  9. use App\Models\v3\Market as MarketModel;
  10. use App\Models\v3\Store as StoreModel;
  11. use Dcat\Admin\Grid\Filter;
  12. use Dcat\Admin\Layout\Content;
  13. use Dcat\Admin\Layout\Row;
  14. use Illuminate\Http\Request;
  15. use Maatwebsite\Excel\Facades\Excel;
  16. class GoodsReportController extends AdminController
  17. {
  18. protected $GoodsActivityReport = null;
  19. public $marketId = 0;
  20. public $newParams = [];
  21. public $marketList = [];
  22. public $storeList = [];
  23. public function __construct()
  24. {
  25. }
  26. /**
  27. * Make a grid builder.
  28. *
  29. * @return Grid
  30. */
  31. protected function grid()
  32. {
  33. return Grid::make(new GoodsReport(), function (Grid $grid) {
  34. $marketList = $this->marketList;
  35. $storeList = $this->storeList;
  36. $grid->column('goods_id')->sortable();
  37. $grid->column('cover_img')->image('',50);
  38. $grid->column('name','商品名称');
  39. $grid->column('market_id')->display(function($marketId){
  40. $item = MarketModel::getMarketInfo($marketId,'name');
  41. return $item->name ?? '';
  42. });
  43. $grid->column('store_id')->display(function($storeId){
  44. $item = StoreModel::getStoreInfo($storeId,'name');
  45. return $item->name ?? '';
  46. })->width('12%');
  47. $grid->column('price');
  48. $grid->column('original_price');
  49. $grid->column('total','销量');
  50. $grid->filter(function (Filter $filter) use($marketList,$storeList) {
  51. // 更改为 panel 布局
  52. $filter->panel();
  53. $filter->equal('start_time','开始时间')->date()->width(2);
  54. $filter->equal('end_time','结束时间')->date()->width(2);
  55. $filter->equal('name','商品名称')->width(3);
  56. if(!$this->marketId){
  57. $filter->equal('market_id','市场')->select($marketList)->width(2);
  58. }
  59. $filter->equal('store_id','店铺')->select($storeList)->width(3);
  60. });
  61. $grid->tools([
  62. new DataReportOption('today','goods_report','今日'),
  63. new DataReportOption('yesterday','goods_report','昨日'),
  64. new DataReportOption('this_week','goods_report','本周'),
  65. new DataReportOption('last_week','goods_report','上周'),
  66. new DataReportOption('this_month','goods_report','本月'),
  67. new DataReportOption('last_month','goods_report','上月'),
  68. new GoodsReportExport()
  69. ]);
  70. // 每页1条
  71. $grid->paginate(10);
  72. $grid->disableCreateButton();
  73. $grid->disableBatchActions();
  74. $grid->disableBatchDelete();
  75. $grid->toolsWithOutline();
  76. $grid->disableDeleteButton();
  77. $grid->disableEditButton();
  78. $grid->disableQuickEditButton();
  79. $grid->disableViewButton();
  80. $grid->disableActions();
  81. $grid->disableRowSelector();
  82. });
  83. }
  84. /**
  85. * 数据导出
  86. * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
  87. */
  88. public function export(Request $request)
  89. {
  90. $this->marketId = Auth::getMarket();
  91. $params = [
  92. 'page' => request()->input('page', 1),
  93. 'name' => request()->input('name', ''),
  94. 'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0),
  95. 'store_id' => request()->input('store_id',0),
  96. 'start_time' => request()->input('start_time',''),
  97. 'end_time' => request()->input('end_time',''),
  98. ];
  99. $name = date('Y-m-d-His',time());
  100. $data = new \App\Admin\Actions\Exporter\GoodsActivitySales($params);
  101. if(empty($data)){
  102. return $this->error('没有数据!');
  103. }
  104. return Excel::download($data, $name.'.xlsx');
  105. }
  106. }