You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
shipin/app/dao/crud/SchoolDao.php

104 lines
3.4 KiB

<?php
/**
* +----------------------------------------------------------------------
* | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
* +----------------------------------------------------------------------
* | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
* +----------------------------------------------------------------------
* | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
* +----------------------------------------------------------------------
* | Author: CRMEB Team <admin@crmeb.com>
* +----------------------------------------------------------------------
*/
/**
* school
* @author crud自动生成代码
* @date 2023/10/11 14:32:28
*/
namespace app\dao\crud;
use app\dao\BaseDao;
use app\model\crud\School;
/**
* Class SchoolDao
* @date 2023/10/11
* @package app\dao\crud
*/
class SchoolDao extends BaseDao
{
/**
* 设置模型
* @return string
* @date 2023/10/11
*/
protected function setModel(): string
{
return School::class;
}
/**
* 搜索
* @param array $where
* @return \crmeb\basic\BaseModel
* @throws \ReflectionException
* @date {%DATE%}
*/
public function searchCrudModel(array $where = [], $field = ['*'], string $order = '', array $with = [])
{
return $this->getModel()->field($field)->where('is_del', 0)->when($order !== '', function ($query) use ($order) {
$query->order($order);
})->when($with, function ($query) use ($with) {
$query->with($with);
})->when(!empty($where['school_name']), function ($query) use ($where) {
$query->whereLike('school_name', '%' . $where['school_name'] . '%');
})->when(!empty($where['school_u_phone']), function ($query) use ($where) {
$query->whereLike('school_u_phone', '%' . $where['school_u_phone'] . '%');
})->when(!empty($where['school_u_name']), function ($query) use ($where) {
$query->whereLike('school_u_name', '%' . $where['school_u_name'] . '%');
})->when(!empty($where['create_time']), function ($query) use ($where) {
$query->whereBetween('create_time', $where['create_time']);
})->when(!empty($where['update_time']), function ($query) use ($where) {
$query->whereBetween('update_time', $where['update_time']);
});
}
/**
* 校验学校邀请码是否存在
*/
public function selectSchoolCodeData(string $code)
{
$schoolData = $this->getModel()->field('school_name, school_u_phone, school_u_name, id')
->where('school_code', $code)
->where('is_del', 0)
->find();
return is_null($schoolData) ? true : $schoolData->toArray();
}
/**
* 查询所有学校
*/
public function selectSchoolDao()
{
$schoolData = $this->getModel()->field('id as value, school_name as label')->where('is_del', 0)->select();
return is_null($schoolData) ? [] : array_merge([['value' => 0, 'label' => '全部']], $schoolData->toArray());
}
/**
* 校验学校是否存在
*/
public function selectSchoolById($id)
{
$schoolData = $this->getModel()->field('school_name')->where('id', $id)->find();
return is_null($schoolData) ? [] : $schoolData->toArray();
}
public function getThisModel()
{
return $this->getModel();
}
}