Address.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace addons\shopro\controller;
  3. use addons\shopro\exception\Exception;
  4. use addons\shopro\model\UserAddress;
  5. use addons\shopro\model\Area;
  6. class Address extends Base
  7. {
  8. protected $noNeedLogin = ['area'];
  9. protected $noNeedRight = ['*'];
  10. public function index()
  11. {
  12. $this->success('收货地址', UserAddress::getUserAddress());
  13. }
  14. public function defaults()
  15. {
  16. $this->success('默认收货地址', UserAddress::getUserDefaultAddress());
  17. }
  18. public function area()
  19. {
  20. $data['provinceData'] = Area::where('level', 1)->order('id asc')->field('id as value, name as label, pid, level')->select();
  21. foreach ($data['provinceData'] as $k => $p) {
  22. $data['cityData'][$k] = Area::where(['level' => 2, 'pid' => $p->value])->order('id asc')->field('id as value, name as label, pid, level')->select();
  23. foreach ($data['cityData'][$k] as $i => $c) {
  24. $data['areaData'][$k][$i] = Area::where(['level' => 3, 'pid' => $c->value])->order('id asc')->field('id as value, name as label, pid, level')->select();
  25. }
  26. }
  27. $this->success('省市区', $data);
  28. }
  29. public function edit()
  30. {
  31. $params = $this->request->post();
  32. // 表单验证
  33. $this->shoproValidate($params, get_class(), 'edit');
  34. $this->success('编辑地址', UserAddress::edit($params));
  35. }
  36. public function info()
  37. {
  38. $params = $this->request->get();
  39. $this->success('地址详情', UserAddress::info($params));
  40. }
  41. public function del()
  42. {
  43. $params = $this->request->post();
  44. $this->success('地址详情', UserAddress::del($params));
  45. }
  46. }