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.
135 lines
5.1 KiB
135 lines
5.1 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers\v3;
|
|
|
|
use App\Admin\Actions\Grid\v3\DataReportOption;
|
|
use App\Admin\Actions\Tools\OrderDeliveryExport;
|
|
use App\Admin\Common\Auth;
|
|
use App\Admin\Renderable\OrderDeliveryById;
|
|
use App\Admin\Repositories\v3\OrderDeliveryReport;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use Dcat\Admin\Grid\Filter;
|
|
use Illuminate\Http\Request;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use App\Models\v3\Market as MarketModel;
|
|
use App\Models\ImsCjdcUser as UserModel;
|
|
|
|
class OrderDeliveryReportController extends AdminController
|
|
{
|
|
/**
|
|
* 订单的配送统计
|
|
*/
|
|
protected $GoodsActivityReport = null;
|
|
public $marketId = 0;
|
|
public $newParams = [];
|
|
public $marketList = [];
|
|
public $storeList = [];
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$this->marketId = Auth::getMarket();
|
|
|
|
if($this->marketId){
|
|
$this->newParams = ['market_id'=>$this->marketId];
|
|
$builder = new OrderDeliveryReport($this->newParams);
|
|
$this->marketList = MarketModel::getMarketArray([['id','=',$this->marketId]]);
|
|
}else{
|
|
$builder = new OrderDeliveryReport();
|
|
$this->marketList = MarketModel::getMarketArray();
|
|
}
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
$marketList = $this->marketList;
|
|
$grid->column('horseman_id','ID');
|
|
$grid->column('user_id','懒ID');
|
|
$grid->column('avatar','微信头像')->display(function(){
|
|
$userId = $this->user_id ?? 0;
|
|
$item = UserModel::select('avatar')->find($userId);
|
|
return $item['avatar'] ?? '';
|
|
})->image('',50);
|
|
$grid->column('name','姓名');
|
|
|
|
$grid->column('market_id','市场')->display(function($marketId) use($marketList){
|
|
return $marketList[$marketId] ?? '';
|
|
});
|
|
|
|
$grid->column('total_number','配送单数')
|
|
->modal(function($modal){
|
|
$name = $this->name;
|
|
$modal->title($name.'的配送明细');
|
|
$startTime = request()->input('start_time') ?? null;
|
|
$endTime = request()->input('end_time') ?? null;
|
|
$table = OrderDeliveryById::make(['horseman_id'=>$this->horseman_id,'start_time'=>$startTime, 'end_time'=>$endTime]);
|
|
return $table;
|
|
})->help('只统计2020年10月01日之后(包括10月01日)的数据');
|
|
$grid->column('total_delivery','总配送费');
|
|
|
|
$grid->filter(function (Filter $filter) use($marketList) {
|
|
// 更改为 panel 布局
|
|
$filter->panel();
|
|
$filter->equal('start_time','开始时间')->date()->width(2);
|
|
$filter->equal('end_time','结束时间')->date()->width(2);
|
|
$filter->equal('horseman_id','配送员ID')->width(2);
|
|
$filter->equal('user_id','懒ID')->width(2);
|
|
$filter->equal('name','姓名')->width(2);
|
|
if(!$this->marketId){
|
|
$filter->equal('market_id','市场')->select($marketList)->width(2);
|
|
}
|
|
});
|
|
|
|
$grid->tools([
|
|
new DataReportOption('today','delivery_report','今日'),
|
|
new DataReportOption('yesterday','delivery_report','昨日'),
|
|
new DataReportOption('this_week','delivery_report','本周'),
|
|
new DataReportOption('last_week','delivery_report','上周'),
|
|
new DataReportOption('this_month','delivery_report','本月'),
|
|
new DataReportOption('last_month','delivery_report','上月'),
|
|
new OrderDeliveryExport()
|
|
]);
|
|
|
|
// 每页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 = [
|
|
'horseman_id' => request()->input('horseman_id', 0),
|
|
'market_id' => $this->marketId ? $this->marketId : request()->input('market_id',0),
|
|
'user_id' => request()->input('user_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\OrderDelivery($params);
|
|
if(empty($data)){
|
|
return $this->error('没有数据!');
|
|
}
|
|
return Excel::download($data, $name.'.xlsx');
|
|
}
|
|
}
|