Delivery.php 3.0 KB

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