From 890c99df3da1585b15b66da401d73e1bc7418e3f Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 20 Nov 2020 14:44:45 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E7=BB=9F=E8=AE=A1-=E5=88=9D=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ReportCommunityController.php | 135 ++++++++++++++++++ app/Admin/Repositories/v3/ReportCommunity.php | 90 ++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 app/Admin/Controllers/v3/ReportCommunityController.php create mode 100644 app/Admin/Repositories/v3/ReportCommunity.php diff --git a/app/Admin/Controllers/v3/ReportCommunityController.php b/app/Admin/Controllers/v3/ReportCommunityController.php new file mode 100644 index 0000000..3f493d2 --- /dev/null +++ b/app/Admin/Controllers/v3/ReportCommunityController.php @@ -0,0 +1,135 @@ +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'); + } +} diff --git a/app/Admin/Repositories/v3/ReportCommunity.php b/app/Admin/Repositories/v3/ReportCommunity.php new file mode 100644 index 0000000..b5413ee --- /dev/null +++ b/app/Admin/Repositories/v3/ReportCommunity.php @@ -0,0 +1,90 @@ +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; + } + +} From 8b0497dfc67c6e51650525c8709a1cfac1e2e116 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 20 Nov 2020 18:05:03 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E7=BB=9F=E8=AE=A1--=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ReportCommunityController.php | 31 ++-- app/Admin/Repositories/v3/ReportCommunity.php | 161 +++++++++++++----- app/Admin/routes.php | 3 + 3 files changed, 143 insertions(+), 52 deletions(-) diff --git a/app/Admin/Controllers/v3/ReportCommunityController.php b/app/Admin/Controllers/v3/ReportCommunityController.php index 3f493d2..5ae54c1 100644 --- a/app/Admin/Controllers/v3/ReportCommunityController.php +++ b/app/Admin/Controllers/v3/ReportCommunityController.php @@ -45,8 +45,12 @@ class ReportCommunityController extends AdminController } return Grid::make($builder, function (Grid $grid) { $marketList = $this->marketList; - $grid->column('horseman_id','ID'); + + $grid->column('market_id','市场')->display(function($marketId) use($marketList){ + return $marketList[$marketId] ?? ''; + }); $grid->column('user_id','懒ID'); + $grid->column('avatar','微信头像')->display(function(){ $userId = $this->user_id ?? 0; $item = UserModel::select('avatar')->find($userId); @@ -54,11 +58,9 @@ class ReportCommunityController extends AdminController })->image('',50); $grid->column('name','姓名'); - $grid->column('market_id','市场')->display(function($marketId) use($marketList){ - return $marketList[$marketId] ?? ''; - }); + $grid->column('total_new_agent','新拓展代理点数'); - $grid->column('total_number','配送单数') + $grid->column('total_bound_new_user','新增绑定用户数') ->modal(function($modal){ $name = $this->name; $modal->title($name.'的配送明细'); @@ -67,14 +69,17 @@ class ReportCommunityController extends AdminController $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->column('total_add_new_user','平台新增用户数'); + $grid->column('total_bound_order_online','绑定用户线上订单总数'); + $grid->column('total_add_order_online','平台新增用户线上订单数'); $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){ @@ -83,12 +88,12 @@ class ReportCommunityController extends AdminController }); $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 DataReportOption('today','report_community','今日'), + new DataReportOption('yesterday','report_community','昨日'), + new DataReportOption('this_week','report_community','本周'), + new DataReportOption('last_week','report_community','上周'), + new DataReportOption('this_month','report_community','本月'), + new DataReportOption('last_month','report_community','上月'), new OrderDeliveryExport() ]); diff --git a/app/Admin/Repositories/v3/ReportCommunity.php b/app/Admin/Repositories/v3/ReportCommunity.php index b5413ee..68a083d 100644 --- a/app/Admin/Repositories/v3/ReportCommunity.php +++ b/app/Admin/Repositories/v3/ReportCommunity.php @@ -2,14 +2,20 @@ namespace App\Admin\Repositories\v3; -use App\Models\ImsCjdcOrderMain as Model; +use App\Models\v3\LanzuEmployees 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; + +use App\Models\LanzuCsInfo as CsInfoModel; +use App\Models\LanzuUserRelationBind as UserRelationBindModel; +use App\Models\ImsCjdcOrderMain as OrderMainModel; + class ReportCommunity extends EloquentRepository { - public $params = []; + protected $params = []; + protected $currentPage = 1; + protected $perPage = 10; /** * Model. * @@ -28,62 +34,139 @@ class ReportCommunity extends EloquentRepository public function get(GridModel $model) { // 获取当前页数 - $currentPage = $model->getCurrentPage(); + $this->currentPage = $model->getCurrentPage(); // 获取每页显示行数 - $perPage = $model->getPerPage(); + $this->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']]; } + + $list = $this->getDataModel($where); - $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 = []) + public function getDataModel($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); + $time = time(); + if(empty($startTime)){ + $startTime = date('Y-m-d', $time) . '00:00:00'; + }else{ + $startTime = $startTime . '00:00:00'; } - if($name){ - $model->where(EmployeesModel::TABLE_NAME.'.name','like',"%$name%"); + if(empty($endTime)){ + $endTime = date('Y-m-d', $time) . '23:59:59'; + }else{ + $endTime = $endTime . '23:59:59'; } - if($marketId){ - $model->where(EmployeesModel::TABLE_NAME.'.market_id',$marketId); + + // 获取懒族员工 + $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(); + + foreach ($employeesList as $key => &$employee) { + // 根据员工信息,查询名下新增绑定的所有服务点 Statistics + $newCsCount = CsInfoModel::where(function ($query) use ($employee) { + $query->where('person_id', '=', $employee['user_id']) + ->orWhere('user_id', '=', $employee['user_id']); + }) + ->where('created_at', '>=', strtotime($startTime ?? 0)) + ->where('created_at', '<=', strtotime($endTime ?? 0)) + ->count(); + + // 查询名下所有的服务点 + $allCsInfos = CsInfoModel::where(function ($query) use ($employee) { + $query->where('person_id', '=', $employee['user_id']) + ->orWhere('user_id', '=', $employee['user_id']); + }) + ->get() + ->map(function ($value) {return (array)$value;}) + ->toArray(); + + // 新增绑定用户数 Statistics + $newBindUserCount = UserRelationBindModel::where('bind_type', '=', 1) + ->whereIn('source_id', array_values(array_column($allCsInfos, 'admin_user_id'))) + ->where('created_at', '>=', strtotime($startTime ?? 0)) + ->where('created_at', '<=', strtotime($endTime ?? 0)) + ->count(); + + // 查询名下所有服务点的所有用户 + $allCsBindUsers = UserRelationBindModel::where('bind_type', '=', 1) + ->whereIn('source_id', array_values(array_column($allCsInfos, 'admin_user_id'))) + ->get() + ->map(function ($value) {return (array)$value;}) + ->toArray(); + + // 平台新增用户数 Statistics + $platNewUsers = OrderMainModel::select('user_id') + ->where('type', '=', 1) + ->whereIn('state', [4,5,10,11]) + ->whereIn('user_id', array_values(array_column($allCsBindUsers, 'user_id'))) + ->groupBy('user_id') + ->havingRaw('MIN(created_at)>='.strtotime($startTime ?? 0).' AND MIN(created_at)<='.strtotime($endTime ?? 0).'') + ->get() + ->map(function ($value) {return (array)$value;}) + ->toArray(); + $platNewUserCount = count($platNewUsers); + + // 所有用户产生的线上订单数 Statistics + $totalOrdersCount = OrderMainModel::where('type', '=', 1) + ->whereIn('state', [4,5,10,11]) + ->whereIn('user_id', array_values(array_column($allCsBindUsers, 'user_id'))) + ->where('created_at', '>=', strtotime($startTime ?? 0)) + ->where('created_at', '<=', strtotime($endTime ?? 0)) + ->count(); + + // 平台新增用户产生的线上订单数 Statistics + $platNewUserOrdersCount =OrderMainModel::where('type', '=', 1) + ->whereIn('state', [4,5,10,11]) + ->whereIn('user_id', array_values(array_column($platNewUsers, 'user_id'))) + ->where('created_at', '>=', strtotime($startTime ?? 0)) + ->where('created_at', '<=', strtotime($endTime ?? 0)) + ->count(); + + $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; } - if($startTime){ - $startTime = $startTime.' 00:00:00'; - $model->where(Model::$tableName.'.created_at','>=',strtotime($startTime)); + + return $employeesList; + } + + /** + * 获取懒族员工 model + */ + public function getEmployeesData($selects, $params = ['status' => 1]) + { + + $model = Model::select(DB::raw($selects)); + + if(isset($params['status']) && is_numeric($params['status'])){ + $model->where('status',$params['status']); } - if($endTime){ - $endTime = $endTime.' 23:59:59'; - $model->where(Model::$tableName.'.created_at','<=',strtotime($endTime)); + 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['market_id']) && is_numeric($params['market_id'])){ + $model->where('market_id', $params['market_id']); } - return $model; } diff --git a/app/Admin/routes.php b/app/Admin/routes.php index eb22da2..4a05c22 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -109,4 +109,7 @@ Route::group([ $router->resource('/share_card_setting', 'v3\ShareCardSettingController'); // 关注公众号设置 $router->any('/official_subscribe_info', 'v3\SystemConfigController@OfficialSubscribeInfoSettingForm'); + + // 社区代理点统计 + $router->resource('/report_community', 'v3\ReportCommunityController'); }); 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 3/5] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=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' => [ + ], +]; From 944c5dbce7f0f0ae41db4ec344fc25d16456886b Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Tue, 24 Nov 2020 18:01:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E7=BB=9F=E8=AE=A1--=E5=A2=9E=E5=8A=A0=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Exporter/ReportCommunity.php | 5 ++++- app/Admin/Actions/Grid/v3/DataReportOption.php | 11 +++++++++-- .../Actions/Tools/ReportCommunityExport.php | 2 +- .../Controllers/v3/ReportCommunityController.php | 16 ++++++++-------- app/Admin/Repositories/v3/ReportCommunity.php | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/Admin/Actions/Exporter/ReportCommunity.php b/app/Admin/Actions/Exporter/ReportCommunity.php index 589c9a3..8fbf4b7 100644 --- a/app/Admin/Actions/Exporter/ReportCommunity.php +++ b/app/Admin/Actions/Exporter/ReportCommunity.php @@ -67,6 +67,9 @@ class ReportCommunity implements FromArray, WithStrictNullComparison, ShouldAuto '平台新增用户线上订单数' ]]; $data = $this->getData($this->params); + if(!isset($data['data']) ){ + $data['data'] = []; + } $markets = MarketModel::getMarketArray(); foreach ($data['data'] as $value){ @@ -96,7 +99,7 @@ class ReportCommunity implements FromArray, WithStrictNullComparison, ShouldAuto $repository = new ReportCommunityRepository(); $selects = 'id,user_id,market_id,name'; $data = $repository->getDataModel($selects,$params,false); - + return $data; } diff --git a/app/Admin/Actions/Grid/v3/DataReportOption.php b/app/Admin/Actions/Grid/v3/DataReportOption.php index 36f7253..9076084 100644 --- a/app/Admin/Actions/Grid/v3/DataReportOption.php +++ b/app/Admin/Actions/Grid/v3/DataReportOption.php @@ -11,13 +11,15 @@ class DataReportOption extends AbstractTool { protected $url; protected $option; - protected $title = ''; + protected $title = ''; + protected $moreOption = []; - public function __construct($option = '', $url = '', $title = '') + public function __construct($option = '', $url = '', $title = '', $more = []) { $this->option = $option; $this->url = $url; $this->title = $title; + $this->moreOption = $more; } /** @@ -46,6 +48,11 @@ class DataReportOption extends AbstractTool $startTime = $date['start'] ?? ''; $endTime = $date['end'] ?? ''; $url = 'admin/'.$this->url.'?start_time='.$startTime.'&end_time='.$endTime; + if(!empty($this->moreOption) && is_array($this->moreOption)){ + foreach($this->moreOption as $key => $value){ + $url .= '&'. $key .'='. $value; + } + } $this->defaultHtmlAttribute('href', url($url)); return <<get('status', 0); + $status = $request->get('status', null); $name = $request->get('name', ''); $marketId = $request->get('market_id',0); $storeId = $request->get('user_id',0); diff --git a/app/Admin/Controllers/v3/ReportCommunityController.php b/app/Admin/Controllers/v3/ReportCommunityController.php index 29760fa..cd7f3b8 100644 --- a/app/Admin/Controllers/v3/ReportCommunityController.php +++ b/app/Admin/Controllers/v3/ReportCommunityController.php @@ -83,17 +83,17 @@ class ReportCommunityController extends AdminController $filter->equal('name','姓名')->width(2); if(!$this->marketId){ $filter->equal('market_id','市场')->select($marketList)->width(2); - $filter->equal('status','状态')->select(EmployeesModel::$_STATUS)->width(2); + $filter->equal('status','状态')->select(EmployeesModel::$_STATUS)->default(1)->width(2); } }); $grid->tools([ - new DataReportOption('today','report_community','今日'), - new DataReportOption('yesterday','report_community','昨日'), - new DataReportOption('this_week','report_community','本周'), - new DataReportOption('last_week','report_community','上周'), - new DataReportOption('this_month','report_community','本月'), - new DataReportOption('last_month','report_community','上月'), + new DataReportOption('today','report_community','今日', $this->newParams), + new DataReportOption('yesterday','report_community','昨日', $this->newParams), + new DataReportOption('this_week','report_community','本周', $this->newParams), + new DataReportOption('last_week','report_community','上周', $this->newParams), + new DataReportOption('this_month','report_community','本月', $this->newParams), + new DataReportOption('last_month','report_community','上月', $this->newParams), new ReportCommunityExport() ]); @@ -140,7 +140,7 @@ class ReportCommunityController extends AdminController { $this->marketId = Auth::getMarket(); $params = [ - 'status' => $request->input('status',1), + 'status' => $request->input('status',null), 'name' => $request->input('name',false), 'market_id' => $this->marketId ? $this->marketId : $request->input('market_id',null), 'user_id' => $request->input('user_id',null), diff --git a/app/Admin/Repositories/v3/ReportCommunity.php b/app/Admin/Repositories/v3/ReportCommunity.php index 0b1de08..4755723 100644 --- a/app/Admin/Repositories/v3/ReportCommunity.php +++ b/app/Admin/Repositories/v3/ReportCommunity.php @@ -57,7 +57,7 @@ class ReportCommunity extends EloquentRepository $endTime = $params['end_time'] ?? request()->input('end_time',''); $status = request()->input('status',false); $params = [ - 'status' => $status !== false ? $status : $params['status'] ?? 1, + 'status' => $status !== false ? $status : $params['status'] ?? null, '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), @@ -76,7 +76,7 @@ class ReportCommunity extends EloquentRepository }else{ $endTime = $endTime . '23:59:59'; } - + // 获取懒族员工 $employeesData = $this->getEmployeesData($selectsEmp,$params); $employeesData->orderBy('id','desc'); @@ -90,7 +90,7 @@ class ReportCommunity extends EloquentRepository 'data' => $list ]; } - + if(!isset($employeeList['data']) || count($employeeList['data']) <= 0 ) { return $employeeList; } From 3999d5952e251daa4a6d02cb0d547d1be43c8594 Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Fri, 27 Nov 2020 11:22:22 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E7=82=B9=E7=BB=9F=E8=AE=A1--=E4=BF=AE=E6=94=B9=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/v3/ReportCommunityController.php | 2 +- app/Admin/Repositories/v3/ReportCommunity.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Admin/Controllers/v3/ReportCommunityController.php b/app/Admin/Controllers/v3/ReportCommunityController.php index cd7f3b8..063b559 100644 --- a/app/Admin/Controllers/v3/ReportCommunityController.php +++ b/app/Admin/Controllers/v3/ReportCommunityController.php @@ -83,8 +83,8 @@ class ReportCommunityController extends AdminController $filter->equal('name','姓名')->width(2); if(!$this->marketId){ $filter->equal('market_id','市场')->select($marketList)->width(2); - $filter->equal('status','状态')->select(EmployeesModel::$_STATUS)->default(1)->width(2); } + $filter->equal('status','状态')->select(EmployeesModel::$_STATUS)->width(2); }); $grid->tools([ diff --git a/app/Admin/Repositories/v3/ReportCommunity.php b/app/Admin/Repositories/v3/ReportCommunity.php index 4755723..6f7f6ee 100644 --- a/app/Admin/Repositories/v3/ReportCommunity.php +++ b/app/Admin/Repositories/v3/ReportCommunity.php @@ -170,7 +170,7 @@ class ReportCommunity extends EloquentRepository /** * 获取懒族员工 model */ - public function getEmployeesData($selects, $params = ['status' => 1]) + public function getEmployeesData($selects, $params = []) { $model = Model::select(DB::raw($selects));