点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 行业软件>> 在线考试系统>> 源文件浏览
[免费版 Free] WebForm,下载次数:252 次 | 关键字: 考试 办公 高校 竞赛 企事业单位

源码截图

源码目录树

;
当前路径:app/common/model/account/Duty.php
<?php

declare(strict_types=1);

namespace app\common\model\account;

use Exception;
use mb\helper\Collection;
use think\facade\Db;
use think\facade\Log;
use think\Model;

/**
 * Class Duty
 * @package app\common\model\account
 */
class Duty
{
    /**
     * filter.title
     * @param array $filters
     * @param int $pIndex
     * @param int $pSize
     * @param int $total
     * @return array
     */
    public static function search(array $filters, int $pIndex = 1, int $pSize = 10, &$total = 0)
    {
        $where = [];
        if (!empty($filters['title'])) {
            $where[] = ['title', 'like', "%{$filters['title']}%"];
        }
        try {
            $total = Db::table('account_dutys')
                ->where($where)
                ->count();

            $query = Db::table('account_dutys')
                ->where($where);
            if (!empty($pIndex)) {
                $query->page($pIndex, $pSize);
            }
            if (!empty($filters['order'])) {
                $query->order($filters['order']);
            }
            $dataSet = $query->select()->toArray();
            if (!empty($dataSet)) {
                return array_map(function ($row) {
                    return Collection::keyStyle($row, Collection::NAME_STYLE_JAVA);
                }, $dataSet);
            }
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return [];
    }

    /**
     * dutyInfo.title
     * @param $dutyInfo
     * @return int|string
     */
    public static function add($dutyInfo)
    {
        $newRow = Collection::elements(['title'], $dutyInfo);
        try {
            return Db::table('account_dutys')
                ->insertGetId($newRow);
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }


    /**
     * @param $filters
     * @return array|bool|Model|null
     */
    public static function fetch($filters)
    {
        $where = self::parseFilters($filters);
        try {
            return Db::table('account_dutys')
                ->where($where)
                ->find();
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }

    /**
     * newState.title
     * @param $filters
     * @param $newState
     * @return bool
     */
    public static function update($filters,$newState)
    {
        $where = self::parseFilters($filters);
        try {
            $offect = Db::table('account_dutys')
                ->where($where)
                ->update($newState);
            if ($offect === 1) {
                return true;
            }
            return false;
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }

    /**
     * @param $filters
     * @return bool
     */
    public static function remove($filters)
    {
        $where = self::parseFilters($filters);
        try {
            $offect = Db::table('account_dutys')
                ->where($where)
                ->delete();
            if ($offect === 1) {
                return true;
            }
            return false;
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }

    /**
     * dutyFilters.id
     * dutyFilters.ids
     * dutyFilters (int) 为ID
     * @param $dutyFilters
     * @return array
     */
    public static function parseFilters($dutyFilters)
    {
        $filters = [];
        if (is_array($dutyFilters)) {
            if (!empty($dutyFilters['id'])) {
                $filters[] = ['id','=',$dutyFilters['id']];
            }
            if (!empty($dutyFilters['ids'])) {
                $filters[] = ['id','in',$dutyFilters['ids']];
            }
        } else {
            $filters[] = ['id','=',intval($dutyFilters)];
        }
        return $filters;
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号