LangCode.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\setting;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\system\lang\LangCodeServices;
  14. use think\facade\App;
  15. class LangCode extends AuthController
  16. {
  17. /**
  18. * @param App $app
  19. * @param LangCodeServices $services
  20. */
  21. public function __construct(App $app, LangCodeServices $services)
  22. {
  23. parent::__construct($app);
  24. $this->services = $services;
  25. }
  26. /**
  27. * 获取语言列表
  28. * @return mixed
  29. * @throws \ReflectionException
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\DbException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. */
  34. public function langCodeList()
  35. {
  36. $where = $this->request->getMore([
  37. ['is_admin', 0],
  38. ['type_id', 0],
  39. ['code', ''],
  40. ['remarks', '']
  41. ]);
  42. return app('json')->success($this->services->langCodeList($where));
  43. }
  44. /**
  45. * 获取语言详情
  46. * @return mixed
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function langCodeInfo()
  52. {
  53. [$code] = $this->request->getMore([
  54. ['code', ''],
  55. ], true);
  56. return app('json')->success($this->services->langCodeInfo($code));
  57. }
  58. /**
  59. * 新增编辑语言
  60. * @return mixed
  61. * @throws \Exception
  62. */
  63. public function langCodeSave()
  64. {
  65. $data = $this->request->postMore([
  66. ['is_admin', 0],
  67. ['code', ''],
  68. ['remarks', ''],
  69. ['edit', 0],
  70. ['list', []]
  71. ]);
  72. $this->services->langCodeSave($data);
  73. return app('json')->success(100000);
  74. }
  75. /**
  76. * 删除语言
  77. * @param $id
  78. * @return mixed
  79. */
  80. public function langCodeDel($id)
  81. {
  82. $this->services->langCodeDel($id);
  83. return app('json')->success(100002);
  84. }
  85. /**
  86. * 机器翻译
  87. * @return mixed
  88. * @throws \Throwable
  89. */
  90. public function langCodeTranslate()
  91. {
  92. [$text] = $this->request->postMore([
  93. ['text', '']
  94. ], true);
  95. if ($text == '') return app('json')->fail(100100);
  96. return app('json')->success($this->services->langCodeTranslate($text));
  97. }
  98. }