Qrcode.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Qrcode extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_qrcode','qrcode');
  7. $this->load->_model('Model_shop','shop');
  8. $this->load->_model('Model_warehouse','warehouse');
  9. $this->load->_model('Model_fullorder','fullorder');
  10. $this->load->_model('Model_fullordertt','fullordertt');
  11. $this->load->_model('Model_fullordersmt','fullordersmt');
  12. }
  13. //定义方法的调用规则 获取URI第二段值
  14. public function _remap($arg,$arg_array)
  15. {
  16. if($arg == 'add')
  17. {
  18. $this->_add();
  19. }
  20. else if($arg == 'edit')
  21. {
  22. $this->_edit();
  23. }
  24. else if($arg == 'see')
  25. {
  26. $this->_see($arg_array);
  27. }
  28. else if($arg == 'automatic')
  29. {
  30. $this->_automatic();
  31. }
  32. else if($arg == 'closepz')
  33. {
  34. $this->_closepz();
  35. }
  36. else
  37. {
  38. $this->_index();
  39. }
  40. }
  41. public function _index()
  42. {
  43. if(isset($_SESSION['api']))
  44. {
  45. $user = $this->user->get_api($_SESSION['api']);
  46. $usp = $user;
  47. $fgshop = "";$sid = "";
  48. $usersp = explode('|',trim($user['shop'],'|'));
  49. foreach ($usersp as $value)
  50. {
  51. $fgshop .= " shop = ".$value." or";
  52. $sid .= " id = ".$value." or";
  53. }
  54. $fgshop .= " shop = '0' or";
  55. }
  56. $post = $this->input->post(NULL, TRUE);
  57. if(isset($post['page']))
  58. {
  59. $page = $this->input->post('page',true);
  60. $perpage = $this->input->post('perpage',true);
  61. $number = $this->input->post('number',true);
  62. $shop = $this->input->post('shop',true);
  63. $warehouse = $this->input->post('warehouse',true);
  64. $timetk = $this->input->post('timetk',true);
  65. $timetj = $this->input->post('timetj',true);
  66. $timetk = strtotime($timetk);
  67. $timetj = strtotime($timetj);
  68. $where = "(".rtrim($fgshop,'or').")";
  69. if($number)
  70. {
  71. $where .= " and number like '%$number%'";
  72. }
  73. if($shop)
  74. {
  75. $where .= " and shop = '$shop'";
  76. }
  77. if($warehouse)
  78. {
  79. $where .= " and warehouse = '$warehouse'";
  80. }
  81. if($timetk && $timetj)
  82. {
  83. $where .= " and time > '$timetk' and time < '$timetj'";
  84. }
  85. //数据排序
  86. $order_str = "id desc";
  87. if(empty($page))
  88. {
  89. $start = 0;
  90. $perpage = 1;
  91. }
  92. else
  93. {
  94. $start = ($page - 1)*$perpage;
  95. }
  96. $info_list = $this->qrcode->find_all($where,'id,number,shop,warehouse,time',$order_str,$start,$perpage);
  97. foreach ($info_list as $key=>$value)
  98. {
  99. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  100. $shop = $this->shop->read($value['shop']);
  101. $info_list[$key]['shop'] = $shop['shopname'];
  102. $warehouse = $this->warehouse->read($value['warehouse']);
  103. $info_list[$key]['warehouse'] = $warehouse['title'];
  104. }
  105. $total = $this->qrcode->find_count($where);
  106. $pagenum = ceil($total/$perpage);
  107. $over = $total-($start+$perpage);
  108. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  109. echo json_encode($rows);exit;
  110. }
  111. //$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  112. //$this->data['wlshop'] = $wlshop;
  113. $this->_Template('qrcode',$this->data);
  114. }
  115. public function _add()
  116. {
  117. if(isset($_SESSION['api']))
  118. {
  119. $user = $this->user->get_api($_SESSION['api']);
  120. $usp = $user;
  121. $fgshop = "";$sid = "";$wid="";$wtype="";
  122. $usersp = explode('|',trim($user['shop'],'|'));
  123. $userwh = explode('|',trim($user['warehouse'],'|'));
  124. foreach ($usersp as $value)
  125. {
  126. $fgshop .= " shop = ".$value." or";
  127. $sid .= " id = ".$value." or";
  128. }
  129. foreach ($userwh as $value)
  130. {
  131. $wid .= " id = ".$value." or";
  132. $wtype .= " type = ".$value." or";
  133. }
  134. }
  135. $post = $this->input->post(NULL, TRUE);
  136. if(isset($post['number']))
  137. {
  138. $time = time();
  139. $bctime = date('Ymd',$time);
  140. $post['number'] = $this->input->post('number',true);
  141. $post['time'] = $time;
  142. $qrcode = $this->qrcode->get_number($post['number']);
  143. if($qrcode)
  144. {
  145. echo json_encode(array('msg'=>'此订单编号已存在!','img'=>$qrcode['img'],'success'=>false));exit;
  146. }
  147. $number = $this->fullorder->get_number($post['number']);
  148. if(!$number)
  149. {
  150. $number = $this->fullordersmt->get_number($post['number']);
  151. if(!$number)
  152. {
  153. echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
  154. }
  155. }
  156. $img = $this->input->post('img',true);
  157. $post['img'] = $this->_img($img,$post['number'],$bctime);
  158. $post['shop'] = $number['shop'];
  159. $post['warehouse'] = $number['type'];
  160. if($this->qrcode->insert($post))
  161. {
  162. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  163. }
  164. else
  165. {
  166. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  167. }
  168. }
  169. //$warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  170. //$this->data['warehouse'] = $warehouse;
  171. $this->_Template('qrcode_add',$this->data);
  172. }
  173. public function _automatic()
  174. {
  175. $this->_Template('qrcode_automatic',$this->data);
  176. }
  177. public function _edit()
  178. {
  179. $post = $this->input->post(NULL, TRUE);
  180. if(isset($post['number']))
  181. {
  182. $time = time();
  183. $bctime = date('Ymd',$time);
  184. $post['number'] = $this->input->post('number',true);
  185. $post['warehouse'] = $this->input->post('warehouse',true);
  186. $post['time'] = $time;
  187. $qrcode = $this->qrcode->get_number($post['number']);
  188. if(!$qrcode)
  189. {
  190. echo json_encode(array('msg'=>'错误,未找到需要修改的订单!','success'=>false));exit;
  191. }
  192. else
  193. {
  194. $number = $this->fullorder->get_number($post['number']);
  195. if(!$number)
  196. {
  197. $number = $this->fullordersmt->get_number($post['number']);
  198. if(!$number)
  199. {
  200. echo json_encode(array('msg'=>'订单中未找到此编号!','success'=>false));exit;
  201. }
  202. }
  203. $img = $this->input->post('img',true);
  204. $post['img'] = $this->_img($img,$post['number'],$bctime);
  205. if($this->qrcode->save(array('img'=>$post['img'],'time'=>time()),$qrcode['id']))
  206. {
  207. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  208. }
  209. else
  210. {
  211. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  212. }
  213. }
  214. }
  215. }
  216. public function _see($arg_array)
  217. {
  218. $arg_array = $arg_array[0];
  219. $qrcode = $this->qrcode->read($arg_array);
  220. $qrcodeimg = explode('|',$qrcode['img']);
  221. $img = '';
  222. foreach ($qrcodeimg as $v)
  223. {
  224. $lx = explode(".",$v);
  225. $lx = strtolower(end($lx));
  226. $img .= "<img src='".$v."'>";
  227. }
  228. $shop = $this->shop->read($qrcode['shop']);
  229. $qrcode['shop'] = $shop['shortname'];
  230. $qrcode['img'] = $img;
  231. $this->data['qrcode'] = $qrcode;
  232. $this->_Template('qrcode_see',$this->data);
  233. }
  234. //删除
  235. public function _del()
  236. {
  237. $post = $this->input->post(NULL, TRUE);
  238. if(isset($post['s']))
  239. {
  240. $id_arr = $this->input->post('s');
  241. $id_arr = explode(',',$id_arr);
  242. if(!$id_arr)
  243. {
  244. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  245. }
  246. //循环删除记录
  247. foreach ($id_arr as $v)
  248. {
  249. $this->qrcode->remove($v);
  250. }
  251. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  252. }
  253. }
  254. public function _img($img,$title,$bctime)
  255. {
  256. $img_path = './data/outimg/'.$bctime.'/';
  257. $file_base64 = $img;
  258. $file_base64 = preg_replace('/data:*;base64,/i', '', $file_base64);
  259. $file_base64 = str_replace('[removed]','',$file_base64);
  260. $file_base64 = base64_decode($file_base64);
  261. if(!is_dir($img_path))mkdir($img_path,0777); //上传目录不存在则创建
  262. file_put_contents($img_path.$title.'.png',$file_base64);
  263. return '/data/outimg/'.$bctime.'/'.$title.'.png';
  264. }
  265. public function _closepz()
  266. {
  267. $post = $this->input->post(NULL, TRUE);
  268. if(isset($post['closepz']))
  269. {
  270. $ch = curl_init();
  271. $url = 'http://'.$_SERVER['SERVER_NAME'].':2121/?type=publish&to=closepz&content=closepz';
  272. curl_setopt($ch,CURLOPT_URL,$url);
  273. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  274. curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
  275. curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
  276. //设置post数据
  277. $res = curl_exec($ch);
  278. curl_close($ch);
  279. if($res == 'ok')
  280. {
  281. echo json_encode(array('success'=>true));
  282. }
  283. else
  284. {
  285. echo json_encode(array('success'=>false));
  286. }
  287. }
  288. }
  289. }