where('max_day','>',0)->field('id,max_day')->select(); $curDate = date('Y-m-d'); $cts = strtotime($curDate.' 00:00:00'); $cte = strtotime($curDate.' 00:00:00')+24*60*60; if($apps){ foreach ($apps as $v){ $st = date('Y-m-d H:i:s',$cts - $v['max_day']*24*60*60); $et = date('Y-m-d H:i:s',$cte - $v['max_day']*24*60*60); $applys = Db::name('apply') ->where('status',1) ->where('approval_id',$v['id']) ->where('create_time','>=',$st) ->where('create_time','<',$et) ->field('id,user_id,nodeid,org_id') ->select(); foreach ($applys as $key=>$val){ model('Apply')->remindAuditCommon($val); } } } } // 获取今年节假日 public function holiday(){ $url = "http://timor.tech/api/holiday/year/".date('Y'); $content = file_get_contents($url); if($content){ $data = json_decode($content,true); if(!empty($data['holiday'])){ $holiday = $data['holiday']; foreach ($holiday as $k=>$v){ $d = [ 'day' => $v['date'], 'holiday' => $v['holiday']?1:0, 'name' => $v['name'], 'target' => isset($v['target'])?$v['target']:'' ]; $day = Db::name('holiday')->where('day',$d['day'])->find(); if(!$day){ Db::name('holiday')->insert($d); } } } } } // 房产合同到期提醒 public function houseContract(){ $curDay = date('Y-m-d'); // 先获取能接受提醒的人 $users = Db::name('house_auth') ->where('type',1) ->where('remind',1) ->field('user_id,ids') ->select(); if(!$users){ exit(); } foreach ($users as $k=>$v){ $users[$k]['ids'] = $v['ids']?explode(',',$v['ids']):[]; } $lists = Db::name('house_contract') ->where('del',0) ->where('status',1) ->where('remind',1) ->where('remind_date',$curDay) ->field('id,sn,org_id') ->select(); if(!$lists){ exit(); } foreach ($lists as $k=>$v){ $levels = Db::name('house_contract_relation') ->alias('hcr') ->join('house h','h.id = hcr.house_id') ->where('hcr.contract_id',$v['id']) ->column('level_id'); $levels = $levels?$levels:[]; foreach ($users as $kk=>$vv){ $arr = array_intersect($levels,$vv['ids']); if($arr){ model('Message')->add(3,$v['id'],9,$vv['user_id'],$v['org_id'],'合同['.$v['sn'].']即将到期,请及时续约'); } } } } // 房产标签到期提醒 public function houseMark(){ $curDay = date('Y-m-d'); // 先获取能接受提醒的人 $users = Db::name('house_auth') ->where('type',1) ->where('remind',1) ->field('user_id,ids') ->select(); if(!$users){ exit(); } foreach ($users as $k=>$v){ $users[$k]['ids'] = $v['ids']?explode(',',$v['ids']):[]; } $lists = Db::name('house_mark') ->alias('hm') ->join('house h','h.id = hm.house_id') ->where('h.del',0) ->where('h.enable',1) ->where('hm.type',1) ->where('hm.end_time',$curDay) ->field('hm.id,h.level_id,hm.content,hm.org_id') ->select(); if(!$lists){ exit(); } foreach ($lists as $k=>$v){ foreach ($users as $kk=>$vv){ if(in_array($v['level_id'],$vv['ids'])){ model('Message')->add(3,$v['id'],10,$vv['user_id'],$v['org_id'],$v['content']); } } } } // 支付单提醒 public function housePay(){ $curDay = date('Y-m-d'); // 先获取能接受提醒的人 $users = Db::name('house_auth') ->where('type',1) ->where('remind',1) ->field('user_id,ids') ->select(); if(!$users){ exit(); } foreach ($users as $k=>$v){ $users[$k]['ids'] = $v['ids']?explode(',',$v['ids']):[]; } $lists = Db::name('house_contract_pay') ->alias('hcp') ->join('house_contract hc','hc.id = hcp.contract_id') ->where('hcp.del',0) ->where('hcp.status',0) ->where('hc.del',0) ->where('hc.status',0) ->where('hcp.remind',1) ->where('hcp.remind_date',$curDay) ->field('hcp.id,hcp.contract_id,hc.org_id') ->select(); if(!$lists){ exit(); } foreach ($lists as $k=>$v){ $levels = Db::name('house_contract_relation') ->alias('hcr') ->join('house h','h.id = hcr.house_id') ->where('hcr.contract_id',$v['id']) ->column('level_id'); $levels = $levels?$levels:[]; foreach ($users as $kk=>$vv){ $arr = array_intersect($levels,$vv['ids']); if($arr){ model('Message')->add(3,$v['contract_id'],9,$vv['user_id'],$v['org_id'],'合同['.$v['sn'].']缴费即将到期,请及时处理'); } } } } // 房产合同到期释放房产 public function houseRelease(){ $curDay = date('Y-m-d'); $lists = Db::name('house_contract') ->where('end_time','<',$curDay) ->where('del',0) ->where('release',1) ->where('is_released',0) ->where('status',1) ->field('id') ->select(); if($lists){ foreach ($lists as $k=>$v){ try{ Db::name('house_contract')->where('id',$v['id'])->update(['is_released'=>1]); $houses = Db::name('house_contract_relation')->where('contract_id',$v['id'])->column('house_id'); if($houses){ $dd = [ 'cur_lessee_id' => 0, 'cur_contract_id' => 0 ]; Db::name('house')->where('id','in',$houses)->update($dd); } Db::commit(); }catch (Exception $e){ trace($e->getMessage()); Db::rollback(); halt($e->getMessage()); } } } } // 发放员工年假 public function annual(){ //年假统一为:工作满1年不满10年:5天; // 满10年不满20年:10天; // 满20年:15天。 $str = date('m-d'); if($str != '01-01'){ // 每年的1月1日执行 exit(); } $year = date('Y'); // 每年的1月1日执行 $users = Db::name('user') ->alias('u') ->join('user_info ui','u.id = ui.user_id') ->where('u.del',0) ->where('u.enable',1) ->where('ui.is_working','in',[1,2]) ->where('ui.work_date','exp','is not null') ->where('ui.work_date','<>','') // ->where('ui.annual_year',2023) ->where('ui.annual_year','<>',$year) ->field('u.id,ui.name,ui.work_date') ->select(); foreach ($users as $k=>$v){ $age = calculate_age($v['work_date']); $day = 0; if($age >= 1 && $age < 10){ $day = 5; }else if($age >= 10 && $age < 20){ $day = 10; }else if($age >= 20){ $day = 15; } $users[$k]['age'] = $age; $users[$k]['day'] = $day; $ret = Db::name('user_info')->where('user_id',$v['id'])->update([ 'annual_year' => $year, 'annual_leave' => $day, 'update_time' => date('Y-m-d H:i:s') ]); if(!$ret){ trace('年假更新失败:'.$v['id']); } } halt($users); } // 每月1号保存用户档案 public function historyUser(){ $company = Db::name('company')->select(); $month = date('Y年m月'); foreach ($company as $k=>$v){ $data = [ 'title' => $month.'-'.$v['title'].'-档案', 'org_id' => $v['org_id'], 'company_id' => $v['id'], 'remark' => '' ]; $ret = model('UserHistory')->add($data); var_dump($ret); } $data = [ 'title' => $month.'-其他-档案', 'org_id' => 4, 'company_id' => 0, 'remark' => '' ]; $ret = model('UserHistory')->add($data); var_dump($ret); } // 下载印花税word文档 public function stampword(){ $ids = input('ids','','trim'); if(!$ids){ exit(); } $templateProcessor = new TemplateProcessor(__DIR__.'/../../../public/word/stamp_tmp.docx'); $arr = []; $ids = explode(',',$ids); foreach ($ids as $k=>$v){ $ret = model('Contract')->info($v); if($ret){ $arr[] = [ 'programSn' => $ret['program_sn'], 'company' => $ret['company'], 'fhUserName' => $ret['fh_user_name'], 'agent' => $ret['agent'], 'name1' => '应税凭证名称', 'title' => $ret['title'], 'name2' => '对方单位名称', 'company2' => $ret['company2'], 'name3' => '签订日期', 'handleDate' => $ret['handle_date'], 'name4' => '适用印花税税目', 'stampTitle' => $ret['stamp']['title'], 'name5' => '计税金额', 'money' => $ret['money'], 'name6' => '适用税率', 'stampBl' => $ret['stamp']['bl'].'‰', 'name7' => '本期应纳税额', 'sdMoney' => $ret['sd_money'], ]; } } // $arr = [ // [ // 'programSn' => 'N0001', // 'company' => '中心', // 'fhUserName' => '张三', // 'agent' => '李四', // 'name1' => '应税凭证名称', // 'title' => '111', // 'name2' => '对方单位名称', // 'company2' => '111', // 'name3' => '签订日期', // 'handleDate' => '111', // 'name4' => '适用印花税税目', // 'stampTitle' => '111', // 'name5' => '计税金额', // 'money' => '111', // 'name6' => '适用税率', // 'stampBl' => '111', // 'name7' => '本期应纳税额', // 'sdMoney' => '111', // ], // [ // 'programSn' => 'N0002', // 'company' => '中心', // 'fhUserName' => '张三', // 'agent' => '李四', // 'name1' => '应税凭证名称', // 'title' => '111', // 'name2' => '对方单位名称', // 'company2' => '111', // 'name3' => '签订日期', // 'handleDate' => '111', // 'name4' => '适用印花税税目', // 'stampTitle' => '111', // 'name5' => '计税金额', // 'money' => '111', // 'name6' => '适用税率', // 'stampBl' => '111', // 'name7' => '本期应纳税额', // 'sdMoney' => '111', // ], // ]; $templateProcessor->cloneBlock('block_name', 0, true, false, $arr); // 将 word 文档保存至 你设置的路径 $file_dir = './word/zs' . time() . ".docx"; $templateProcessor->saveAs($file_dir); $file = fopen ( $file_dir, "rb" );//以只读和二进制模式打开文件 Header ( "Content-type: application/octet-stream" ); //告诉浏览器这是一个文件流格式的文件 Header ( "Accept-Ranges: bytes" ); //请求范围的度量单位 Header ( "Accept-Length: " . filesize ( $file_dir ) ); //Content-Length是指定包含于请求或响应中数据的字节长度 //用来告诉浏览器,文件是可以当做附件被下载,下载后的文件名称为$file_name该变量的值。 Header ( "Content-Disposition: attachment; filename=印花税计算表.docx" ); echo fread ( $file, filesize ( $file_dir ) ); //读取文件内容并直接输出到浏览器 fclose ( $file ); @unlink($file_dir); exit (); } // 提醒即将超时的记录,每天早上8点执行一次 public function importantRecord(){ $curTime = date('Y-m-d H:i:s',time() + 24*60*60); $lists = Db::name('important_record') ->where('status','in',[0,1]) ->where('end_time','<=',$curTime) ->where('end_time','>',date('Y-m-d H:i:s')) ->field('id,user_id,org_id') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ model('Message')->add(3,$v['id'],14,$v['user_id'],$v['org_id'],'您有一项重要事项即将超时,请及时处理.'); } } public function cpay(){ $lists = Db::name('contract_pay') ->alias('cp') ->join('apply a','a.id = cp.apply_id') ->where('cp.dep_user_id',0) ->where('cp.status',1) ->where('a.approval_id',88) ->field('cp.id,cp.apply_id') ->limit(5) ->select(); dump($lists); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ model('ContractPay')->formatContractPay($v['apply_id']); } } public function editIpmcEmail(){ $config = config('app.email'); $str = 'ABCDEFHHIGKLMNOPGRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'; $str1 = msubstr(str_shuffle($str), 0, mt_rand(2,6)); $str2 = msubstr(str_shuffle($str), 0, mt_rand(2,6)); $str3 = msubstr(str_shuffle($str), 0, mt_rand(2,6)); $password = $str1.'&'.$str2.'.'.$str3; $data = [ 'id' => 176, 'password' => $password, 'is_password' => 1, 'uname' => '', 'position' => '', 'tel' => '', 'branch_id' => 0, 'active' => 1, // 启用 'is_imap' => 0, 'limits' => 0, 'limitg' => 0, 'is_convert' => 0, 'login_password' => 0, 'disabled_password' => 1, 'my_spam_mode' => 1, '_key' => $config['key'], '_lang' => 'zh-cn', ]; $url = $config['host'].'User/update'; $ret = $this->http_post($url,$data); } private function http_post($url,$param){ try{ $ret = curl_post($url,$param); $data = json_decode($ret,true); if($data['status'] == 1){ return $data; }else{ \exception($data['msg']); } }catch (\think\Exception $e){ trace($data['msg']); return false; } } // 自动处理待确定订餐变为已确定 public function dinner(){ $vals = Db::name('config')->where('name','dinner_apply_limit')->value('value'); if($vals){ $limitTime = date('Y-m-d').' '.$vals; $curTime = date('Y-m-d H:i'); if($curTime > $limitTime){ Db::name('dinner_orders')->where('del',0)->where('status',1)->update([ 'status'=>2, 'update_time'=>date('Y-m-d H:i:s') ]); } } } // 提醒审核人员确认订单,每分钟运行一次 public function dinnerapply(){ $curTime = date('H:i:s'); $cates = Db::name('dinner_cate') ->where('del',0) ->where('enable',1) ->where('end',$curTime) ->select(); if(!$cates){ exit(); } $company = Db::name('dinner_company') ->where('del',0) ->where('enable',1) ->where('user_id','>',0) ->select(); if(!$company){ exit(); } foreach ($cates as $k=>$v){ foreach ($company as $kk=>$vv){ $orders = Db::name('dinner_order_goods') ->alias('a') ->join('dinner_orders b','b.id = a.order_id') ->where('a.company_id',$vv['id']) ->where('b.cate_id',$v['id']) ->where('b.status',1) ->where('b.del',0) ->field('a.id') ->find(); if($orders){ $context = $v['title'].'售卖已结束,请及时确认订单。'; model('Message')->add(3,0,0,$vv['user_id'],4,$context,1); } } } } // 更新打卡状态 public function attendance(){ $yday = date('Y-m-d',time() - 86400); // 昨天不跨天进行中的状态改为已完成 $map1[] = ['day','=',$yday]; $map1[] = ['next','=',0]; $map1[] = ['status','=',0]; $yyday = date('Y-m-d',time() - 2*86400); // 昨天跨天进行中的状态改为已完成 $map2[] = ['day','=',$yyday]; $map2[] = ['next','=',1]; $map2[] = ['status','=',0]; $lists = Db::name('attendance_user_class') ->whereOr([ $map1, $map2 ]) ->field('id,content') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $dates = json_decode($v['content'],true); foreach ($dates as $kk=>$vv){ $dates[$kk]['sstatus'] = 1; $dates[$kk]['estatus'] = 1; } Db::name('attendance_user_class')->where('id',$v['id'])->update([ 'content' => json_encode($dates), 'status' => 1, 'update_time' => date('Y-m-d H:i:s') ]); } } // 昨日未打卡的日期 public function attendanceReissue(){ $yday = date('Y-m-d',time() - 86400); model('AttendanceUserClass')->attendanceReissueFixed($yday); // 固定班制 model('AttendanceUserClass')->attendanceReissueClass($yday); // 排班制 } }