Setting.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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['mobile'])) {
  26. $where[] = ['mobile', 'like', '%' . $input['mobile'] . '%'];
  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. Session::clear();
  41. $data = $model::where(['id' => (int)input('id')])->find();
  42. Until::output(['info' => Until::modelToArray($data)]);
  43. }
  44. /**
  45. * 保存更新的资源
  46. *
  47. * @return \think\Response
  48. */
  49. public function update() {
  50. $input = Until::getInput();
  51. $rule = [
  52. 'site_id' => 'require',
  53. 'unique_key' => 'require',
  54. 'domain|域名' => 'require',
  55. 'channel_id|频道id' => 'require',
  56. 'channel_name|频道id' => 'require',
  57. 'channel_auth_code|频道授权码' => 'require',
  58. 'redirct_url|跳转链接' => 'require',
  59. 'auth_redirct_url|乙方跳转链接' => 'require',
  60. 'id' => 'require'
  61. ];
  62. Until::check($rule, $input);
  63. (new SettingModel())::where(['id' => (int)$input['id']])->update([
  64. 'site_id' => $input['site_id'],
  65. 'unique_key' => $input['unique_key'],
  66. 'domain' => $input['domain'],
  67. 'channel_id' => $input['channel_id'],
  68. 'channel_name' => $input['channel_name'],
  69. 'channel_auth_code' => $input['channel_auth_code'],
  70. 'redirct_url' => $input['redirct_url'],
  71. 'auth_redirct_url' => $input['auth_redirct_url'],
  72. ]);
  73. Until::output(['id' => $input['id']]);
  74. }
  75. public function save() {
  76. $input = Until::getInput();
  77. $rule = [
  78. 'site_id' => 'require',
  79. 'unique_key' => 'require',
  80. 'domain|域名' => 'require',
  81. 'channel_id|频道id' => 'require',
  82. 'channel_name|频道名称' => 'require',
  83. 'channel_auth_code|频道授权码' => 'require',
  84. 'redirct_url|跳转链接' => 'require',
  85. 'auth_redirct_url|乙方跳转链接' => 'require',
  86. ];
  87. Until::check($rule, $input);
  88. $service = new SettingService();
  89. $service->verifyChannelName($input['channel_id'], $input['channel_name']);
  90. $service->setAuthUrl($input['channel_id'], $input['redirct_url']);
  91. $id = (new SettingModel())->insertGetId([
  92. 'site_id' => $input['site_id'],
  93. 'unique_key' => $input['unique_key'],
  94. 'domain' => $input['domain'],
  95. 'channel_id' => $input['channel_id'],
  96. 'channel_name' => $input['channel_name'],
  97. 'channel_auth_code' => $input['channel_auth_code'],
  98. 'redirct_url' => $input['redirct_url'],
  99. 'auth_redirct_url' => $input['auth_redirct_url'],
  100. ]);
  101. Until::output(['id' => $id]);
  102. }
  103. public function authCode($channelId) {
  104. $authCode = (new SettingService())->getAuthCode((int)$channelId);
  105. Until::output(['authCode' => $authCode]);
  106. }
  107. }