CustomSendStatsController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace App\Http\Controllers\Channel\OfficialAccount;
  3. use App\Modules\OfficialAccount\Models\CustomMsgSwitchs;
  4. use App\Modules\OfficialAccount\Services\CustomMsgService;
  5. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  6. use App\Modules\OfficialAccount\Services\CustomSendStatsService;
  7. use App\Http\Controllers\Channel\OfficialAccount\Transformers\CustomSendStatsTransformers;
  8. use Illuminate\Http\Request;
  9. class CustomSendStatsController extends ChannelBaseController
  10. {
  11. /**
  12. * @apiDefine OfficialAccount 公众号
  13. */
  14. /**
  15. * @apiVersion 1.0.0
  16. * @api {GET} OfficialAccount/customSendDayStatsByChannelAndFrom 获取每日智能推送分析数据
  17. * @apiGroup OfficialAccount
  18. * @apiName customSendDayStatsByChannelAndFrom
  19. * @apiParam {String} from 智能分析类型 not_pay未支付提醒 recovery_push三天回本 hot_push热门推送 point_push书籍推荐.
  20. * @apiSuccess {String} distribution_channel_id 渠道号.
  21. * @apiSuccess {String} date 日期.
  22. * @apiSuccess {String} push_user_num 推送次数.
  23. * @apiSuccess {String} click_num 点击次数.
  24. * @apiSuccess {String} amount 充值金额.
  25. * @apiSuccess {String} success_pay_num 充值笔数.
  26. * @apiSuccess {String} success_pay_rate 充值率.
  27. * @apiSuccess {String} click_rate 点击率.
  28. * @apiSuccess {String} from 智能分析类型 not_pay未支付提醒 recovery_push三天回本 hot_push热门推送 point_push书籍推荐..
  29. * @apiSuccessExample {json} Success-Response:
  30. *
  31. * {
  32. * "code": 0,
  33. * "msg": "",
  34. * "data": {
  35. * "list": [
  36. * {
  37. * "id": 1,
  38. * "distribution_channel_id": 2,
  39. * "date": "2018-01-17",
  40. * "push_user_num": 1211,
  41. * "click_num": 211,
  42. * "click_rate": 0.000,
  43. * "amount": "2312.00",
  44. * "success_pay_num": 123,
  45. * "success_pay_rate": "0.5100",
  46. * "from": "not_pay"
  47. * },
  48. * {
  49. * "id": 2,
  50. * "distribution_channel_id": 2,
  51. * "date": "2018-01-16",
  52. * "push_user_num": 1312,
  53. * "click_num": 421,
  54. * "click_rate": 0.000,
  55. * "amount": "16421.00",
  56. * "success_pay_num": 3212,
  57. * "success_pay_rate": "0.2100",
  58. * "from": "not_pay"
  59. * }
  60. * ],
  61. * "meta": {
  62. * "total": 2,
  63. * "per_page": 15,
  64. * "current_page": 1,
  65. * "last_page": 1,
  66. * "next_page_url": "",
  67. * "prev_page_url": ""
  68. * }
  69. * }
  70. * }
  71. */
  72. function customSendDayStatsByChannelAndFrom(Request $request) {
  73. $distribution_channel_id = $this->getChannelId();
  74. $from = $request->has('from') ? $request->input('from') : '';
  75. if(empty($from)) {
  76. return response()->error("PARAM_EMPTY");
  77. }
  78. \Log::info('日推送智能分析 渠道ID:'.$distribution_channel_id);
  79. \Log::info('日推送智能分析 类型:'.$from);
  80. $customMsgService = CustomSendStatsService::customSendDayStatsByChannelAndFrom($distribution_channel_id,$from);
  81. if (!empty($customMsgService)) {
  82. return response()->pagination(new CustomSendStatsTransformers(), $customMsgService);
  83. }else{
  84. $customMsgService['distribution_channel_id'] = $distribution_channel_id;
  85. $customMsgService['date'] = date("Y-m-d");
  86. $customMsgService['push_user_num'] = 0;
  87. $customMsgService['click_num'] = 0;
  88. $customMsgService['amount'] = 0;
  89. $customMsgService['success_pay_num'] = 0;
  90. $customMsgService['success_pay_rate'] = 0;
  91. $customMsgService['click_rate'] = 0;
  92. $customMsgService['from'] = $from;
  93. return response()->item(new CustomSendStatsTransformers(), $customMsgService);
  94. }
  95. }
  96. /**
  97. * @apiVersion 1.0.0
  98. * @api {GET} OfficialAccount/customSendStatsByChannelAndFrom 获取智能推送分析总数据
  99. * @apiGroup OfficialAccount
  100. * @apiName customSendStatsByChannelAndFrom
  101. * @apiParam {String} from 智能分析类型 not_pay未支付提醒 recovery_push三天回本 hot_push热门推送 point_push书籍推荐.
  102. * @apiSuccess {String} distribution_channel_id 渠道号.
  103. * @apiSuccess {String} date 日期.
  104. * @apiSuccess {String} push_user_num 推送次数.
  105. * @apiSuccess {String} click_num 点击次数.
  106. * @apiSuccess {String} amount 充值金额.
  107. * @apiSuccess {String} success_pay_num 充值笔数.
  108. * @apiSuccess {String} success_pay_rate 充值率.
  109. * @apiSuccess {String} click_rate 点击率.
  110. * @apiSuccess {String} from 智能分析类型 not_pay未支付提醒 recovery_push三天回本 hot_push热门推送 point_push书籍推荐..
  111. * @apiSuccessExample {json} Success-Response:
  112. *
  113. * {
  114. * "code": 0,
  115. * "msg": "",
  116. * "data": {
  117. * "id": 1,
  118. * "distribution_channel_id": 2,
  119. * "date": "2018-01-18",
  120. * "push_user_num": 4123,
  121. * "click_num": 543,
  122. * "amount": "123141.00",
  123. * "success_pay_num": 2132,
  124. * "success_pay_rate": "0.3100",
  125. * "click_rate": "0.0000",
  126. * "from": "not_pay"
  127. * }
  128. * }
  129. */
  130. function customSendStatsByChannelAndFrom(Request $request) {
  131. $distribution_channel_id = $this->getChannelId();
  132. $from = $request->has('from') ? $request->input('from') : '';
  133. if(empty($from)) {
  134. return response()->error("PARAM_EMPTY");
  135. }
  136. \Log::info('日推送智能分析 渠道ID:'.$distribution_channel_id);
  137. \Log::info('日推送智能分析 类型:'.$from);
  138. $customMsgService = CustomSendStatsService::customSendStatsByChannelAndFrom($distribution_channel_id,$from);
  139. if (!empty($customMsgService)) {
  140. return response()->item(new CustomSendStatsTransformers(), $customMsgService);
  141. }else{
  142. $customMsgService['distribution_channel_id'] = $distribution_channel_id;
  143. $customMsgService['date'] = date("Y-m-d");
  144. $customMsgService['push_user_num'] = 0;
  145. $customMsgService['click_num'] = 0;
  146. $customMsgService['amount'] = 0;
  147. $customMsgService['success_pay_num'] = 0;
  148. $customMsgService['success_pay_rate'] = 0;
  149. $customMsgService['click_rate'] = 0;
  150. $customMsgService['from'] = $from;
  151. return response()->item(new CustomSendStatsTransformers(), $customMsgService);
  152. }
  153. }
  154. /**
  155. * 获取智能推送列表
  156. * @param Request $request
  157. */
  158. function customSendStatsFromTypes(Request $request) {
  159. $customMsgSwitchs = CustomMsgSwitchs::getCustomMsgSwitchs();
  160. return response()->success($customMsgSwitchs);
  161. }
  162. }