SendOrderBreakevenStatsController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/12/1
  6. * Time: 14:17
  7. */
  8. namespace App\Http\Controllers\Manage\SendOrder;
  9. use App\Http\Controllers\Channel\BaseController;
  10. use App\Http\Controllers\Manage\SendOrder\Transformers\SendOrderBreakevenStatsTransformer;
  11. use App\Modules\Channel\Services\ChannelService;
  12. use App\Modules\Statistic\Services\SendOrderBreakevenStatsService;
  13. use Illuminate\Http\Request;
  14. class SendOrderBreakevenStatsController extends BaseController
  15. {
  16. /**
  17. * @apiDefine sendOrder 派单
  18. */
  19. /**
  20. * @apiVersion 1.0.0
  21. * @api {GET} sendOrder/getSendOrderBreakevenStats 获取30日回本率数据
  22. * @apiGroup sendOrder
  23. * @apiName getSendOrderBreakevenStats
  24. *
  25. * @apiParam {Number} [distribution_channel_id] 分销渠道ID
  26. * @apiParam {String} [start_date] 开始日期
  27. * @apiParam {String} [end_date] 结束日期
  28. *
  29. * @apiSuccess {Number} id id.
  30. * @apiSuccess {Number} distribution_channel_id 渠道id.
  31. * @apiSuccess {Number} distribution_channel_name 渠道名称.
  32. * @apiSuccess {Number} official_account_id 服务号id.
  33. * @apiSuccess {String} official_account_name 服务号名称.
  34. * @apiSuccess {String} date 日期
  35. * @apiSuccess {Number} force_user_num 粉丝数
  36. * @apiSuccess {Number} total_force_user_num 总粉丝数
  37. * @apiSuccess {Number} unsubscribe_in_one_day_user_num 24小时取关用户数
  38. * @apiSuccess {String} created_at 创建时间
  39. * @apiSuccess {String} updated_at 更新时间
  40. * @apiSuccess {Number} recharge_amount_in_one_day 24小时充值
  41. * @apiSuccess {Number} recharge_amount_in_three_days 72小时充值
  42. * @apiSuccess {Number} recharge_amount_in_one_month 30天充值
  43. * @apiSuccess {Number} recharge_amount_in_two_months 60天充值
  44. * @apiSuccess {Number} recharge_amount_in_three_months 90天充值
  45. * @apiSuccessExample {json} Success-Response:
  46. *
  47. * {
  48. * "code": 0,
  49. * "msg": "",
  50. * "data": [
  51. * {
  52. * "id": 2,
  53. * "distribution_channel_id": 2,
  54. * "distribution_channel_name":"渠道名称",
  55. * "official_account_id": 1233,
  56. * "official_account_name": "杭州掌维",
  57. * "date": "2018-2-9",
  58. * "force_user_num": 11,
  59. * "total_force_user_num": 111,
  60. * "unsubscribe_in_one_day_user_num": 5,
  61. * "created_at": "2017-12-01 10:20:04",
  62. * "updated_at": "2017-12-01 10:20:04",
  63. * "recharge_amount_in_one_day": 9,
  64. * "recharge_amount_in_three_days": 6,
  65. * "recharge_amount_in_one_month": 23,
  66. * "recharge_amount_in_two_months":11,
  67. * "recharge_amount_in_three_months": 112
  68. * }
  69. * ]
  70. * }
  71. */
  72. function getSendOrderBreakevenStats(Request $request)
  73. {
  74. $params = [];
  75. $request->has('end_date') && $request->input('end_date') && $params['end_date'] = $request->input('end_date');
  76. $request->has('start_date') && $request->input('start_date') && $params['start_date'] = $request->input('start_date');
  77. $request->has('distribution_channel_id') && $request->input('distribution_channel_id') && $params['distribution_channel_id'] = (int)$request->input('distribution_channel_id');
  78. $data = SendOrderBreakevenStatsService::getInfos($params, false);
  79. foreach ($data as $item) {
  80. $item->distribution_channel_name = ChannelService::getChannelNicknameById($item->distribution_channel_id);
  81. }
  82. return response()->pagination(new SendOrderBreakevenStatsTransformer(), $data);
  83. }
  84. /**
  85. * @apiVersion 1.0.0
  86. * @api {GET} sendOrder/exportSendOrderBreakevenStats 导出30日回本率数据
  87. * @apiGroup sendOrder
  88. * @apiName exportSendOrderBreakevenStats
  89. *
  90. * @apiParam {Number} [distribution_channel_id] 分销渠道ID
  91. * @apiParam {String} [start_date] 开始日期
  92. * @apiParam {String} [end_date] 结束日期
  93. * @apiSuccess {Number} id id.
  94. * @apiSuccess {Number} distribution_channel_id 渠道id.
  95. * @apiSuccess {Number} official_account_id 服务号id.
  96. * @apiSuccess {String} official_account_name 服务号名称.
  97. * @apiSuccess {String} date 日期
  98. * @apiSuccess {Number} force_user_num 粉丝数
  99. * @apiSuccess {Number} total_force_user_num 总粉丝数
  100. * @apiSuccess {Number} unsubscribe_in_one_day_user_num 24小时取关用户数
  101. * @apiSuccess {String} created_at 创建时间
  102. * @apiSuccess {String} updated_at 更新时间
  103. * @apiSuccess {Number} recharge_amount_in_one_day 24小时充值
  104. * @apiSuccess {Number} recharge_amount_in_three_days 72小时充值
  105. * @apiSuccess {Number} recharge_amount_in_one_month 30天充值
  106. * @apiSuccess {Number} recharge_amount_in_two_months 60天充值
  107. * @apiSuccess {Number} recharge_amount_in_three_months 90天充值
  108. * @apiSuccessExample {json} Success-Response:
  109. *
  110. * {
  111. * "code": 0,
  112. * "msg": "",
  113. * "data": [
  114. * {
  115. * "id": 2,
  116. * "distribution_channel_id": 2,
  117. * "official_account_id": 1233,
  118. * "official_account_name": "杭州掌维",
  119. * "date": "2018-2-9",
  120. * "force_user_num": 11,
  121. * "total_force_user_num": 111,
  122. * "unsubscribe_in_one_day_user_num": 5,
  123. * "created_at": "2017-12-01 10:20:04",
  124. * "updated_at": "2017-12-01 10:20:04",
  125. * "recharge_amount_in_one_day": 9,
  126. * "recharge_amount_in_three_days": 6,
  127. * "recharge_amount_in_one_month": 23,
  128. * "recharge_amount_in_two_months":11,
  129. * "recharge_amount_in_three_months": 112
  130. * }
  131. * ]
  132. * }
  133. */
  134. function exportSendOrderBreakevenStats(Request $request)
  135. {
  136. $params = [];
  137. $request->has('end_date') && $request->input('end_date') && $params['end_date'] = $request->input('end_date');
  138. $request->has('start_date') && $request->input('start_date') && $params['start_date'] = $request->input('start_date');
  139. $request->has('distribution_channel_id') && $request->input('distribution_channel_id') && $params['distribution_channel_id'] = (int)$request->input('distribution_channel_id');
  140. $data = SendOrderBreakevenStatsService::getInfos($params, true);
  141. header("Content-type:application/vnd.ms-excel");
  142. header("Content-Disposition:attachment;filename=" . "数据统计" . date("YmdHis") . ".csv");
  143. echo("\"" . mb_convert_encoding("\"日期\",\"渠道id\",\"渠道名称\",\"服务号id\",\"服务号名称\",\"粉丝数\",\"总粉丝数\",\"24小时取关用户数\",\"创建时间\",\"更新时间\",\"24小时充值\",\"72小时充值\",\"30天充值\",\"60天充值\",\"90天充值\"\r\n", "GBK", "UTF-8") . "\",");
  144. if ($data) {
  145. foreach ($data as $item) {
  146. $official_account_name = $item->official_account_name;
  147. $distribution_channel_name = ChannelService::getChannelNicknameById($item->distribution_channel_id);
  148. echo("\"" . mb_convert_encoding(date('Y-m-d', strtotime($item->date)), "GBK", "UTF-8") . "\",");
  149. echo("\"" . $item->distribution_channel_id . "\",");
  150. echo("\"" . mb_convert_encoding($distribution_channel_name ? $distribution_channel_name : "未知", "GBK", "UTF-8") . "\",");
  151. echo("\"" . $item->official_account_id . "\",");
  152. echo("\"" . mb_convert_encoding($official_account_name ? $official_account_name : "未知", "GBK", "UTF-8") . "\",");
  153. echo("\"" . $item->force_user_num . "\",");
  154. echo("\"" . $item->total_force_user_num . "\",");
  155. echo("\"" . $item->unsubscribe_in_one_day_user_num . "\",");
  156. echo("\"" . mb_convert_encoding(date('Y-m-d H:i:s', strtotime($item->created_at)), "GBK", "UTF-8") . "\",");
  157. echo("\"" . mb_convert_encoding(date('Y-m-d H:i:s', strtotime($item->updated_at)), "GBK", "UTF-8") . "\",");
  158. echo("\"" . $item->recharge_amount_in_one_day . "\",");
  159. echo("\"" . $item->recharge_amount_in_three_days . "\",");
  160. echo("\"" . $item->recharge_amount_in_one_month . "\",");
  161. echo("\"" . $item->recharge_amount_in_two_months . "\",");
  162. echo("\"" . $item->recharge_amount_in_three_months . "\"\r\n");
  163. }
  164. }
  165. exit();
  166. }
  167. }