| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | 
							- <?php
 
- namespace User\Lib;
 
- use Dever;
 
- class Address
 
- {
 
- 	public function manage_update($id, $name, $param)
 
-     {
 
-         $area = Dever::param('area', $param);
 
-         $type = Dever::param('type', $param);
 
-         if ($area && is_array($area)) {
 
-             $update['where_id'] = $id;
 
-             $update['province'] = $area[0];
 
-             $update['city'] = $area[1];
 
-             $update['county'] = isset($area[2]) ? $area[2] : '';
 
-             $update['town'] = isset($area[3]) ? $area[3] : '';
 
-             if ($type == 2) {
 
-                 Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
 
-             }
 
-             $address = Dever::param('address', $param);
 
-             if ($address) {
 
-                 $geo = Dever::geo($address, $update['city']);
 
-                 if ($geo) {
 
-                     $update['lng'] = $geo[0];
 
-                     $update['lat'] = $geo[1];
 
-                 }
 
-             }
 
-             
 
-             $update['type'] = $type;
 
-             Dever::db('user/address')->update($update);
 
-         }
 
-     }
 
-     public function getInfo($data)
 
-     {
 
-         $data['area_string'] = Dever::load('area/api')->string($data['area']);
 
-         $data['province_name'] = $data['city_name'] = $data['county_name'] = $data['town_name'] = '';
 
-         if ($data['town'] && $data['town'] > 0) {
 
-             $info = Dever::db('area/town')->find($data['town']);
 
-             if ($info) {
 
-                 $data['town_name'] = $info['name'];
 
-             }
 
-         }
 
-         
 
-         if ($data['county']) {
 
-             $info = Dever::db('area/county')->find($data['county']);
 
-             if ($info) {
 
-                 $data['county_name'] = $info['name'];
 
-             }
 
-         }
 
-         if ($data['city']) {
 
-             $info = Dever::db('area/city')->find($data['city']);
 
-             if ($info) {
 
-                 $data['city_name'] = $info['name'];
 
-             }
 
-         }
 
-         if ($data['province']) {
 
-             $info = Dever::db('area/province')->find($data['province']);
 
-             if ($info) {
 
-                 $data['province_name'] = $info['name'];
 
-             }
 
-         }
 
-         return $data;
 
-     }
 
-     # 添加或者更新地址
 
-     public function update($id, $source_id, $source_table, $type = 2, $mobile, $contact, $province = '', $city = '', $county = '', $town = '', $address = '', $country = '', $tag = '')
 
-     {
 
-         if ($contact) {
 
-             $update['contact'] = $contact;
 
-         }
 
-         if ($mobile) {
 
-             $update['mobile'] = $mobile;
 
-         } else {
 
-             Dever::alert('请输入手机号');
 
-         }
 
-         if ($province) {
 
-             $update['province'] = $province;
 
-         } else {
 
-             Dever::alert('请选择省份');
 
-         }
 
-         if ($city) {
 
-             $update['city'] = $city;
 
-         } else {
 
-             Dever::alert('请选择城市');
 
-         }
 
-         if ($county) {
 
-             $update['county'] = $county;
 
-         } else {
 
-             Dever::alert('请选择区域');
 
-         }
 
-         if ($town) {
 
-             $update['town'] = $town;
 
-         }
 
-         
 
-         if ($province && $city && $county) {
 
- 	        $update['area'] = $province . ',' . $city . ',' . $county;
 
-         }
 
-         if ($town) {
 
-             $update['area'] .= ',' . $town;
 
-         }
 
-         $update['type'] = $type;
 
-         if ($address) {
 
-             $update['address'] = $address;
 
-             if ($address && isset($update['city']) && $update['city']) {
 
-                 $geo = Dever::geo($address, $update['city']);
 
-                 if ($geo) {
 
-                     $update['lng'] = $geo[0];
 
-                     $update['lat'] = $geo[1];
 
-                 }
 
-             }
 
-         }
 
-         if ($tag) {
 
-             $update['tag'] = $tag;
 
-         }
 
-         if ($type == 2) {
 
-             Dever::db('user/address')->updateType(array('where_type' => 2, 'set_type' => 1));
 
-         }
 
-         
 
-         if ($id) {
 
-             $update['where_id'] = $id;
 
-             Dever::db('user/address')->update($update);
 
-         } else {
 
-             $update['source_id'] = $source_id;
 
-             $update['source_table'] = $source_table;
 
-             $id = Dever::db('user/address')->insert($update);
 
-         }
 
-         return $id;
 
-     }
 
-     public function getSource($source_table, $source_id)
 
-     {
 
-         $info = Dever::db($source_table)->one($source_id);
 
-         return $info;
 
-     }
 
- }
 
 
  |