Address.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. $update['type'] = $type;
  20. Dever::db('user/address')->update($update);
  21. }
  22. }
  23. public function getInfo($data)
  24. {
  25. $data['area_string'] = Dever::load('area/api')->string($data['area']);
  26. $data['province_name'] = $data['city_name'] = $data['county_name'] = $data['town_name'] = '';
  27. if ($data['town'] && $data['town'] > 0) {
  28. $info = Dever::db('area/town')->find($data['town']);
  29. if ($info) {
  30. $data['town_name'] = $info['name'];
  31. }
  32. }
  33. if ($data['county']) {
  34. $info = Dever::db('area/county')->find($data['county']);
  35. if ($info) {
  36. $data['county_name'] = $info['name'];
  37. }
  38. }
  39. if ($data['city']) {
  40. $info = Dever::db('area/city')->find($data['city']);
  41. if ($info) {
  42. $data['city_name'] = $info['name'];
  43. }
  44. }
  45. if ($data['province']) {
  46. $info = Dever::db('area/province')->find($data['province']);
  47. if ($info) {
  48. $data['province_name'] = $info['name'];
  49. }
  50. }
  51. return $data;
  52. }
  53. # 添加或者更新地址
  54. public function update($id, $uid, $type = 2, $mobile, $contact, $province = '', $city = '', $county = '', $town = '', $address = '', $country = '', $tag = '')
  55. {
  56. if ($contact) {
  57. $update['contact'] = $contact;
  58. }
  59. if ($mobile) {
  60. $update['mobile'] = $mobile;
  61. } else {
  62. Dever::alert('请输入手机号');
  63. }
  64. if ($province) {
  65. $update['province'] = $province;
  66. } else {
  67. Dever::alert('请选择省份');
  68. }
  69. if ($city) {
  70. $update['city'] = $city;
  71. } else {
  72. Dever::alert('请选择城市');
  73. }
  74. if ($county) {
  75. $update['county'] = $county;
  76. } else {
  77. Dever::alert('请选择区域');
  78. }
  79. if ($town) {
  80. $update['town'] = $town;
  81. }
  82. if ($province && $city && $county) {
  83. $update['area'] = $province . ',' . $city . ',' . $county;
  84. }
  85. if ($town) {
  86. $update['area'] .= ',' . $town;
  87. }
  88. $update['type'] = $type;
  89. if ($address) {
  90. $update['address'] = $address;
  91. }
  92. if ($tag) {
  93. $update['tag'] = $tag;
  94. }
  95. if ($type == 2) {
  96. Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
  97. }
  98. if ($id) {
  99. $update['where_id'] = $id;
  100. Dever::db('user/address')->update($update);
  101. } else {
  102. $update['uid'] = $uid;
  103. $id = Dever::db('user/address')->insert($update);
  104. }
  105. return $id;
  106. }
  107. }