Address.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Address
  5. {
  6. public function manage_update($id, $name, $param)
  7. {
  8. $area = Dever::param('area', $param);
  9. $type = Dever::param('type', $param);
  10. if ($area && is_array($area)) {
  11. $update['where_id'] = $id;
  12. $update['province'] = $area[0];
  13. $update['city'] = $area[1];
  14. $update['county'] = isset($area[2]) ? $area[2] : '';
  15. $update['town'] = isset($area[3]) ? $area[3] : '';
  16. if ($type == 2) {
  17. Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
  18. }
  19. $address = Dever::param('address', $param);
  20. if ($address) {
  21. $geo = Dever::geo($address, $update['city']);
  22. if ($geo) {
  23. $update['lng'] = $geo[0];
  24. $update['lat'] = $geo[1];
  25. }
  26. }
  27. $update['type'] = $type;
  28. Dever::db('user/address')->update($update);
  29. }
  30. }
  31. public function getInfo($data)
  32. {
  33. $data['area_string'] = Dever::load('area/api')->string($data['area']);
  34. $data['province_name'] = $data['city_name'] = $data['county_name'] = $data['town_name'] = '';
  35. if ($data['town'] && $data['town'] > 0) {
  36. $info = Dever::db('area/town')->find($data['town']);
  37. if ($info) {
  38. $data['town_name'] = $info['name'];
  39. }
  40. }
  41. if ($data['county']) {
  42. $info = Dever::db('area/county')->find($data['county']);
  43. if ($info) {
  44. $data['county_name'] = $info['name'];
  45. }
  46. }
  47. if ($data['city']) {
  48. $info = Dever::db('area/city')->find($data['city']);
  49. if ($info) {
  50. $data['city_name'] = $info['name'];
  51. }
  52. }
  53. if ($data['province']) {
  54. $info = Dever::db('area/province')->find($data['province']);
  55. if ($info) {
  56. $data['province_name'] = $info['name'];
  57. }
  58. }
  59. return $data;
  60. }
  61. # 添加或者更新地址
  62. public function update($id, $source_id, $source_table, $type = 2, $mobile, $contact, $province = '', $city = '', $county = '', $town = '', $address = '', $country = '', $tag = '')
  63. {
  64. if ($contact) {
  65. $update['contact'] = $contact;
  66. }
  67. if ($mobile) {
  68. $update['mobile'] = $mobile;
  69. } else {
  70. Dever::alert('请输入手机号');
  71. }
  72. if ($province) {
  73. $update['province'] = $province;
  74. } else {
  75. Dever::alert('请选择省份');
  76. }
  77. if ($city) {
  78. $update['city'] = $city;
  79. } else {
  80. Dever::alert('请选择城市');
  81. }
  82. if ($county) {
  83. $update['county'] = $county;
  84. } else {
  85. Dever::alert('请选择区域');
  86. }
  87. if ($town) {
  88. $update['town'] = $town;
  89. }
  90. if ($province && $city && $county) {
  91. $update['area'] = $province . ',' . $city . ',' . $county;
  92. }
  93. if ($town) {
  94. $update['area'] .= ',' . $town;
  95. }
  96. $update['type'] = $type;
  97. if ($address) {
  98. $update['address'] = $address;
  99. if ($address && isset($update['city']) && $update['city']) {
  100. $geo = Dever::geo($address, $update['city']);
  101. if ($geo) {
  102. $update['lng'] = $geo[0];
  103. $update['lat'] = $geo[1];
  104. }
  105. }
  106. }
  107. if ($tag) {
  108. $update['tag'] = $tag;
  109. }
  110. if ($type == 2) {
  111. Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
  112. }
  113. if ($id) {
  114. $update['where_id'] = $id;
  115. Dever::db('user/address')->update($update);
  116. } else {
  117. $update['source_id'] = $source_id;
  118. $update['source_table'] = $source_table;
  119. $id = Dever::db('user/address')->insert($update);
  120. }
  121. return $id;
  122. }
  123. public function getSource($source_table, $source_id)
  124. {
  125. $info = Dever::db($source_table)->one($source_id);
  126. return $info;
  127. }
  128. }