Config.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace app\controller\admin;
  3. use app\extra\basic\Base;
  4. use app\extra\tools\OssRegionExtend;
  5. use app\middleware\AuthMiddleware;
  6. use app\model\system\SystemConfig;
  7. use LinFly\Annotation\Attributes\Route\Controller;
  8. use LinFly\Annotation\Attributes\Route\GetMapping;
  9. use LinFly\Annotation\Attributes\Route\Middleware;
  10. use LinFly\Annotation\Attributes\Route\PostMapping;
  11. use support\Request;
  12. use support\Response;
  13. #[Controller("/api/config"),Middleware(AuthMiddleware::class)]
  14. class Config extends Base
  15. {
  16. #[GetMapping('list')]
  17. public function getConfigList(Request $request): Response
  18. {
  19. try {
  20. $type = $request->get("type","service");
  21. $data = (new SystemConfig)->where("type",$type)->where("status",1)->field("name,value")->select()->toArray();
  22. $result = [];
  23. foreach ($data as $item) {
  24. $result[$item['name']] = $item['value'];
  25. }
  26. if ($type == "sms") {
  27. $result['channel'] = $this->getSmsChannel();
  28. $result['login_sms'] = '您的验证码为:${code},请勿泄露于他人!';
  29. }
  30. return successTrans("success.data",$result);
  31. } catch (\Throwable $throwable) {
  32. return error($throwable->getMessage());
  33. }
  34. }
  35. #[PostMapping("save")]
  36. public function setConfigData(Request $request): Response
  37. {
  38. try {
  39. $param = $request->post();
  40. if (isset($param['data']['channel'])) unset($param['data']['channel']);
  41. foreach ($param['data'] as $k => $v){
  42. if(is_array($v)) $v = implode(",",$v);
  43. sConf($param['type'].'.'.$k, $v);
  44. }
  45. return successTrans("success.data",[]);
  46. } catch (\Throwable $exception){
  47. return error($exception->getMessage());
  48. }
  49. }
  50. #[GetMapping("regin")]
  51. public function getConfigRegin(): Response
  52. {
  53. try {
  54. return successTrans(100010,[
  55. "oss" => OssRegionExtend::OssRegion(),
  56. "cos" => OssRegionExtend::CosRegion(),
  57. "qiniu" => OssRegionExtend::QiniuRegion(),
  58. ]);
  59. } catch (\Exception $exception) {
  60. return error($exception->getMessage());
  61. }
  62. }
  63. }