Express.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\Express as ExpressModel;
  16. /**
  17. * 物流公司
  18. * Class Express
  19. * @package app\store\controller\setting
  20. */
  21. class Express extends Controller
  22. {
  23. /**
  24. * 物流公司列表
  25. * @return Json
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function list(): Json
  29. {
  30. $model = new ExpressModel;
  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 ExpressModel;
  44. $list = $model->getAll($this->request->param());
  45. return $this->renderSuccess(compact('list'));
  46. }
  47. /**
  48. * 删除物流公司
  49. * @param int $expressId
  50. * @return Json
  51. */
  52. public function delete(int $expressId): Json
  53. {
  54. $model = ExpressModel::detail($expressId);
  55. if (!$model->remove()) {
  56. return $this->renderError($model->getError() ?: '删除失败');
  57. }
  58. return $this->renderSuccess('删除成功');
  59. }
  60. /**
  61. * 添加物流公司
  62. * @return Json
  63. */
  64. public function add(): Json
  65. {
  66. // 新增记录
  67. $model = new ExpressModel;
  68. if ($model->add($this->postForm())) {
  69. return $this->renderSuccess('添加成功');
  70. }
  71. return $this->renderError($model->getError() ?: '添加失败');
  72. }
  73. /**
  74. * 编辑物流公司
  75. * @param int $expressId
  76. * @return Json
  77. */
  78. public function edit(int $expressId): Json
  79. {
  80. // 模板详情
  81. $model = ExpressModel::detail($expressId);
  82. // 更新记录
  83. if ($model->edit($this->postForm())) {
  84. return $this->renderSuccess('更新成功');
  85. }
  86. return $this->renderError($model->getError() ?: '更新失败');
  87. }
  88. }