//增
//获取实际需求的字段
$model['username'] = $data['username'];
$model['password'] = $data['password'];
连接数据库添加
$user = UserModel::create($model);
判断是否添加成功,并返回JSON值
if($user === null){
$msg = '注册失败!';
$data['status'] = 1;
return['code'=>$code,'msg'=>$msg,'data'=>$data];
}
//查:
//检查账号 设置查询条件
$map = [
'username' => $data['username'],
'email' => $data['email'],
];
查询:
$checkUser = UserModel::get($map);
判断是否查询成功
if($checkUser == null){
$msg = '账号不存在或密保邮箱错误';
$data['status'] = 1;
return['code'=>$code,'msg'=>$msg,'data'=>$data];
}
//删
软删除--根据主键删除
$res = ArticleModel::update(['is_delete'=>1],['id'=> $article_id]);
批处理删除
$count = count($article);
for($i=0;$i<$count;$i++){
Article::destroy($article[$i]['id']);
}
return ['code'=>0,'msg'=>'删除成功','data'=>$data];
//改
$data = $request->param();//这是表单提交的需要修改的
$result = ArticleModel::update($data,['id'=> $id]);
$data['status']=1;
$msg='';
if($result){
$msg = '更新成功';
}else{
$data['status']=0;
$msg = '更新失败';
}
return ['code'=>0,'msg'=>$msg,'data'=>$data];