Delivery.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\setting;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\Delivery as DeliveryModel;
  16. /**
  17. * 配送设置
  18. * Class Delivery
  19. * @package app\store\controller\setting
  20. */
  21. class Delivery extends Controller
  22. {
  23. /**
  24. * 配送模板列表
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. $model = new DeliveryModel;
  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 DeliveryModel;
  44. $list = $model->getAll();
  45. return $this->renderSuccess(compact('list'));
  46. }
  47. /**
  48. * 获取详情记录
  49. * @param int $deliveryId
  50. * @return Json
  51. */
  52. public function detail(int $deliveryId): Json
  53. {
  54. $detail = DeliveryModel::detail($deliveryId, ['rule']);
  55. return $this->renderSuccess(compact('detail'));
  56. }
  57. /**
  58. * 添加配送模板
  59. * @return Json
  60. */
  61. public function add(): Json
  62. {
  63. // 新增记录
  64. $model = new DeliveryModel;
  65. if ($model->add($this->postForm())) {
  66. return $this->renderSuccess('添加成功');
  67. }
  68. return $this->renderError($model->getError() ?: '添加失败');
  69. }
  70. /**
  71. * 编辑配送模板
  72. * @param int $deliveryId
  73. * @return Json
  74. */
  75. public function edit(int $deliveryId): Json
  76. {
  77. // 模板详情
  78. $model = DeliveryModel::detail($deliveryId);
  79. // 更新记录
  80. if ($model->edit($this->postForm())) {
  81. return $this->renderSuccess('更新成功');
  82. }
  83. return $this->renderError($model->getError() ?: '更新失败');
  84. }
  85. /**
  86. * 删除模板
  87. * @param int $deliveryId
  88. * @return Json
  89. */
  90. public function delete(int $deliveryId): Json
  91. {
  92. // 模板详情
  93. $model = DeliveryModel::detail($deliveryId);
  94. if (!$model->remove()) {
  95. return $this->renderError($model->getError() ?: '删除失败');
  96. }
  97. return $this->renderSuccess('删除成功');
  98. }
  99. }