Address.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Address
  5. {
  6. # 获取某个收货地址
  7. public function getOne($mid, $id)
  8. {
  9. $where['mid'] = $mid;
  10. $where['id'] = $id;
  11. $data = Dever::db('agent/member_address')->find($where);
  12. if ($data && Dever::project('area')) {
  13. $data = $this->getInfo($data);
  14. }
  15. return $data;
  16. }
  17. private function getInfo($data)
  18. {
  19. $data['address_info'] = $data['add_string'] = $data['address'] . $data['house_number'];
  20. $data['province_name'] = $data['city_name'] = $data['county_name'] = '';
  21. if ($data['county']) {
  22. $info = Dever::db('area/county')->find($data['county']);
  23. if ($info) {
  24. $data['county_name'] = $info['name'];
  25. $data['city'] = $info['city_id'];
  26. $info = Dever::db('area/city')->find($data['city']);
  27. $data['city_name'] = $info['name'];
  28. $data['province'] = $info['province_id'];
  29. $info = Dever::db('area/province')->find($data['province']);
  30. $data['province_name'] = $info['name'];
  31. //$data['address_info'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'];
  32. $data['add_string'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'] .','. $data['contact'] .','. $data['mobile'];
  33. }
  34. } elseif ($data['city']) {
  35. $info = Dever::db('area/county')->find($data['city']);
  36. if ($info) {
  37. $data['county_name'] = $info['name'];
  38. $data['city'] = $info['city_id'];
  39. $info = Dever::db('area/city')->find($data['city']);
  40. $data['city_name'] = $info['name'];
  41. $data['province'] = $info['province_id'];
  42. $info = Dever::db('area/province')->find($data['province']);
  43. $data['province_name'] = $info['name'];
  44. //$data['address_info'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'];
  45. $data['add_string'] = $data['province_name'] . $data['city_name'] . $data['county_name'] .','. $data['address'] .','. $data['house_number'] .','. $data['contact'] .','. $data['mobile'];
  46. }
  47. }
  48. if (!$data['county_name']) {
  49. $city = '';
  50. if (strstr($data['address'], '省')) {
  51. $temp = explode('省', $data['address']);
  52. $data['province_name'] = $temp[0] . '省';
  53. unset($temp[0]);
  54. $city = $temp[1];
  55. } elseif (strstr($data['address'], '市')) {
  56. $temp = explode('市', $data['address']);
  57. $data['province_name'] = $temp[0] . '市';
  58. $city = '';
  59. unset($temp[0]);
  60. $city = implode('市', $temp);
  61. } elseif (strstr($data['address'], '区')) {
  62. $temp = explode('区', $data['address']);
  63. $data['province_name'] = $temp[0] . '区';
  64. $city = '';
  65. unset($temp[0]);
  66. $city = implode('区', $temp);
  67. }
  68. if (strstr($city, '市')) {
  69. $temp = explode('市', $city);
  70. $data['city_name'] = $temp[0] . '市';
  71. }
  72. if (isset($temp[1])) {
  73. $data['county_name'] = $temp[1];
  74. }
  75. }
  76. return $data;
  77. }
  78. }