Express.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\setting;
  10. use app\store\controller\Controller;
  11. use app\store\model\Express as ExpressModel;
  12. /**
  13. * 物流公司
  14. * Class Express
  15. * @package app\store\controller\setting
  16. */
  17. class Express extends Controller
  18. {
  19. /**
  20. * 物流公司列表
  21. * @return mixed
  22. * @throws \think\exception\DbException
  23. */
  24. public function index()
  25. {
  26. $model = new ExpressModel;
  27. $list = $model->getList();
  28. return $this->fetch('index', compact('list'));
  29. }
  30. /**
  31. * 删除物流公司
  32. * @param $express_id
  33. * @return array
  34. * @throws \think\exception\DbException
  35. */
  36. public function delete($express_id)
  37. {
  38. $model = ExpressModel::detail($express_id);
  39. if (!$model->remove()) {
  40. $error = $model->getError() ?: '删除失败';
  41. return $this->renderError($error);
  42. }
  43. return $this->renderSuccess('删除成功');
  44. }
  45. /**
  46. * 添加物流公司
  47. * @return array|mixed
  48. */
  49. public function add()
  50. {
  51. if (!$this->request->isAjax()) {
  52. return $this->fetch('add');
  53. }
  54. // 新增记录
  55. $model = new ExpressModel;
  56. if ($model->add($this->postData('express'))) {
  57. return $this->renderSuccess('添加成功', url('setting.express/index'));
  58. }
  59. return $this->renderError($model->getError() ?: '添加失败');
  60. }
  61. /**
  62. * 编辑物流公司
  63. * @param $express_id
  64. * @return array|mixed
  65. * @throws \think\exception\DbException
  66. */
  67. public function edit($express_id)
  68. {
  69. // 模板详情
  70. $model = ExpressModel::detail($express_id);
  71. if (!$this->request->isAjax()) {
  72. return $this->fetch('edit', compact('model'));
  73. }
  74. // 更新记录
  75. if ($model->edit($this->postData('express'))) {
  76. return $this->renderSuccess('更新成功', url('setting.express/index'));
  77. }
  78. return $this->renderError($model->getError() ?: '更新失败');
  79. }
  80. /**
  81. * 物流公司编码表
  82. * @return mixed
  83. */
  84. public function company()
  85. {
  86. return $this->fetch('company');
  87. }
  88. }