Wigprint.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Wigprint extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_fullordersmt','fullordersmt');
  9. $this->load->_model('Model_wigprint','wigprint');
  10. $this->load->_model('Model_typeclass','typeclass');
  11. $this->load->_model('Model_warehouse','warehouse');
  12. $this->load->_model('Model_productprice','productprice');
  13. $this->load->_model('Model_express','express');
  14. $this->load->_model('Model_excel','excel');
  15. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg,$arg_array)
  18. {
  19. if($arg == 'excel')
  20. {
  21. $this->_excel();
  22. }
  23. else if($arg == 'rk')
  24. {
  25. $this->_rk();
  26. }
  27. else if($arg == 'bbprint')
  28. {
  29. $this->_bbprint();
  30. }
  31. else
  32. {
  33. $this->_index();
  34. }
  35. }
  36. //管理
  37. public function _index()
  38. {
  39. if(isset($_SESSION['api']))
  40. {
  41. $power = 0;
  42. $user = $this->user->get_api($_SESSION['api']);
  43. if($user['power'] == 37)//老厂小单
  44. {
  45. $power = $user['power'];
  46. }
  47. }
  48. $post = $this->input->post(NULL, TRUE);
  49. if(isset($post['page']))
  50. {
  51. $page = $this->input->post('page',true);
  52. $perpage = $this->input->post('perpage',true);
  53. $number = $this->input->post('number',true);
  54. $wiglibrary = $this->input->post('wiglibrary',true);
  55. $wigprint = $this->input->post('wigprint',true);
  56. $shipremarks = $this->input->post('shipremarks',true);
  57. $czwarehouse = $this->input->post('czwarehouse',true);
  58. $time = $this->input->post('time',true);
  59. $timetk = $this->input->post('timetk',true);
  60. $timetj = $this->input->post('timetj',true);
  61. $timetk = strtotime($timetk);
  62. $timetj = strtotime($timetj);
  63. $where = "1=1 ";
  64. //数据排序
  65. $order_str = "$time desc";
  66. if(empty($page))
  67. {
  68. $start = 0;
  69. $perpage = 1;
  70. }
  71. else
  72. {
  73. $start = ($page - 1)*$perpage;
  74. }
  75. if($timetk && $timetj)
  76. {
  77. $where .= " and ".$time." > '$timetk' and ".$time." < '$timetj'";
  78. }
  79. if($number)
  80. {
  81. $where .= " and number like '%$number%'";
  82. }
  83. if($wiglibrary)
  84. {
  85. $where .= " and wiglibrary = '$wiglibrary'";
  86. }
  87. if($wigprint)
  88. {
  89. $where .= " and wigprint = '$wigprint'";
  90. }
  91. if($shipremarks)
  92. {
  93. $where .= " and shipremarks like '%$shipremarks%'";
  94. }
  95. if($czwarehouse != '')
  96. {
  97. $where .= " and czwarehouse = '$czwarehouse'";
  98. }
  99. //取得信息列表
  100. $info_list = $this->wigprint->find_all($where,'id,number,printtime,wiglibraryrtime,wigprinttime,shipremarks',$order_str,$start,$perpage);
  101. //格式化数据
  102. foreach ($info_list as $key=>$value)
  103. {
  104. if($value['printtime'] != 0)
  105. {
  106. $info_list[$key]['printtime'] = date('Y-m-d H:i',$value['printtime']);
  107. }
  108. else
  109. {
  110. $info_list[$key]['printtime'] = '无';
  111. }
  112. if($value['wiglibraryrtime'] != 0)
  113. {
  114. $info_list[$key]['wiglibraryrtime'] = date('Y-m-d H:i',$value['wiglibraryrtime']);
  115. }
  116. else
  117. {
  118. $info_list[$key]['wiglibraryrtime'] = '无';
  119. }
  120. if($value['wigprinttime'] != 0)
  121. {
  122. $info_list[$key]['wigprinttime'] = date('Y-m-d H:i',$value['wigprinttime']);
  123. }
  124. else
  125. {
  126. $info_list[$key]['wigprinttime'] = '无';
  127. }
  128. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt','&gt'),$value['shipremarks']);
  129. }
  130. $total = $this->wigprint->find_count($where);
  131. $pagenum = ceil($total/$perpage);
  132. $over = $total-($start+$perpage);
  133. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  134. echo json_encode($rows);exit;
  135. }
  136. $this->data['czwarehouse'] = $power;
  137. $this->_Template('wigprint',$this->data);
  138. }
  139. public function _rk()
  140. {
  141. if(isset($_SESSION['api']))
  142. {
  143. $power = 0;
  144. $user = $this->user->get_api($_SESSION['api']);
  145. if($user['power'] == 37)//老厂小单
  146. {
  147. $power = $user['power'];
  148. }
  149. }
  150. $post = $this->input->post(NULL, TRUE);
  151. if(isset($post['barcode']))
  152. {
  153. $barcode = $this->input->post('barcode',true);
  154. $outtype = 1;
  155. $y = $this->fullorder->find_all("number = '$barcode' and print = '3'");
  156. if(!$y)
  157. {
  158. $y = $this->fullordersmt->find_all("number = '$barcode' and print = '3'");
  159. if(!$y)
  160. {
  161. $y = $this->fullordertt->find_all("number = '$barcode' and print = '3'");
  162. if(!$y)
  163. {
  164. echo json_encode(array('msg'=>'无此数据','success'=>false));exit;
  165. }
  166. }
  167. }
  168. $y = $y[0];
  169. $wy = $this->wigprint->get_number($y['number']);
  170. if($wy)
  171. {
  172. if($this->wigprint->save(array('type'=>$y['type'],'express'=>$y['express'],'waybill'=>$y['waybill'],'printtime'=>$y['printtime'],'wiglibraryrtime'=>time(),'shipremarks'=>$y['shipremarks'],'czwarehouse'=>$power),$wy['id']))
  173. {
  174. echo json_encode(array('msg'=>'已有此编号的数据,信息已更新','success'=>false));exit;
  175. }
  176. else
  177. {
  178. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  179. }
  180. }
  181. if($this->wigprint->insert(array('shop'=>$y['shop'],'type'=>$y['type'],'number'=>$y['number'],'express'=>$y['express'],'waybill'=>$y['waybill'],'printtime'=>$y['printtime'],'wiglibrary'=>1,'wiglibraryrtime'=>time(),'shipremarks'=>$y['shipremarks'],'czwarehouse'=>$power)))
  182. {
  183. echo json_encode(array('success'=>true));exit;
  184. }
  185. else
  186. {
  187. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  188. }
  189. }
  190. }
  191. public function _bbprint_()//一单一单检测是否打印完成版本 先保留 不要删
  192. {
  193. $post = $this->input->post(NULL, TRUE);
  194. if(isset($post['s']))
  195. {
  196. $v = $this->input->post('s');
  197. $va = explode(',',rtrim($v,','));
  198. $n = $this->input->post('n');
  199. $text = array();$text['data'] = array();$time = time();
  200. $data = $this->wigprint->read($va[$n]);
  201. $dd = $this->fullordersmt->get_number($data['number']);
  202. if(!$dd)
  203. {
  204. $dd = $this->fullorder->get_number($data['number']);
  205. }
  206. if(!$dd)
  207. {
  208. $dd = $this->fullordertt->get_number($data['number']);
  209. }
  210. if(!$dd)
  211. {
  212. echo json_encode(array('msg'=>'未找到此订单','success'=>false));exit;
  213. }
  214. else if($dd['type'] == 5)
  215. {
  216. echo json_encode(array('msg'=>'该单已改成美国仓发货,不用再安排生产!','success'=>false));exit;
  217. }
  218. $rows = array('number'=>$data['number'],'shipremarks'=>$data['shipremarks'],'data'=>$v,'n'=>$n-1);
  219. if($this->wigprint->save(array('wigprint'=>2,'wigprinttime'=>$time),$data['id']))
  220. {
  221. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  222. }
  223. else
  224. {
  225. echo json_encode(array('msg'=>'数据写入异常,请重新打印!','success'=>false));exit;
  226. }
  227. }
  228. }
  229. public function _bbprint()//全部发送不检测
  230. {
  231. $fx = '';
  232. if(isset($_SESSION['api']))
  233. {
  234. $power = 0;
  235. $user = $this->user->get_api($_SESSION['api']);
  236. if($user['power'] == 27)//成品库
  237. {
  238. $fx = '***成品库返修***';
  239. }
  240. }
  241. $post = $this->input->post(NULL, TRUE);
  242. if(isset($post['s']))
  243. {
  244. $rows = array();
  245. $s = $this->input->post('s');
  246. $s = explode(',',rtrim($s,','));
  247. $time = time();
  248. /**测试用
  249. foreach ($s as $v)
  250. {
  251. $ck = '';
  252. $data = $this->wigprint->read($v);
  253. if($data['type'] == '16')
  254. {
  255. $warehouse = $this->warehouse->read($data['type']);
  256. $ck = $warehouse['title'].' ';
  257. }
  258. $express = $this->express->read($data['express']);
  259. $shipremarks = str_replace(array('<','>'),array('&lt','&gt'),$data['shipremarks']);
  260. $rows[] = array('number'=>$data['number'],'shipremarks'=>$ck.$shipremarks,'ex'=>$express['servicename'],'time'=>date('Y-m-d H:i:s',$data['printtime']));
  261. }
  262. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  263. **/
  264. $this->db->trans_begin();
  265. foreach ($s as $v)
  266. {
  267. if($this->wigprint->save(array('wigprint'=>2,'wigprinttime'=>$time),$v))
  268. {
  269. $ck = '';
  270. $data = $this->wigprint->read($v);
  271. if($data['type'] == '16')
  272. {
  273. $warehouse = $this->warehouse->read($data['type']);
  274. $ck = $warehouse['title'].' ';
  275. }
  276. $express = $this->express->read($data['express']);
  277. $shipremarks = str_replace(array('<','>'),array('&lt','&gt'),$data['shipremarks']);
  278. $rows[] = array('number'=>$data['number'],'shipremarks'=>$ck.$shipremarks,'ex'=>$express['servicename'],'time'=>date('Y-m-d H:i:s',$data['printtime']),'fx'=>$fx);
  279. }
  280. }
  281. if ($this->db->trans_status() === TRUE)
  282. {
  283. $this->db->trans_commit();
  284. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  285. }
  286. else
  287. {
  288. $this->db->trans_commit();
  289. echo json_encode(array('msg'=>'数据异常,请重试!','success'=>false));exit;
  290. }
  291. }
  292. }
  293. public function _excel()
  294. {
  295. if(isset($_GET['fexcel']))
  296. {
  297. $ex = array();
  298. $express = $this->express->find_all();
  299. foreach ($express as $v)
  300. {
  301. $ex[$v['id']] = $v['servicename'];
  302. }
  303. $number = $this->input->get('number',true);
  304. $wiglibrary = $this->input->get('wiglibrary',true);
  305. $wigprint = $this->input->get('wigprint',true);
  306. $shipremarks = $this->input->get('shipremarks',true);
  307. $czwarehouse = $this->input->get('czwarehouse',true);
  308. $time = $this->input->get('time',true);
  309. $timetk = $this->input->get('timetk',true);
  310. $timetj = $this->input->get('timetj',true);
  311. $timetk = strtotime($timetk);
  312. $timetj = strtotime($timetj);
  313. $where = "1=1";
  314. $order_str = "$time desc";
  315. if($timetk)
  316. {
  317. $where .= " and $time > '$timetk' and $time < '$timetj'";
  318. }
  319. if($number)
  320. {
  321. $where .= " and number like '%$number%'";
  322. }
  323. if($wiglibrary)
  324. {
  325. $where .= " and wiglibrary = '$wiglibrary'";
  326. }
  327. if($wigprint)
  328. {
  329. $where .= " and wigprint = '$wigprint'";
  330. }
  331. if($shipremarks)
  332. {
  333. $where .= " and shipremarks like '%$shipremarks%'";
  334. }
  335. if($czwarehouse != '')
  336. {
  337. $where .= " and czwarehouse = '$czwarehouse'";
  338. }
  339. $info_list = $this->wigprint->find_all($where,'number,express,printtime,wiglibraryrtime,wigprinttime,shipremarks',$order_str);
  340. foreach ($info_list as $key=>$value)
  341. {
  342. $info_list[$key]['express'] = $ex[$value['express']];
  343. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  344. if($value['wiglibraryrtime'] > 0)
  345. {
  346. $info_list[$key]['wiglibraryrtime'] = date('Y-m-d H:i:s',$value['wiglibraryrtime']);
  347. }
  348. else
  349. {
  350. $info_list[$key]['wiglibraryrtime'] = '';
  351. }
  352. if($value['wigprinttime'] > 0)
  353. {
  354. $info_list[$key]['wigprinttime'] = date('Y-m-d H:i:s',$value['wigprinttime']);
  355. }
  356. else
  357. {
  358. $info_list[$key]['wigprinttime'] = '';
  359. }
  360. }
  361. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 头套仓统计';
  362. $titlename = "<table border=1>
  363. <tr>
  364. <td>编号</td>
  365. <td>物流类型</td>
  366. <td>发货单时间</td>
  367. <td>扫码时间</td>
  368. <td>打印时间</td>
  369. <td>仓库品名</td>
  370. </tr>
  371. </table>";
  372. $filename = $title.".xls";
  373. $tail = "\n";
  374. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  375. }
  376. }
  377. }