Browse Source

修改班级和排课

wangzeyan
王泽彦 11 months ago
parent
commit
4664e25258
  1. 2
      niucloud/app/adminapi/route/class.php
  2. 2
      niucloud/app/adminapi/route/classroom.php
  3. 123
      niucloud/app/common.php
  4. 12
      niucloud/app/model/classroom/Classroom.php
  5. 6
      niucloud/app/service/admin/classroom/ClassroomService.php
  6. 2
      niucloud/app/service/admin/personnel/PersonnelService.php

2
niucloud/app/adminapi/route/class.php

@ -57,8 +57,6 @@ Route::group('class', function () {
Route::get('personnel_all','class.Class/getPersonnelAll');
Route::get('personnel_all','class.Class/getPersonnelAll');
})->middleware([
AdminCheckToken::class,
AdminCheckRole::class,

2
niucloud/app/adminapi/route/classroom.php

@ -33,8 +33,6 @@ Route::group('classroom', function () {
Route::get('personnel_all','classroom.Classroom/getPersonnelAll');
Route::get('personnel_all','classroom.Classroom/getPersonnelAll');
})->middleware([
AdminCheckToken::class,
AdminCheckRole::class,

123
niucloud/app/common.php

@ -21,13 +21,13 @@ use app\service\core\sys\CoreSysConfigService;
* @param int $http_code
* @return Response
*/
function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 200) : Response
function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 200): Response
{
if (is_array($msg)) {
$data = $msg;
$msg = 'SUCCESS';
}
return Response::create([ 'data' => $data, 'msg' => get_lang($msg), 'code' => $code ], 'json', $http_code);
return Response::create(['data' => $data, 'msg' => get_lang($msg), 'code' => $code], 'json', $http_code);
}
@ -39,13 +39,13 @@ function success($msg = 'SUCCESS', $data = [], int $code = 1, int $http_code = 2
* @param int $http_code
* @return Response
*/
function fail($msg = 'FAIL', ?array $data = [], int $code = 0, int $http_code = 200) : Response
function fail($msg = 'FAIL', ?array $data = [], int $code = 0, int $http_code = 200): Response
{
if (is_array($msg)) {
$data = $msg;
$msg = 'FAIL';
}
return Response::create([ 'data' => $data, 'msg' => get_lang($msg), 'code' => $code ], 'json', $http_code);
return Response::create(['data' => $data, 'msg' => get_lang($msg), 'code' => $code], 'json', $http_code);
}
/**
@ -76,17 +76,17 @@ function list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'child', $root =
// 创建基于主键的数组引用
$refer = array();
foreach ($list as $key => $data) {
$refer[ $data[ $pk ] ] =& $list[ $key ];
$refer[$data[$pk]] =& $list[$key];
}
foreach ($list as $key => $data) {
// 判断是否存在parent
$parent_id = $data[ $pid ];
$parent_id = $data[$pid];
if ($root == $parent_id) {
$tree[] =& $list[ $key ];
$tree[] =& $list[$key];
} else {
if (isset($refer[ $parent_id ])) {
$parent =& $refer[ $parent_id ];
$parent[ $child ][] =& $list[ $key ];
if (isset($refer[$parent_id])) {
$parent =& $refer[$parent_id];
$parent[$child][] =& $list[$key];
}
}
}
@ -137,11 +137,11 @@ function array_keys_search($array, $keys, $index = '', $is_sort = true)
$list = array();
foreach ($keys as $key) {
if (isset($array[ $key ])) {
if (isset($array[$key])) {
if ($is_sort) {
$list[] = $array[ $key ];
$list[] = $array[$key];
} else {
$list[ $key ] = $array[ $key ];
$list[$key] = $array[$key];
}
}
@ -166,7 +166,7 @@ function del_target_dir($path, $delDir)
//打开目录句柄
$handle = opendir($path);
if ($handle) {
while (false !== ( $item = readdir($handle) )) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
if (is_dir("$path/$item")) {
del_target_dir("$path/$item", $delDir);
@ -200,7 +200,7 @@ function system_name(?string $key = '')
'channel_name' => env('system.channel_name', 'channel'),
];
if (!empty($key)) {
return $params[ $key ];
return $params[$key];
} else {
return $params;
}
@ -219,11 +219,11 @@ function get_date_by_time(?int $time = null)
function get_start_and_end_time_by_day($day = '')
{
$date = $day ? : date('Y-m-d');
$date = $day ?: date('Y-m-d');
$day_start_time = strtotime($date);
//当天结束之间
$day_end_time = $day_start_time + 86400;
return [ $day_start_time, $day_end_time ];
return [$day_start_time, $day_end_time];
}
/**
@ -361,7 +361,7 @@ function format_money($number)
function format_float_money($number, $precision = 2)
{
if ($precision > 0) {
return sprintf('%.' . $precision . 'f', floor($number * ( 10 ** $precision )) / ( 10 ** $precision ));
return sprintf('%.' . $precision . 'f', floor($number * (10 ** $precision)) / (10 ** $precision));
} else {
return sprintf('%.' . $precision . 'f', floor($number));
}
@ -491,19 +491,19 @@ function array_merge2(array $array1, array $array2)
if (array_key_exists($array2_k, $array1)) {
if (is_array($array2_v)) {
foreach ($array2_v as $array2_kk => $array2_vv) {
if (array_key_exists($array2_kk, $array1[ $array2_k ])) {
if (array_key_exists($array2_kk, $array1[$array2_k])) {
if (is_array($array2_vv)) {
$array1[ $array2_k ][ $array2_kk ] = array_merge($array1[ $array2_k ][ $array2_kk ], $array2_vv);
$array1[$array2_k][$array2_kk] = array_merge($array1[$array2_k][$array2_kk], $array2_vv);
}
} else {
$array1[ $array2_k ][ $array2_kk ] = $array2_vv;
$array1[$array2_k][$array2_kk] = $array2_vv;
}
}
} else {
$array1[ $array2_k ] = $array2_v;
$array1[$array2_k] = $array2_v;
}
} else {
$array1[ $array2_k ] = $array2_v;
$array1[$array2_k] = $array2_v;
}
}
return $array1;
@ -550,8 +550,8 @@ function dir_copy(string $src = '', string $dst = '', &$files = [], $exclude_dir
}
$dir = opendir($src);
dir_mkdir($dst);
while (false !== ( $file = readdir($dir) )) {
if (( $file != '.' ) && ( $file != '..' )) {
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
// 排除目录
if (count($exclude_dirs) && in_array($file, $exclude_dirs)) continue;
@ -631,7 +631,7 @@ function parse_sql($content = '', $string = false, $replace = [])
// 多行注释标记
$comment = false;
// 按行分割,兼容多个平台
$content = str_replace([ "\r\n", "\r" ], "\n", $content);
$content = str_replace(["\r\n", "\r"], "\n", $content);
$content = explode("\n", trim($content));
// 循环处理每一行
foreach ($content as $line) {
@ -723,10 +723,10 @@ function getFileMap($path, $arr = [])
if ($file_path != '.' && $file_path != '..') {
$temp_path = $path . '/' . $file_path;
if (is_dir($temp_path)) {
$arr[ $temp_path ] = $file_path;
$arr[$temp_path] = $file_path;
$arr = getFileMap($temp_path, $arr);
} else {
$arr[ $temp_path ] = $file_path;
$arr[$temp_path] = $file_path;
}
}
}
@ -751,9 +751,9 @@ function cache_remember(string $name = null, $value = '', $tag = null, $options
$value = Container::getInstance()->invokeFunction($value);
}
if (is_null($tag)) {
Cache::set($name, $value, $options[ 'expire' ] ?? null);
Cache::set($name, $value, $options['expire'] ?? null);
} else {
Cache::tag($tag)->set($name, $value, $options[ 'expire' ] ?? null);
Cache::tag($tag)->set($name, $value, $options['expire'] ?? null);
}
return $value;
@ -778,7 +778,7 @@ function image_to_base64(string $path, $is_delete = false)
{
if (!file_exists($path)) return 'image not exist';
$mime = getimagesize($path)[ 'mime' ];
$mime = getimagesize($path)['mime'];
$image_data = file_get_contents($path);
// 将图片转换为 base64
$base64_data = base64_encode($image_data);
@ -799,7 +799,7 @@ function image_to_base64(string $path, $is_delete = false)
function get_thumb_images($image, $thumb_type = 'all', bool $is_throw_exception = false)
{
return ( new CoreImageService() )->thumb($image, $thumb_type, $is_throw_exception);
return (new CoreImageService())->thumb($image, $thumb_type, $is_throw_exception);
}
/**
@ -811,10 +811,10 @@ function version_to_int($version)
{
$version_array = explode(".", $version);
$v1 = sprintf('%03s', (int) $version_array[ 0 ] ?? 0);
$v2 = sprintf('%03s', (int) $version_array[ 1 ] ?? 0);
$v3 = sprintf('%03s', (int) $version_array[ 2 ] ?? 0);
return (int) "{$v1}{$v2}{$v3}";
$v1 = sprintf('%03s', (int)$version_array[0] ?? 0);
$v2 = sprintf('%03s', (int)$version_array[1] ?? 0);
$v3 = sprintf('%03s', (int)$version_array[2] ?? 0);
return (int)"{$v1}{$v2}{$v3}";
}
/**
@ -827,13 +827,13 @@ function version_to_string($ver)
if ($ver > 999) {
if ($ver > 999999) {
$ver .= "";
$v3 = (int) substr($ver, -3);
$v2 = (int) substr($ver, -6, 3);
$v1 = (int) substr($ver, 0, -6);
$v3 = (int)substr($ver, -3);
$v2 = (int)substr($ver, -6, 3);
$v1 = (int)substr($ver, 0, -6);
} else {
$ver .= "";
$v3 = (int) substr($ver, -3);
$v2 = (int) substr($ver, 0, -3);
$v3 = (int)substr($ver, -3);
$v2 = (int)substr($ver, 0, -3);
$v1 = 0;
}
} else {
@ -889,10 +889,10 @@ function file_copy(string $source_file, string $to_file)
* @param $size
* @return string
*/
function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_transparent' => true ], $outfile = true)
function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = ['is_transparent' => true], $outfile = true)
{
if ($outfile) {
$dir = $dir ? : 'upload' . '/' . 'qrcode/';//二维码默认存储位置
$dir = $dir ?: 'upload' . '/' . 'qrcode/';//二维码默认存储位置
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir));
}
@ -911,8 +911,8 @@ function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_t
'channel' => $channel,
'outfile' => $outfile
])));
if (!empty($result[ 0 ])) {
$path = $result[ 0 ];
if (!empty($result[0])) {
$path = $result[0];
}
return $path;
}
@ -928,7 +928,7 @@ function qrcode($url, $page, $data, $dir = '', $channel = 'h5', $style = [ 'is_t
*/
function poster($id, $type, array $param = [], string $channel = '', bool $is_throw_exception = true)
{
return ( new \app\service\core\poster\CorePosterService() )->get($id, $type, $param, $channel, $is_throw_exception);
return (new \app\service\core\poster\CorePosterService())->get($id, $type, $param, $channel, $is_throw_exception);
}
/**
@ -949,7 +949,7 @@ function is_url($string)
* 获取站点插件
* @return array
*/
function get_site_addons() : array
function get_site_addons(): array
{
$addons = Cache::get("local_install_addons");
return is_null($addons) ? [] : $addons;
@ -957,7 +957,7 @@ function get_site_addons() : array
function get_wap_domain()
{
$wap_url = ( new CoreSysConfigService() )->getSceneDomain()[ 'wap_url' ];
$wap_url = (new CoreSysConfigService())->getSceneDomain()['wap_url'];
return $wap_url;
}
@ -970,7 +970,7 @@ function get_wap_domain()
*/
function str_sub($str, $length = 10, $is_need_apostrophe = true)
{
return mb_substr($str, 0, $length, 'UTF-8') . ( $is_need_apostrophe ? '...' : '' );
return mb_substr($str, 0, $length, 'UTF-8') . ($is_need_apostrophe ? '...' : '');
}
/**
@ -1010,10 +1010,10 @@ function get_last_time($time = null)
$text = floor($t / 60) . '分钟前'; //一小时内
break;
case $t < 60 * 60 * 24:
$text = floor($t / ( 60 * 60 )) . '小时前'; // 一天内
$text = floor($t / (60 * 60)) . '小时前'; // 一天内
break;
case $t < 60 * 60 * 24 * 3:
$text = floor($time / ( 60 * 60 * 24 )) == 1 ? '昨天' . date('H:i', $time) : '前天' . date('H:i', $time); //昨天和前天
$text = floor($time / (60 * 60 * 24)) == 1 ? '昨天' . date('H:i', $time) : '前天' . date('H:i', $time); //昨天和前天
break;
case $t < 60 * 60 * 24 * 30:
$text = date('m-d H:i', $time); //一个月内
@ -1028,21 +1028,22 @@ function get_last_time($time = null)
return $text;
}
function get_campus_where($user_id){
function get_campus_where($user_id)
{
$where = [];
if($user_id == 1){
if ($user_id == 1) {
return $where;
}
$personnel = new Personnel();
$role = new CampusPersonRole();
$personnel_id = $personnel->where(['sys_user_id' => $user_id])->value('id');
if(!$personnel_id){
$where[] = ['campus_id','in',[]];
if (!$personnel_id) {
$where[] = ['campus_id', 'in', []];
}
$campus_ids = $role->where(['person_id' => $personnel_id])->column('campus_id');
$where[] = ['campus_id','in',$campus_ids];
$where[] = ['campus_id', 'in', $campus_ids];
return $where;
}
@ -1074,3 +1075,13 @@ function getModifiedFields(array $oldData, array $newData): array
'new_values' => json_encode($newValues, JSON_UNESCAPED_UNICODE),
];
}
// 获取员工编号
function getEmployeeNumber()
{
$personnel = new Personnel();
// 获取最新id
$max_id = $personnel->max('id') + 1;
$max_id = str_pad($max_id, 5, '0', STR_PAD_LEFT);
return date('Ymd') . $max_id;
}

12
niucloud/app/model/classroom/Classroom.php

@ -15,12 +15,9 @@ use core\base\BaseModel;
use think\model\concern\SoftDelete;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
use app\model\campus\Campus;
use app\model\personnel\Personnel;
use app\model\personnel\Personnel;
/**
* 场地管理模型
@ -139,12 +136,7 @@ class Classroom extends BaseModel
$query->where("status", $value);
}
}
public function campus(){
return $this->hasOne(Campus::class, 'id', 'campus_id')->joinType('left')->withField('campus_name,id')->bind(['campus_id_name'=>'campus_name']);
}
@ -153,8 +145,4 @@ class Classroom extends BaseModel
return $this->hasOne(Personnel::class, 'id', 'head_coach')->joinType('left')->withField('name,id')->bind(['head_coach_name'=>'name']);
}
public function personnel(){
return $this->hasOne(Personnel::class, 'id', 'assistant_coach')->joinType('left')->withField('name,id')->bind(['assistant_coach_name'=>'name']);
}
}

6
niucloud/app/service/admin/classroom/ClassroomService.php

@ -14,7 +14,6 @@ namespace app\service\admin\classroom;
use app\model\classroom\Classroom;
use app\model\campus\Campus;
use app\model\personnel\Personnel;
use app\model\personnel\Personnel;
use core\base\BaseAdminService;
@ -109,10 +108,5 @@ class ClassroomService extends BaseAdminService
return $personnelModel->select()->toArray();
}
public function getPersonnelAll(){
$personnelModel = new Personnel();
return $personnelModel->select()->toArray();
}
}

2
niucloud/app/service/admin/personnel/PersonnelService.php

@ -88,6 +88,8 @@ class PersonnelService extends BaseAdminService
]);
$data['sys_user_id'] = $uid;
}
// 员工编号
$data['employee_number'] = getEmployeeNumber();
$res = $this->model->create($data);
Db::commit();
return $res->id;

Loading…
Cancel
Save