Setting.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/10/27 23:19
  5. */
  6. namespace app\index\controller;
  7. use app\common\service\SettingService;
  8. use app\index\BaseController;
  9. use app\index\model\SettingModel;
  10. use app\common\until\Until;
  11. use think\facade\Session;
  12. use think\Request;
  13. class Setting extends BaseController {
  14. public function index() {
  15. $input = request()->get();
  16. $model = new SettingModel();
  17. $model->setPage((int)$input['page'] ?: 1);
  18. $model->setPageSize((int)$input['pageSize'] ?: 10);
  19. // if($this->isAdmin()){
  20. // $where = [];
  21. // }else {
  22. // $where[] = ['status', '=', 1];
  23. // }
  24. $where = [];
  25. if (!empty($input['channel_name'])) {
  26. $where[] = ['channel_name', 'like', '%' . $input['channel_name'] . '%'];
  27. }
  28. $model->setWhere($where);
  29. $data = $model->getPageList($model);
  30. Until::output($data);
  31. }
  32. /**
  33. * 显示指定的资源
  34. *
  35. * @param int $id
  36. * @return \think\Response
  37. */
  38. public function read() {
  39. $model = new SettingModel();
  40. $data = $model::where(['id' => (int)input('id')])->find();
  41. Until::output(['info' => Until::modelToArray($data)]);
  42. }
  43. /**
  44. * 保存更新的资源
  45. *
  46. * @return \think\Response
  47. */
  48. public function update() {
  49. $input = Until::getInput();
  50. $rule = [
  51. 'site_id' => 'require',
  52. 'unique_key' => 'require',
  53. 'domain|域名' => 'require',
  54. 'channel_id|频道id' => 'require',
  55. 'channel_name|频道id' => 'require',
  56. 'channel_auth_code|频道授权码' => 'require',
  57. 'redirct_url|跳转链接' => 'require',
  58. 'auth_redirct_url|乙方跳转链接' => 'require',
  59. 'id' => 'require'
  60. ];
  61. Until::check($rule, $input);
  62. $service = new SettingService();
  63. $service->setAuthUrl($input['channel_id'], $input['redirct_url']);
  64. (new SettingModel())::where(['id' => (int)$input['id']])->update([
  65. 'site_id' => $input['site_id'],
  66. 'unique_key' => $input['unique_key'],
  67. 'domain' => $input['domain'],
  68. 'channel_id' => $input['channel_id'],
  69. 'channel_name' => $input['channel_name'],
  70. 'channel_auth_code' => $input['channel_auth_code'],
  71. 'redirct_url' => $input['redirct_url'],
  72. 'auth_redirct_url' => $input['auth_redirct_url'],
  73. ]);
  74. Until::output(['id' => $input['id']]);
  75. }
  76. public function save() {
  77. $input = Until::getInput();
  78. $rule = [
  79. 'site_id' => 'require',
  80. 'unique_key' => 'require',
  81. 'domain|域名' => 'require',
  82. 'channel_id|频道id' => 'require',
  83. 'channel_name|频道名称' => 'require',
  84. 'channel_auth_code|频道授权码' => 'require',
  85. 'redirct_url|跳转链接' => 'require',
  86. 'auth_redirct_url|乙方跳转链接' => 'require',
  87. ];
  88. Until::check($rule, $input);
  89. $service = new SettingService();
  90. $service->verifyChannelName($input['channel_id'], $input['channel_name']);
  91. $service->setAuthUrl($input['channel_id'], $input['redirct_url']);
  92. $id = (new SettingModel())->insertGetId([
  93. 'site_id' => $input['site_id'],
  94. 'unique_key' => $input['unique_key'],
  95. 'domain' => $input['domain'],
  96. 'channel_id' => $input['channel_id'],
  97. 'channel_name' => $input['channel_name'],
  98. 'channel_auth_code' => $input['channel_auth_code'],
  99. 'redirct_url' => $input['redirct_url'],
  100. 'auth_redirct_url' => $input['auth_redirct_url'],
  101. ]);
  102. Until::output(['id' => $id]);
  103. }
  104. public function authCode($channelId) {
  105. $authCode = (new SettingService())->getAuthCode((int)$channelId);
  106. Until::output(['authCode' => $authCode]);
  107. }
  108. }