Schools.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: thinkphp <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\model\School as SchoolsModel;
  15. use app\common\exception\BaseException;
  16. /**
  17. * 学校管理控制器
  18. * Class Schools
  19. * @package app\store\controller
  20. */
  21. class Schools extends Controller
  22. {
  23. /**
  24. * 列表
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. // 获取列表记录
  31. $model = new SchoolsModel();
  32. $list = $model->getList($this->request->param());
  33. return $this->renderSuccess(compact('list'));
  34. }
  35. /**
  36. * 商品详情
  37. * @param int $goodsId
  38. * @return Json
  39. * @throws BaseException
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \cores\exception\BaseException
  44. */
  45. public function detail(int $id): Json
  46. {
  47. // 获取详情
  48. $model = new SchoolsModel();
  49. $info = $model->detail($id);
  50. return $this->renderSuccess(compact('info'));
  51. }
  52. /**
  53. * 添加
  54. * @return Json
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \cores\exception\BaseException
  59. */
  60. public function add(): Json
  61. {
  62. $model = new SchoolsModel();
  63. if ($model->add($this->postForm())) {
  64. return $this->renderSuccess('添加成功');
  65. }
  66. return $this->renderError($model->getError() ?: '添加失败');
  67. }
  68. /**
  69. * 编辑
  70. * @param int $id
  71. * @return Json
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. * @throws \cores\exception\BaseException
  76. */
  77. public function edit(int $id): Json
  78. {
  79. // 详情
  80. $model = SchoolsModel::detail($id);
  81. // 更新记录
  82. if ($model->edit($this->postForm())) {
  83. return $this->renderSuccess('更新成功');
  84. }
  85. return $this->renderError($model->getError() ?: '更新失败');
  86. }
  87. /**
  88. * 修改状态(审核通过)
  89. * @param array $ids id集
  90. * @param bool $state 为true表示通过
  91. * @return Json
  92. */
  93. public function state(array $ids, bool $state): Json
  94. {
  95. $model = new SchoolsModel();
  96. if (!$model->setStatus($ids, $state)) {
  97. return $this->renderError($model->getError() ?: '操作失败');
  98. }
  99. return $this->renderSuccess('操作成功');
  100. }
  101. /**
  102. * 删除
  103. * @param array $ids
  104. * @return Json
  105. */
  106. public function delete(array $ids): Json
  107. {
  108. $model = new SchoolsModel();
  109. if (!$model->setDelete($ids)) {
  110. return $this->renderError($model->getError() ?: '删除失败');
  111. }
  112. return $this->renderSuccess('删除成功');
  113. }
  114. }