ChannelSubscribeSettingController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Controllers\Channel\Channel;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Channel\BaseController;
  5. use App\Modules\Channel\Services\ChannelSubscribeSettingService;
  6. use App\Http\Controllers\Channel\Channel\Transformers\ChannelSubscribeTransformer;
  7. class ChannelSubscribeSettingController extends BaseController
  8. {
  9. /**
  10. * @apiDefine ChannelSubscribe 渠道强关
  11. */
  12. /**
  13. * @apiVersion 1.0.0
  14. * @apiDescription 获取强关配置
  15. * @api {GET} channels/getSubscribeSetting 获取强关配置
  16. * @apiGroup ChannelSubscribe
  17. * @apiName getSubscribeSetting
  18. * @apiParam {String} appid appid
  19. * @apiSuccess {Number} force_subscribe_type 强关类型
  20. * @apiSuccess {String} resource_url 跳转地址
  21. * @apiSuccessExample {json} Success-Response:
  22. *
  23. * {
  24. * "code": 0,
  25. * "msg": "",
  26. * "data":
  27. * {
  28. * id:123,
  29. * force_subscribe_type:2,
  30. * resource_url:12222
  31. * }
  32. * }
  33. */
  34. public function getSubscribeSetting(Request $request){
  35. $channel_id = $this->getChannelId();
  36. $appid = $request->input('appid');
  37. $setting = ChannelSubscribeSettingService::getSubscribeTypeByAppId($appid);
  38. if($setting){
  39. $setting->id = $channel_id;
  40. return response()->item(new ChannelSubscribeTransformer,$setting);
  41. }
  42. return response()->success();
  43. }
  44. /**
  45. * @apiVersion 1.0.0
  46. * @apiDescription 设置强关类型
  47. * @api {POST} channels/setSubscribeType 设置强关类型
  48. * @apiGroup ChannelSubscribe
  49. * @apiName setSubscribeType
  50. * @apiParam {Number} force_subscribe_type 强关类型
  51. * @apiParam {String} resource_url 跳转地址
  52. * @apiParam {String} appid appid
  53. * @apiSuccessExample {json} Success-Response:
  54. *
  55. * {
  56. * "code": 0,
  57. * "msg": "",
  58. * "data":
  59. * {
  60. * id:123,
  61. * force_subscribe_type:2,
  62. * resource_url:12222
  63. * }
  64. * }
  65. */
  66. public function setSubscribeType(Request $request){
  67. $force_subscribe_type = $request->input('force_subscribe_type');
  68. $resource_url = $request->input('resource_url');
  69. $distribution_channel_id = $this->getChannelId();
  70. $appid = $request->input('appid');
  71. if(empty($force_subscribe_type) || empty($appid)){
  72. return response()->error('PARAM_EMPTY');
  73. }
  74. ChannelSubscribeSettingService::updateOrSettingForceSubScribe(compact('force_subscribe_type','resource_url','distribution_channel_id','appid'));
  75. $setting = ChannelSubscribeSettingService::getSubscribeTypeByAppId($appid);
  76. $setting->force_subscribe_type_text = str_replace(['1','2','3'],['强制关注','弱关注','强制链接关注'],$setting->force_subscribe_type);
  77. $setting->force_subscribe_type = explode(',',$setting->force_subscribe_type);
  78. return response()->success($setting);
  79. }
  80. }