<?php

namespace app\api\controller\cert;

use app\api\middleware\Auth;
use app\api\service\UtilService;
use app\api\validate\CertValidate;
use app\BaseController;
use think\queue\Queueable;
use think\Request;
use app\model\CertOrder as OrderModel;

class CertOrder extends BaseController
{

    protected $middleware = [
        Auth::class,
    ];


    //报名
    public function enrollCert(Request $request)
    {
        $allowArray = ['cert_id','name','idcard','idcard_q','idcard_h','mobile','email','head_img_id','other_file_id','pay_type'];

        $vo = (new CertValidate())->goCheck($allowArray);
        if ($vo !== true) {
            return $vo;
        }
        $data = $request->only($allowArray);

        $data['user_id'] = $request->userId;
        $data['createtime'] = time();
//        $data['order_sn'] = UtilService::generateOrderNo($request->userId,'cert');

        unset($data['pay_type']);

        $where = ['is_del'=>0,'user_id'=>$data['user_id'],'cert_id'=>$data['cert_id']];
        $count = OrderModel::where($where)->count();
        if ($count > 0) {
            return $this->returnMsg('请勿重复提交');
        }
        $enrollCert = OrderModel::create($data);

        return $this->returnMsg('success',1,$enrollCert);

    }

}