2 changed files with 225 additions and 0 deletions
-
135app/Admin/Controllers/v3/ReportCommunityController.php
-
90app/Admin/Repositories/v3/ReportCommunity.php
@ -0,0 +1,135 @@ |
|||||
|
<?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 ReportCommunityController 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'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories\v3; |
||||
|
|
||||
|
use App\Models\ImsCjdcOrderMain as Model; |
||||
|
use Dcat\Admin\Grid\Model as GridModel; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use App\Models\v3\LanzuEmployees as EmployeesModel; |
||||
|
class ReportCommunity 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 = 'count('.Model::$tableName.'.id) AS total_number,horseman_id,'.EmployeesModel::TABLE_NAME.'.user_id,'.EmployeesModel::TABLE_NAME.'.name,'.EmployeesModel::TABLE_NAME.'.market_id,SUM( CASE WHEN delivery_money=0 THEN 3.5 when delivery_money>0 THEN delivery_money+3.5 ELSE 0 END) as total_delivery'; |
||||
|
$delivery = $this->getDataModel($selects,$where); |
||||
|
$list = $delivery->groupBy('horseman_id',EmployeesModel::TABLE_NAME.'.market_id',EmployeesModel::TABLE_NAME.'.name',EmployeesModel::TABLE_NAME.'.user_id')->paginate($perPage); |
||||
|
// ->orderBy('total_number','desc')
|
||||
|
$list = $list->toArray(); |
||||
|
|
||||
|
return $model->makePaginator( |
||||
|
$list['total'] ?? 0,$list['data'] ?? [] |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public function getDataModel($selects,$params = []) |
||||
|
{ |
||||
|
// 获取筛选参数
|
||||
|
$userId = $params['user_id'] ?? request()->input('user_id',0); |
||||
|
$name = $params['name'] ?? request()->input('name', ''); |
||||
|
$marketId = $params['market_id'] ?? request()->input('market_id',0); |
||||
|
|
||||
|
$startTime = $params['start_time'] ?? request()->input('start_time',''); |
||||
|
$endTime = $params['end_time'] ?? request()->input('end_time',''); |
||||
|
// 外卖类型 type = 1
|
||||
|
$model = Model::select(DB::raw($selects)) |
||||
|
// ->with('employees:id,user_id,name,market_id')
|
||||
|
->join(EmployeesModel::TABLE_NAME,EmployeesModel::TABLE_NAME.'.id','=',Model::$tableName.'.horseman_id','left') |
||||
|
->where(Model::$tableName.'.type',1) |
||||
|
->where('shipping_type',1) |
||||
|
->whereIn('state',Model::ORDER_STATE_FINISH) |
||||
|
->where(Model::$tableName.'.created_at','>=',strtotime('2020-10-01 00:00:00')); |
||||
|
|
||||
|
if($userId){ |
||||
|
$model->where(EmployeesModel::TABLE_NAME.'.user_id',$userId); |
||||
|
} |
||||
|
if($name){ |
||||
|
$model->where(EmployeesModel::TABLE_NAME.'.name','like',"%$name%"); |
||||
|
} |
||||
|
if($marketId){ |
||||
|
$model->where(EmployeesModel::TABLE_NAME.'.market_id',$marketId); |
||||
|
} |
||||
|
if($startTime){ |
||||
|
$startTime = $startTime.' 00:00:00'; |
||||
|
$model->where(Model::$tableName.'.created_at','>=',strtotime($startTime)); |
||||
|
} |
||||
|
if($endTime){ |
||||
|
$endTime = $endTime.' 23:59:59'; |
||||
|
$model->where(Model::$tableName.'.created_at','<=',strtotime($endTime)); |
||||
|
} |
||||
|
|
||||
|
return $model; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue