From e7fa02cb1613b7f86a9cf78ab31677eb2b9e69a0 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 24 Nov 2020 17:13:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86=E7=82=B9?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1--=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Actions/Exporter/ReportCommunity.php | 112 ++++++++++++++++++ .../Actions/Tools/ReportCommunityExport.php | 91 ++++++++++++++ .../v3/ReportCommunityController.php | 82 +++++++------ app/Admin/Repositories/v3/ReportCommunity.php | 58 ++++++--- app/Admin/routes.php | 3 +- resources/lang/zh-CN/report-community.php | 12 ++ 6 files changed, 305 insertions(+), 53 deletions(-) create mode 100644 app/Admin/Actions/Exporter/ReportCommunity.php create mode 100644 app/Admin/Actions/Tools/ReportCommunityExport.php create mode 100644 resources/lang/zh-CN/report-community.php diff --git a/app/Admin/Actions/Exporter/ReportCommunity.php b/app/Admin/Actions/Exporter/ReportCommunity.php new file mode 100644 index 0000000..589c9a3 --- /dev/null +++ b/app/Admin/Actions/Exporter/ReportCommunity.php @@ -0,0 +1,112 @@ +params = $params; + } + + public function headings(): array + { + $startTime = $this->params['start_time'] ?? null; + $endTime = $this->params['end_time'] ?? null; + $nowDay = date('Y年m月d日', time()); + + if(empty($startTime)){ + $startTime = '2020年7月1日'; + }else if(empty($endTime)){ + $endTime = $nowDay; + } + + return [ + '统计时间:'.$startTime.' 至 '.$endTime + ]; + } + + public function styles(Worksheet $sheet) + { + $sheet->mergeCells('A1:H1');// 合并 + + $sheet->getRowDimension(1)->setRowHeight(40); // 行高 + $sheet->getRowDimension(2)->setRowHeight(25); // 行高 + $sheet->getStyle('A1:H1')->getAlignment()->setVertical('center');// 垂直居中 + $sheet->getStyle('A1:H1')->getAlignment()->setHorizontal('center');// 水平居中 + $sheet->getStyle('A2:H2')->getAlignment()->setVertical('center');// 垂直居中 + + return [ + 1 => ['font' => ['bold' => true,'size' => 18, 'name' => '微软雅黑 Light']], + 2 => ['font' => ['bold' => true,'size' => 12, 'name' => '微软雅黑 Light']], + ]; + } + + public function array(): array + { + $result = [[ + '市场', + '懒ID', + '姓名', + '新拓展代理点数', + '新增绑定用户数', + '平台新增用户数', + '绑定用户线上订单总数', + '平台新增用户线上订单数' + ]]; + $data = $this->getData($this->params); + $markets = MarketModel::getMarketArray(); + + foreach ($data['data'] as $value){ + $item = [ + $markets[$value['market_id']] ?? '', + $value['user_id'] ?? 0, + $value['name'] ?? '', + + $value['new_cs_count'] ?? 0, + $value['new_bind_user_count'] ?? 0, + $value['plat_new_user_count'] ?? 0, + $value['bound_order_online_count'] ?? 0, + $value['plat_new_user_order_online_count'] ?? 0, + ]; + + $result[] = $item; + } + return $result; + } + + /** + * 获取数据 + */ + public function getData($option = []) + { + $params = $option; + $repository = new ReportCommunityRepository(); + $selects = 'id,user_id,market_id,name'; + $data = $repository->getDataModel($selects,$params,false); + + return $data; + } + + /** + * sheet 表名称 + * @return string + */ + public function title(): string + { + return '统计'; + } + +} diff --git a/app/Admin/Actions/Tools/ReportCommunityExport.php b/app/Admin/Actions/Tools/ReportCommunityExport.php new file mode 100644 index 0000000..b90dbfe --- /dev/null +++ b/app/Admin/Actions/Tools/ReportCommunityExport.php @@ -0,0 +1,91 @@ +导出'; + + /** + * Handle the action request. + * + * @param Request $request + * + * @return Response + */ + public function handle(Request $request) + { + $url = '/report_community_export?'; + $status = $request->get('status', 0); + $name = $request->get('name', ''); + $marketId = $request->get('market_id',0); + $storeId = $request->get('user_id',0); + $startTime = $request->get('start_time',''); + $endTime = $request->get('end_time',''); + if(empty($startTime) && empty($endTime)){ + return $this->response()->error('请先选择时间查询!'); + } + + if(!empty($status)){ + $url .= '&status='.$status; + } + if(!empty($name)){ + $url .= '&name='.$name; + } + if(!empty($marketId)){ + $url .= '&market_id='.$marketId; + } + if(!empty($storeId)){ + $url .= '&user_id='.$storeId; + } + if(!empty($startTime)){ + $url .= '&start_time='.$startTime; + } + + if(!empty($endTime)){ + $url .= '&end_time='.$endTime; + } + return $this->response() + ->success('导出中~') + ->redirect($url); + } + public function parameters() + { + return [ + 'status' => request()->input('status', 0), + 'name' => request()->input('name', ''), + 'market_id' => request()->input('market_id',0), + 'user_id' => request()->input('user_id',0), + 'start_time' => request()->input('start_time',''), + 'end_time' => request()->input('end_time',''), + ]; + } + /** + * @return string|array|void + */ + public function confirm() + { + return '确定导出数据吗?'; + } + + /** + * @param Model|Authenticatable|HasPermissions|null $user + * + * @return bool + */ + protected function authorize($user): bool + { + return true; + } +} diff --git a/app/Admin/Controllers/v3/ReportCommunityController.php b/app/Admin/Controllers/v3/ReportCommunityController.php index 5ae54c1..29760fa 100644 --- a/app/Admin/Controllers/v3/ReportCommunityController.php +++ b/app/Admin/Controllers/v3/ReportCommunityController.php @@ -3,10 +3,9 @@ namespace App\Admin\Controllers\v3; use App\Admin\Actions\Grid\v3\DataReportOption; -use App\Admin\Actions\Tools\OrderDeliveryExport; +use App\Admin\Actions\Tools\ReportCommunityExport; use App\Admin\Common\Auth; -use App\Admin\Renderable\OrderDeliveryById; -use App\Admin\Repositories\v3\OrderDeliveryReport; +use App\Admin\Repositories\v3\ReportCommunity; use Dcat\Admin\Grid; use Dcat\Admin\Controllers\AdminController; use Dcat\Admin\Grid\Filter; @@ -14,6 +13,10 @@ use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; use App\Models\v3\Market as MarketModel; use App\Models\ImsCjdcUser as UserModel; +use App\Models\v3\LanzuEmployees as EmployeesModel; +use Dcat\Admin\Layout\Content; +use Dcat\Admin\Layout\Row; +use Dcat\Admin\Widgets\Alert; class ReportCommunityController extends AdminController { @@ -22,9 +25,10 @@ class ReportCommunityController extends AdminController */ protected $GoodsActivityReport = null; public $marketId = 0; - public $newParams = []; + public $newParams = ['status' => 1]; public $marketList = []; public $storeList = []; + protected $reportDate = ''; /** * Make a grid builder. @@ -36,16 +40,17 @@ class ReportCommunityController extends AdminController $this->marketId = Auth::getMarket(); if($this->marketId){ - $this->newParams = ['market_id'=>$this->marketId]; - $builder = new OrderDeliveryReport($this->newParams); + $this->newParams['market_id'] = $this->marketId; + $builder = new ReportCommunity($this->newParams); $this->marketList = MarketModel::getMarketArray([['id','=',$this->marketId]]); }else{ - $builder = new OrderDeliveryReport(); + $builder = new ReportCommunity($this->newParams); $this->marketList = MarketModel::getMarketArray(); } + return Grid::make($builder, function (Grid $grid) { $marketList = $this->marketList; - + $grid->column('market_id','市场')->display(function($marketId) use($marketList){ return $marketList[$marketId] ?? ''; }); @@ -58,32 +63,27 @@ class ReportCommunityController extends AdminController })->image('',50); $grid->column('name','姓名'); - $grid->column('total_new_agent','新拓展代理点数'); + $grid->column('new_cs_count','新拓展代理点数'); - $grid->column('total_bound_new_user','新增绑定用户数') - ->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('new_bind_user_count','新增绑定用户数'); - $grid->column('total_add_new_user','平台新增用户数'); - $grid->column('total_bound_order_online','绑定用户线上订单总数'); - $grid->column('total_add_order_online','平台新增用户线上订单数'); + $grid->column('plat_new_user_count','平台新增用户数'); + $grid->column('bound_order_online_count','绑定用户线上订单总数'); + $grid->column('plat_new_user_order_online_count','平台新增用户线上订单数'); $grid->filter(function (Filter $filter) use($marketList) { // 更改为 panel 布局 $filter->panel(); - $filter->equal('start_time','开始时间')->date()->width(2); + $filter->where('start_time',function(){ + $this->newParams['start_time'] = $this->input['start_time']; + },'开始时间',)->date()->width(2); $filter->equal('end_time','结束时间')->date()->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); + $filter->equal('status','状态')->select(EmployeesModel::$_STATUS)->width(2); } }); @@ -94,7 +94,7 @@ class ReportCommunityController extends AdminController new DataReportOption('last_week','report_community','上周'), new DataReportOption('this_month','report_community','本月'), new DataReportOption('last_month','report_community','上月'), - new OrderDeliveryExport() + new ReportCommunityExport() ]); // 每页1条 @@ -115,6 +115,23 @@ class ReportCommunityController extends AdminController }); } + /** + * 页面 + */ + public function index(Content $content) + { + $startTime = request()->get('start_time'); + $endTime = request()->get('end_time'); + if(empty($startTime) && empty($endTime)){ + $content->row(Alert::make('请先选择时间查询!','')->removable()); + } + + return $content->title('社区代理点统计报表') + ->body(function(Row $row){ + $row->column(12,$this->grid()); + }); + } + /** * 数据导出 * @return \Symfony\Component\HttpFoundation\BinaryFileResponse @@ -123,18 +140,17 @@ class ReportCommunityController extends AdminController { $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',''), + 'status' => $request->input('status',1), + 'name' => $request->input('name',false), + 'market_id' => $this->marketId ? $this->marketId : $request->input('market_id',null), + 'user_id' => $request->input('user_id',null), + 'start_time' => $request->input('start_time',null), + 'end_time' => $request->input('end_time',null), ]; - + $name = date('Y-m-d-His',time()); - $data = new \App\Admin\Actions\Exporter\OrderDelivery($params); - if(empty($data)){ - return $this->error('没有数据!'); - } + $data = new \App\Admin\Actions\Exporter\ReportCommunity($params); + return Excel::download($data, $name.'.xlsx'); } } diff --git a/app/Admin/Repositories/v3/ReportCommunity.php b/app/Admin/Repositories/v3/ReportCommunity.php index 68a083d..0b1de08 100644 --- a/app/Admin/Repositories/v3/ReportCommunity.php +++ b/app/Admin/Repositories/v3/ReportCommunity.php @@ -42,41 +42,61 @@ class ReportCommunity extends EloquentRepository if(!empty($this->params) && isset($this->params['market_id']) && !empty($this->params['market_id'])){ $where = ['market_id'=>$this->params['market_id']]; } - - $list = $this->getDataModel($where); - + $selectsEmp = 'id,user_id,position,market_id,name,tel,status'; + $list = $this->getDataModel($selectsEmp, $where); + return $model->makePaginator( $list['total'] ?? 0,$list['data'] ?? [] ); } - public function getDataModel($params = []) + public function getDataModel($selectsEmp, $params = [], $isPerPage = true) { // 获取筛选参数 如果没有时间,则用当天的数据 $startTime = $params['start_time'] ?? request()->input('start_time',''); $endTime = $params['end_time'] ?? request()->input('end_time',''); - $time = time(); + $status = request()->input('status',false); + $params = [ + 'status' => $status !== false ? $status : $params['status'] ?? 1, + 'user_id' => $params['user_id'] ?? request()->input('user_id', null), + 'market_id' => $params['market_id'] ?? request()->input('market_id',null), + 'name' => $params['name'] ?? request()->input('name',false), + ]; + if(empty($startTime) && empty($endTime)){ + return []; + } + $nowDay = date('Y-m-d', time()); if(empty($startTime)){ - $startTime = date('Y-m-d', $time) . '00:00:00'; + $startTime = '2020-07-01 00:00:00'; }else{ $startTime = $startTime . '00:00:00'; } if(empty($endTime)){ - $endTime = date('Y-m-d', $time) . '23:59:59'; + $endTime = $nowDay . '23:59:59'; }else{ $endTime = $endTime . '23:59:59'; } // 获取懒族员工 - $selectsEmp = 'id,user_id,person_id,market_id,name,phone,status'; $employeesData = $this->getEmployeesData($selectsEmp,$params); - $employeesList = $employeesData->orderBy('id','desc') - ->paginate($this->perPage) - ->map(function ($value) {return (array)$value;}) - ->toArray(); - // $employeesList = $employeesList->toArray(); + $employeesData->orderBy('id','desc'); + if($isPerPage){ + $employeeList = $employeesData->paginate($this->perPage); + $employeeList = $employeeList->toArray(); + }else{ + $list = $employeesData->get()->toArray(); + $employeeList = [ + 'total' => count($list), + 'data' => $list + ]; + } + + if(!isset($employeeList['data']) || count($employeeList['data']) <= 0 ) { + return $employeeList; + } - foreach ($employeesList as $key => &$employee) { + foreach ($employeeList['data'] as $key => &$employee) { + // 根据员工信息,查询名下新增绑定的所有服务点 Statistics $newCsCount = CsInfoModel::where(function ($query) use ($employee) { $query->where('person_id', '=', $employee['user_id']) @@ -140,11 +160,11 @@ class ReportCommunity extends EloquentRepository $employee['new_cs_count'] = $newCsCount; $employee['new_bind_user_count'] = $newBindUserCount; $employee['plat_new_user_count'] = $platNewUserCount; - $employee['total_order_count'] = $totalOrdersCount; - $employee['plat_new_user_order_count'] = $platNewUserOrdersCount; + $employee['bound_order_online_count'] = $totalOrdersCount; + $employee['plat_new_user_order_online_count'] = $platNewUserOrdersCount; } - return $employeesList; + return $employeeList; } /** @@ -161,8 +181,8 @@ class ReportCommunity extends EloquentRepository if(isset($params['user_id']) && is_numeric($params['user_id'])){ $model->where('user_id', $params['user_id']); } - if(isset($params['user_id'])){ - $model->where('name','like','%'.$params['user_id'].'%'); + if(isset($params['name']) && $params['name']){ + $model->where('name','like','%'.$params['name'].'%'); } if(isset($params['market_id']) && is_numeric($params['market_id'])){ $model->where('market_id', $params['market_id']); diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 4a05c22..935ac58 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -111,5 +111,6 @@ Route::group([ $router->any('/official_subscribe_info', 'v3\SystemConfigController@OfficialSubscribeInfoSettingForm'); // 社区代理点统计 - $router->resource('/report_community', 'v3\ReportCommunityController'); + $router->any('/report_community', 'v3\ReportCommunityController@index'); + $router->any('/report_community_export', 'v3\ReportCommunityController@export'); }); diff --git a/resources/lang/zh-CN/report-community.php b/resources/lang/zh-CN/report-community.php new file mode 100644 index 0000000..2bae85d --- /dev/null +++ b/resources/lang/zh-CN/report-community.php @@ -0,0 +1,12 @@ + [ + 'ReportCommunity' => '社区代理点统计报表', + 'report_community' => '社区代理点统计报表', + ], + 'fields' => [ + 'id' => 'ID', + ], + 'options' => [ + ], +];