| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560 | <?phpnamespace app\api\controller;use PhpOffice\PhpWord\TemplateProcessor;use think\Controller;use think\Db;use think\Exception;use tools\Qxsms;class Timer extends Controller{    public function apply(){ // 流程超时提醒        $apps = Db::name('approval')->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); // 排班制    }}
 |