<?php

namespace plugin\admin\app\controller;

use app\business\CheckInBusiness;
use app\business\StreamBusiness;
use Respect\Validation\Validator;
use support\Db;
use support\Request;
use support\Response;
use plugin\admin\app\model\CheckIn;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 股权认领 
 */
class CheckInController extends Crud
{
    
    /**
     * @var CheckIn
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new CheckIn;
    }
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('check-in/index');
    }

    /** 通过
     * @return Response
     */
    public function pass(Request $request): Response
    {
        $param=$request->all();
        Db::beginTransaction();
        try {
            Validator::input($param,[
                'id'                  =>    Validator::notEmpty()->setName('标识'),
            ]);
            CheckInBusiness::pass($param['id']);

        }catch (\Throwable $exception){
            Db::rollBack();
            return json(['code' => 1, 'msg' => $exception->getMessage()]);
        }
        Db::commit();
        return json(['code' => 0, 'msg' => '成功']);
    }

    /** 驳回
     * @return Response
     */
    public function reject(Request $request): Response
    {
        $param=$request->all();
        Db::beginTransaction();
        try {
            Validator::input($param,[
                'id'                  =>    Validator::notEmpty()->setName('标识'),
            ]);
            CheckInBusiness::reject($param['id']);
        }catch (\Throwable $exception){
            Db::rollBack();
            return json(['code' => 1, 'msg' => $exception->getMessage()]);
        }
        Db::commit();
        return json(['code' => 0, 'msg' => '成功']);
    }

}
