yii 存在就保存 不存在添加


$data=UserDomain::findOne(['domain_id'=>$domain['domain_id']]);
if($data)
{
$data->agentname=$domain['agentname'];
$data->mobile=$domain['mobile'];
$data->region=$domain['region'];
$data->create_time=$domain['create_time'];
$data->uid=$domain['uid'];
$data->longitude=$domain['longitude'];
$data->latitude=$domain['latitude'];
$data->are_region_id=$domain['are_region_id'];
$data->save();

}else{
$model=new UserDomain();
$model->domain_id=$domain['domain_id'];
$model->agentname=$domain['agentname'];
$model->mobile=$domain['mobile'];
$model->region=$domain['region'];
$model->create_time=$domain['create_time'];
$model->uid=$domain['uid'];
$model->longitude=$domain['longitude'];
$model->latitude=$domain['latitude'];
$model->are_region_id=$domain['are_region_id'];
$model->save();
}

声明:祁志飞||小祁的博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - yii 存在就保存 不存在添加


QQ:137867590