0) { $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); $call = Dever::config('base')->address; if ($call) { $source_table = Dever::param('source_table', $param); $source_id = Dever::param('source_id', $param); $address = Dever::param('address', $param); $contacts = Dever::param('contacts', $param); $phone = Dever::param('phone', $param); $address_string = Dever::load('area/api')->string($area) . ',' . $address . ',' . $contacts . ',' . $phone; Dever::load($call, $source_table, $source_id, '修改地址:' . $address_string); } } } # 获取地址 public function get($source_id, $source_table, $uid, $address_id) { $info = $this->getData($source_id, $source_table, 1); if (!$info) { $info = $this->getInfo($uid, $address_id); } return $info; } # 按照类型获取地址 public function getData($source_id, $source_table = 'user/info', $type = 2) { $where['source_table'] = $source_table; $where['source_id'] = $source_id; $where['type'] = $type; $data = Dever::db('user/address')->one($where); if ($data && Dever::project('area')) { $data = $this->info($data); } return $data; } # 获取某个收货地址 public function getInfo($source_id, $id, $source_table = 'user/info') { $where['source_table'] = $source_table; $where['source_id'] = $source_id; $where['id'] = $id; $data = Dever::db('user/address')->one($where); if ($data && Dever::project('area')) { $data = $this->info($data); } return $data; } # 获取地址列表 public function getList($source_id, $source_table = 'user/info') { $where['source_table'] = $source_table; $where['source_id'] = $source_id; $data = Dever::db('user/address')->getList($where); if ($data && Dever::project('area')) { foreach ($data as $k => $v) { $data[$k] = $this->info($v); } } return $data; } public function info($data) { if (is_array($data['area'])) { $data['area'] = implode(',', $data['area']); } $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 = '', $tag = '') { if ($contact) { $update['contact'] = $contact; } if ($mobile) { $update['phone'] = $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 delete($source_id, $id, $state = 2, $source_table = 'user/info') { $info = $this->getInfo($source_id, $id, $source_table); if ($info) { $update['where_id'] = $info['id']; $update['state'] = $state; Dever::db('user/address')->update($update); } else { Dever::alert('更新失败'); } return 'ok'; } public function getSource($source_table, $source_id) { $info = Dever::db($source_table)->one($source_id); return $info; } public function getManageUrl($source_table, $source_id, $type, $address = array()) { $info = Dever::db('user/address')->one(array('source_table' => $source_table, 'source_id' => $source_id)); $url = Dever::url('project/database/update?project=user&table=address&search_option_source_table=' . $source_table . '&search_option_source_id=' . $source_id, 'manage'); if ($info) { $url .= '&where_id=' . $info['id']; } if ($address) { $url .= '&type=' . $type . '&area=' . $address['area'] . '&address=' . $address['address'] . '&contacts=' . $address['contacts'] . '&phone=' . $address['phone']; } return $url; } }