CustomTemplateSendStatsController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: hp
  5. * Date: 2017/11/30
  6. * Time: 17:24
  7. */
  8. namespace App\Http\Controllers\Manage\OfficialAccount;
  9. use App\Http\Controllers\Manage\BaseController;
  10. use App\Http\Controllers\Manage\OfficialAccount\Transformers\CustomTemplateSendStatTransformer;
  11. use App\Modules\OfficialAccount\Services\CustomTemplateSendStatService;
  12. use App\Modules\Statistic\Services\SendStatistics;
  13. use Illuminate\Http\Request;
  14. class CustomTemplateSendStatsController extends BaseController
  15. {
  16. /**
  17. * @apiDefine OfficialAccount 客服模板消息发送统计
  18. */
  19. /**
  20. * @apiVersion 1.0.0
  21. * @api {GET} OfficialAccount/customTemplateSendStats 客服模板消息发送统计
  22. * @apiGroup OfficialAccount
  23. * @apiName customTemplateSendStats
  24. * @apiParam {Number} stat_type 类型(templateMessage,customerServiceNews,intelligentRecommendation).
  25. * @apiParam {Number} start_date 起始查询.
  26. * @apiParam {Number} start_date 截止查询.
  27. */
  28. //http://zzsy/api/OfficialAccount/customTemplateSendStats?start_date=2018-03-01&end_date=2018-03-08&stat_type=templateMessage
  29. function customTemplateSendStats(Request $request)
  30. {
  31. $stat_type = $request->has('stat_type') ? $request->input('stat_type') : 'templateMessage';
  32. $start_date = $request->has('start_date') ? $request->input('start_date') : date('Y-m-d',strtotime('-7 day'));
  33. $end_date = $request->has('end_date') ? $request->input('end_date') : date('Y-m-d',strtotime('+1 day'));
  34. \Log::info('customTemplateSendStats:stat_type.'.$stat_type.' start_date:'.$start_date.' end_date:'.$end_date);
  35. $base_datas = CustomTemplateSendStatService::getMainCustomTemplateSendStat($stat_type,$start_date,$end_date);
  36. \Log::info('$base_datas');\Log::info($base_datas);
  37. return response()->pagination(new CustomTemplateSendStatTransformer(), $base_datas);
  38. }
  39. /**
  40. * @apiVersion 1.0.0
  41. * @api {GET} OfficialAccount/exportCustomTemplateSendStats 导出-客服模板消息发送统计
  42. * @apiGroup OfficialAccount
  43. * @apiName exportCustomTemplateSendStats
  44. * @apiParam {Number} stat_type 类型(templateMessage,customerServiceNews,intelligentRecommendation).
  45. * @apiParam {Number} start_date 起始查询.
  46. * @apiParam {Number} start_date 截止查询.
  47. */
  48. //http://zzsy/api/OfficialAccount/exportCustomTemplateSendStats?stat_type=templateMessage&start_date=2017-03-01&end_date=2018-03-08
  49. function exportCustomTemplateSendStats(Request $request)
  50. {
  51. $stat_type = $request->has('stat_type') ? $request->input('stat_type') : 'templateMessage';
  52. $start_date = $request->has('start_date') ? $request->input('start_date') : date('Y-m-d',strtotime('-7 day'));
  53. $end_date = $request->has('end_date') ? $request->input('end_date') : date('Y-m-d',strtotime('+1 day'));
  54. \Log::info('customTemplateSendStats:stat_type.'.$stat_type.' start_date:'.$start_date.' end_date:'.$end_date);
  55. $CustomTemplateSendStats = CustomTemplateSendStatService::getMainCustomTemplateSendStat($stat_type,$start_date,$end_date,true);
  56. \Log::info('export_customTemplateSendStats_stats');\Log::info($CustomTemplateSendStats);
  57. // return response()->collection(new CustomTemplateSendStatTransformer(), $CustomTemplateSendStats);
  58. header("Content-type:application/vnd.ms-excel");
  59. header("Content-Disposition:attachment;filename=" . "客服模板消息发送统计" . date("YmdHis") . ".csv");
  60. echo iconv("UTF-8","GBK","\"日期\",\"模板名称\",\"任务名称\",\"渠道id\",\"公众号名称\",\"标签\",\"发送时间\",\"成功发送人数\",\"UV\",\"总订单数\",\"成功订单数\",\"充值金额\",\"非首充用户数\"\r\n");
  61. if($CustomTemplateSendStats)
  62. {
  63. foreach($CustomTemplateSendStats as $CustomTemplateSendStat){
  64. echo("\"" . (isset($CustomTemplateSendStat->created_date) ? $CustomTemplateSendStat->created_date : "") . "\",");
  65. echo("\"" . (iconv('utf-8','gbk',isset($CustomTemplateSendStat->template_name) ? $CustomTemplateSendStat->template_name : "")) . "\",");
  66. echo("\"" . (iconv('utf-8','gbk',isset($CustomTemplateSendStat->task_name) ? $CustomTemplateSendStat->task_name : "")) . "\",");
  67. echo("\"" . (isset($CustomTemplateSendStat->site_id) ? $CustomTemplateSendStat->site_id : "") . "\",");
  68. echo("\"" . (iconv('utf-8','gbk',isset($CustomTemplateSendStat->official_account_name) ? $CustomTemplateSendStat->official_account_name : "")) . "\",");
  69. echo("\"" . (iconv('utf-8','gbk',isset($CustomTemplateSendStat->tag) ? $CustomTemplateSendStat->tag : "")) . "\",");
  70. echo("\"" . (isset($CustomTemplateSendStat->send_time) ? $CustomTemplateSendStat->send_time : "") . "\",");
  71. echo("\"" . (isset($CustomTemplateSendStat->suc_send_num) ? $CustomTemplateSendStat->suc_send_num : "") . "\",");
  72. echo("\"" . (isset($CustomTemplateSendStat->uv) ? $CustomTemplateSendStat->uv : "") . "\",");
  73. echo("\"" . (isset($CustomTemplateSendStat->total_order_num) ? $CustomTemplateSendStat->total_order_num : "") . "\",");
  74. echo("\"" . (isset($CustomTemplateSendStat->suc_order_num) ? $CustomTemplateSendStat->suc_order_num : "") . "\",");
  75. echo("\"" . (isset($CustomTemplateSendStat->charge_amount) ? $CustomTemplateSendStat->charge_amount : "") . "\",");
  76. echo("\"" . (isset($CustomTemplateSendStat->not_first_charge_user_num) ? $CustomTemplateSendStat->not_first_charge_user_num : "") . "\"\r\n");
  77. }
  78. }
  79. exit();
  80. }
  81. }