DistributionSelfDefineContentsController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace App\Http\Controllers\Channel\OfficialAccount;
  3. use App\Http\Controllers\Channel\BaseController as ChannelBaseController;
  4. use App\Http\Controllers\Channel\OfficialAccount\Transformers\SmartPushMsgTransformer;
  5. use Illuminate\Http\Request;
  6. use GuzzleHttp\Client;
  7. use App\Modules\OfficialAccount\Services\MsgService;
  8. use App\Modules\Statistic\Services\SendStatistics;
  9. /**
  10. * 关注回复
  11. */
  12. class DistributionSelfDefineContentsController extends ChannelBaseController
  13. {
  14. /**
  15. * @apiDefine OfficialAccount 公众号
  16. */
  17. /**
  18. * @apiVersion 1.0.0
  19. * @api {GET} distribution_self_define_contents 获取关注回复
  20. * @apiGroup OfficialAccount
  21. * @apiName distribution_self_define_contents
  22. * @apiParam {String} distribution_channel_id 渠道ID.
  23. */
  24. function getSubReply(Request $request)
  25. {
  26. $distribution_channel_id = $this->getChannelId();
  27. if(empty($distribution_channel_id)) {
  28. return response()->error("PARAM_EMPTY");
  29. }
  30. $sub_reply = MsgService::getReply($distribution_channel_id);
  31. $data = [];
  32. $list = [];
  33. $data['mode'] = 1;
  34. if($sub_reply)
  35. {
  36. isset($sub_reply['current']) && $data['mode'] = $sub_reply['current'];
  37. if(isset($sub_reply[2]))//有设置图文
  38. {
  39. $list[] = [
  40. 'content'=>json_decode($sub_reply[2]),
  41. 'is_pic'=>1,
  42. 'status'=>$data['mode'] == 2 ? 1 : 0
  43. ];
  44. }
  45. if(isset($sub_reply[3]))//有设置文本
  46. {
  47. $list[] = [
  48. 'content'=>$sub_reply[3],
  49. 'is_pic'=>0,
  50. 'status'=>$data['mode'] == 3 ? 1 : 0
  51. ];
  52. }
  53. }
  54. $data['list'] = $list;
  55. return response()->success($data);
  56. }
  57. /**
  58. * @apiVersion 1.0.0
  59. * @api {GET} distribution_self_define_contents 获取关注回复列表
  60. * @apiGroup OfficialAccount
  61. * @apiName distribution_self_define_contents
  62. * @apiParam {String} distribution_channel_id 渠道ID.
  63. */
  64. function getSubReplyList(Request $request)
  65. {
  66. $distribution_channel_id = $this->getChannelId();
  67. if(empty($distribution_channel_id)) {
  68. return response()->error("PARAM_EMPTY");
  69. }
  70. $sub_reply = MsgService::getReply($distribution_channel_id);
  71. if(!isset($sub_reply['content_mode_2'])){
  72. $sub_reply['content_mode_2'] = '';
  73. }
  74. if(!isset($sub_reply['content_mode_3'])){
  75. $sub_reply['content_mode_3'] = '';
  76. }
  77. if(!isset($sub_reply['current'])){
  78. $sub_reply['current'] = '1';
  79. }
  80. // $pic_list = isset($sub_reply['content_mode_2'])?$sub_reply['content_mode_2']:'';
  81. // $pic_list = object_to_array(json_decode($pic_list));
  82. // $text_list = isset($sub_reply['content_mode_3'])?$sub_reply['content_mode_3']:'';
  83. // $text_list = object_to_array(json_decode($text_list));
  84. // $mode = isset($sub_reply['current'])?$sub_reply['current']:'1';
  85. // \Log::info('pic_list');\Log::info($pic_list);
  86. // \Log::info('text_list');\Log::info($text_list);
  87. // $data = [
  88. // 'pic_list'=>$pic_list,
  89. // 'text_list'=>$text_list,
  90. // 'mode'=>$mode,
  91. // ];
  92. return response()->success($sub_reply);
  93. }
  94. function getCurrentReply(Request $request)
  95. {
  96. $distribution_channel_id = $this->getChannelId();
  97. if(empty($distribution_channel_id)) {
  98. return response()->error("PARAM_EMPTY");
  99. }
  100. $sub_reply = MsgService::getCurrentReply($distribution_channel_id);
  101. $sub_reply = object_to_array($sub_reply);
  102. return response()->success($sub_reply);
  103. }
  104. /**
  105. * @apiVersion 1.0.0
  106. * @api {GET} distribution_self_define_contents 设置关注回复
  107. * @apiGroup OfficialAccount
  108. * @apiName set_distribution_self_define_contents
  109. * @apiParam {String} distribution_channel_id 渠道ID.
  110. */
  111. function setSubReply(Request $request)
  112. {
  113. $distribution_channel_id = $this->getChannelId();
  114. $mode = $request->has('mode') ? (int)$request->input('mode') : 1;
  115. $is_pic = $request->has('is_pic') ? (int)$request->input('is_pic') : 0;
  116. $start_time = $request->has('start_time') ?$request->input('start_time') : '2018-01-01';
  117. $end_time = $request->has('end_time') ? $request->input('end_time') : '2030-01-01';
  118. $content = $request->has('content') ? $request->input('content') : '';
  119. $key = $request->has('key') ? $request->input('key') : '0';
  120. $action = $request->has('action') ? $request->input('action') : 'update';
  121. $status = $request->has('status') ? (int)$request->input('status') : 1;
  122. $is_pic && $content = json_encode($content);
  123. if(empty($distribution_channel_id)) {
  124. return response()->error("PARAM_EMPTY");
  125. }
  126. \Log::info('setSubReply');\Log::info($content);
  127. if(strpos($content,'w.url.cn') > -1){
  128. \Log::info('setSubReply_url_false');
  129. return response()->error("SHORT_URL_NOT_ALLOW_ERROR");
  130. }
  131. $sub_reply = MsgService::setReply(compact('distribution_channel_id','is_pic','content','mode','start_time','end_time','key','action','status'));
  132. return response()->success();
  133. }
  134. }