SystemOut.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\v1\out;
  12. use app\controller\admin\AuthController;
  13. use app\services\out\OutAccountServices;
  14. use think\facade\App;
  15. /**
  16. * 对外接口账户
  17. * Class SystemCity
  18. * @package app\controller\admin\v1\setting
  19. */
  20. class SystemOut extends AuthController
  21. {
  22. /**
  23. * 构造方法
  24. * SystemCity constructor.
  25. * @param App $app
  26. * @param OutAccountServices $services
  27. */
  28. public function __construct(App $app, OutAccountServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 账号信息
  35. * @return string
  36. * @throws \Exception
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. ['name', '', ''],
  42. ['status', ''],
  43. ]);
  44. return $this->success($this->services->getList($where));
  45. }
  46. /**
  47. * 修改状态
  48. * @param string $status
  49. * @param string $id
  50. * @return mixed
  51. */
  52. public function set_status($id = '', $status = '')
  53. {
  54. if ($status == '' || $id == '') return $this->fail('缺少参数');
  55. $this->services->update($id, ['status' => $status]);
  56. return $this->success($status == 1 ? '开启成功' : '禁用成功');
  57. }
  58. /**
  59. * 删除
  60. * @param $id
  61. * @return mixed
  62. */
  63. public function delete($id)
  64. {
  65. if ($id == '') return $this->fail('缺少参数');
  66. $this->services->update($id, ['is_del' => 1]);
  67. return $this->success('删除成功!');
  68. }
  69. public function info($id)
  70. {
  71. return $this->success($this->services->getOne(['id' => $id]));
  72. }
  73. /**
  74. * 添加保存
  75. * @return mixed
  76. */
  77. public function save()
  78. {
  79. $data = $this->request->postMore([
  80. [['appid', 's'], ''],
  81. [['appsecret', 's'], ''],
  82. [['title', 's'], ''],
  83. ]);
  84. if (!$data['appid']) {
  85. return $this->fail('参数错误');
  86. }
  87. if ($this->services->getOne(['appid' => $data['appid']])) return $this->fail('账号重复');
  88. if (!$data['appsecret']) {
  89. unset($data['appsecret']);
  90. } else {
  91. $data['appsecret'] = password_hash($data['appsecret'], PASSWORD_DEFAULT);
  92. }
  93. $data['add_time'] = time();
  94. if (!$this->services->save($data)) {
  95. return $this->fail('添加失败');
  96. } else {
  97. return $this->success('添加成功');
  98. }
  99. }
  100. /**
  101. * 修改保存
  102. * @param string $id
  103. * @return mixed
  104. */
  105. public function update($id = '')
  106. {
  107. $data = $this->request->postMore([
  108. [['appid', 's'], ''],
  109. [['appsecret', 's'], ''],
  110. [['title', 's'], ''],
  111. ]);
  112. if (!$data['appid']) {
  113. return $this->fail('参数错误');
  114. }
  115. if (!$data['appsecret']) {
  116. unset($data['appsecret']);
  117. } else {
  118. $data['appsecret'] = password_hash($data['appsecret'], PASSWORD_DEFAULT);
  119. }
  120. if (!$this->services->getOne(['id' => $id])) return $this->fail('没有此账号');
  121. $res = $this->services->update($id, $data);
  122. if (!$res) {
  123. return $this->fail('修改失败');
  124. } else {
  125. return $this->success('修改成功!');
  126. }
  127. }
  128. }