ChannelTransformer.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace App\Transformer\Channel;
  3. class ChannelTransformer
  4. {
  5. // 站点统计日数据
  6. public function newBuildStatisticsByDay($data): array
  7. {
  8. return [
  9. 'meta' => getMeta($data),
  10. 'list' => $this->newEachStatisticsByDay($data->items())
  11. ];
  12. }
  13. private function newEachStatisticsByDay($list): array
  14. {
  15. $result = [];
  16. if (empty($list)) return $result;
  17. foreach ($list as $item) {
  18. $result[] = [
  19. 'date' => getProp($item, 'day'),
  20. 'total_order_num' => (int)getProp($item, 'total_order_num'),
  21. 'paid_order_num' => (int)getProp($item, 'paid_order_num'),
  22. 'register_num' => (int)getProp($item, 'register_num'),
  23. 'register_pay_num' => (int)getProp($item, 'register_pay_num'),
  24. 'register_pay_amount' => (float)getProp($item, 'register_pay_amount'),
  25. 'register_pay_percent' => getProp($item, 'register_num') ? (float)sprintf('%.2f', getProp($item, 'register_pay_num') / getProp($item, 'register_num') * 100) : 0,
  26. 'total_pay_num' => (int)getProp($item, 'total_pay_num'),
  27. 'total_pay_amount' => (float)getProp($item, 'total_pay_amount'),
  28. ];
  29. }
  30. return $result;
  31. }
  32. // 站点统计推广员日数据
  33. public function newBuildStatisticsByDayForMaster($data): array
  34. {
  35. return [
  36. 'meta' => getMeta($data),
  37. 'list' => $this->newEachStatisticsByDayForMaster($data->items())
  38. ];
  39. }
  40. private function newEachStatisticsByDayForMaster($list): array
  41. {
  42. $result = [];
  43. if (empty($list)) return $result;
  44. foreach ($list as $item) {
  45. $result[] = [
  46. 'date' => getProp($item, 'day'),
  47. 'distribution_channel_id' => getProp($item, 'distribution_channel_id'),
  48. 'promote_user' => getProp($item, 'nickname'),
  49. 'total_order_num' => (int)getProp($item, 'total_order_num'),
  50. 'paid_order_num' => (int)getProp($item, 'paid_order_num'),
  51. 'register_num' => (int)getProp($item, 'register_num'),
  52. 'register_pay_num' => (int)getProp($item, 'register_pay_num'),
  53. 'register_pay_amount' => (float)getProp($item, 'register_pay_amount'),
  54. 'register_pay_percent' => getProp($item, 'register_num') ? (float)sprintf('%.2f', getProp($item, 'register_pay_num') / getProp($item, 'register_num') * 100) : 0,
  55. 'total_pay_num' => (int)getProp($item, 'total_pay_num'),
  56. 'total_pay_amount' => (float)getProp($item, 'total_pay_amount'),
  57. ];
  58. }
  59. return $result;
  60. }
  61. // 站点统计月数据
  62. public function newBuildStatisticsByMonth($data): array
  63. {
  64. return [
  65. 'meta' => getMeta($data),
  66. 'list' => $this->newEachStatisticsByMonth($data->items())
  67. ];
  68. }
  69. private function newEachStatisticsByMonth($list): array
  70. {
  71. $result = [];
  72. if (empty($list)) return $result;
  73. foreach ($list as $item) {
  74. $result[] = [
  75. 'date' => getProp($item, 'month'),
  76. 'total_order_num' => (int)getProp($item, 'total_order_num'),
  77. 'paid_order_num' => (int)getProp($item, 'paid_order_num'),
  78. 'register_num' => (int)getProp($item, 'register_num'),
  79. 'register_pay_num' => (int)getProp($item, 'register_pay_num'),
  80. 'register_pay_amount' => (float)getProp($item, 'register_pay_amount'),
  81. 'register_pay_percent' => getProp($item, 'register_num') ? (float)sprintf('%.2f', getProp($item, 'register_pay_num') / getProp($item, 'register_num') * 100) : 0,
  82. 'total_pay_num' => (int)getProp($item, 'total_pay_num'),
  83. 'total_pay_amount' => (float)getProp($item, 'total_pay_amount'),
  84. ];
  85. }
  86. return $result;
  87. }
  88. // 站点统计推广员月数据
  89. public function newBuildStatisticsByMonthForMaster($data): array
  90. {
  91. return [
  92. 'meta' => getMeta($data),
  93. 'list' => $this->newEachStatisticsByMonthForMaster($data->items())
  94. ];
  95. }
  96. private function newEachStatisticsByMonthForMaster($list): array
  97. {
  98. $result = [];
  99. if (empty($list)) return $result;
  100. foreach ($list as $item) {
  101. $result[] = [
  102. 'date' => getProp($item, 'month'),
  103. 'promote_user' => getProp($item, 'nickname'),
  104. 'distribution_channel_id' => getProp($item, 'distribution_channel_id'),
  105. 'total_order_num' => (int)getProp($item, 'total_order_num'),
  106. 'paid_order_num' => (int)getProp($item, 'paid_order_num'),
  107. 'register_num' => (int)getProp($item, 'register_num'),
  108. 'register_pay_num' => (int)getProp($item, 'register_pay_num'),
  109. 'register_pay_amount' => (float)getProp($item, 'register_pay_amount'),
  110. 'register_pay_percent' => getProp($item, 'register_num') ? (float)sprintf('%.2f', getProp($item, 'register_pay_num') / getProp($item, 'register_num') * 100) : 0,
  111. 'total_pay_num' => (int)getProp($item, 'total_pay_num'),
  112. 'total_pay_amount' => (float)getProp($item, 'total_pay_amount'),
  113. ];
  114. }
  115. return $result;
  116. }
  117. }