链街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.

112 lines
3.3 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. $markets = MarketModel::getMarketArray();
  60. foreach ($data['data'] as $value){
  61. $item = [
  62. $markets[$value['market_id']] ?? '',
  63. $value['user_id'] ?? 0,
  64. $value['name'] ?? '',
  65. $value['new_cs_count'] ?? 0,
  66. $value['new_bind_user_count'] ?? 0,
  67. $value['plat_new_user_count'] ?? 0,
  68. $value['bound_order_online_count'] ?? 0,
  69. $value['plat_new_user_order_online_count'] ?? 0,
  70. ];
  71. $result[] = $item;
  72. }
  73. return $result;
  74. }
  75. /**
  76. * 获取数据
  77. */
  78. public function getData($option = [])
  79. {
  80. $params = $option;
  81. $repository = new ReportCommunityRepository();
  82. $selects = 'id,user_id,market_id,name';
  83. $data = $repository->getDataModel($selects,$params,false);
  84. return $data;
  85. }
  86. /**
  87. * sheet 表名称
  88. * @return string
  89. */
  90. public function title(): string
  91. {
  92. return '统计';
  93. }
  94. }