数据库表:表名:idCard
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": ["realName","id_zheng","id_fan","bankCard","phoneNumber"],
"permission": {
"read": true,
"create": true,
"update": "doc.user_id==auth.uid",
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id":{
"description": "用户id",
"bsonType": "string",
"foreignKey": "uni-id-users._id",
"defaultValue":{
"$env": "uid"
}
},
"realName":{
"title":"真实姓名",
"description": "请输入真实姓名",
"bsonType": "string",
"trim": "both"
},
"id_zheng":{
"title":"身份证正面",
"bsonType": "object"
},
"id_fan":{
"title":"身份证反面",
"bsonType": "object"
},
"bankCard":{
"title": "银行卡号",
"bsonType": "string",
"minLength": 19,
"maxLength": 19
},
"phoneNumber":{
"title": "电话号码",
"bsonType": "string",
"pattern": "^\\+?[0-9-]{3,20}$",
"errorMessage":{
"pattern":"电话号码格式错误"
}
},
"status":{
"description": "用户身份验证的状态,0为没有验证,1是已经提交但是还没通过,2是管理员已经通过",
"bsonType": "int",
"defaultValue":0,
"enum":[
{
"text":"已经审核,但是审核未通过",
"value":-1
},
{
"text":"没有验证",
"value":0
},
{
"text":"已经提交,还未通过",
"value":1
},
{
"text":"管理员已经通过身份审核",
"value":2
}
]
},
"subTime":{
"description": "用户提交身份验证的时间",
"bsonType": "string"
},
"updateRecord":{
"description": "用户对自己的信息进行修改添加的操作记录,例如:x年X月X日用户添加了身份信息,X年X月X日用户修改了信息,X年X月X日用户通过了审核之类的记录",
"bsonType": "array",
"arrayType": "string"
}
}
},
前端用户点击了按钮提交时触发的方法:
const idCard = uniCloud.importObject("idCard");
//经过上面,表单已经检验成功,可以提交入库,该方法为表单提交的方法
async formSubmit(){
let user_id= this.hasLogin().user_id;
//用户走到这里说明数据已经按照要求通过校验,并符合相关正则校验
//如果是新用户之前没有提交过个人信息,就将信息添加到数据库中
if(!this.isVer){
await idCard.addIdCard({
user_id,
realName:this.formObj.realname,
id_zheng:this.success_zheng_url,
id_fan:this.success_fan_url,
bankCard:this.formObj.bankCard,
phoneNumber:this.formObj.phoneNumber,
status:1,
//将时间戳转换为x年x日x分:x秒的格式
subTime:utils.getOrderTime(Date.now())
})
this.showToast("添加成功")
}else{
//走到这里,说明用户提交过个人信息,则用户可能希望的是修改个人信息,先提示用户
uni.showModal({
title:"确认对身份验证信息进行修改吗?",
success:async res => {
console.log(this.formObj);
//用户点击确认
if(res.confirm){
//说明是数据修改
await idCard.updateIdCard({
user_id,
realName:this.formObj.realname,
id_zheng:this.success_zheng_url,
id_fan:this.success_fan_url,
bankCard:this.formObj.bankCard,
phoneNumber:this.formObj.phoneNumber,
status:1,
subTime:utils.getOrderTime(Date.now())
})
}
}
})
}
},
后端云对象的相关入库方法:云对象名:idCard
//添加新用户信息验证
async addIdCard(param){
let {user_id,realName,id_zheng,id_fan,bankCard,phoneNumber,status,subTime} = param;
let newRecord = ${subTime}用户新增了身份验证
;
//console.log(newRecord);
return await db.collection("school_idcard").add({
user_id,
realName,
id_zheng,
id_fan,
bankCard,
phoneNumber,
status,
subTime,
updateRecord:newRecord,
})
},
//用户已经通过验证,但是用户现在想修改当前的验证信息
async updateIdCard(param){
let {_id,user_id,realName,id_zheng,id_fan,bankCard,phoneNumber,subTime,status} = param;
let newRecord = ${subTime}用户修改了身份验证信息
;
let result = await db.collection("school_idcard").where({
_id,
user_id,
}).update({
realName,
id_zheng,
id_fan,
bankCard,
phoneNumber,
status,
subTime,
updateRecord:dbCmd.unshift([newRecord])
})
return result;
},
王翔 (作者)
好的,多谢
2023-11-01 17:01
王翔 (作者)
老哥,有空能帮我看看这个问题吗?谢谢,问题地址:https://ask.dcloud.net.cn/question/181147
2023-11-08 15:05