<?php
/**
 * Created by PhpStorm.
 * User: wuzhenke
 * Date: 2018/11/13
 * Time: 17:47
 */

namespace App\Repositories;

use App\Models\CompanyImg;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;

class CompanyImgRepository extends BaseRepository
{
    public function model()
    {
        return CompanyImg::class;
    }

    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }

    public function list($id)
    {
        return $this->findWhere(['company_id'=>$id]);
    }

    public function getImgInfo($id)
    {
        return $this->find($id);
    }

    /**
     * @企业风采保存
     * @param $data
     * @return mixed
     * @throws \Prettus\Validator\Exceptions\ValidatorException
     */
    public function store($data)
    {
        return $this->create($data);
    }
    public function imgCount()
    {
        return $this->model->where('company_id', auth('web-company')->user()->id)->count();
    }

    public function saveRemark($data, $where)
    {
        return $this->model->where($where)->update($data);
    }
    public function delImg($id,$company_id)
    {
       return $this->deleteWhere(['company_id'=>$company_id,'id'=>$id]);
    }

    public function getImages($where)
    {
        return $this->model->where($where)->get();
    }

    public function getCount($subsite_id, $orwhere)
    {
        return $this->model->when($subsite_id,function ($query) use($subsite_id) {
            $query->whereHas('companys', function ($query) use($subsite_id) {
                $query->where($subsite_id);
            });
        })->whereHas('companys')->WhereIn('audit', $orwhere)->count();
    }

}