<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/13
 * Time: 9:53
 */
namespace Modules\Project\Services;

use Modules\Base\Entities\File;
use Modules\Base\Entities\User;
use Modules\Project\Entities\Distributor;

class DistributorService extends BaseService
{
    public function __construct(Distributor $model)
    {
        $this->model = $model;
    }

    public function update($id, $data)
    {
        return parent::update($id, $data); // TODO: Change the autogenerated stub
    }

    public function delete($id)
    {
        $this->model = $this->model->find($id);

        return $this->model->delete($id);
    }

    public function insert($data)
    {
        if (isset($data['file_id_1']) && $file = File::find($data['file_id_1'])) {
            $data['id_card'] = $file['path'];
        }
        if (isset($data['file_id_2']) && $file = File::find($data['file_id_2'])) {
            $data['id_card_back'] = $file['path'];
        }
        $user = \Auth::user();

        return $user->distributor()->create($data);
    }
}
