SystemOutAccount.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\outapi\validate\StoreOutAccountValidate;
  14. use app\services\out\LoginServices;
  15. use think\facade\App;
  16. /**
  17. * 对外接口账户
  18. * Class SystemOutAccount
  19. * @package app\adminapi\controller\v1\setting
  20. */
  21. class SystemOutAccount extends AuthController
  22. {
  23. /**
  24. * 构造方法
  25. * SystemOut constructor.
  26. * @param App $app
  27. * @param LoginServices $services
  28. */
  29. public function __construct(App $app, LoginServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 账号信息
  36. * @return string
  37. * @throws \Exception
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['name', '', ''],
  43. ['status', ''],
  44. ]);
  45. return app('json')->success($this->services->getList($where));
  46. }
  47. /**
  48. * 修改状态
  49. * @param string $status
  50. * @param string $id
  51. * @return mixed
  52. */
  53. public function set_status($id = '', $status = '')
  54. {
  55. if ($status == '' || $id == '') return $this->fail('缺少参数');
  56. $this->services->update($id, ['status' => $status]);
  57. return app('json')->success($status == 1 ? '开启成功' : '关闭成功');
  58. }
  59. /**
  60. * 删除
  61. * @param $id
  62. * @return mixed
  63. */
  64. public function delete($id)
  65. {
  66. if ($id == '') return $this->fail('缺少参数');
  67. $this->services->update($id, ['is_del' => 1]);
  68. return app('json')->success('删除成功!');
  69. }
  70. /**
  71. * 保存
  72. * @return mixed
  73. */
  74. public function save()
  75. {
  76. $data = $this->request->postMore([
  77. [['appid', 's'], ''],
  78. [['appsecret', 's'], ''],
  79. [['title', 's'], ''],
  80. ]);
  81. $this->validate($data, StoreOutAccountValidate::class, 'save');
  82. if ($this->services->getOne(['appid' => $data['appid']])) return app('json')->fail('账号重复');
  83. if (!$data['appsecret']) {
  84. unset($data['appsecret']);
  85. } else {
  86. $data['appsecret'] = password_hash($data['appsecret'], PASSWORD_DEFAULT);
  87. }
  88. $data['add_time'] = time();
  89. if (!$this->services->save($data)) {
  90. return app('json')->fail('添加失败');
  91. } else {
  92. return app('json')->success('添加成功');
  93. }
  94. }
  95. /**
  96. * 修改
  97. * @param string $id
  98. * @return mixed
  99. */
  100. public function update($id = '')
  101. {
  102. $data = $this->request->postMore([
  103. [['appsecret', 's'], ''],
  104. [['title', 's'], ''],
  105. ]);
  106. $this->validate($data, StoreOutAccountValidate::class, 'update');
  107. if (!$data['appsecret']) {
  108. unset($data['appsecret']);
  109. } else {
  110. $data['appsecret'] = password_hash($data['appsecret'], PASSWORD_DEFAULT);
  111. }
  112. if (!$this->services->getOne(['id' => $id])) return app('json')->fail('没有此账号');
  113. $res = $this->services->update($id, $data);
  114. if (!$res) {
  115. return app('json')->fail('修改失败');
  116. } else {
  117. return app('json')->success('修改成功!');
  118. }
  119. }
  120. }