SystemOutAccount.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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\OutAccountServices;
  15. use app\services\out\OutInterfaceServices;
  16. use think\facade\App;
  17. /**
  18. * 对外接口账户
  19. * Class SystemOutAccount
  20. * @package app\adminapi\controller\v1\setting
  21. */
  22. class SystemOutAccount extends AuthController
  23. {
  24. /**
  25. * 构造方法
  26. * SystemOut constructor.
  27. * @param App $app
  28. * @param OutAccountServices $services
  29. */
  30. public function __construct(App $app, OutAccountServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * 账号信息
  37. * @return string
  38. * @throws \Exception
  39. */
  40. public function index()
  41. {
  42. $where = $this->request->getMore([
  43. ['name', '', ''],
  44. ['status', ''],
  45. ]);
  46. return app('json')->success($this->services->getList($where));
  47. }
  48. /**
  49. * 修改状态
  50. * @param string $status
  51. * @param string $id
  52. * @return mixed
  53. */
  54. public function set_status($id = '', $status = '')
  55. {
  56. if ($status == '' || $id == '') return $this->fail('缺少参数');
  57. $this->services->update($id, ['status' => $status]);
  58. return app('json')->success($status == 1 ? '开启成功' : '关闭成功');
  59. }
  60. /**
  61. * 删除
  62. * @param $id
  63. * @return mixed
  64. */
  65. public function delete($id)
  66. {
  67. if ($id == '') return $this->fail('缺少参数');
  68. $this->services->update($id, ['is_del' => 1]);
  69. return app('json')->success('删除成功!');
  70. }
  71. /**
  72. * 保存
  73. * @return mixed
  74. * @throws \think\db\exception\DataNotFoundException
  75. * @throws \think\db\exception\DbException
  76. * @throws \think\db\exception\ModelNotFoundException
  77. */
  78. public function save()
  79. {
  80. $data = $this->request->postMore([
  81. [['appid', 's'], ''],
  82. [['appsecret', 's'], ''],
  83. [['title', 's'], ''],
  84. ['rules', []],
  85. ]);
  86. $this->validate($data, StoreOutAccountValidate::class, 'save');
  87. if ($this->services->getOne(['appid' => $data['appid']])) return app('json')->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. $data['rules'] = implode(',', $data['rules']);
  95. if (!$this->services->save($data)) {
  96. return app('json')->fail('添加失败');
  97. } else {
  98. return app('json')->success('添加成功');
  99. }
  100. }
  101. /**
  102. * 修改
  103. * @param string $id
  104. * @return mixed
  105. * @throws \think\db\exception\DataNotFoundException
  106. * @throws \think\db\exception\DbException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. */
  109. public function update($id = '')
  110. {
  111. $data = $this->request->postMore([
  112. [['appsecret', 's'], ''],
  113. [['title', 's'], ''],
  114. ['rules', []],
  115. ]);
  116. $this->validate($data, StoreOutAccountValidate::class, 'update');
  117. if (!$data['appsecret']) {
  118. unset($data['appsecret']);
  119. } else {
  120. $data['appsecret'] = password_hash($data['appsecret'], PASSWORD_DEFAULT);
  121. }
  122. if (!$this->services->getOne(['id' => $id])) return app('json')->fail('没有此账号');
  123. $data['rules'] = implode(',', $data['rules']);
  124. $res = $this->services->update($id, $data);
  125. if (!$res) {
  126. return app('json')->fail('修改失败');
  127. } else {
  128. return app('json')->success('修改成功!');
  129. }
  130. }
  131. /**
  132. * 设置账号推送接口表单
  133. * @param $id
  134. * @return mixed
  135. * @throws \FormBuilder\Exception\FormBuilderException
  136. * @throws \think\db\exception\DataNotFoundException
  137. * @throws \think\db\exception\DbException
  138. * @throws \think\db\exception\ModelNotFoundException
  139. */
  140. public function outSetUpForm($id)
  141. {
  142. return app('json')->success($this->services->outSetUpForm($id));
  143. }
  144. /**
  145. * 设置账号推送接口
  146. * @param $id
  147. * @return mixed
  148. */
  149. public function outSetUpSave($id)
  150. {
  151. $data = $this->request->postMore([
  152. ['push_open', 0],
  153. ['order_create_push', ''],
  154. ['order_pay_push', ''],
  155. ['refund_create_push', ''],
  156. ['refund_cancel_push', ''],
  157. ]);
  158. $this->services->outSetUpSave($id, $data);
  159. return app('json')->success('修改成功');
  160. }
  161. /**
  162. * 对外接口列表
  163. * @param OutInterfaceServices $service
  164. * @return mixed
  165. * @throws \think\db\exception\DataNotFoundException
  166. * @throws \think\db\exception\DbException
  167. * @throws \think\db\exception\ModelNotFoundException
  168. */
  169. public function outInterfaceList(OutInterfaceServices $service)
  170. {
  171. return app('json')->success($service->outInterfaceList());
  172. }
  173. }