//统计默认地址状态没有设置的用户的数量
$address_sql = "select lender_id,count(*) as count from address where is_default=0 and status=0 group by lender_id having count>=1 limit $offset,$limit";
foreach($address_data as $k=>$val){
$sql = "select is_default from address where lender_id=".$val['lender_id'];
$address_arr = $db_other->execute($sql);
$defaults = array();
foreach ($address_arr as $value){
$defaults[] = $value['is_default'];
}
//判断是否已经设置默认地址
if(in_array(1, $defaults)){
continue;
}else{
//获取最新添加的一条并更新会默认地址
$newsql = "select id from address where lender_id=".$val['lender_id']." order by id desc limit 1 ";
$address_info = $db_other->execute($newsql);
if(!empty($address_info)){
$db_other->execute("update address set is_default= 1 where id=".$address_info[0]['id']);
}
}
}