UserHistory.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use app\Request;
  5. use think\Db;
  6. use think\Exception;
  7. use think\Model;
  8. class UserHistory extends Model
  9. {
  10. public function add($data){
  11. $curTime = date('Y-m-d H:i:s');
  12. $data['create_time'] = $curTime;
  13. $result = validate('UserHistory')->check($data,[],'');
  14. if(true !== $result){
  15. HelpHander::error(validate('UserHistory')->getError());
  16. }
  17. $lists = model('UserInfo')->all($data['org_id'],$data['company_id']);
  18. $data['nums'] = count($lists);
  19. Db::startTrans();
  20. try{
  21. $historyId = Db::name('user_history')->insertGetId($data);
  22. if(!$historyId){
  23. \exception('操作失败');
  24. }
  25. $arr = [];
  26. foreach ($lists as $k=>$v){
  27. $arr[] = $v;
  28. if(count($arr) == 100){
  29. $res = Db::name('user_history_data')->insert(['history_id'=>$historyId,'content'=>json_encode($arr)]);
  30. if(!$res){
  31. \exception('操作失败');
  32. }
  33. }
  34. }
  35. if($arr){
  36. $res = Db::name('user_history_data')->insert(['history_id'=>$historyId,'content'=>json_encode($arr)]);
  37. if(!$res){
  38. \exception('操作失败');
  39. }
  40. }
  41. Db::commit();
  42. }catch (Exception $e){
  43. Db::rollback();
  44. HelpHander::error('操作失败'.$e->getMessage());
  45. }
  46. return true;
  47. }
  48. public function lists($page,$size,$orgId){
  49. $map[] = ['org_id','=',$orgId];
  50. $map[] = ['del','=',0];
  51. $lists = Db::name('user_history')
  52. ->where($map)
  53. ->page($page,$size)
  54. ->order('id desc')
  55. ->select();
  56. $lists = $lists?$lists:[];
  57. foreach ($lists as $k=>$v){
  58. $company = Db::name('company')->where('id',$v['company_id'])->value('title');
  59. $lists[$k]['company'] = $company?$company:'';
  60. }
  61. $total = Db::name('user_history')->where($map)->count();
  62. $data = [
  63. 'total' => $total,
  64. 'list' => $lists
  65. ];
  66. return $data;
  67. }
  68. public function exportLists($id){
  69. $info = Db::name('user_history')->where('del',0)->where('id',$id)->find();
  70. if(!$info){
  71. HelpHander::error('参数错误');
  72. }
  73. $lists = Db::name('user_history_data')->where('history_id',$id)->select();
  74. $lists = $lists?$lists:[];
  75. $users = [];
  76. foreach ($lists as $k=>$v){
  77. $arr = json_decode($v['content'],true);
  78. foreach ($arr as $kk=>$vv){
  79. $arr[$kk]['jobDateText'] = '';
  80. if($vv['job'] || $vv['job_date']){
  81. $arr[$kk]['jobDateText'] = $vv['job'].'/'.$vv['job_date'];
  82. }
  83. $arr[$kk]['genderText'] = '';
  84. if($vv['gender'] == 1){
  85. $arr[$kk]['genderText'] = '男';
  86. }else if($vv['gender'] == 2){
  87. $arr[$kk]['genderText'] = '女';
  88. }
  89. }
  90. $users = array_merge($users,$arr);
  91. }
  92. $columns = [
  93. ["title" => "部门","key" => "dep"],
  94. ["title" => "行政职务","key" => "position"],
  95. ["title" => "姓名","key" => "name"],
  96. ["title" => "岗位及时间","key" => "jobDateText"],
  97. ["title" => "性别","key" => "genderText"],
  98. ["title" => "民族","key" => "nation"],
  99. ["title" => "籍贯","key" => "nativePlace"],
  100. ["title" => "出生日期","key" => "birthday"],
  101. ["title" => "身份证号码","key" => "idCard"],
  102. ["title" => "年龄","key" => "age"],
  103. ["title" => "学历","key" => "education"],
  104. ["title" => "专业","key" => "profession"],
  105. ["title" => "入党时间","key" => "dangDate"],
  106. ["title" => "工作时间","key" => "workDate"],
  107. ["title" => "任现职时间","key" => "curJobDate"],
  108. ["title" => "专业技术职务","key" => "professionPosition"],
  109. ["title" => "评定时间","key" => "assessDate"],
  110. ["title" => "职业资格","key" => "qualification"],
  111. ["title" => "来办时间","key" => "joinTime"],
  112. ["title" => "进入形式","key" => "inShape"],
  113. ["title" => "同级职务时间","key" => "levelJobDate"],
  114. ];
  115. $data = [
  116. 'columns' => $columns,
  117. 'list' => $users,
  118. 'title' => $info['title']
  119. ];
  120. return $data;
  121. }
  122. public function del($id){
  123. $ret = $this->where('id',$id)->setField('del',1);
  124. if(!$ret){
  125. HelpHander::error('删除失败');
  126. }
  127. return true;
  128. }
  129. }