Api.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\admin\controller\store;
  13. use app\admin\controller\Controller;
  14. use app\admin\model\store\Api as ApiModel;
  15. /**
  16. * 商家后台API权限控制器
  17. * Class Api
  18. * @package app\store\controller
  19. */
  20. class Api extends Controller
  21. {
  22. /**
  23. * 权限列表
  24. * @return array
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\DbException
  27. * @throws \think\db\exception\ModelNotFoundException
  28. */
  29. public function index()
  30. {
  31. $model = new ApiModel;
  32. $list = $model->getList();
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 添加权限
  37. * @return array
  38. */
  39. public function add()
  40. {
  41. // 新增记录
  42. $model = new ApiModel;
  43. if ($model->add($this->postForm())) {
  44. return $this->renderSuccess('添加成功');
  45. }
  46. return $this->renderError($model->getError() ?: '添加失败');
  47. }
  48. /**
  49. * 更新权限
  50. * @param $apiId
  51. * @return array|string
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function edit(int $apiId)
  57. {
  58. // 权限详情
  59. $model = ApiModel::detail($apiId);
  60. // 更新记录
  61. if ($model->edit($this->postForm())) {
  62. return $this->renderSuccess('更新成功');
  63. }
  64. return $this->renderError($model->getError() ?: '更新失败');
  65. }
  66. /**
  67. * 删除权限
  68. * @param $apiId
  69. * @return array
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function delete(int $apiId)
  75. {
  76. // 权限详情
  77. $model = ApiModel::detail($apiId);
  78. if (!$model->remove()) {
  79. return $this->renderError($model->getError() ?: '删除失败');
  80. }
  81. return $this->renderSuccess('删除成功');
  82. }
  83. }