

/*=============================================================================================
	author:ZhaoJun
	version:1.2
	email:2732810281@qq.com
=============================================================================================*/

 
//严格模式
/*-------------------------------------------------------------------------------------------*/	
    'use strict';
/*-------------------------------------------------------------------------------------------*/
    
// 用户信息
/*-------------------------------------------------------------------------------------------*/	
    class index
    {
        //--------------------------
		//<分组>用户-用户信息
		//<消息备注>获取验证码 
		//<请求方式>post
		//<请求地址>/http/user/index/code
		//<请求参数>tel=电话号码
		//<返回参数>{
        // "code": 0,
        // "message": "",
        // "param": {}
        //}
		//<结束>
		//--------------------------
        async code(req,res)
        { 
            let match=
            {
                tel:$DbMysqlr.su_user.tel,
            } 
            let result=$Sys.model('/fun/filter','eval')(req.post,match); 

            const code=$Sys.rand(1000,9999)
            result=await req.session.sets({code_tel:result.where.tel,code:code})
            result.code=code
            return  $Sys.model('/fun/filter','echo')({check:result,message:"获取失败"});
        }         
      
        reg(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"注册新用户",requestMethod:"post"},
                service:{path:"/sql",method:"insert",db:"main"},
                requestParam:  
                {
                    code:{descript:'验证码',len:4,other:true},                                                 
                    pass:{...$DbMysqlr.su_user.pass,field:true},  
                    tel:{...$DbMysqlr.su_user.tel,field:true}, 
                },                  
                async fun(param)    
                {       
                    await $Sys.su.code(req,param.other.code)
                    param.field.openid=$Sys.comm.sha1(param.field.tel+$Config.pass)
                    param.field.time=Date.now()/1000
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }
        
        _reg(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"注册新用户测试",requestMethod:"post"},
                service:{path:"/sql",method:"insert",db:"main"},
                requestParam:  
                {                                               
                    pass:{...$DbMysqlr.su_user.pass,field:true},  
                    tel:{...$DbMysqlr.su_user.tel,field:true}, 
                },                  
                async fun(param)    
                {       
                    param.field.openid=$Sys.comm.sha1(param.field.tel+$Config.pass)
                    param.field.time=Date.now()/1000
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }

        _login(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"登录测试",requestMethod:"post"},
                service:{path:"/sql",method:"selectOne",db:"main"}, 
                requestParam:  
                {
                    pass:{...$DbMysqlr.su_user.pass},                                                
                    tel:{...$DbMysqlr.su_user.tel}
                },                  
                async fun(param)    
                {   
                    param.key="name,image,role,openid,id"
                    param.table='su_user'
                },
                async funAfter(param)
                {
                    if(param)
                    {
                        await req.session.sets({id:param.id,role:param.role,openid:param.openid})
                        Reflect.deleteProperty(param,'id')
                    }
                } 
            };
 
            this.$doc=doc
        }

        login(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"登录",requestMethod:"post"},
                service:{path:"/sql",method:"selectOne",db:"main"},    
                requestParam:  
                {
                    code:{descript:'验证码',len:4,delete:true,other:true},  
                    pass:{...$DbMysqlr.su_user.pass,delete:true,where:true},                                                
                    tel:{...$DbMysqlr.su_user.tel,where:true}, 
                },                  
                async fun(param)    
                {   
                    if(!(param.other || param.where.pass))$Sys.err({message:'请输入密码或者验证码'})    
                    if(param.other && param.other.code)await $Sys.su.code(req,param.other.code)
                    param.key="name,image,role,openid,id"
                    param.table='su_user'
                },
                async funAfter(param)
                {
                    if(param)
                    {
                        await req.session.sets({id:param.id,role:param.role,openid:param.openid})
                        Reflect.deleteProperty(param,'id')
                    }
                },
            };
 
            this.$doc=doc
        }

        backPass(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"找回密码",requestMethod:"post"},
                service:{path:"/sql",method:"update",db:"main"},
                requestParam:  
                {
                    code:{descript:'验证码',len:4,other:true},                                                 
                    pass:{...$DbMysqlr.su_user.pass,field:true},  
                    tel:{...$DbMysqlr.su_user.tel,where:true}, 
                },                  
                async fun(param)    
                {       
                    await $Sys.su.code(req,param.other.code)
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }

        revTelToken(req)
        {
            let doc = 
            {                     
                base:{group:"用户-用户信息",descript:"更换手机",requestMethod:"post"},
                service:{path:"/sql",method:"update",db:"main"},
                requestParam:  
                {
                    code:{descript:'验证码',len:4,other:true},                                                 
                    tel:{...$DbMysqlr.su_user.tel,field:true},  
                },                  
                async fun(param)    
                {        
                    await $Sys.su.code(req,param.other.code)
                    param.where={id:req.token.id}
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }

        infoToken(req)
        {
            let doc = 
            {                    
                base:{group:"用户-用户信息",descript:"修改用户信息",requestMethod:"post"},
                service:{path:"/sql",method:"update",db:"main"},
                requestParam:  
                {
                    image:{...$DbMysqlr.su_user.image,delete:true,field:true},                                                  
                    name:{...$DbMysqlr.su_user.name,delete:true,field:true},  
                },                  
                async fun(param)    
                {       
                    param.where.id=req.token.id 
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }

        getInfo(req)
        {
            let doc = 
            {                     
                base:{group:"用户-用户信息",descript:"得到用户信息",requestMethod:"post"},
                service:{path:"/sql",method:"selectOne",db:"main"},
                requestParam:  
                {
                    openid:{...$DbMysqlr.su_user.openid}
                },                  
                async fun(param)    
                {       
                    param.key="name,image,time,role"
                    param.table='su_user'
                } 
            };
 
            this.$doc=doc
        }
    }
/*-------------------------------------------------------------------------------------------*/    
module.exports=index;