ProjectRepository.php 1.84 KB
<?php

namespace domain\project;

use domain\project\models\Project as ProjectModel;


/**

 * Class ProjectRepository
 * @package domain\model
 */
class ProjectRepository
{
    /**
     * 获取分页数据
     * @param $where
     * @param $offset
     * @param $limit
     * @return array|\yii\db\ActiveRecord[]
     */
    static function getPageList($where, $offset, $limit)
    {
        $modelFind = ProjectModel::find()->alias("p")
                            ->select([
                                "p.*"
                            ]);

        if (!empty($where)) {
            $modelFind->where($where);
        }
        if ($offset) {
            $modelFind->offset($offset);
        }
        if ($limit) {
            $modelFind->limit($limit);
        }
        $modelFind->andWhere(["is_delete" => 0]);
        $modelFind->orderBy("p.id desc");
        $modelFind->asArray();
        $dataList = $modelFind->all();

        return $dataList;
    }

    /**
     * 列表页面分页器数量
     * @param string $map
     */
    static function getPageCount($map = '')
    {
        $modelFind = ProjectModel::find()->alias("p");
        if (!empty($map)) {
            $modelFind->where($map);
        }
        $modelFind->andWhere(["is_delete" => 0]);
        $pageCount = $modelFind->count();

        return $pageCount;
    }

    /**
     * @param $id
     * @param bool|false $asArr
     * @return null|static
     */
    static function selectOne($id, $asArr = false)
    {
        $model = ProjectModel::findOne($id);
        if ($asArr && $model) {
            $model = $model->toArray();
        }
        return $model;
    }

    /**
     * @param $id
     * @param bool|false $asArr
     * @return null|static
     */
    static function findOne($condition)
    {
        $model = ProjectModel::findOne($condition);
        return $model;
    }
}