NoticesController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace App\Http\Controllers\Channel\Notice;
  3. use App\Http\Controllers\Channel\BaseController;
  4. use App\Http\Controllers\Channel\Notice\Transformers\NoticeTransformer;
  5. use App\Http\Controllers\Channel\Notice\Transformers\SimpleNoticeTransformer;
  6. use App\Modules\Channel\Services\ChannelService;
  7. use App\Modules\Notice\Services\fansLimitNoticeService;
  8. use App\Modules\Notice\Services\NoticeService;
  9. use Illuminate\Http\Request;
  10. class NoticesController extends BaseController
  11. {
  12. /**
  13. * @apiDefine Notice 公告
  14. */
  15. /**
  16. * @apiVersion 1.0.0
  17. * @apiDescription 获取公告列表
  18. * @api {GET} notices 获取公告列表
  19. * @apiGroup Notice
  20. * @apiName notices
  21. * @apiParam {Number} [notice_type_id] 公告分类id.(可不传,不传获取所有分类公告)
  22. * @apiParam {Number} [status] 状态.0:正常状态; -1:删除 (可不传,不传获取所有分类公告)
  23. * @apiSuccess {Number} id 公告ID.
  24. * @apiSuccess {String} is_popup 是否弹出. 0:普通;1:弹框;
  25. * @apiSuccess {String} title 标题.
  26. * @apiSuccess {String} content 内容.
  27. * @apiSuccess {status} status 状态.0:正常状态; -1:删除
  28. * @apiSuccess {String} updated_time 更新时间.
  29. * @apiSuccess {String} type_name 类型名称
  30. * @apiSuccess {Number} type_id 类型ID
  31. * @apiSuccessExample {json} Success-Response:
  32. *
  33. * {
  34. * "code": 0,
  35. * "msg": "",
  36. * "data":
  37. * {
  38. * "list":[
  39. * {
  40. * "id": "121",
  41. * "is_popup": "1",
  42. * "title": "1212-12-12-12",
  43. * "content": "对不起,我爱你",
  44. * "status": 0,
  45. * "updated_time": "2017-12-12 12:12:12"
  46. * "type_name": "测试类型",
  47. * "type_id": 1
  48. * }
  49. * ],
  50. * "meta":{
  51. * "total"=>224,
  52. * "per_page"=>15,
  53. * "current_page"=>1,
  54. * "last_page"=>15,
  55. * "next_page_url"=>"",
  56. * "prev_page_url"=>""
  57. * }
  58. * }
  59. * }
  60. */
  61. function get_list(Request $request)
  62. {
  63. $notice_type_id = $request->has('notice_type_id') && $request->input('notice_type_id') ? $request->input('notice_type_id') : null;
  64. $status = $request->has('status') && $request->input('status') ? $request->input('status') : null;
  65. $status = 0;
  66. $notices = NoticeService::getAllNoticeList($notice_type_id, $status);
  67. return response()->pagination(new NoticeTransformer(), $notices);
  68. }
  69. //获取简易的通知列表
  70. function get_simple_list(Request $request)
  71. {
  72. $notice_type_id = $request->has('notice_type_id') && $request->input('notice_type_id') ? $request->input('notice_type_id') : null;
  73. $status = $request->has('status') && $request->input('status') ? $request->input('status') : null;
  74. $status = 0;
  75. $notices = NoticeService::getSimpleNoticeList($notice_type_id, $status);
  76. return response()->pagination(new SimpleNoticeTransformer(), $notices);
  77. }
  78. /**
  79. * @apiVersion 1.0.0
  80. * @apiDescription 获取一个公告
  81. * @api {get} getNotice 获取一个公告
  82. * @apiGroup Notice
  83. * @apiName getNotice
  84. * @apiParam {Number} id 公告ID.
  85. * @apiSuccess {String} is_popup 是否弹出. 0:普通;1:弹框;
  86. * @apiSuccess {String} title 标题.
  87. * @apiSuccess {String} content 内容.
  88. * @apiSuccess {status} status 状态.0:正常状态; -1:删除
  89. * @apiSuccess {String} updated_time 更新时间.
  90. * @apiSuccess {String} type_name 类型名称
  91. * @apiSuccess {Number} type_id 类型ID
  92. * @apiSuccessExample {json} Success-Response:
  93. * {
  94. * "code": 0,
  95. * "msg": "",
  96. * "data":{
  97. * "id": "121",
  98. * "is_popup": "1",
  99. * "title": "1212-12-12-12",
  100. * "content": "对不起,我爱你",
  101. * "status": 0,
  102. * "updated_time": "2017-12-12 12:12:12"
  103. * "type_name": "测试类型",
  104. * "type_id": 1
  105. * }
  106. * }
  107. */
  108. function get_notice(Request $request) {
  109. $id = $request->has('id') ? $request->input('id') : '';
  110. if(!is_numeric($id)) {
  111. return response()->error("PARAM_ERROR");
  112. }
  113. $notice = NoticeService::getNotice($id);
  114. if(empty($notice)) {
  115. return response()->error("PARAM_ERROR");
  116. }
  117. return response()->item(new NoticeTransformer(), $notice);
  118. }
  119. public function getfansLimitNotice(){
  120. $channel_user_id = $this->getChannelUserId();
  121. if(!$channel_user_id) return response()->error('PARAM_ERROR');
  122. $distribution_channel_ids = ChannelService::getUserChannelIds($channel_user_id);
  123. $notice = fansLimitNoticeService::getAllOfficialAccountsLimit($distribution_channel_ids);
  124. $data=[];
  125. if(!$notice->isEmpty()){
  126. $official_accounts = [];
  127. foreach ($notice as $item){
  128. $official_accounts[] = $item->account_nickname;
  129. $item->is_read=1;
  130. $item->save();
  131. }
  132. $official_accounts = implode(',',$official_accounts);
  133. $data = [
  134. 'title'=>'阈值提醒',
  135. 'contents'=>"站点服务号{$official_accounts}今日增粉阈值0,请关注服务号解封情况!
  136. 解封后请前往系统设置-服务号设置-编辑,调高日关注上限!"
  137. ];
  138. return response()->success($data);
  139. }
  140. return response()->success($data);
  141. }
  142. }