DeviceAuthFailRepository.php 2.2 KB
<?php

namespace domain\device;

use Yii;
use domain\device\models\DeviceAuthFail as DeviceAuthFailModel;

class DeviceAuthFailRepository
{
    /**
     * @param $condition
     * @return static
     */
    static function findOne($condition)
    {
        return DeviceAuthFailModel::findOne($condition);
    }


    /**
     * @param $where
     * @return array|\yii\db\ActiveRecord[]
     */
    static function getList($where, $limit = 0, $offset = 0)
    {
        $deviceFind = DeviceAuthFailModel::find();
        $deviceFind->alias('a');
        $deviceFind->select(['a.*', 'm.name as manufacture','p.name as project','pd.name as production','mo.name as model']);
        $deviceFind->leftJoin('manufacture as m', 'm.manufacture_no = a.manufacture_no');
        $deviceFind->leftJoin('project as p', 'p.project_no = a.project_no');
        $deviceFind->leftJoin('model as mo', 'mo.model_no = a.model_no');
        $deviceFind->leftJoin('production as pd', 'pd.production_no = a.production_no');

        $deviceFind->where($where);
        $deviceFind->orderBy('created_at desc');
        $deviceFind->asArray();
        if ($offset) {
            $deviceFind->offset($offset);
        }
        if ($limit) {
            $deviceFind->limit($limit);
        }
        $all = $deviceFind->all();

        return $all;
    }

    /**
     * @param $where
     * @return int|string
     */
    static function getListCount($where)
    {
        $deviceFind = DeviceAuthFailModel::find();
        $deviceFind->alias('a');
        $deviceFind->leftJoin('manufacture as m', 'm.manufacture_no = a.manufacture_no');
        $deviceFind->leftJoin('project as p', 'p.project_no = a.project_no');
        $deviceFind->leftJoin('model as mo', 'mo.model_no = a.model_no');
        $deviceFind->leftJoin('production as pd', 'pd.production_no = a.production_no');
        $deviceFind->where($where);
        $all = $deviceFind->count();

        return $all;
    }

    /**
     * @param $condition
     * @return array|\yii\db\ActiveRecord[]
     */
    static function findAll($condition)
    {
        $deviceModel = DeviceAuthFailModel::find();
        $deviceModel->where($condition);
        $list = $deviceModel->all();

        return $list;
    }
}