123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- <?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));
- }
- $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, $uid, $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 ($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['uid'] = $uid;
- $id = Dever::db('user/address')->insert($update);
- }
- return $id;
- }
- }
|