<?php

namespace app\index\controller;

use app\BaseController;
use app\common\command\AddAgreementPdf;
use app\common\model\master_worker\MasterWorkerAgree;
use app\common\model\tenant\TenantAgree;
use app\common\model\tenant\TenantRegister;
use app\common\service\JsonService;
use think\facade\View;

class TenantAgreementController extends BaseController
{
    //http:// /index/tenant_agreement/index?code=
    public function index()
    {
        $code = $this->request->param('code');
        if(empty($code)){
            return JsonService::fail('code不存在');
        }
        $agree = TenantAgree::with(['masterWorkerInfo','masterWorkerTeam'])->where('code', $code)->findOrEmpty();
        if($agree->isEmpty() || empty($agree['sign'])){
            return JsonService::fail('协议不存在');
        }
        $register_info = TenantRegister::where('tenant_id', $agree['masterWorkerTeam']['tenant_id']??-1)->findOrEmpty();
        $agree['sign'] = $this->request->domain().'/'.$agree['sign'];
        View::assign([
            'agree'  => $agree,
            'register_info'  => $register_info,
            'start_date'=> date('Y年m月d日'),
            'end_date'=> date('Y年m月d日', strtotime(date('Y-m-d'). ' +1 year')),
        ]);
        return view('tenant_agree');
    }
}
