Setting.php 4.0 KB

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