load->library('session');
$this->load->_model('Model_colour','colour');
$this->load->_model('Model_shop','shop');
$this->load->_model('Model_warehouse','warehouse');
$this->load->_model('Model_fullorder','fullorder');
$this->load->_model('Model_fullordertt','fullordertt');
$this->load->_model('Model_fullordersmt','fullordersmt');
}
//定义方法的调用规则 获取URI第二段值
public function _remap($arg,$arg_array)
{
if($arg == 'add')
{
$this->_add();
}
else if($arg == 'edit')
{
$this->_edit($arg_array);
}
else if($arg == 'see')
{
$this->_see($arg_array);
}
else if($arg == 'seeindex')
{
$this->_seeindex();
}
else if($arg == 'seephone')
{
$this->_seephone();
}
else if($arg == 'del')
{
$this->_del();
}
else
{
$this->_index();
}
}
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";
}
$fgshop .= " shop = '0' or";
}
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$number = $this->input->post('number',true);
$shop = $this->input->post('shop',true);
$warehouse = $this->input->post('warehouse',true);
$timetk = $this->input->post('timetk',true);
$timetj = $this->input->post('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "(".rtrim($fgshop,'or').")";
if($number)
{
$where .= " and number like '%$number%'";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
if($warehouse)
{
$where .= " and warehouse = '$warehouse'";
}
if($timetk && $timetj)
{
$where .= " and time > '$timetk' and time < '$timetj'";
}
//数据排序
$order_str = "id desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
$info_list = $this->colour->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
foreach ($info_list as $key=>$value)
{
$info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
if($value['shop'] == '0')
{
$info_list[$key]['shop'] = '常用色';
}
else
{
$shop = $this->shop->read($value['shop']);
$info_list[$key]['shop'] = $shop['shopname'];
}
$warehouse = $this->warehouse->read($value['warehouse']);
$info_list[$key]['warehouse'] = $warehouse['title'];
}
$total = $this->colour->find_count($where);
$pagenum = ceil($total/$perpage);
$over = $total-($start+$perpage);
$rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$fgshop);
echo json_encode($rows);exit;
}
$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
$this->data['wlshop'] = $wlshop;
$this->_Template('colour',$this->data);
}
public function _add()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['number']))
{
$number = $this->input->post('number',true);
$post['number'] = trim($number,' ');
$post['warehouse'] = $this->input->post('warehouse',true);
$img = $this->input->post('img',true);
$post['img'] = rtrim($img,'|');
$post['content'] = $this->input->post('content',true);
$post['time'] = time();
if($this->colour->get_number($post['number']))
{
echo json_encode(array('msg'=>'此订单编号已存在!','success'=>false));exit;
}
if(stripos($post['number'],'#') !== false)
{
$post['shop'] = 0;
}
else
{
$number = $this->fullorder->get_number($post['number']);
if(!$number)
{
$number = $this->fullordersmt->get_number($post['number']);
if(!$number)
{
$number = $this->fullordertt->get_number($post['number']);
if(!$number)
{
echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
}
}
}
}
$post['shop'] = $number['shop'];
if($this->colour->insert($post))
{
echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
}
}
$this->_Template('colour_add',$this->data);
}
public function _edit($arg_array)
{
$user = $this->user->get_api($_SESSION['api']);
$post = $this->input->post(NULL, TRUE);
if(isset($post['id']))
{
$id = $this->input->post('id',true);
$post['warehouse'] = $this->input->post('warehouse',true);
$img = $this->input->post('img',true);
$post['img'] = rtrim($img,'|');
$post['content'] = $this->input->post('content',true);
$post['edittime'] = time();
if($this->colour->save($post,$id))
{
echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
}
else
{
echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
}
}
$arg_array = $arg_array[0];
$colour = $this->colour->read($arg_array);
$colourimg = explode('|',$colour['img']);
$img = '';
foreach ($colourimg as $v)
{
$lx = explode(".",$v);
$lx = strtolower(end($lx));
if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
{
$img .= ''."X";
}
else if($v != '')
{
$url = str_replace(array('http://'.$_SERVER['HTTP_HOST'],'http://erp.hnwmzp.cn','https://erp.hnwmzp.cn','http://1.wepolicy.cn/','https://1.wepolicy.cn/','/img/thumb?src='),'',$v);
$url = explode('&',$url);
$url = $url[0];
$img .= ''."
"."X";
}
else
{
$img = '';
}
}
$this->data['userid'] = $user['userid'];
$colour['img'] = $img;
$this->data['colour'] = $colour;
$this->_Template('colour_edit',$this->data);
}
public function _see($arg_array)
{
$arg_array = $arg_array[0];
$colour = $this->colour->read($arg_array);
$colourimg = explode('|',$colour['img']);
$img = array();$i = 1;
foreach ($colourimg as $v)
{
$lx = explode(".",$v);
$lx = strtolower(end($lx));
/**
if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
{
$img .= '';
}
else if($v != '')
{
$img .= "
";
}
else
{
$img = '';
}
**/
if($lx == "3gp" || $lx == "rmvb" || $lx == "flv" || $lx == "wmv" || $lx == "avi" || $lx == "mkv" || $lx == "wav" || $lx == "mp4")
{
$img[] = array('sp',$v);
}
else if($v != '')
{
$img[] = array('tp',"
");
}
$i++;
}
$colour['img'] = $img;
$this->data['colour'] = $colour;
$this->_Template('colour_see',$this->data);
}
public function _seeindex()
{
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 .= " warehouse = ".$value." or";
}
$fgshop .= " shop = '0' or";
}
$post = $this->input->post(NULL, TRUE);
if(isset($post['page']))
{
$page = $this->input->post('page',true);
$perpage = $this->input->post('perpage',true);
$number = $this->input->post('number',true);
$shop = $this->input->post('shop',true);
$warehouse = $this->input->post('warehouse',true);
$timetk = $this->input->post('timetk',true);
$timetj = $this->input->post('timetj',true);
$timetk = strtotime($timetk);
$timetj = strtotime($timetj);
$where = "(".rtrim($fgshop,'or').")";
if($number)
{
$where .= " and number like '%$number%'";
}
if($shop)
{
$where .= " and shop = '$shop'";
}
if($warehouse)
{
$where .= " and warehouse = '$warehouse'";
}
if($timetk && $timetj)
{
$where .= " and time > '$timetk' and time < '$timetj'";
}
//数据排序
$order_str = "id desc";
if(empty($page))
{
$start = 0;
$perpage = 1;
}
else
{
$start = ($page - 1)*$perpage;
}
$info_list = $this->colour->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
foreach ($info_list as $key=>$value)
{
$info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
if($value['shop'] == '0')
{
$info_list[$key]['shop'] = '常用色';
}
else
{
$shop = $this->shop->read($value['shop']);
$info_list[$key]['shop'] = $shop['shopname'];
}
$warehouse = $this->warehouse->read($value['warehouse']);
$info_list[$key]['warehouse'] = $warehouse['title'];
}
$total = $this->colour->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;
}
$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
$this->data['wlshop'] = $wlshop;
$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
$this->data['warehouse'] = $warehouse;
$this->_Template('colour_seeindex',$this->data);
}
public function _seephone()
{
$this->_Template('colour_seephone',$this->data);
}
//删除
public function _del()
{
$post = $this->input->post(NULL, TRUE);
if(isset($post['s']))
{
$id_arr = $this->input->post('s');
$id_arr = explode(',',$id_arr);
if(!$id_arr)
{
echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
}
//循环删除记录
foreach ($id_arr as $v)
{
$this->colour->remove($v);
}
echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
}
}
}