1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace Passport\Src;
- use Dever;
- use Passport\Lib\Base;
- class Address extends Base
- {
- # 获取默认地址
- public function getDefaultAddress($uid)
- {
- $where['uid'] = $uid;
- $where['type'] = 2;
- $data = Dever::db('passport/address')->one($where);
- return $data;
- }
- # 获取地址列表
- public function getAddress($uid)
- {
- $where['uid'] = $uid;
- $data = Dever::db('passport/address')->getList($where);
- return $data;
- }
- # 添加或者更新地址接口
- public function up()
- {
- $uid = $this->check();
- $id = Dever::input('id');
- $type = Dever::input('type', 2);
- $province = Dever::input('province');
- $city = Dever::input('city');
- $county = Dever::input('county');
- $address = Dever::input('address');
- $country = Dever::input('country');
- $sex = Dever::input('sex');
- $house_number = Dever::input('house_number');
- $tag = Dever::input('tag');
- return $this->upAddress($id, $uid, $type, $province, $city, $county, $address, $country, $sex, $house_number, $tag);
- }
- # 添加或者更新地址
- public function upAddress($id, $uid, $type = 2, $province = '', $city = '', $county = '', $address = '', $country = '', $sex = '', $house_number = '', $tag = '')
- {
- if ($country) {
- $update['country'] = $country;
- }
-
- if ($province && $city && $county && $address) {
- $update['province'] = $province;
- $update['city'] = $city;
- $update['county'] = $county;
- $update['area'] = $province . ',' . $city . ',' . $county;
- $update['address'] = $address;
- }
- $update['type'] = $type;
- if ($sex) {
- $update['sex'] = $sex;
- }
- if ($house_number) {
- $update['house_number'] = $house_number;
- }
- if ($tag) {
- $update['tag'] = $tag;
- }
-
- if ($id) {
- $update['where_id'] = $id;
- Dever::db('passport/address')->update($update);
- } else {
- $update['uid'] = $uid;
- $id = Dever::db('passport/address')->insert($update);
- }
- return $id;
- }
- }
|