6 changed files with 305 additions and 53 deletions
-
112app/Admin/Actions/Exporter/ReportCommunity.php
-
91app/Admin/Actions/Tools/ReportCommunityExport.php
-
78app/Admin/Controllers/v3/ReportCommunityController.php
-
56app/Admin/Repositories/v3/ReportCommunity.php
-
3app/Admin/routes.php
-
12resources/lang/zh-CN/report-community.php
@ -0,0 +1,112 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Exporter; |
|||
|
|||
use Maatwebsite\Excel\Concerns\FromArray; |
|||
use Maatwebsite\Excel\Concerns\WithStrictNullComparison; |
|||
use Maatwebsite\Excel\Concerns\ShouldAutoSize; |
|||
use Maatwebsite\Excel\Concerns\WithHeadings; |
|||
use Maatwebsite\Excel\Concerns\WithStyles; |
|||
use Maatwebsite\Excel\Concerns\WithTitle; |
|||
|
|||
use App\Admin\Repositories\v3\ReportCommunity as ReportCommunityRepository; |
|||
use App\Models\v3\Market as MarketModel; |
|||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
|||
|
|||
class ReportCommunity implements FromArray, WithStrictNullComparison, ShouldAutoSize, WithTitle, WithHeadings, WithStyles |
|||
{ |
|||
protected $params = []; |
|||
public function __construct($params) |
|||
{ |
|||
$this->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 '统计'; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Actions\Tools; |
|||
|
|||
use Dcat\Admin\Actions\Response; |
|||
use Dcat\Admin\Traits\HasPermissions; |
|||
use Dcat\Admin\Tree\AbstractTool; |
|||
use Illuminate\Contracts\Auth\Authenticatable; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class ReportCommunityExport extends AbstractTool |
|||
{ |
|||
|
|||
/** |
|||
* @return string |
|||
*/ |
|||
protected $title = '<span class="feather icon-download">导出<span>'; |
|||
|
|||
/** |
|||
* 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; |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'ReportCommunity' => '社区代理点统计报表', |
|||
'report_community' => '社区代理点统计报表', |
|||
], |
|||
'fields' => [ |
|||
'id' => 'ID', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue