<?php

    namespace app\controller;

    use app\api\repositories\UsersRepositories;
    use app\business\BankCardBusiness;
    use app\business\LoginBusiness;
    use app\business\UserIdentityBusiness;
    use Illuminate\Support\Arr;
    use Respect\Validation\Validator;
    use support\Db;
    use support\Redis;
    use support\Request;
    use hg\apidoc\annotation as Apidoc;
    use Webman\Captcha\CaptchaBuilder;
    use Webman\Captcha\PhraseBuilder;

    #[Apidoc\Title("实名认证+修改实名信息")]
    #[Apidoc\Group("UserIdentity")]
    #[Apidoc\Sort(5)]
    class UserIdentityController
    {

        #[Apidoc\Title("实名认证+修改实名信息")]
        #[Apidoc\Url("api/user/identity.html")]
        #[Apidoc\Method("POST")]
        #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
        #[Apidoc\Param("name", type: "string", require: true, desc: "姓名", mock: "张三")]
        #[Apidoc\Param("number", type: "string", require: true, desc: "身份证号码 16-18位", mock: 500221233312836451)]
        public function Updata(Request $request)
        {
            $param              = $request->param_data;
            $param              = Arr::only($param, ['name', 'number']);
            $param['user_data'] = $request->user_data;
            Db::beginTransaction();
            try {
                Validator::input($param, [
                    'name'   => Validator::notEmpty()->stringType()->setName('姓名'),
                    'number' => Validator::notEmpty()->stringType()->Length(16, 18)->setName('身份证号码'),
                ]);
                UserIdentityBusiness::UpData($param);
            } catch (\Throwable $exception) {
                Db::rollBack();
                return error($exception->getMessage());
            }
            Db::commit();
            return success();


        }


    }
