Express.php 2.2 KB

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