<?php

namespace App\Admin\Repositories;

use App\Models\DistInquiry as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class DistInquiry extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    /*
     * 检测状态是否为0，即未处理
     */
    public static function assessTheStatus($ids) {
        $inquirieCount = Model::whereIn('id', $ids)->where('status', '=', 0)->count();
        if ($inquirieCount != count($ids)) {
            return false;
        }
        return true;
    }

    /*
     * 分配询价单
     */
    public static function assignData($ids, $distId) {
        $inquiries = Model::whereIn('id', $ids)->get();
        foreach ($inquiries as $inquiry) {
            $inquiry->dist_id = $distId;
            $inquiry->status = 1;
            $inquiry->save();
        }
    }

}
