<?php
namespace app\workerapi\controller;


use app\adminapi\validate\tenant\TenantRegisterValidate;
use app\workerapi\logic\TenantAgreeLogic;
use app\workerapi\logic\TenantRegisterLogic;
use app\workerapi\validate\MasterWorkerAgreeValidate;

/**
 * 门店H5注册
 * Class TenantController
 * @package app\workerapi\controller
 */
class TenantController extends BaseApiController
{

    public array $notNeedLogin = ['register'];


    /**
     * @notes 注册账号
     * @return \think\response\Json
     * @author 段誉
     * @date 2022/9/7 15:38
     */
    public function register()
    {
        $params = (new TenantRegisterValidate())->post()->goCheck('apiadd');
        $result = TenantRegisterLogic::add($params);
        if (true === $result) {
            return $this->success('入驻成功', [], 1, 1);
        }
        return $this->fail(TenantRegisterLogic::getError());
    }


    /**
     * 协议详情
     * @return \think\response\Json
     */
    public function agreement_detail()
    {
        $type = $this->request->get('type/s', '');
        $result = TenantAgreeLogic::getAgreeByType($type,$this->userId);
        return $this->data($result);
    }

    /**
     * 协议签名
     * @return \think\response\Json
     */
    public function agreeSign()
    {
        $params = (new MasterWorkerAgreeValidate())->post()->goCheck('sign', [
            'user_id' => $this->userId,
            'user_info' => $this->userInfo
        ]);
        $result = TenantAgreeLogic::sign($params);
        if (false === $result) {
            return $this->fail(TenantAgreeLogic::getError());
        }
        return $this->success('签名成功', [], 1, 1);
    }


}