123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserHistory extends Model
- {
- public function add($data){
- $curTime = date('Y-m-d H:i:s');
- $data['create_time'] = $curTime;
- $result = validate('UserHistory')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserHistory')->getError());
- }
- $lists = model('UserInfo')->all($data['org_id'],$data['company_id']);
- $data['nums'] = count($lists);
- Db::startTrans();
- try{
- $historyId = Db::name('user_history')->insertGetId($data);
- if(!$historyId){
- \exception('操作失败');
- }
- $arr = [];
- foreach ($lists as $k=>$v){
- $arr[] = $v;
- if(count($arr) == 100){
- $res = Db::name('user_history_data')->insert(['history_id'=>$historyId,'content'=>json_encode($arr)]);
- if(!$res){
- \exception('操作失败');
- }
- }
- }
- if($arr){
- $res = Db::name('user_history_data')->insert(['history_id'=>$historyId,'content'=>json_encode($arr)]);
- if(!$res){
- \exception('操作失败');
- }
- }
- Db::commit();
- }catch (Exception $e){
- Db::rollback();
- HelpHander::error('操作失败'.$e->getMessage());
- }
- return true;
- }
- public function lists($page,$size,$orgId){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- $lists = Db::name('user_history')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $company = Db::name('company')->where('id',$v['company_id'])->value('title');
- $lists[$k]['company'] = $company?$company:'';
- }
- $total = Db::name('user_history')->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function exportLists($id){
- $info = Db::name('user_history')->where('del',0)->where('id',$id)->find();
- if(!$info){
- HelpHander::error('参数错误');
- }
- $lists = Db::name('user_history_data')->where('history_id',$id)->select();
- $lists = $lists?$lists:[];
- $users = [];
- foreach ($lists as $k=>$v){
- $arr = json_decode($v['content'],true);
- foreach ($arr as $kk=>$vv){
- $arr[$kk]['jobDateText'] = '';
- if($vv['job'] || $vv['job_date']){
- $arr[$kk]['jobDateText'] = $vv['job'].'/'.$vv['job_date'];
- }
- $arr[$kk]['genderText'] = '';
- if($vv['gender'] == 1){
- $arr[$kk]['genderText'] = '男';
- }else if($vv['gender'] == 2){
- $arr[$kk]['genderText'] = '女';
- }
- }
- $users = array_merge($users,$arr);
- }
- $columns = [
- ["title" => "部门","key" => "dep"],
- ["title" => "行政职务","key" => "position"],
- ["title" => "姓名","key" => "name"],
- ["title" => "岗位及时间","key" => "jobDateText"],
- ["title" => "性别","key" => "genderText"],
- ["title" => "民族","key" => "nation"],
- ["title" => "籍贯","key" => "nativePlace"],
- ["title" => "出生日期","key" => "birthday"],
- ["title" => "身份证号码","key" => "idCard"],
- ["title" => "年龄","key" => "age"],
- ["title" => "学历","key" => "education"],
- ["title" => "专业","key" => "profession"],
- ["title" => "入党时间","key" => "dangDate"],
- ["title" => "工作时间","key" => "workDate"],
- ["title" => "任现职时间","key" => "curJobDate"],
- ["title" => "专业技术职务","key" => "professionPosition"],
- ["title" => "评定时间","key" => "assessDate"],
- ["title" => "职业资格","key" => "qualification"],
- ["title" => "来办时间","key" => "joinTime"],
- ["title" => "进入形式","key" => "inShape"],
- ["title" => "同级职务时间","key" => "levelJobDate"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $users,
- 'title' => $info['title']
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- }
|