Address.php 2.0 KB

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