链街Dcat后台
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.

115 lines
3.4 KiB

  1. <?php
  2. namespace App\Admin\Actions\Exporter;
  3. use Maatwebsite\Excel\Concerns\FromArray;
  4. use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
  5. use Maatwebsite\Excel\Concerns\ShouldAutoSize;
  6. use Maatwebsite\Excel\Concerns\WithHeadings;
  7. use Maatwebsite\Excel\Concerns\WithStyles;
  8. use Maatwebsite\Excel\Concerns\WithTitle;
  9. use App\Admin\Repositories\v3\ReportCommunity as ReportCommunityRepository;
  10. use App\Models\v3\Market as MarketModel;
  11. use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
  12. class ReportCommunity implements FromArray, WithStrictNullComparison, ShouldAutoSize, WithTitle, WithHeadings, WithStyles
  13. {
  14. protected $params = [];
  15. public function __construct($params)
  16. {
  17. $this->params = $params;
  18. }
  19. public function headings(): array
  20. {
  21. $startTime = $this->params['start_time'] ?? null;
  22. $endTime = $this->params['end_time'] ?? null;
  23. $nowDay = date('Y年m月d日', time());
  24. if(empty($startTime)){
  25. $startTime = '2020年7月1日';
  26. }else if(empty($endTime)){
  27. $endTime = $nowDay;
  28. }
  29. return [
  30. '统计时间:'.$startTime.' 至 '.$endTime
  31. ];
  32. }
  33. public function styles(Worksheet $sheet)
  34. {
  35. $sheet->mergeCells('A1:H1');// 合并
  36. $sheet->getRowDimension(1)->setRowHeight(40); // 行高
  37. $sheet->getRowDimension(2)->setRowHeight(25); // 行高
  38. $sheet->getStyle('A1:H1')->getAlignment()->setVertical('center');// 垂直居中
  39. $sheet->getStyle('A1:H1')->getAlignment()->setHorizontal('center');// 水平居中
  40. $sheet->getStyle('A2:H2')->getAlignment()->setVertical('center');// 垂直居中
  41. return [
  42. 1 => ['font' => ['bold' => true,'size' => 18, 'name' => '微软雅黑 Light']],
  43. 2 => ['font' => ['bold' => true,'size' => 12, 'name' => '微软雅黑 Light']],
  44. ];
  45. }
  46. public function array(): array
  47. {
  48. $result = [[
  49. '市场',
  50. '懒ID',
  51. '姓名',
  52. '新拓展代理点数',
  53. '新增绑定用户数',
  54. '平台新增用户数',
  55. '绑定用户线上订单总数',
  56. '平台新增用户线上订单数'
  57. ]];
  58. $data = $this->getData($this->params);
  59. if(!isset($data['data']) ){
  60. $data['data'] = [];
  61. }
  62. $markets = MarketModel::getMarketArray();
  63. foreach ($data['data'] as $value){
  64. $item = [
  65. $markets[$value['market_id']] ?? '',
  66. $value['user_id'] ?? 0,
  67. $value['name'] ?? '',
  68. $value['new_cs_count'] ?? 0,
  69. $value['new_bind_user_count'] ?? 0,
  70. $value['plat_new_user_count'] ?? 0,
  71. $value['bound_order_online_count'] ?? 0,
  72. $value['plat_new_user_order_online_count'] ?? 0,
  73. ];
  74. $result[] = $item;
  75. }
  76. return $result;
  77. }
  78. /**
  79. * 获取数据
  80. */
  81. public function getData($option = [])
  82. {
  83. $params = $option;
  84. $repository = new ReportCommunityRepository();
  85. $selects = 'id,user_id,market_id,name';
  86. $data = $repository->getDataModel($selects,$params,false);
  87. return $data;
  88. }
  89. /**
  90. * sheet 表名称
  91. * @return string
  92. */
  93. public function title(): string
  94. {
  95. return '统计';
  96. }
  97. }