Address.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\ReturnAddress as ReturnAddressModel;
  12. /**
  13. * 退货地址
  14. * Class Delivery
  15. * @package app\store\controller\setting
  16. */
  17. class Address extends Controller
  18. {
  19. /**
  20. * 退货地址列表
  21. * @return mixed
  22. * @throws \think\exception\DbException
  23. */
  24. public function index()
  25. {
  26. $model = new ReturnAddressModel;
  27. $list = $model->getList();
  28. return $this->fetch('index', compact('list'));
  29. }
  30. /**
  31. * 添加退货地址
  32. * @return array|mixed
  33. */
  34. public function add()
  35. {
  36. if (!$this->request->isAjax()) {
  37. return $this->fetch('add');
  38. }
  39. // 新增记录
  40. $model = new ReturnAddressModel;
  41. if ($model->add($this->postData('address'))) {
  42. return $this->renderSuccess('添加成功', url('setting.address/index'));
  43. }
  44. return $this->renderError($model->getError() ?: '添加失败');
  45. }
  46. /**
  47. * 编辑退货地址
  48. * @param $address_id
  49. * @return array|mixed
  50. * @throws \think\exception\DbException
  51. */
  52. public function edit($address_id)
  53. {
  54. // 模板详情
  55. $model = ReturnAddressModel::detail($address_id);
  56. if (!$this->request->isAjax()) {
  57. return $this->fetch('edit', compact('model'));
  58. }
  59. // 更新记录
  60. if ($model->edit($this->postData('address'))) {
  61. return $this->renderSuccess('更新成功', url('setting.address/index'));
  62. }
  63. return $this->renderError($model->getError() ?: '更新失败');
  64. }
  65. /**
  66. * 删除退货地址
  67. * @param $address_id
  68. * @return array
  69. * @throws \think\exception\DbException
  70. */
  71. public function delete($address_id)
  72. {
  73. $model = ReturnAddressModel::detail($address_id);
  74. if (!$model->remove()) {
  75. return $this->renderError($model->getError() ?: '删除失败');
  76. }
  77. return $this->renderSuccess('删除成功');
  78. }
  79. }