Fastflow.php 5.92 KB
<?php

namespace app\admin\behavior;
use think\Db;
use think\Request;

class Fastflow
{
    //发起审批前
    public function fastflowBeforeStart(&$params){

    }
    //发起审批后
    public function fastflowAfterStart(&$params){

    }

    //同意前
    public function fastflowBeforeAgree(&$params){

    }
    //同意后
    public function fastflowAfterAgree(&$params){
        // \think\Cache::set('ab',$params);
    }

    //驳回前
    public function fastflowBeforeBack(&$params){

    }
    //驳回后
    public function fastflowAfterBack(&$params){

    }

    //会签前
    public function fastflowBeforeSign(&$params){

    }
    //会签后
    public function fastflowAfterSign(&$params){

    }

    //结束前
    public function fastflowBeforeEnd(&$params){

    }
    //结束后
    public function fastflowAfterEnd(&$params){
        // \think\Cache::set('abbbb',$params);
        
        if($params['bill']=='ats_asiitn'){
            $this->card_late($params);
        }
        if($params['bill']=='ats_hvuxhg'){
            \think\Cache::set('aabb', $params);
		
            $this->leave($params);
        }
	
        $this->endSendNotice($params);
    }
    
    
    //处理结束草送
    public function endSendNotice($params)
    {
    	   //$headers = Request::header();
	   //\think\Cache::set('abbbb',$headers);
    	   
//    	   return;  
        $api = new \fastflow\api();
        $last_thread = $api->getThreadById($params['thread_id']);
        
        $thread = \think\Db::name('fastflow_thread')->where('prethread_id',$params['thread_id'])->where('process_id',$params['process_id'])->find();
        //$fid = \think\Db::name('fastflow_bill')->where('bill_table',$params['bill'])->value('id');
        $fid = \think\Db::name('fastflow_flow')->where('bill',$params['bill'])->value('id');
        $list = $api->getAllNodes($fid);
        // halt();
        $staff_ids = null;
        foreach ($list as $item){
            if($item['id']==$thread['step_id']){
                $staff_ids = $item['data']['workers']??null;
            }
        }
        if(empty($staff_ids))return false;
        $data = [
            'carbon_scope'=>1,
            'carbon_range'=>2,
            'carbon_receiver'=>$staff_ids,
            'bill'=>$params['bill'],
            'bill_id'=>$params['bill_id']
        ];
        $log_ids = [];
        $log_rows = $api->getThreadLog($params['bill'],$params['bill_id']);
        if ($log_rows) {
            foreach ($log_rows as $row) {
                foreach ($row as $item) {
                    $log_ids[] = $item['id'];
                }
            }
        }
        $staff_id = (explode(',',$thread['worker_checked_ids'])[0])??1;
        //进行抄送
        $res = $api->sendDealCarbon($data,$log_ids[0],$staff_id?$staff_id:1);
        
        return true;
    }
    
    //处理补卡
    public function card_late($params)
    {
        $find = Db::table($params['bill'])->where('id',$params['bill_id'])->find();
        if($find){
            //获取到了员工id和补卡时间,更改考勤打卡表和考勤规则表
            $time = date('Y-m-d',strtotime($find['mdnidpcc']));
            $staff_id = $find['initiator_id'];
            //查询
            Db::name('qingdong_attendance_statisc')->where('staff_id',$staff_id)->where('time',$time)->update([
                'clock_in_status'=>5,
            ]);
        }
        
    }
    //处理请假流程
    public function leave($params)
    {

    		
        $find = Db::table($params['bill'])->where('id',$params['bill_id'])->find();
        
        if($find){
            //获取到了员工id和请假时间段
            $staff_id = $find['initiator_id'];
          
            $start = $find['xyoqksln'];
            $end = $find['izlpkveb'];


//                halt($end="0000-00-00 00:00:00");
            if($start=='0000-00-00 00:00:00' || $end=="0000-00-00 00:00:00"){
                return false;
            }

            
          
            
            $time = date('Y-m-d',strtotime($start));
           
            $statisc = Db::name('qingdong_attendance_statisc')->where(['time' => $time, 'staff_id' => $staff_id])->find();
            if(empty($statisc)){
            	return;
            	throw new \think\Exception('暂未参加考勤打卡');
            	
            }
             //halt([$time,$staff_id]); 
            $list = $this->getLeaveDates($start,$end,$statisc['start_time'],$statisc['end_time']);
            \think\Cache::set('abd',$list);

            
            foreach ($list as $ite){
                Db::name('qingdong_attendance_statisc')->where('staff_id',$staff_id)->where('time',$ite)->update([
                    'clock_in_status'=>6,
                ]);
            }
        }
        
    }
    public function getLeaveDates($startDate, $endDate, $workStartTime, $workEndTime) {
        // 将输入的日期和时间转换为时间戳
        $leaveStart = strtotime($startDate);
        $leaveEnd = strtotime($endDate);

        // 获取两个日期之间的所有日期
        $dates = [];
        $currentDate = strtotime(date('Y-m-d', $leaveStart));
        $endDate = strtotime(date('Y-m-d', $leaveEnd));

        while ($currentDate <= $endDate) {
            $dates[] = date('Y-m-d', $currentDate);
            $currentDate = strtotime('+1 day', $currentDate);
        }

        // 判断日期是否在工作时间内
        $leaveDates = [];
        foreach ($dates as $date) {
            $workStart = strtotime("$date $workStartTime");
            $workEnd = strtotime("$date $workEndTime");

            // 如果请假开始时间或结束时间在当天工作时间内,则算作请假
            if (($leaveStart <= $workEnd && $leaveStart >= $workStart) || 
                ($leaveEnd >= $workStart && $leaveEnd <= $workEnd) || 
                ($leaveStart < $workStart && $leaveEnd > $workEnd)) {
                $leaveDates[] = $date;
            }
        }

        return $leaveDates;
    }
}