Setting.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Author: luzheng.liu
  4. * Time: 2020/10/27 23:19
  5. */
  6. namespace app\index\controller;
  7. use app\index\BaseController;
  8. use app\index\model\SettingModel;
  9. use app\common\until\Until;
  10. use think\Request;
  11. class Setting extends BaseController {
  12. /**
  13. * 显示指定的资源
  14. *
  15. * @param int $id
  16. * @return \think\Response
  17. */
  18. public function read() {
  19. $model = new SettingModel();
  20. $data = $model::where(['id' => 1])->find();
  21. Until::output(['info' => Until::modelToArray($data)]);
  22. }
  23. /**
  24. * 保存更新的资源
  25. *
  26. * @return \think\Response
  27. */
  28. public function update() {
  29. $input = Until::getInput();
  30. $rule = [
  31. 'site_id' => 'require',
  32. 'unique_key' => 'require',
  33. 'domain|域名' => 'require',
  34. 'channel_id|频道id' => 'require',
  35. 'channel_auth_code|频道授权码' => 'require',
  36. 'redirct_url|跳转链接' => 'require',
  37. ];
  38. Until::check($rule, $input);
  39. (new SettingModel())::where(['id' => 1])->update([
  40. 'site_id' => $input['site_id'],
  41. 'unique_key' => $input['unique_key'],
  42. 'domain' => $input['domain'],
  43. 'channel_id' => $input['channel_id'],
  44. 'channel_auth_code' => $input['channel_auth_code'],
  45. 'redirct_url' => $input['redirct_url'],
  46. ]);
  47. Until::output(['id' => $input['id']]);
  48. }
  49. }