将老师表数据同步到管理中表中

This commit is contained in:
小松树 committed 2021-02-18 21:12:14 +08:00
1 parent c5dfc12664
commit df36c72654
46 files changed
+1100 -565

No files matched your search

+142 -3
View File
@@ -73,12 +73,120 @@ class Admin extends BaseModel
}
// 根据姓名、首拼查询教师
public function strSrcTeachers($srcfrom)
{
$src = [
'str' => ''
,'school_id' => ''
];
$src = array_cover($srcfrom, $src);
// 如果有数据则查询教师信息
$list = self::field('id, xingming, school_id, shengri, sex')
->whereOr('xingming', 'like', '%' . $src['str'] . '%')
->whereOr('shoupin', 'like', $src['str'] . '%')
->when(strlen($src['school_id']) > 0, function ($query) use($src) {
$query->where('school_id', $src['danwei_id']);
})
->with(
[
'adSchool' => function($query){
$query->field('id, jiancheng');
},
]
)
->append(['age'])
->select();
return $list;
}
// 表格导入教师信息
public function createAll($arr, $School_id)
{
$pinyin = new \Overtrue\Pinyin\Pinyin;
// 整理表格数据
array_splice($arr, 0, 4); # 删除标题行
$arr = array_filter($arr,function($item){ #过滤空值
return $item[1] !== null && $item[2] !== null && $item[3] !== null ;
});
// 组合需要保存的数据
$i = 0;
$teacherlist = array();
foreach ($arr as $key => $value) {
$phone = str_replace(' ', '', $value[4]);
$teacherlist[$i]['xingming'] = $value[1];
$teacherlist[$i]['sex'] = $this->cutStr($value[2]);
$teacherlist[$i]['shengri'] = $value[3];
$teacherlist[$i]['phone'] = $phone;
$teacherlist[$i]['worktime'] = $value[5];
$teacherlist[$i]['zhiwu_id'] = $this->cutStr($value[6]);
$teacherlist[$i]['zhicheng_id'] = $this->cutStr($value[7]);
$teacherlist[$i]['school_id'] = $School_id;
$teacherlist[$i]['biye'] = $value[9];
$teacherlist[$i]['subject_id'] = $this->cutStr($value[8]);
$teacherlist[$i]['zhuanye'] = $value[9];
$teacherlist[$i]['xueli_id'] = $this->cutStr($value[11]);
$quanpin = $pinyin->sentence($value[1]);
$jianpin = $pinyin->abbr($value[1]);
$teacherlist[$i]['quanpin'] = trim(strtolower(str_replace(' ', '', $quanpin)));
$teacherlist[$i]['shoupin'] = trim(strtolower($jianpin));
$teacherlist[$i]['username'] = $teacherlist[$i]['quanpin'] .'.'. \app\facade\Tools::sjStr(3);
$temp = $this->whereOrPhone($phone)->find();
if($temp)
{
if($temp->delete_time > 0)
{
$temp->restore();
}
$teacherlist[$i]['id'] = $temp->id;
}
$i++;
}
// 查找相同值,如果重复则重新命名。
$teacherlist = \app\facade\Tools::sortArrByManyField($teacherlist,'username');
foreach ($teacherlist as $key => $value) {
if ($key > 1) {
if($value['username'] == $teacherlist[$key-1]['username']){
$teacherlist[$key]['username'] = $teacherlist[$key]['quanpin'] .'.'. \app\facade\Tools::sjStr(4);
}else{
break;
}
}
}
$teacherlist = array_filter($teacherlist, function($q){ ## 过滤姓名、身份证号或班级为空的数据
return $q['xingming'] != null && $q['sex'] != null && $q['zhiwu_id'] != null && $q['zhicheng_id'] != null && $q['subject_id'] != null && $q['xueli_id'] != null;
});
// 保存或更新信息
$data = $this->saveAll($teacherlist);
$data ? $data = true : $data = false;
return $data;
}
// 关联用户组
public function glGroup()
{
return $this->belongsToMany('AuthGroup', 'AuthGroupAccess', 'group_id', 'uid');
}
// 单位关联模型
public function adSchool()
{
return $this->belongsTo('\app\system\model\School', 'school_id', 'id');
}
// 获取密码
public function password($username)
{
@@ -148,6 +256,20 @@ class Admin extends BaseModel
}
// 参加工作时间获取器
public function getWorktimeAttr($value)
{
return date('Y-m-d', $value);
}
// 参加工作时间修改器
public function setWorktimeAttr($value)
{
return strtotime($value);
}
// 获取角色名称
public function getGroupnames($userid)
{
@@ -181,9 +303,26 @@ class Admin extends BaseModel
}
// 单位关联模型
public function adSchool()
// 分割表格上传数据
private function cutStr($value)
{
return $this->belongsTo('\app\system\model\School', 'school_id', 'id');
$value = explode('|', $value);
$str = '';
if(isset($value[1]) && $value >0 )
{
$str = $value[1];
}
return $str;
}
static function newId($oldId)
{
$id = self::withTrashed()->whereTeacherId($oldId)->value('id');
return $id;
}
}