BusinessChannelDataController.php 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/26
  6. * Time: 下午5:32
  7. */
  8. namespace App\Http\Controllers\Manage\Channel;
  9. use App\Http\Controllers\Manage\Channel\Transformers\BusinessChannelDataTransformer;
  10. use App\Http\Controllers\Manage\Finance\BaseController;
  11. use App\Modules\Channel\Services\ChannelService;
  12. use App\Modules\Manage\Services\ManageService;
  13. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  14. use Illuminate\Http\Request;
  15. /**
  16. * 商务运营-渠道粉丝阈值模块
  17. * Class BusinessChannelDataController
  18. * @package App\Http\Controllers\Manage\Channel
  19. */
  20. class BusinessChannelDataController extends BaseController
  21. {
  22. /**
  23. * 获取商务各自的渠道信息
  24. * @param Request $request
  25. */
  26. function getBusinessChannelData(Request $request)
  27. {
  28. $result = [];
  29. $manageId = $request->session()->get('manage_auth');
  30. $distribution_channel_id = $request->input('distribution_channel_id');
  31. $distribution_channel_name = $request->input('distribution_channel_name');
  32. $official_account_name = $request->input('official_account_name');
  33. if (!empty($manageId)) {
  34. $manageModel = ManageService::getById($manageId);
  35. if ($manageModel) {
  36. $role = $manageModel->role;
  37. $channels = ($role == 'admin') ? [] : ChannelService::getByDistributionManagesId($manageId);
  38. if ($distribution_channel_id) {
  39. $channels = [$distribution_channel_id];
  40. }
  41. \Log::info('getBusinessChannelData_official_account_name:'.$official_account_name.' $distribution_channel_name:'.$distribution_channel_name);
  42. $result = OfficialAccountService::getBusinessChannelData($channels, $distribution_channel_name, $official_account_name,false);
  43. }
  44. }
  45. return response()->pagination(new BusinessChannelDataTransformer(), $result);
  46. }
  47. /**
  48. * 导出商务各自的渠道信息
  49. * @param Request $request
  50. */
  51. function exportBusinessChannelData(Request $request)
  52. {
  53. $result = [];
  54. $distribution_channel_id = $request->input('distribution_channel_id');
  55. $distribution_channel_name = $request->input('distribution_channel_name');
  56. $official_account_name = $request->input('official_account_name');
  57. $manageId = $request->session()->get('manage_auth');
  58. if (!empty($manageId)) {
  59. $manageModel = ManageService::getById($manageId);
  60. if ($manageModel) {
  61. $role = $manageModel->role;
  62. $channels = ($role == 'admin') ? [] : ChannelService::getByDistributionManagesId($manageId);
  63. if ($distribution_channel_id) {
  64. $channels = [$distribution_channel_id];
  65. }
  66. \Log::info('getBusinessChannelData_official_account_name:'.$official_account_name.' $distribution_channel_name:'.$distribution_channel_name);
  67. $result = OfficialAccountService::getBusinessChannelData($channels, $distribution_channel_name, $official_account_name,false);
  68. }
  69. header("Content-type:application/vnd.ms-excel");
  70. header("Content-Disposition:attachment;filename=" . "明细" . date("YmdHis") . ".csv");
  71. echo iconv("UTF-8", "GBK", "\"渠道ID\",\"渠道名称\",\"服务号名称\",\"日关注粉丝阈值\",\"总关注粉丝阈值\",\"当日实时关注粉丝数\",\"当日实时累计总粉丝数\"\r\n");
  72. foreach ($result as $item) {
  73. echo("\"" . mb_convert_encoding($item->distribution_channel_id, "GBK", "UTF-8") . "\",");
  74. echo("\"" . mb_convert_encoding($item->distribution_channel_name, "GBK", "UTF-8") . "\",");
  75. echo("\"" . mb_convert_encoding($item->service_name, "GBK", "UTF-8") . "\",");
  76. echo("\"" . mb_convert_encoding($item->subscribe_day_maximum, "GBK", "UTF-8") . "\",");
  77. echo("\"" . mb_convert_encoding($item->subscribe_top_num, "GBK", "UTF-8") . "\",");
  78. echo("\"" . mb_convert_encoding($item->day_fans_num, "GBK", "UTF-8") . "\",");
  79. echo("\"" . $item->day_total_fans_num . "\"\r\n");
  80. }
  81. exit();
  82. }
  83. }
  84. }