Service.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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\store\controller\goods;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\goods\Service as ServiceModel;
  16. /**
  17. * 商品服务与承诺管理
  18. * Class Service
  19. * @package app\store\controller\goods
  20. */
  21. class Service extends Controller
  22. {
  23. /**
  24. * 获取列表记录
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. $model = new ServiceModel;
  31. $list = $model->getList($this->request->param());
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 获取全部记录
  36. * @return Json
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function all(): Json
  42. {
  43. $model = new ServiceModel;
  44. $list = $model->getAll($this->request->param());
  45. return $this->renderSuccess(compact('list'));
  46. }
  47. /**
  48. * 添加记录
  49. * @return Json
  50. */
  51. public function add(): Json
  52. {
  53. // 新增记录
  54. $model = new ServiceModel;
  55. if ($model->add($this->postForm())) {
  56. return $this->renderSuccess('添加成功');
  57. }
  58. return $this->renderError($model->getError() ?: '添加失败');
  59. }
  60. /**
  61. * 更新记录
  62. * @param int $serviceId
  63. * @return Json
  64. */
  65. public function edit(int $serviceId): Json
  66. {
  67. // 记录详情
  68. $model = ServiceModel::detail($serviceId);
  69. // 更新记录
  70. if ($model->edit($this->postForm())) {
  71. return $this->renderSuccess('更新成功');
  72. }
  73. return $this->renderError($model->getError() ?: '更新失败');
  74. }
  75. /**
  76. * 删除记录
  77. * @param int $serviceId
  78. * @return Json
  79. * @throws \Exception
  80. */
  81. public function delete(int $serviceId): Json
  82. {
  83. // 记录详情
  84. $model = ServiceModel::detail($serviceId);
  85. if (!$model->remove()) {
  86. return $this->renderError($model->getError() ?: '删除失败');
  87. }
  88. return $this->renderSuccess('删除成功');
  89. }
  90. }