<?php

namespace App\Http\Controllers;

use App\Http\Services\RoleService;
use App\Http\Services\SupplierContactService;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierStatisticsService;
use App\Http\Services\ViewCheckService;
use App\Model\IntracodeModel;
use App\Model\SupplierAttachmentsModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SupplierAttachmentController extends Controller
{
    public function info(Request $request, $id = '')
    {
        {
            if ($request->path() == '/') {
                $path = 'web/index';
            } else {
                $path = $request->path();
            }
            $this->data = [
                'menus' => $request->menus,
                'header' => $request->user->header,
                'username' => $request->user->email,
                'user_email' => $request->user->email,
                'uri' => '/' . $path,
                'id' => $id,
            ];
            return $this->$id($request);
        }
    }

    public function __call($name, $arr)
    {
        $data['errinfo'] = '访问路径错误';
        return view('errors.error', $data);
    }


    //供应商详情
    public function AddSupplierAttachment($request)
    {
        $this->data['title'] = '添加附件';
        return $this->view('添加附件');
    }

    //供应商详情
    public function UpdateSupplierAttachment($request)
    {
        $attachmentId = $request->get('attachment_id');
        if (!empty($attachmentId)) {
            $model = new SupplierAttachmentsModel();
            $attachment = $model->where('attachment_id', $attachmentId)->first()->toArray();
            $attachment['validity_period'] = $attachment['validity_start'] ? date('Y-m-d',
                    $attachment['validity_start']) . '~' . date('Y-m-d', $attachment['validity_start']) : '';
            $this->data['attachment'] = $attachment;
        }
        $this->data['title'] = '修改附件';
        $this->data['view'] = 'AddSupplierAttachment';
        return $this->view('修改附件');
    }



}