| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 | <?php defined('BASEPATH') OR exit('No direct script access allowed');class Wigs extends Start_Controller {    public function __construct(){		parent::__construct();        $this->load->library('session');        $this->load->_model('Model_fullorder','fullorder');		$this->load->_model('Model_fullordertt','fullordertt');		$this->load->_model('Model_fullordersmt','fullordersmt');		$this->load->_model('Model_shop','shop');		$this->load->_model('Model_typeclass','typeclass');		$this->load->_model('Model_express','express');		$this->load->_model('Model_warehouse','warehouse');		$this->load->_model('Model_customer','customer');		$this->load->_model('Model_user','user');		$this->load->_model('Model_headorder','headorder');		$this->load->_model('Model_headorder_item','headorder_item');		$this->load->_model('Model_whlabel','whlabel');		$this->load->_model('Model_employee','employee');		$this->load->library('order_process');		$this->load->library('order_operation');    }    public function _remap($arg,$arg_array)    {		if($arg == 'add')//添加        {             $this->_add();        }		else if($arg == 'edit')//修改        {             $this->_edit($arg_array);        }		else if($arg == 'rows')//获取数据        {             $this->wigslist();		}		else if($arg == 'test')//获取数据        {             $this->test();		}		else if($arg == 'assign')//获取数据        {             $this->assign();		}		else if($arg == 'processAdd')//获取数据        {             $this->processAdd();		}		else if($arg == 'printall')//获取数据        {             $this->printAll();		}		else if($arg == 'print')//获取数据        {             $this->_print();		}		else if($arg == 'ok')//获取数据        {             $this->_ok();		}		else if($arg == 'print_ok')//获取数据        {             $this->print_ok();        }else if($arg=="scan"){			$this->scan();		}		else		{			 $this->_index();		}	}	public function _ok(){     $this->_Template('wigslist_ok',$this->data);		}	public function _print()	{		$post = $this->input->post(NULL, TRUE);		if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";$wid="";$wtype="";		    $usersp = explode('|',trim($user['shop'],'|'));			$userwh = explode('|',trim($user['warehouse'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			foreach ($userwh as $value) 		    {				$wid .= " id = ".$value." or";				$wtype .= " type = ".$value." or";			}		}		if(isset($post['page']))  		{		    $page = $this->input->post('page',true);		    $perpage = $this->input->post('perpage',true);			$timetk = $this->input->post('timetk',true);//订单开始时间			$timetj = $this->input->post('timetj',true);//订单结束时间			$shop = $this->input->post('shop',true);//店铺			$wigs = $this->input->post('wigs',true);//订单状态 9.未打印 1.已打印 2.已分配 3. 已完成			$orderinfo = $this->input->post('orderinfo',true);//订单号			$print = $this->input->post('print',true);			$number = $this->input->post('number',true);//订单编号			$info = $this->input->post('info',true);            $type = $this->input->post('type',true);//仓库			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);			$where = (isset($_SESSION['api']))?"mergeid != '1' and (state = '207' or state = '209') and (".rtrim($fgshop,'or').") and (".rtrim($wtype,'or').")":"id = '0'";			if(empty($wigs)){				$wigs=9;			}			// $wigs=9;			if($wigs == '1')//已打印的订单            {                $where  .= " and printtime > '$timetk' and printtime < '$timetj'";            }			else//未打印			{				$where  .= " and express != 0 and printtype > 0 and printtype < 3 and print = 2 and review > 4 and library = 1";						}			if($shop)            {                $where  .= " and shop = '$shop'";            }			if($wigs)            {                $where  .= " and wigs>0  and wigs != 8   and wigs <= '$wigs'";            }			if($orderinfo)            {                $where  .= " and orderinfo = '$orderinfo'";            }			if($number)            {                $where  .= " and number = '$number'";            }            // if($type)            // {            //     $where  .= " and type = '$type'";			// }			//$where .=" and fpdata like '%Wigs%' ";			$where  .= " and type = 4";            //数据排序			// $order_str = ($print != 3)?"id desc":"printtime desc";			$order_str = "id desc";            if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;            }			$info_list = array();			$info_listsmt = array();			$dlz = 0; $smt = 0;			if($info != 'fullordersmt')			{            //取得信息列表            $info_list = $this->fullorder->find_all($where,'id,shop,orderinfo,number,shipremarks,wigs,wigsprinttime',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_list as $key=>$value) 		    {				$info_list[$key]['id'] = $value['id'].'-fullorder';				$shop = $this->shop->read($value['shop']);				$info_list[$key]['shop'] = $shop['shopname'];				$info_list[$key]['wigsprinttime'] = ($value['wigsprinttime'] != '0')?date('Y-m-d H:i',$value['wigsprinttime']):'无';				$info_list[$key]['orderinfo']='<div class="orderinfo">'.$info_list[$key]['orderinfo'].'</div>'; 				if($value['wigs'] == 9)				{					$info_list[$key]['wigs'] = "未打印";				}				else if($value['wigs'] = 1)				{					$info_list[$key]['wigs'] = "已打印";				}				else if($value['wigs'] = 2)				{					$info_list[$key]['wigs'] = "已分配";				}				else if($value['wigs'] = 3)				{					$info_list[$key]['wigs'] = "已完成";				}            }			    $dlz = $this->fullorder->find_count($where);			}			if($info != 'fullorder')			{			$info_listsmt = $this->fullordersmt->find_all($where,'id,shop,orderinfo,number,shipremarks,wigs,wigsprinttime',$order_str,$start,$perpage);			 //格式化数据            foreach ($info_listsmt as $key=>$value) 		    {				$info_listsmt[$key]['id'] = $value['id'].'-fullordersmt';				$shop = $this->shop->read($value['shop']);				$info_listsmt[$key]['shop'] = $shop['shopname'];				$info_listsmt[$key]['wigsprinttime'] = ($value['wigsprinttime'] != '0')?date('Y-m-d H:i',$value['wigsprinttime']):'无';				$info_listsmt[$key]['orderinfo']='<div class="orderinfo">'.$info_listsmt[$key]['orderinfo'].'</div>'; 				if($value['wigs'] == '9')				{					$info_listsmt[$key]['wigs'] = "未打印";				}				else if($value['wigs'] = 1)				{					$info_listsmt[$key]['wigs'] = "已打印";				}				else if($value['wigs'] = 2)				{					$info_listsmt[$key]['wigs'] = "已分配";				}				else if($value['wigs'] = 3)				{					$info_listsmt[$key]['wigs'] = "已完成";				}            }			    $smt += $this->fullordersmt->find_count($where);			}			//$total += $this->fullorder_smt->find_count($where);			$total = $dlz+$smt;			$rows = array_merge($info_list,$info_listsmt);			//$rows = array_slice($rows,$start,$perpage);		    $pagenum = ceil($total/$perpage);		    $over = $total-($start+$perpage);		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($rows));//array_merge($info_list,$info_list_smt,$info_listsmt)		    echo json_encode($rows);exit;		}		if(isset($_SESSION['api']))		{			$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));			$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'));		    $this->data['wlshop'] = $wlshop;		    $this->data['warehouse'] = $warehouse;		}		$this->_Template('wigsprint',$this->data);	}	public function processAdd(){		$post = $this->input->post(NULL, TRUE);		$ids = $this->input->post('ids',true);		// if();		$success=[];		$fail=[];		foreach($ids as $id){			$process=$this->order_operation->handle('add',$id);			if($process){				$success[]=$id;			}else{				$fail[]=$id;			}		}		//两种方案 1 只打印success 2 打印所有 		if(!empty($success)){			$this->printAll($success);		}		echo json_encode(['status'=>0]);exit;				// echo json_encode(['data'=>[		// 	'success'=>$success,		// 	'fail'=>$fail,		// ]]);exit;			}	//头套带打印列表	public function _index(){					if(isset($_SESSION['api']))		{			$user = $this->user->get_api($_SESSION['api']);			$usp = $user;		    $fgshop = "";$sid = "";		    $usersp = explode('|',trim($user['shop'],'|'));			foreach ($usersp as $value) 		    {				$fgshop .= " shop = ".$value." or";				$sid .= " id = ".$value." or";			}			if($user['vip'] == 1)			{				$vip = 1;			}			else			{				$vip = 0;			}		}		else		{			$vip = 0;		}		$post = $this->input->post(NULL, TRUE);		if(isset($post['page']))		{			$where='1=1';			$page = $this->input->post('page',true);			$perpage = $this->input->post('perpage',true);			$status = $this->input->post('status',true);			$orderinfo = $this->input->post('orderinfo',true);			$number = $this->input->post('number',true);			$timetk = $this->input->post('timetk',true);//订单开始时间			$timetj = $this->input->post('timetj',true);//订单结束时间			$timetk = strtotime($timetk);			$timetj = strtotime($timetj);									if(empty($page))		    {                $start = 0;		    	$perpage = 1;            }		    else		    {                $start = ($page - 1)*$perpage;			}			if($status){				$where.=' and b.status="'.$status.'" ' ;			}			if($orderinfo){				$where.=' and a.orderinfo like "%'.trim($orderinfo).'%" ' ;			}			if($number){				$where.=' and a.orderinfo like "%'.trim($number).'%" ' ;			}			if(!empty($timetk))            {                $where  .= " and a.created_at > '$timetk' and a.created_at < '$timetj'";            }					// $select=" a.id,a.number,a.shipma,a.warehouse,a.whlable,a.number,a.orderinfo,a.shipremarks,a.created_at,b.status_id,b.status,b.state,b.flow_id";			$select="a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks";			$query=$this->db->select($select)			->from('headorder_item as a')			->join('process as b',' a.`id`=b.`order_id`','inner')			// ->join('flow_status as c','b.`status_id`=c.id')			->where($where);			$total=$query->count_all_results();			$select='a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks,e.name as username';			$query=$this->db->select($select)			->from('headorder_item as a')			->join('process as b',' a.`id`=b.`order_id`','inner')			->join('employee as e', 'b.`uid`=e.id','left')			->order_by('a.id','DESC')			// ->join('flow_status as c','b.`status_id`=c.id')			->where($where);			$info_list=$query->limit($perpage,$start)->get()->result_array();			foreach ($info_list as $k=>$v) {				$warehouse = $this->warehouse->read($v['warehouse']);				$warehousetitle = $warehouse['title'];				if($v['warehouse'] != 1){$warehousetitle = "<font style='color:#f64b4b'>".$warehouse['title']."</font>";}				$info_list[$k]['orderinfo']='<div class="orderinfo">'.$info_list[$k]['orderinfo'].'</div>'; 				$info_list[$k]['warehouse'] = $warehousetitle;				$info_list[$k]['status']=$this->headorder_item->getStatus($v['status']);				if(empty($info_list[$k]['username'])){					$info_list[$k]['username']='';				}				$info_list[$k]['action']='';				// $info_list[$k]['action'].="<p class='ckn'><b class='fojzof' data-type='8' data-id='".$v['id']."'>打印</b></p>";				$info_list[$k]['action'].="<p ><b class='assign' data-id='".$v['id']."'>分配订单</b></p>";			}			// $total = $this->headorder_item->find_count($where);			$pagenum = ceil($total/$perpage);			$over = $total-($start+$perpage);			$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));			echo json_encode($rows);exit;					}		$this->_Template('wigslist',$this->data);	}	public function printAll($orderids=''){		//获取所有状态<=1的订单 包含flow		if(!isset($orderids)||empty($orderids)){			$orderids = $this->input->post('orderids',true);		}		$orderinfo = $this->input->post('orderinfo',true);		if(!$orderids and !$orderinfo){			echo json_encode(['status'=>0,'msg'=>'缺少参数']);exit;		}				$where='c.flow_id=1  and b.state="'.Model_Process::STATUS_PROCESSING.'"';		$select="a.id,a.number,a.shipremarks,a.warehouse,a.orderinfo,b.status,a.orderremarks";		$query=$this->db->select($select)				->from('headorder_item as a')				->join('process as b',' a.`id`=b.`order_id`','inner')				->join('flow_status as c','b.`status_id`=c.id')					->where($where);		if($orderids){			$query->where_in('p_order',$orderids);		}		if($orderinfo){			$query->where_in('orderinfo',$orderinfo);		}		$info_list=$query->get()->result_array();		$data=[			'status'=>1,			'data'=>$info_list,		];		echo json_encode($data);exit;	}	//	public function print_ok(){		$flow_id=1;		$post = $this->input->post(NULL, TRUE);		$orderIds=$post['ids'];		// $orderIds=187;		if(!$orderIds){			echo json_encode(['status'=>'false'],true);exit;		}		$query=	$this->db->select('*')			->from('process')			->where_in('order_id',$orderIds)			// ->where('status','waitPrint')			->where('flow_id',$flow_id)			->where('state',Model_Process::STATUS_PROCESSING)			->get();		$process_list=$query->result_array();		foreach($process_list as $k=>$v){			if($v['status']=="waitPrint"){				$order=$this->headorder_item->read($v['order_id']);				$order_process=new Model_Process();				$order_process->read($v['id']);				$order_process->toNextStatus($order);			}					}		echo json_encode(['status'=>'ok'],true);exit;	}	public function scan(){		$number = $this->input->post('number', TRUE);		$flow_id=1;		if(!$number){			echo json_encode(['success'=>false,'msg'=>'缺少参数'],true);exit;		}		$headorder_item=$this->headorder_item->find('number="'.$number.'"');		$info=$this->order_process->process($headorder_item['id']);		if(empty($info)){			echo json_encode(['success'=>false,'msg'=>'扫描数据有误'],true);exit;		}		if($info['status']=='waitScan'){			if($info['state']!=Model_Process::STATUS_PROCESSING){				echo json_encode(['success'=>false,'msg'=>'该订单已被取消,请确认订单状态'],true);exit;			}			$order=$this->headorder_item->read($info['order_id']);			$order_process=new Model_Process();			$order_process->read($info['id']);			$order_process->toNextStatus($order);			echo json_encode(['success'=>true,'msg'=>'扫描成功'],true);exit;		}else{			echo json_encode(['success'=>false,'msg'=>'已扫描'],true);exit;		}			}	public function assign(){		//TODO 判断权限		$post = $this->input->post(NULL, TRUE);		if(!isset($post['employee_id'])||empty($post['employee_id'])){			$employee_list=$this->employee->find_all('sign_at >='.strtotime(date('Y-m-d 00:00:00')));			if(empty($employee_list)){				echo json_encode(array('msg'=>'未打卡,请打卡','success'=>false));exit;			}				echo json_encode(array('data'=>$employee_list,'success'=>true));exit;		}else{			$order_id=$post['order_id'];			$employee_id=$post['employee_id'];			if(!$order_id||!$employee_id){				echo json_encode(['success'=>false,'msg'=>'缺少参数']);exit;			}			$info=$this->employee->read($employee_id);			if(empty($info['sign_at'])||$info['sign_at']<strtotime(date('Y-m-d 00:00:00)'))){					echo json_encode(['success'=>false,'msg'=>'未打卡']);exit;			}			//todo 判断订单状态			$order=$this->headorder_item->read($order_id);			$process=$this->order_process->process($order_id);			if($process['state']!=Model_Process::STATUS_PROCESSING){				echo json_encode(['success'=>false,'msg'=>'订单已经被取消,请确认订单状态']);exit;			}			$res=$this->db->set('uid',$employee_id)->where('order_id',$order_id)->update('process');			if($process['status']!='waitAssign'){				echo json_encode(['success'=>false,'msg'=>'状态异常']);exit;			}			$order_process=new Model_Process();			$order_process->read($process['id']);			if($res){				$order_process->toNextStatus($order);				echo json_encode(['success'=>true,'msg'=>'成功']);exit;			}		}	}}
 |