UserAudit.php 14.7 KB
<?php


namespace app\api\controller;


use app\api\validate\UserAuditA;
use app\api\validate\UserAuditB;
use app\common\controller\Api;

/**
 * 微信审核
 * @package app\api\controller
 */
class UserAudit extends BaseApi
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 判断用户是否什么身份都没有
     * @ApiTitle    (判断用户是否什么身份都没有)
     * @ApiSummary  (判断用户是否什么身份都没有:{用于增加文章部分})
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user_audit/is_auth_all)
     * @ApiBody     (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
            "code": 1,
            "msg": "有权限",
            "time": "1608605278",
            "data": null
        })
     */
    public function is_auth_all(){
        //2.获取用户数据
        $user = model('user')->where('id',$this->auth->id)->find();
        //3.判断用户是否有权限
        if (!$user['authlist']){
            $this->error('无权限');
        }
        //4.返回
        $this->success('有权限');
    }
    /**
     * 判断用户权限
     * @ApiTitle    (判断用户权限)
     * @ApiSummary  (判断用户是不是有已经有此种身份)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user_audit/is_auth)
     * @ApiParams   (name="status", type="integer", required=true, description="身份:1=实名认证,2=书家,3=书协,4=企业")
     * @ApiBody    (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
            "code": 0,
            "msg": "身份必须必填",
            "time": "1608280579",
            "data": {
                "stu": "0=审核中,1=审核成功,2=审核失败,3=没有提交"
            }
        })
     */
    public function is_auth(){
        //1.获取用户信息
        $status = $this->get_data('status','身份必须必填');
        //2.获取用户数据
        $user = model('user')->where('id',$this->auth->id)->find();
        //3.判断用户是否有权限
        $data = [
            'stu'=>3
        ];
        if (!in_array($status,Turn_an_array($user['authlist']))){
            $this->error('无权限',$data);
        }
        //4.查询身份
        if(in_array($status,[1,2])){
            $res = model('user_audit_a')
                ->where('user_id',$this->auth->id)
                ->where('status',$status)
                ->find();
            //审核状态:0=审核中,1=审核成功,2=审核失败
            if ($res){
                $data['stu'] = $res['is_stu'];
            }
        }
        if(in_array($status,[3,4])){
            $res = model('user_audit_b')
                ->where('user_id',$this->auth->id)
                ->where('status',$status-2)
                ->find();
            //审核状态:0=审核中,1=审核成功,2=审核失败
            if ($res){
                $data['stu'] = $res['is_stu'];
            }
        }

        //4.返回
        $this->success('有权限',$data);
    }
    /**
     * 用户实名认证/书家申请
     * @ApiTitle    (用户实名认证/书家申请)
     * @ApiSummary  (用户实名认证/书家申请 调用前请先调用{判断用户权限}接口)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user_audit/user_audit_a)
     * @ApiParams   (name="name", type="string", required=true, description="用户姓名")
     * @ApiParams   (name="sex_data", type="integer", required=true, description="性别:1=男,0=女")
     * @ApiParams   (name="id_number", type="integer", required=true, description="身份证号码")
     * @ApiParams   (name="auth_true_image", type="string", required=true, description="身份证正面")
     * @ApiParams   (name="auth_false_image", type="string", required=true, description="身份证反面")
     * @ApiParams   (name="auth_xiehui_image", type="string", required=true, description="书协会员证")
     * @ApiParams   (name="status", type="integer", required=true, description="类别:1=实名认证审核,2=书家审核")
     * @ApiParams   (name="user_audit_a_id", type="integer", required=false, description="审核id:如果存在,则代表更新,用于用户审核失败时候重新审核")
     * @ApiBody    (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "提交成功",
        "time": "1608284784",
        "data": {
            "name": "用户姓名",
            "sex_data": "性别:1=男,0=女",
            "id_number": "身份证号码",
            "auth_true_image": "身份证号码",
            "auth_false_image": "身份证反面",
            "auth_xiehui_image": "书协会员证",
            "status": "类别:1=实名认证审核,2=书家审核",
            "user_id": "用户id",
            "is_stu": "审核状态:0=审核中,1=审核成功,2=审核失败",
            "createtime": "2020-12-18 17:46:24",
            "updatetime": "2020-12-18 17:46:24",
            "id": "19"
        }
    })
     */
    public function user_audit_a(){
        //1.表单验证
        (new UserAuditA())->goCheck();
        //2.获取数据
        $data = g();
        //3.用户验证
        $res = model('user_audit_a')
            ->where('user_id',$this->auth->id)
            ->where('status',$data['status'])
            ->find();
        if ($res){
            if(!isset($data['user_audit_a_id']) && empty($data['user_audit_a_id'])){
                $this->error('您已经提交认证申请,如果修改请填写user_audit_a_id');
            }
        }
        //4.验证数据
        $data['user_id'] = $this->auth->id;
        $data['auth_xiehui_image'] = input('param.auth_xiehui_image');
        if($data['status'] == 2){
            $data['auth_xiehui_image'] = $this->get_data('auth_xiehui_image','书协会员证不能为空');
        }
        //5.更新或者增加
        if (isset($data['user_audit_a_id']) || !empty($data['user_audit_a_id'])){
            //5.更新数据
            $user_audit_a = model('user_audit_a')
                ->where('user_id',$this->auth->id)
                ->where('id',$data['user_audit_a_id'])
                ->find();
            if (!$user_audit_a){
                $this->error('user_audit_a_id 参数错误,未查询到审核内容!');
            }
            if ($user_audit_a['is_stu'] == 1){
                $this->error('您已经审核成功');
            }
            $user_audit_a->name = $data['name'];
            $user_audit_a->sex_data = $data['sex_data'];
            $user_audit_a->id_number = $data['id_number'];
            $user_audit_a->auth_true_image = $data['auth_true_image'];
            $user_audit_a->auth_false_image = $data['auth_false_image'];
            $user_audit_a->auth_xiehui_image = $data['auth_xiehui_image'];
            $user_audit_a->status = $data['status'];
            $user_audit_a->is_stu = 0;
            $user_audit_a->message = '';
            $user_audit_a->save();
            //6.返回成功
            $this->success('重新审核中',$user_audit_a);
        }else{
            //5.增加数据
            $res = model('user_audit_a')->create($data);
            //6.返回成功
            $this->success('提交成功',$res);
        }
    }
    /**
     * @ApiTitle (获取 用户实名认证/书家申请)
     * @ApiSummary (用户实名认证/书家申请  如果有code返回1 没有返回0)
     * @ApiMethod (POST)
     * @ApiRoute (/api/user_audit/get_user_audit_a)
     * @ApiParams (name="status", type="integer", required=true, description="类别:1=实名认证审核,2=书家审核")
     * @ApiBody (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": {
            "id": 19,
            "user_id": "用户ID",
            "name": "用户姓名",
            "sex_data": "性别:1=男,0=女",
            "id_number": "身份证号码",
            "auth_true_image": "身份证正面",
            "auth_false_image": "身份证反面",
            "auth_xiehui_image": "书协会员证",
            "status": "类别:1=实名认证审核,2=书家审核",
            "is_stu": "审核状态:0=审核中,1=审核成功,2=审核失败",
            "message": "提示",
            "createtime": "2020-12-18 17:46:24",
            "updatetime": "2020-12-18 17:46:24"
        },
        "time": "1608519985",
        "data": null
        })
     */
    public function get_user_audit_a(){
        //1.获取数据
        $data = g();
        //2.查询数据
        $res = model('user_audit_a')
            ->where('user_id',$this->auth->id)
            ->where('status',$data['status'])
            ->find();
        if ($res){
            $this->success($res);
        }
        $this->error('没有查询出任何提交');
    }
    /**
     * 用户 书协认证/企业认证接口
     * @ApiTitle    (书协认证/企业认证接口)
     * @ApiSummary  (书协认证/企业认证接口 调用前请先调用{判断用户权限}接口)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/user_audit/user_audit_b)
     * @ApiParams   (name="name", type="string", required=true, description="用户姓名")
     * @ApiParams   (name="auth_true_image", type="string", required=true, description="营业执照正面")
     * @ApiParams   (name="auth_false_image", type="string", required=true, description="营业执照反面")
     * @ApiParams   (name="status", type="integer", required=true, description="类别:1=书协审核,2=企业审核")
     * @ApiParams   (name="user_audit_b_id", type="integer", required=false, description="审核id:如果存在,则代表更新,用于用户审核失败时候重新审核")
     * @ApiBody    (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "提交成功",
        "time": "1608284784",
        "data": {
            "name": "用户姓名",
            "auth_true_image": "营业执照正面",
            "auth_false_image": "营业执照反面",
            "status": "类别:1=书协审核,2=企业审核",
            "user_id": "用户id",
            "createtime": "2020-12-18 17:46:24",
            "updatetime": "2020-12-18 17:46:24",
            "id": "19"
        }
        })
     */
    public function user_audit_b(){
        //1.表单验证
        (new UserAuditB())->goCheck();
        //2.获取数据
        $data = g();
        //3.用户验证
        $res = model('user_audit_b')
            ->where('user_id',$this->auth->id)
            ->where('status',$data['status'])
            ->find();
        if ($res){
            if(!isset($data['user_audit_b_id']) || empty($data['user_audit_b_id'])){
                $this->error('您已经提交认证申请,如果修改请填写user_audit_b_id');
            }
        }
        //4.验证数据
        $data['user_id'] = $this->auth->id;
        //5.更新或者增加
        if (isset($data['user_audit_b_id']) && !empty($data['user_audit_b_id'])){
            //5.更新数据
            $user_audit_b = model('user_audit_b')
                ->where('id',$data['user_audit_b_id'])
                ->where('user_id',$this->auth->id)
                ->find();
            if (!$user_audit_b){
                $this->error('user_audit_b_id 参数错误,未查询到审核内容!');
            }
            if ($user_audit_b['is_stu'] == 1){
                $this->error('您已经审核成功');
            }
            $user_audit_b->name = $data['name'];
            $user_audit_b->auth_true_image = $data['auth_true_image'];
            $user_audit_b->auth_false_image = $data['auth_false_image'];
            $user_audit_b->status = $data['status'];
            $user_audit_b->is_stu = 0;
            $user_audit_b->message = '';
            $user_audit_b->save();
            //6.返回成功
            $this->success('重新审核中',$user_audit_b);
        }else{
            //5.增加数据
            if (isset($data['user_audit_b_id'])){
                unset($data['user_audit_b_id']);
            }
            $res = model('user_audit_b')->create($data);
            //6.返回成功
            $this->success('提交成功',$res);
        }

    }
    /**
     * @ApiTitle (获取 书协认证/企业认证)
     * @ApiSummary (书协认证/企业认证  如果有code返回1 没有返回0)
     * @ApiMethod (POST)
     * @ApiRoute (/api/user_audit/get_user_audit_b)
     * @ApiParams (name="status", type="integer", required=true, description="类别:1=书协审核,2=企业审核")
     * @ApiBody (无内容)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": {
            "id": 19,
            "user_id": "用户ID",
            "name": "用户姓名",
            "auth_true_image": "营业执照正面",
            "auth_false_image": "营业执照反面",
            "status": "类别:1=书协审核,2=企业审核",
            "is_stu": "审核状态:0=审核中,1=审核成功,2=审核失败",
            "message": "提示",
            "createtime": "2020-12-18 17:46:24",
            "updatetime": "2020-12-18 17:46:24"
        },
        "time": "1608519985",
        "data": null
        })
     */
    public function get_user_audit_b(){
        //1.获取数据
        $data = g();
        //2.查询数据
        $res = model('user_audit_b')
            ->where('user_id',$this->auth->id)
            ->where('status',$data['status'])
            ->find();
        if ($res){
            $this->success($res);
        }
        $this->error('没有查询出任何提交');
    }
}