123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Qrcode extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->load->library('session');
- $this->load->_model('Model_qrcode','qrcode');
- $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();
- }
- else if($arg == 'see')
- {
- $this->_see($arg_array);
- }
- else if($arg == 'automatic')
- {
- $this->_automatic();
- }
- else if($arg == 'closepz')
- {
- $this->_closepz();
- }
- 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->qrcode->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']);
- $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->qrcode->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;
- $this->_Template('qrcode',$this->data);
- }
-
- public function _add()
- {
- 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";
- }
- }
-
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['number']))
- {
- $time = time();
- $bctime = date('Ymd',$time);
- $post['number'] = $this->input->post('number',true);
- $post['time'] = $time;
- $qrcode = $this->qrcode->get_number($post['number']);
- if($qrcode)
- {
- echo json_encode(array('msg'=>'此订单编号已存在!','img'=>$qrcode['img'],'success'=>false));exit;
- }
- $number = $this->fullorder->get_number($post['number']);
- if(!$number)
- {
- $number = $this->fullordersmt->get_number($post['number']);
- if(!$number)
- {
- echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
- }
- }
- $img = $this->input->post('img',true);
- $post['img'] = $this->_img($img,$post['number'],$bctime);
- $post['shop'] = $number['shop'];
- $post['warehouse'] = $number['type'];
- if($this->qrcode->insert($post))
- {
- echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
- }
- }
- //$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
- //$this->data['warehouse'] = $warehouse;
- $this->_Template('qrcode_add',$this->data);
- }
-
- public function _automatic()
- {
- $this->_Template('qrcode_automatic',$this->data);
- }
-
- public function _edit()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['number']))
- {
- $time = time();
- $bctime = date('Ymd',$time);
- $post['number'] = $this->input->post('number',true);
- $post['warehouse'] = $this->input->post('warehouse',true);
- $post['time'] = $time;
- $qrcode = $this->qrcode->get_number($post['number']);
- if(!$qrcode)
- {
- echo json_encode(array('msg'=>'错误,未找到需要修改的订单!','success'=>false));exit;
- }
- else
- {
- $number = $this->fullorder->get_number($post['number']);
- if(!$number)
- {
- $number = $this->fullordersmt->get_number($post['number']);
- if(!$number)
- {
- echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
- }
- }
- $img = $this->input->post('img',true);
- $post['img'] = $this->_img($img,$post['number'],$bctime);
- if($this->qrcode->save(array('img'=>$post['img'],'time'=>time()),$qrcode['id']))
- {
- echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
- }
- else
- {
- echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
- }
- }
- }
- }
-
- public function _see($arg_array)
- {
- $arg_array = $arg_array[0];
- $qrcode = $this->qrcode->read($arg_array);
- $qrcodeimg = explode('|',$qrcode['img']);
- $img = '';
- foreach ($qrcodeimg as $v)
- {
- $lx = explode(".",$v);
- $lx = strtolower(end($lx));
- $img .= "<img src='".$v."'>";
- }
- $shop = $this->shop->read($qrcode['shop']);
- $qrcode['shop'] = $shop['shortname'];
- $qrcode['img'] = $img;
- $this->data['qrcode'] = $qrcode;
- $this->_Template('qrcode_see',$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->qrcode->remove($v);
- }
- echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
- }
- }
-
- public function _img($img,$title,$bctime)
- {
- $img_path = './data/outimg/'.$bctime.'/';
- $file_base64 = $img;
- $file_base64 = preg_replace('/data:*;base64,/i', '', $file_base64);
- $file_base64 = str_replace('[removed]','',$file_base64);
- $file_base64 = base64_decode($file_base64);
- if(!is_dir($img_path))mkdir($img_path,0777); //上传目录不存在则创建
- file_put_contents($img_path.$title.'.png',$file_base64);
- return '/data/outimg/'.$bctime.'/'.$title.'.png';
- }
-
- public function _closepz()
- {
- $post = $this->input->post(NULL, TRUE);
- if(isset($post['closepz']))
- {
- $ch = curl_init();
- $url = 'http://'.$_SERVER['SERVER_NAME'].':2121/?type=publish&to=closepz&content=closepz';
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
- //设置post数据
- $res = curl_exec($ch);
- curl_close($ch);
- if($res == 'ok')
- {
- echo json_encode(array('success'=>true));
- }
- else
- {
- echo json_encode(array('success'=>false));
- }
- }
- }
- }
|