Address.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\store;
  13. use app\store\controller\Controller;
  14. use app\store\model\store\Address as AddressModel;
  15. /**
  16. * 商家地址管理
  17. * Class Delivery
  18. * @package app\store\controller\setting
  19. */
  20. class Address extends Controller
  21. {
  22. /**
  23. * 列表记录
  24. * @return array
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function list()
  28. {
  29. $model = new AddressModel;
  30. $list = $model->getList($this->request->param());
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 全部记录
  35. * @return array
  36. * @throws \think\db\exception\DbException
  37. */
  38. public function all()
  39. {
  40. $model = new AddressModel;
  41. $list = $model->getAll($this->request->param());
  42. return $this->renderSuccess(compact('list'));
  43. }
  44. /**
  45. * 添加记录
  46. * @return array|string
  47. */
  48. public function add()
  49. {
  50. // 新增记录
  51. $model = new AddressModel;
  52. if ($model->add($this->postForm())) {
  53. return $this->renderSuccess('添加成功');
  54. }
  55. return $this->renderError($model->getError() ?: '添加失败');
  56. }
  57. /**
  58. * 编辑记录
  59. * @param int $addressId
  60. * @return array|mixed
  61. */
  62. public function edit(int $addressId)
  63. {
  64. // 详情记录
  65. $model = AddressModel::detail($addressId);
  66. // 更新记录
  67. if ($model->edit($this->postForm())) {
  68. return $this->renderSuccess('更新成功');
  69. }
  70. return $this->renderError($model->getError() ?: '更新失败');
  71. }
  72. /**
  73. * 删除记录
  74. * @param int $addressId
  75. * @return array
  76. */
  77. public function delete(int $addressId)
  78. {
  79. // 详情记录
  80. $model = AddressModel::detail($addressId);
  81. if (!$model->remove()) {
  82. return $this->renderError($model->getError() ?: '删除失败');
  83. }
  84. return $this->renderSuccess('删除成功');
  85. }
  86. }