| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 | <?php defined('BASEPATH') OR exit('No direct script access allowed');/** * 作为检测车间功效的定时任务 */class Apicjgx extends Start_Controller {	public function __construct(){		parent::__construct();        $this->load->_model('Model_systemtransfer','systemtransfer');        $this->load->_model("Model_systemtransfer_cr",'systemtransfer_cr');        $this->load->_model("Model_transfer",'transfer');        $this->load->_model("Model_fullorder","fullorder");        $this->load->_model("Model_fullordersmt","fullordersmt");        $this->load->_model("Model_fullordertt","fullordertt");    }    //定义方法的调用规则 获取URI第二段值    public function _remap($arg,$arg_array)    {		if($arg ==  'cjgx' ){            //执行车间效率检测            $this->_cjgx();        }else{            $this->_index();        }    }    public function  _index(){        echo "程序异常";    }    public function dd($val){        echo "<pre>";        var_dump($val);        die;    }    public function _cjgx(){        $limit_time = time() - 3600*24*30;        $list = $this->systemtransfer->find_all("status < 10 and time >= ".$limit_time);        if(empty($list)){            die(json_encode(array('code'=>0,'msg'=>'没有需要检测的工单'),JSON_UNESCAPED_UNICODE));        }        echo date('Y-m-d H:i:s')."开始执行车间效率检测".PHP_EOL;        foreach ($list as $val){            $this->doSingleData($val);        }        echo date('Y-m-d H:i:s')."执行车间效率检测结束".PHP_EOL;            }    //单独处理每个工单的状态判断    public function doSingleData($info){        $lbrk = array_reverse(explode('|',trim($info['rk'],'|')));       		$lbck = array_reverse(explode('|',trim($info['ck'],'|')));        //如果是11 说明是成品库 说明已经入库完毕了 表示已经完毕         if($lbrk[0] == 11){            $this->checkOver($info['id']);            return;        }        //检测出入库都存在时 是否做过标记  在出库的时候已经同步过了   这里需要判断下        if($lbrk[0] == $lbck[0]){            // if(!in_array($lbrk[0],[11,12,15,16])){            //     $this->checkIsOver($info,$lbrk[0]);            //     return;            // }            $this->checkCirculat($info,$lbrk[0]);            return ;        }        //如果是 成品库 布标打印 发块 滞销款 不做处理  再次判定状态是否是 超时一次 超时两次         if(!in_array($lbrk[0],[11,12,15,16])){            $this->jdgeTimeOut($info,$lbrk[0]);        }           }    //检测一下当前的流转单是够长期没有流转    /**     * $info 主表相关信息     * $transfer  附表相关信息     */    public function checkCirculat($info,$transfer){        $fid = $info['id'];        $list = $this->systemtransfer_cr->find_all("fid = ".$fid,"*",'id desc',0,2);        if(empty($list)){            return;        }        //如果没2条就不执行了  因为        if(count($list) < 2){            return ;        }        //操作车间不一致  就直接返回        if($list[0]['lx'] !=  $list[1]['lx']){            return ;        }        $scan_time = $list[0]['time'];        $do_id = $list[0]['id'];        if(time() - $scan_time < 3600 * 24){            return ;        }elseif(time() - $scan_time < 3600 * 24 * 3){            $this->systemtransfer_cr->save([                'extra_status'=>1            ],$do_id);            return ;        }else{            $this->systemtransfer_cr->save([                'extra_status'=>2            ],$do_id);        }    }    // public function cancelWjf($info){    //     $fid = $info['id'];    //     $list = $this->systemtransfer_cr->find_all("fid = ".$fid,"*",'id desc',0,2);    //     if(empty($list)){    //         return;    //     }    //     //如果没2条就不执行了  因为    //     if(count($list) < 2){    //         return ;    //     }    //     //操作车间一致  就直接返回    //     if($list[0]['lx'] ==  $list[1]['lx']){    //         return ;    //     }    //     if($list[1]['extra_status'] == 1){    //         $this->systemtransfer_cr->save([    //             'extra_status'=>0    //         ],$list[1]['id']);    //     }    // }    //如果检测到最后的入库是    /**     * $id  工单主键id     */    public function checkOver($id){        $this->systemtransfer->save(array('status'=>10),$id);        $this->load->database();        //同步表示 此单已经到成品库 完结了        $this->db->where('fid',$id);        $this->db->update('systemtransfer_cr',array('is_over'=>3));        $this->db->affected_rows();    }    //检测是否已经完结 如果完结 且已经标记 那么不做处理 如果为做标记 那么就坐下处理    /**     * $fid  工单主键id     * $lx  车间id     */    public function checkIsOver($info,$lx){        $fid = $info['id'];        $list = $this->systemtransfer_cr->find_all("fid = ".$fid,"*",'id desc',0,2);        //如果查到的数据小于2 那么就说明此单异常        if(count($list) < 2){            //echo json_encode(array('code'=>0,'msg'=>'程序异常','data'=>['info'=>$info,'list'=>$list]),JSON_UNESCAPED_UNICODE);            return ;        }              //如果查到的数据不等于指定的车间id 说明程序异常了 先不执行        if(($list[0]['lx'] != $lx) || ($list[1]['lx'] != $lx)){            return ;        }               if(($list[0]['is_over'] == 0) || ($list[1]['is_over'] == 0)){                        if($list[1]['orver_flag'] == 2){                $this->systemtransfer_cr->save(['is_over'=>1,'orver_flag'=>2],$list[0]['id']);            }else{                $this->systemtransfer_cr->save(['is_over'=>1],$list[0]['id']);            }            $this->systemtransfer_cr->save(['is_over'=>1],$list[1]['id']);                    }               return ;    }    //判定是否超时    public function jdgeTimeOut($info,$lx){        $list = $this->systemtransfer_cr->find_all("fid = ".$info['id'],"*",'id desc',0,1);        if(empty($list)){            return ;        }        if($list[0]['lx'] != $lx){            return ;        }        //查询流转部分要求        $depart_info  = $this->transfer->find("id = ".$lx);        if(empty($depart_info)){            return ;        }        $now_time = time();        $ru_time =  $list[0]['time'];//扫描时间        // $overtime_one = $depart_info['overtime_one'] * 3600;        // $overtime_two = $depart_info['overtime_two'] * 3600;        //如果时间节点一样 就不再执行了        if($depart_info['overtime_one'] == $depart_info['overtime_two']){            return ;        }        $overtime_one = $depart_info['overtime_one'] * 3600 ;        $overtime_two = $depart_info['overtime_two']  * 3600;        //不选超时        if(($now_time - $ru_time) < $overtime_one){            return ;        }        $limit_time = [            'overtime_one'=> $depart_info['overtime_one'],            'overtime_two'=>$depart_info['overtime_two'],        ];                $remain_time = $now_time - $ru_time;                $num = $this->weektimes($ru_time , $now_time);        if($num > 0 ){            $remain_time = $remain_time - 24 * 3600 * $num;        }        //前处理有时间1 就是超时提醒        // if($lx == 5){        //     //超时一次的        //     if(($now_time - $ru_time) >= $overtime_one ){        //         if($list['0']['orver_flag'] == 0){        //             $this->systemtransfer_cr->save(['orver_flag'=>1,'limit_time_str'=> json_encode($limit_time)],$list['0']['id']);        //         }        //     }        // }else{            //超时一次的            if(( $remain_time) >= $overtime_one && ( $remain_time) < $overtime_two){                if($list['0']['orver_flag'] == 0){                                        $type = $this->checkOrderInfo($info['number']);                    if($type == 1){//订单取消了或者其他原因 在没出库的情况下就完成了                        $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);                    }elseif($type == 10){                        $this->systemtransfer_cr->save(['orver_flag'=>1,'limit_time_str'=> json_encode($limit_time)],$list[0]['id']);                    }                                   }            }            //超时2次的            if(( $remain_time) >= $overtime_two){                if($list[0]['orver_flag'] <= 1){                    //$this->systemtransfer_cr->save(['orver_flag'=>2,'limit_time_str'=> json_encode($limit_time)],$list['0']['id']);                                        $type = $this->checkOrderInfo($info['number']);                    if($type == 1){//订单取消了或者其他原因 在没出库的情况下就完成了                        $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);                    }elseif($type == 10){                        $this->systemtransfer_cr->save(['orver_flag'=>2,'limit_time_str'=> json_encode($limit_time)],$list[0]['id']);                    }else{                    }                }            }        //}           }    //检测是否含有周日    protected function weektimes($start_time,$endstime)    {        //是否有周六周日         $week_array = [7, 1, 2, 3, 4, 5, 6];         $i = 0;         while ($start_time <= $endstime) {             $now_time = date('Y-m-d', $start_time);             // 可根据自己想要的返回格式进行调整             $alltime[$i]['week'] = $week_array[date("w", strtotime($now_time))];             $start_time = strtotime('+1 day', $start_time);             $i++;         }         $list = [];         foreach ($alltime as $key => $value) {         		//周日数组             if ($value['week'] > 6) {                 $list[] = $value['week'];             }         }                          return count($list);    }         //检验订单的状态     protected function checkOrderInfo($number){        $nu = $this->fullorder->get_number($number);        if(!$nu)        {            $nu = $this->fullordersmt->get_number($number);            if(!$nu)            {                $nu = $this->fullordertt->get_number($number);            }        }        //此单已取消!请联系店员核实        if($nu['state'] == '214' || $nu['state'] == '217')        {            return 1;        }        //因为某些原因订单虽然现实是完成 但是实际上是终止了 所以就按照取消计算吧          // if($nu['state'] == '216' || $nu['state'] == '215')        // {        //     return 1;        // }        return 10;    }}
 |