设置位置:ecs_users标的 country字段,默认是0,默认地址是 users_address 的address_id
设置默认收货地址
/** * 设置默认地址 * * @access public * @param integer $id 收货地址id * @return boolean */function set_default_addr($id){ $uid = $_SESSION['user_id']; $sql = "UPDATE " .$GLOBALS['ecs']->table('users') . " SET address_id = '$id' WHERE user_id = '$uid'"; $res = $GLOBALS['db']->query($sql); return $res;}
删除收货地址
/** * 删除一个收货地址 * * @access public * @param integer $id * @return boolean */function drop_consignee($id){ $sql = "SELECT user_id FROM " .$GLOBALS['ecs']->table('user_address') . " WHERE address_id = '$id'"; $uid = $GLOBALS['db']->getOne($sql); if ($uid != $_SESSION['user_id']) { return false; } else { $sql = "DELETE FROM " .$GLOBALS['ecs']->table('user_address') . " WHERE address_id = '$id'"; $res = $GLOBALS['db']->query($sql); return $res; }}
取得收货地址列表
/** * 取得收货人地址列表 * @param int $user_id 用户编号 * @param int $id 收货地址id * @return array */ function get_consignee_list($user_id, $id = 0, $num = 10, $start = 0) { if ($id) { $where['address_id'] = $id; $this->table = 'user_address'; return $this->find($where); } else { $sql = 'select * from ' . $this->pre . 'user_address where user_id = ' . $user_id . ' order by address_id limit ' . $start . ', ' . $num; return $this->query($sql); } }
查询默认user地址
public function select_default_address(){ $user_id =$_SESSION['user_id']; $info = M()->query("SELECT address_id FROM " .$this->model->pre. "users WHERE user_id='$user_id'"); print_r($info[0]['address_id']); }
设置收货默认地址
public function set_default_address(){ $id = $_GET['address_id']; $userid = $_SESSION['user_id']; $sql = "UPDATE " .$this->model->pre. "users SET address_id = '$id' WHERE user_id = '$userid'"; $res = M()->query($sql); show_message('设置成功', $_LANG['address_list_lnk'], U('user/address_list')); }