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.
		
		
		
		
		
			
		
			
				
					
					
						
							172 lines
						
					
					
						
							6.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							172 lines
						
					
					
						
							6.3 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;
							 | 
						|
								use Dcat\Admin\Layout\Content;
							 | 
						|
								use Dcat\Admin\Layout\Row;
							 | 
						|
								use Dcat\Admin\Widgets\Alert;
							 | 
						|
								
							 | 
						|
								class OrderDeliveryReportController extends AdminController
							 | 
						|
								{
							 | 
						|
								    /**
							 | 
						|
								     * 订单的配送统计
							 | 
						|
								     */
							 | 
						|
								    protected $GoodsActivityReport = null;
							 | 
						|
								    protected $marketId = 0;
							 | 
						|
								    protected $newParams = [];
							 | 
						|
								    protected $marketList = [];
							 | 
						|
								    protected $tools = [];
							 | 
						|
								
							 | 
						|
								    /**
							 | 
						|
								     * Make a grid builder.
							 | 
						|
								     *
							 | 
						|
								     * @return Grid
							 | 
						|
								     */
							 | 
						|
								    protected function grid()
							 | 
						|
								    {
							 | 
						|
								       $marketId = $this->marketId;
							 | 
						|
								        if($marketId){
							 | 
						|
								            $this->newParams = ['market_id'=>$marketId];
							 | 
						|
								            $builder = new OrderDeliveryReport($this->newParams);
							 | 
						|
								            $this->marketList = MarketModel::getMarketArray([['id','=',$marketId]]);
							 | 
						|
								        }else{
							 | 
						|
								            $builder = new OrderDeliveryReport($this->newParams);
							 | 
						|
								            $this->marketList = MarketModel::getMarketArray();
							 | 
						|
								        }
							 | 
						|
								        return Grid::make($builder, function (Grid $grid) use($marketId){
							 | 
						|
								            $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($market_id) use($marketList){
							 | 
						|
								                return $marketList[$market_id] ?? '';
							 | 
						|
								            });
							 | 
						|
								
							 | 
						|
								            $grid->column('total_number','配送单数')
							 | 
						|
								                ->modal(function($modal) use($marketId){
							 | 
						|
								                  
							 | 
						|
								                    $modal->title($this->name.'的配送明细');
							 | 
						|
								                    $params = [
							 | 
						|
								                        'horseman_id'   => $this->horseman_id,
							 | 
						|
								                        'market_id' => $marketId,
							 | 
						|
								                        'user_id' => request()->input('user_id',0),
							 | 
						|
								                        'start_time' => request()->input('start_time', ''),
							 | 
						|
								                        'end_time' => request()->input('end_time', ''),
							 | 
						|
								                    ];
							 | 
						|
								                    // dd($params);
							 | 
						|
								                    $table = OrderDeliveryById::make($params);
							 | 
						|
								                    return $table;
							 | 
						|
								                })->help('只统计2020年10月01日之后(包括10月01日)的数据');
							 | 
						|
								            $grid->column('total_delivery','总配送费');
							 | 
						|
								
							 | 
						|
								            $grid->filter(function (Filter $filter) use($marketList,$marketId){
							 | 
						|
								                // 更改为 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')->placeholder('多个懒ID使用英文逗号隔开')->width(2);
							 | 
						|
								                $filter->equal('name','姓名')->width(2);
							 | 
						|
								                if(!$marketId){
							 | 
						|
								                    $filter->equal('market_id','市场')->select($marketList)->width(2);
							 | 
						|
								                }
							 | 
						|
								            });
							 | 
						|
								
							 | 
						|
								            $grid->tools($this->tools);
							 | 
						|
								
							 | 
						|
								            // 每页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();
							 | 
						|
								
							 | 
						|
								        $this->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','上月')
							 | 
						|
								        ];
							 | 
						|
								        $startTime = request()->get('start_time');
							 | 
						|
								        $endTime = request()->get('end_time');
							 | 
						|
								        $user_id = request()->get('user_id');
							 | 
						|
								        $name = request()->get('name');
							 | 
						|
								        $marketId = request()->get('market_id');
							 | 
						|
								        if(
							 | 
						|
								            ($this->marketId && (empty($startTime) && empty($endTime) && empty($user_id) && empty($name))
							 | 
						|
								            || 
							 | 
						|
								            (empty($startTime) && empty($endTime) && empty($user_id) && empty($name) && empty($marketId))
							 | 
						|
								        )){
							 | 
						|
								            $content->row(Alert::make('请选择筛选条件查询!','')->removable());
							 | 
						|
								        }else{
							 | 
						|
								            $this->tools[] = new OrderDeliveryExport();
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        return $content->title('订单配送统计报表')
							 | 
						|
								            ->body(function(Row $row){
							 | 
						|
								                $row->column(12,$this->grid());
							 | 
						|
								            });
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    /**
							 | 
						|
								     * 数据导出
							 | 
						|
								     * @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);
							 | 
						|
								        
							 | 
						|
								        return Excel::download($data, $name.'.xlsx');
							 | 
						|
								    }
							 | 
						|
								}
							 |