diff --git a/app/Luru/controller/Index.php b/app/Luru/controller/Index.php index 28bc1b2e..7f919260 100644 --- a/app/Luru/controller/Index.php +++ b/app/Luru/controller/Index.php @@ -20,18 +20,19 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; class Index extends BaseController { protected $middleware = []; - protected $userid = ''; + protected $luruTeacherId = ''; + protected $online = ''; protected function initialize() { - $online = session('onlineCategory'); - if($online == 'teacher') + $this->online = session('onlineCategory'); + if($this->online == 'teacher') { $this->middleware = [ 'online' ,'terlogin' ]; - $this->userid = session('teacher.userid'); + $this->luruTeacherId = session('teacher.userid'); }else{ $this->middleware = [ @@ -39,9 +40,7 @@ class Index extends BaseController ,'login' ,'auth' ]; - $ad = new \app\admin\model\Admin; - $adInfo = $ad->searchOne(session('admin.userid')); - $this->userid = $adInfo->teacher_id; + $this->luruTeacherId = session('admin.userid'); } } @@ -79,7 +78,8 @@ class Index extends BaseController ,'order' => 'desc' ,'subject_id' => '' ,'searchval' - ,'teacher_id' => $this->userid + ,'user_id' => $this->luruTeacherId + ,'user_group' => $this->online ], 'POST'); // 根据条件查询数据 @@ -157,18 +157,20 @@ class Index extends BaseController } if ($cjone->defen == $list['defen']) { - $data = ['msg' => '与原成绩相同,不需要修改。', 'val' => 1]; + $data = ['msg' => '与原成绩相同,不需要修改。', 'val' => 0]; return json($data); } $cjone->defen = $list['defen']; + $cjone->user_group = $this->online; + $cjone->user_id = $this->luruTeacherId; $cjone->defenlv = $list['defen'] / $manfen * 100; $data = $cjone->save(); } else { $data = [ 'kaohao_id' => $list['kaohao_id'] ,'subject_id' => $list['subject_id'] - ,'teacher_id' => $this->userid + ,'user_id' => $this->luruTeacherId ,'defen' => $list['defen'] ,'defenlv' => $list['defen'] / $manfen * 100 ]; @@ -242,13 +244,15 @@ class Index extends BaseController $cjone->defen = $list['newdefen']; $cjone->defenlv = $list['newdefen'] / $manfen * 100; - $cjone->teacher_id = $this->userid; + $cjone->user_id = $this->luruTeacherId; + $cjone->user_group = $this->online; $data = $cjone->save(); } else { $data = [ 'kaohao_id' => $list['kaohao_id'] ,'subject_id' => $subject_id - ,'teacher_id' => $this->userid + ,'user_id' => $this->luruTeacherId + ,'user_group' => $this->online ,'defen' => $list['newdefen'] ,'defenlv' => $list['newdefen'] / $manfen * 100 ]; @@ -362,7 +366,8 @@ class Index extends BaseController } } - $user_id = $this->userid; # 获取用户id + $user_id = $this->luruTeacherId; # 获取用户id + $user_group = $this->online; # 获取用户id $data = array(); // 重新组合数组 @@ -398,7 +403,8 @@ class Index extends BaseController $cjone->restore(); $cjone->defen = $defen; $cjone->defenlv = $defen / $manfen * 100; - $cjone->teacher_id = $user_id; + $cjone->user_id = $user_id; + $cjone->user_group = $user_group; $cjone->save(); } } else { @@ -406,7 +412,8 @@ class Index extends BaseController $data = [ 'kaohao_id' => $val[1] ,'subject_id' => $value['id'] - ,'teacher_id' => $this->userid + ,'user_id' => $user_id + ,'user_group' => $user_group ,'defen' => $defen ,'defenlv' => $defen / $manfen * 100 ]; @@ -476,7 +483,7 @@ class Index extends BaseController ->setCreator("尚码成绩管理系统") //作者 ->setTitle("尚码成绩管理") //标题 ->setLastModifiedBy(session('username')) //最后修改者 - ->setDescription("该表格由" . $this->userid . "于" . $thistime . "在尚码成绩管理系统中下载,只作为内部交流材料,不允许外泄。") //描述 + ->setDescription("该表格由" . $this->luruTeacherId . "于" . $thistime . "在尚码成绩管理系统中下载,只作为内部交流材料,不允许外泄。") //描述 ->setKeywords("尚码 成绩管理") //关键字 ->setCategory("成绩管理"); //分类 diff --git a/app/chengji/controller/Index.php b/app/chengji/controller/Index.php index 843dacd0..49c75fd8 100644 --- a/app/chengji/controller/Index.php +++ b/app/chengji/controller/Index.php @@ -618,21 +618,14 @@ class Index extends AdminBase $data = $chengji ->where('kaohao_id',$src['kaohao']) - ->field('id,kaohao_id,subject_id,teacher_id,defen,update_time') + ->field('id,kaohao_id,subject_id,user_id,user_group,defen,update_time') ->order([$src['field']=>$src['order']]) ->with([ 'subjectName'=>function($query){ $query->field('id,title'); - }, - 'userName'=>function($query){ - $query->field('id,danwei_id,xingming') - ->with([ - 'jsDanwei'=>function($query){ - $query->field('id,jiancheng'); - } - ]); } ]) + ->append(['userInfo']) ->select(); $cnt = count($data); diff --git a/app/chengji/model/Chengji.php b/app/chengji/model/Chengji.php index 05df9baf..19c69c32 100644 --- a/app/chengji/model/Chengji.php +++ b/app/chengji/model/Chengji.php @@ -16,9 +16,16 @@ class Chengji extends BaseModel // 学科关联 - public function userName() + public function cjTeacher() { - return $this->belongsTo('\app\teacher\model\Teacher','teacher_id','id'); + return $this->belongsTo('\app\teacher\model\Teacher','user_id','id'); + } + + + // 学科关联 + public function cjAdmin() + { + return $this->belongsTo('\app\admin\model\Admin','user_id','id'); } @@ -39,6 +46,7 @@ class Chengji extends BaseModel ,'subject_id' => '' ,'searchval' => '' ,'user_id' => '' + ,'user_group' =>'' ); $src = array_cover($srcfrom, $src) ; $src['kaoshi_id'] = strToarray($src['kaoshi_id']); @@ -70,8 +78,9 @@ class Chengji extends BaseModel ->when(count($src['kaoshi_id']) == 0 && count($src['banji_id']) ==0, function($query) { $query->whereMonth('update_time'); }) - ->when(strlen($src['user_id']) > 0, function ($query) use($src){ - $query->where('user_id', $src['user_id']); + ->when(strlen($src['user_id']) > 0 && strlen($src['user_group']) > 0, function ($query) use($src){ + $query->where('user_id', $src['user_id']) + ->where('user_group', $src['user_group']); }) ->when(count($src['subject_id']) > 0, function ($query) use ($src) { $query->where('subject_id', 'in', $src['subject_id']); @@ -212,4 +221,41 @@ class Chengji extends BaseModel return true; } + + // 上传人信息获取器 + public function getUserInfoAttr($value, $data) + { + // halt($data); + $xm = ''; + if($data['user_group'] === 'admin') + { + if($this->cjAdmin) + { + $xm = $this->cjAdmin->xingming . '(' . $this->cjAdmin->adSchool->jiancheng . ')'; + } + }else{ + if($this->cjTeacher) + { + $xm = $this->cjTeacher->xingming . '(' . $this->cjTeacher->jsDanwei->jiancheng . ')'; + } + } + + $arr = [ + 'admin' => '管理员' + ,'teacher' => '教师' + ,'student' => '学生' + ]; + + if(isset($arr[$data['user_group']])) + { + $group = $arr[$data['user_group']]; + }else{ + $group = '未知'; + } + + $str = $group . ' ' . $xm; + + return $str; + } + } diff --git a/app/chengji/view/index/read_add.html b/app/chengji/view/index/read_add.html index 8f472ec5..fdc7ccb2 100644 --- a/app/chengji/view/index/read_add.html +++ b/app/chengji/view/index/read_add.html @@ -43,14 +43,11 @@ return str; }}, {field: 'defen', title: '得分 ', minWidth:100,sort:false}, - {title: '成绩录入',templet:function(d){ + {field:'user_id', title: '成绩录入',templet:function(d){ var str=''; - if(d.userName) + if(d.userInfo) { - if(d.userName.jsDanwei) - { - str = d.userName.jsDanwei.jiancheng + ' ' + d.userName.xingming; - } + str = d.userInfo; } return str; }}, diff --git a/app/system/controller/Fields.php b/app/system/controller/Fields.php index 81a2b00d..30ff1cc5 100644 --- a/app/system/controller/Fields.php +++ b/app/system/controller/Fields.php @@ -47,12 +47,13 @@ class Fields extends AdminBase ->visible([ 'id' ,'flCategory'=>['title'] - ,'flTeacher'=>['xingming'] + // ,'flTeacher'=>['xingming'] ,'oldname' ,'fieldsize' - ,'flTeacher'=>['xingming'] + // ,'flTeacher'=>['xingming'] ,'bianjitime' ,'update_time' + ,'userInfo' ]); $data = reSetObject($data, $src); diff --git a/app/system/model/Fields.php b/app/system/model/Fields.php index acda4198..0df19ca5 100644 --- a/app/system/model/Fields.php +++ b/app/system/model/Fields.php @@ -40,21 +40,11 @@ class Fields extends BaseModel $query->where('oldname', 'like', '%' . $src['searchval'] . '%'); }) ->with([ - 'flTeacher' => function($query){ - $query - ->field('id, xingming, danwei_id') - ->with([ - 'jsDanwei' => function($q){ - $q->field('id, jiancheng'); - } - ]); + 'flCategory' => function ($query) { + $query->field('id, title'); } - ,'flCategory' => function($query){ - $query - ->field('id, title'); - } - ]) + ->append(['userInfo']) ->select(); return $data; @@ -64,14 +54,52 @@ class Fields extends BaseModel // 上传人数据关联 public function flTeacher() { - return $this->belongsTo('\app\teacher\model\Teacher', 'teacher_id', 'id'); + return $this->belongsTo('\app\teacher\model\Teacher', 'user_id', 'id'); } + // 上传人数据关联 + public function flAdmin() + { + return $this->belongsTo('\app\admin\model\Admin', 'user_id', 'id'); + } + + + // 文件种类数模型关联 public function flCategory() { return $this->belongsTo('\app\system\model\Category', 'category_id', 'id'); } + + // 上传人信息获取器 + public function getUserInfoAttr($value, $data) + { + // halt($data); + $xm = ''; + if($data['user_group'] === 'admin') + { + if($this->flAdmin) + { + $xm = $this->flAdmin->xingming . '(' . $this->flAdmin->adSchool->jiancheng . ')'; + } + }else{ + if($this->flTeacher) + { + $xm = $this->flTeacher->xingming . '(' . $this->flTeacher->jsDanwei->jiancheng . ')'; + } + } + + $arr = [ + 'admin' => '管理员' + ,'teacher' => '教师' + ,'student' => '学生' + ]; + + $str = $arr[$data['user_group']] . ' ' . $xm; + + return $str; + } + } diff --git a/app/system/view/fields/index.html b/app/system/view/fields/index.html index 6028da50..ff7519b1 100644 --- a/app/system/view/fields/index.html +++ b/app/system/view/fields/index.html @@ -61,15 +61,11 @@ } return str; }}, - {field: 'teacher_id', title: '上传人', minWidth:150,sort: true,templet:function(d){ + {field: 'user_id', title: '上传人', minWidth:150,sort: true,templet:function(d){ var str=''; - if(d.flTeacher) + if(d.userInfo) { - str = d.flTeacher.xingming; - if(d.flTeacher.jsDanwei) - { - str = d.flTeacher.jsDanwei.jiancheng + ' ' + d.flTeacher.xingming; - } + str = d.userInfo; } return str; }}, diff --git a/app/tools/controller/File.php b/app/tools/controller/File.php index bcf1f8b2..02aba8df 100644 --- a/app/tools/controller/File.php +++ b/app/tools/controller/File.php @@ -13,18 +13,18 @@ use PhpOffice\PhpSpreadsheet\IOFactory; class File extends BaseController { - + // 初始化变量 protected function initialize() { - $online = session('onlineCategory'); - if($online == 'teacher') + $this->online = session('onlineCategory'); + if($this->online == 'teacher') { $this->middleware = [ 'online' ,'terlogin' ]; - $this->userid = session('teacher.userid'); + $this->luruTeacherId = session('teacher.userid'); }else{ $this->middleware = [ @@ -32,9 +32,7 @@ class File extends BaseController ,'login' ,'auth' ]; - $ad = new \app\admin\model\Admin; - $adInfo = $ad->searchOne(session('admin.userid')); - $this->userid = $adInfo->teacher_id; + $this->luruTeacherId = session('admin.userid'); } } @@ -59,7 +57,7 @@ class File extends BaseController if($serFile) { - $serFile->user_id = session('admin.userid'); + $serFile->user_id = $this->luruTeacherId; $serFile->save(); $data['msg'] = '文件已经存在'; $data['val'] = true; @@ -77,10 +75,10 @@ class File extends BaseController $list['url'] = $savename; $list['newname'] = substr($savename ,strripos($savename, '\\') + 1 - ,strlen($savename) - strripos($savename - ,'\\')); + ,strlen($savename) - strripos($savename ,'\\')); $list['hash'] = $file->hash('sha1'); - $list['teacher_id'] = $this->userid; + $list['user_id'] = $this->luruTeacherId; + $list['user_group'] = $this->online; $list['oldname'] = $file->getOriginalName(); $list['fieldsize'] = $file->getSize(); $list['category_id'] = $list['category_id']; diff --git a/database/migrations/20181101040801_fields.php b/database/migrations/20181101040801_fields.php index 3c43d22a..ecc891c7 100644 --- a/database/migrations/20181101040801_fields.php +++ b/database/migrations/20181101040801_fields.php @@ -40,7 +40,8 @@ class Fields extends Migrator ->addColumn('extension','string',['limit'=>100,'default'=>'.a','null'=>false,'comment'=>'文件扩展名']) ->addColumn('fieldsize','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'文件大小']) ->addColumn('hash','string',['limit'=>100,'default'=>'a','null'=>false,'comment'=>'散列值']) - ->addColumn('teacher_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'用户ID']) + ->addColumn('user_group','string',['limit'=>11,'null'=>true,'comment'=>'用户身份']) + ->addColumn('user_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'用户ID']) ->addColumn('url','string',['limit'=>100,'null'=>true,'comment'=>'文件储存位置']) ->addColumn('create_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'创建时间']) ->addColumn('update_time','integer',['limit'=>11,'default'=>'1539158918','null'=>false,'comment'=>'更新时间']) diff --git a/database/migrations/20190430034853_chengji.php b/database/migrations/20190430034853_chengji.php index 1fc983b6..7c5814a2 100644 --- a/database/migrations/20190430034853_chengji.php +++ b/database/migrations/20190430034853_chengji.php @@ -35,7 +35,8 @@ class Chengji extends Migrator $table ->addColumn('kaohao_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'考试']) ->addColumn('subject_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'学科']) - ->addColumn('teacher_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'学生']) + ->addColumn('user_group','string',['limit'=>11, 'null'=>true,'comment'=>'用户组']) + ->addColumn('user_id','integer',['limit'=>11,'default'=>0,'null'=>false,'comment'=>'用户']) ->addColumn('defen','decimal',['precision'=>5,'scale'=>1,'default'=>Null,'null'=>false,'comment'=>'得分']) ->addColumn('defenlv','decimal',['precision'=>6,'scale'=>2,'default'=>Null,'null'=>false,'comment'=>'得分率'])