Systemwigsout.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Systemwigsout extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_systemwigsout','systemwigsout');
  7. $this->load->_model('Model_excel','excel');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_warehouse','warehouse');
  10. $this->load->_model('Model_fullorder','fullorder');
  11. $this->load->_model('Model_fullordertt','fullordertt');
  12. $this->load->_model('Model_fullordersmt','fullordersmt');
  13. $this->load->_model('Model_typeclass','typeclass');
  14. $this->load->_model('Model_transfer','transfer');
  15. $this->load->_model('Model_apiyy','apiyy');
  16. $this->load->_model('Model_classid','classid');
  17. }
  18. //定义方法的调用规则 获取URI第二段值
  19. public function _remap($arg,$arg_array)
  20. {
  21. if($arg == 'data')
  22. {
  23. $this->_data();
  24. }
  25. else if($arg == 'out')
  26. {
  27. $this->_out();
  28. }
  29. else if($arg == 'del')
  30. {
  31. $this->_del();
  32. }
  33. else if($arg == 'add')
  34. {
  35. $this->_add();
  36. }
  37. else if($arg == 'excel')
  38. {
  39. $this->_excel();
  40. }
  41. else if($arg == 'barcode')
  42. {
  43. $this->_barcode($arg_array);
  44. }
  45. else if($arg == 'hb')
  46. {
  47. $this->_hb();
  48. }
  49. else if($arg == 'xz')
  50. {
  51. $this->_xz();
  52. }
  53. else
  54. {
  55. $this->_index();
  56. }
  57. }
  58. public function _index()
  59. {
  60. $power = 0;
  61. if(isset($_SESSION['api']))
  62. {
  63. $kx = '';$xz = '';
  64. $user = $this->user->get_api($_SESSION['api']);
  65. $usp = $user;
  66. $fgshop = "";$sid = "";$wid="";$wtype="";
  67. $usersp = explode('|',trim($user['shop'],'|'));
  68. $userwh = explode('|',trim($user['warehouse'],'|'));
  69. $transferdata = explode('|',trim($user['transfer'],'|'));
  70. foreach ($usersp as $value)
  71. {
  72. $fgshop .= " shop = ".$value." or";
  73. $sid .= " id = ".$value." or";
  74. }
  75. foreach ($userwh as $value)
  76. {
  77. $wid .= " id = ".$value." or";
  78. $wtype .= " type = ".$value." or";
  79. }
  80. foreach ($transferdata as $v)
  81. {
  82. $tf = $this->transfer->read($v);
  83. if($v == 11)
  84. {
  85. $xz = '<option value="">查看全部</option>';
  86. }
  87. $kx .= '<option value="'.$v.'">'.$tf['title'].'</option>';
  88. }
  89. $kx .= $xz;
  90. if(stripos($user['userid'],'hr') !== false)//老厂小单
  91. {
  92. $power = 37;
  93. }
  94. }
  95. if(isset($_SESSION['api']))
  96. {
  97. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  98. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  99. $this->data['wlshop'] = $wlshop;
  100. $this->data['warehouse'] = $warehouse;
  101. $this->data['vip'] = $user['vip'];
  102. $this->data['kx'] = $kx;
  103. }
  104. if(stripos($user['userid'],'baozhuang') !== false)
  105. {
  106. $this->data['xz'] = 1;
  107. }
  108. else
  109. {
  110. $this->data['xz'] = 0;
  111. }
  112. $this->data['userid'] = $user['userid'];
  113. $this->data['czwarehouse'] = $power;
  114. $this->_Template('systemwigsout',$this->data);
  115. }
  116. public function _data()
  117. {
  118. $wh = array();
  119. $w = $this->warehouse->find_all('1=1','id,title');
  120. foreach ($w as $v)
  121. {
  122. $wh[$v['id']] = $v['title'];
  123. }
  124. $post = $this->input->post(NULL, TRUE);
  125. if(isset($post['page']))
  126. {
  127. $api = $this->input->post('api',true);
  128. $page = $this->input->post('page',true);
  129. $perpage = $this->input->post('perpage',true);
  130. $number = $this->input->post('number',true);
  131. $type = $this->input->post('type',true);
  132. $color = $this->input->post('color',true);
  133. $cz = $this->input->post('cz',true);
  134. $zjtab = $this->input->post('zjtab',true);
  135. $czwarehouse = $this->input->post('czwarehouse',true);
  136. $timetk = $this->input->post('timetk',true);
  137. $timetj = $this->input->post('timetj',true);
  138. $timetk = strtotime($timetk);
  139. $timetj = strtotime($timetj);
  140. $where = "type != 0";
  141. if(isset($_SESSION['api']))
  142. {
  143. if($type)
  144. {
  145. $where .= " and type = '$type'";
  146. }
  147. else
  148. {
  149. $uw = '';
  150. $u = $this->user->get_api($_SESSION['api']);
  151. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  152. foreach ($u['warehouse'] as $v)
  153. {
  154. $uw .= " type = '$v' or";
  155. }
  156. $uw = rtrim($uw,'or');
  157. $uw = " and (".ltrim($uw,' ').")";
  158. $where .= $uw;
  159. }
  160. }
  161. if(!$cz)
  162. {
  163. $cxctime = "time";
  164. }
  165. else
  166. {
  167. $cxctime = "ctime".$cz;
  168. }
  169. if($timetk)
  170. {
  171. $where .= " and $cxctime > '$timetk' and $cxctime < '$timetj'";
  172. }
  173. if($number)
  174. {
  175. $where .= " and number = '$number'";
  176. }
  177. if($cz)
  178. {
  179. $where .= " and cz like '%|".$cz."|%'";
  180. }
  181. if($zjtab)
  182. {
  183. $where .= " and cz like '%~".$zjtab."-%'";
  184. }
  185. if($color)
  186. {
  187. $where .= " and fpdata like '%-".$color."-%'";
  188. }
  189. if($czwarehouse != '')
  190. {
  191. $where .= " and czwarehouse = '$czwarehouse'";
  192. }
  193. //数据排序
  194. $order_str = "time desc";
  195. if(empty($page))
  196. {
  197. $start = 0;
  198. $perpage = 1;
  199. }
  200. else
  201. {
  202. $start = ($page - 1)*$perpage;
  203. }
  204. $transfer = array();
  205. $t = $this->transfer->find_all("1=1");
  206. foreach ($t as $v)
  207. {
  208. $transfer[$v['id']] = $v['title'];
  209. }
  210. //取得信息列表
  211. $info_list = $this->systemwigsout->find_all($where,'id,type,number,shipremarks,printtime,time,quantity',$order_str,$start,$perpage);
  212. //格式化数据
  213. foreach ($info_list as $key=>$value)
  214. {
  215. $info_list[$key]['type'] = $wh[$value['type']];
  216. $dd = $this->systemwigsout->read($value['id']);
  217. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  218. $cz = explode('|',trim($dd['cz'],'|'));
  219. $cztime = explode('|',trim($dd['cztime'],'|'));
  220. $zw = $transfer;
  221. if($dd['cz'] != '' && count($cz) > 0)
  222. {
  223. $info_list[$key]['time'] = '';
  224. for($i=0;$i<count($cz);$i++)
  225. {
  226. if(isset($cztime[$i]))
  227. {
  228. $info_list[$key]['time'] .= $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]).'<br>';
  229. }
  230. else
  231. {
  232. $info_list[$key]['time'] .= $zw[$cz[$i]].' :'.'未获取到时间<br>';
  233. }
  234. }
  235. }
  236. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  237. }
  238. $total = $this->systemwigsout->find_count($where);
  239. $pagenum = ceil($total/$perpage);
  240. $over = $total-($start+$perpage);
  241. $exdata = 0;
  242. $count = $this->systemwigsout->find_all($where);
  243. foreach ($count as $v)
  244. {
  245. $exdata += $v['quantity'];
  246. }
  247. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'datacount'=>$exdata,'exdata'=>$exdata);
  248. echo json_encode($rows);exit;
  249. }
  250. }
  251. public function _out()
  252. {
  253. $post = $this->input->post(NULL, TRUE);
  254. if(isset($post['number']))
  255. {
  256. $time = time();
  257. $number = $this->input->post('number',true);
  258. $type = $this->input->post('type',true);
  259. $ps = $this->input->post('ps',true);
  260. $cz = $this->input->post('cz',true);
  261. $lx = $this->input->post('lx',true);
  262. $ly = $this->input->post('ly',true);
  263. $czwarehouse = $this->input->post('czwarehouse',true);
  264. $timetk = $this->input->post('timetk',true);
  265. $timetj = $this->input->post('timetj',true);
  266. $timetk = strtotime($timetk);
  267. $timetj = strtotime($timetj);
  268. if(!$number)
  269. {
  270. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  271. }
  272. if(!$cz)
  273. {
  274. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  275. }
  276. if(!$lx)
  277. {
  278. echo json_encode(array('msg'=>'请选择需要操作的类型!','success'=>false));exit;
  279. }
  280. if(!$ly)
  281. {
  282. $ly = 0;
  283. }
  284. $fullorder = 'fullorder';
  285. $nu = $this->fullorder->get_number($number);
  286. if(!$nu)
  287. {
  288. $fullorder = 'fullordersmt';
  289. $nu = $this->fullordersmt->get_number($number);
  290. }
  291. if(!$nu)
  292. {
  293. $fullorder = 'fullordertt';
  294. $nu = $this->fullordertt->get_number($number);
  295. }
  296. if(!$nu)
  297. {
  298. echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
  299. }
  300. if($nu['state'] == '214' || $nu['state'] == '217')
  301. {
  302. echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;
  303. }
  304. $systemwigsout = $this->systemwigsout->get_czwarehouse($number,$czwarehouse);
  305. //$systemwigsout = $this->systemwigsout->get_number($number);
  306. if(!$systemwigsout)
  307. {
  308. if($this->systemwigsout->insert(array('type'=>$nu['type'],'cz'=>'|'.$cz.'|','cztime'=>'|'.$time.'|','number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',$time),'time'=>$time,'fpdata'=>$nu['fpdata'],'ctime'.$cz=>$time,'czwarehouse'=>$czwarehouse)))
  309. {
  310. echo json_encode(array('music'=>'1','success'=>true));exit;
  311. }
  312. else
  313. {
  314. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  315. }
  316. }
  317. $czarray = explode('|',trim($systemwigsout['cz'],'|'));
  318. $cztimearray = explode('|',trim($systemwigsout['cztime'],'|'));
  319. $czarray = array_flip($czarray);
  320. if(stripos($systemwigsout['cz'],'|'.$cz.'|') !== false && $cztimearray[$czarray[$cz]] > $time-1200 && $cz != 11)
  321. {
  322. echo json_encode(array('msg'=>'错误,系统20分钟内已录入过!','success'=>false));exit;
  323. }
  324. $fg = 0;
  325. if($systemwigsout['ctime11'] != 0)
  326. {
  327. $fg = 1;
  328. }
  329. if($this->systemwigsout->save(array('cz'=>$systemwigsout['cz'].$cz.'|','cztime'=>$systemwigsout['cztime'].$time.'|','ctime'.$cz=>$time,'fg'=>$fg,'time'=>$time),$systemwigsout['id']))
  330. {
  331. if($nu['state'] == '216')
  332. {
  333. echo json_encode(array('msg'=>'数据已录入成功!此订单已出库,请终止生产。','success'=>false));exit;
  334. }
  335. else if($nu['type'] == '5')
  336. {
  337. echo json_encode(array('msg'=>'数据已录入成功!该单已改成美国仓发货,请终止生产。','success'=>false));exit;
  338. }
  339. else
  340. {
  341. if($nu['scapi'] == 99 && $nu['scid'] != '' && $nu['scid'] != '|' && $nu['dbapi'] != '99' && $cz == 11)
  342. {
  343. @$rk = $this->apiyy->_rk($nu,$fullorder);
  344. if($rk['c'] == 1)
  345. {
  346. $this->apiyy->insert(array('number'=>$rk['number'],'lx'=>$rk['lc'],'type'=>2,'error'=>$rk['error']));
  347. $this->$fullorder->save(array('dbapi'=>$rk['lc']),$nu['id']);
  348. echo json_encode(array('music'=>'1','cs'=>$rk,'success'=>true));exit;
  349. }
  350. else
  351. {
  352. echo json_encode(array('music'=>'1','cs'=>'0','success'=>true));exit;
  353. $this->$fullorder->save(array('dbapi'=>99),$nu['id']);
  354. }
  355. }
  356. else
  357. {
  358. echo json_encode(array('music'=>'1','cs'=>'2','success'=>true));exit;
  359. }
  360. }
  361. }
  362. else
  363. {
  364. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  365. }
  366. }
  367. }
  368. public function _barcode($arg_array)
  369. {
  370. $dir = 'data/img/'.date('Ymd',time()).'/';
  371. if(!is_dir('./'.$dir))mkdir('./'.$dir,0777);
  372. $imgUrl = $dir.$arg_array.'.png';
  373. // 引用class文件夹对应的类
  374. require_once('./data/barcodegen/class/BCGFontFile.php');
  375. require_once('./data/barcodegen/class/BCGColor.php');
  376. require_once('./data/barcodegen/class/BCGDrawing.php');
  377. // 条形码的编码格式
  378. require_once('./data/barcodegen/class/BCGcode128.barcode.php');
  379. // 加载字体大小
  380. $font = new \BCGFontFile('./data/barcodegen/Arial.ttf', 18);
  381. //设置条形码颜色
  382. $color_black = new \BCGColor(0, 0, 0);
  383. $color_white = new \BCGColor(255, 255, 255);
  384. $drawException = null;
  385. try
  386. {
  387. $code = new \BCGcode128();
  388. $code->setScale(2);
  389. $code->setThickness(30); // 条形码的厚度
  390. $code->setForegroundColor($color_black); // 条形码颜色
  391. $code->setBackgroundColor($color_white); // 条形码间隙颜色
  392. $code->setFont($font); //设置引用字体 条形码下方的文字
  393. $code->parse($arg_array); // 条形码需要的数据内容
  394. }
  395. catch(\Exception $exception)
  396. {
  397. $drawException = $exception;
  398. }
  399. $drawing = new \BCGDrawing($imgUrl, $color_white);
  400. if($drawException)
  401. {
  402. $drawing->drawException($drawException);
  403. }
  404. else
  405. {
  406. $drawing->setBarcode($code);
  407. $drawing->draw();
  408. }
  409. // Header that says it is an image (remove it if you save the barcode to a file)
  410. //header('Content-Type: image/png');
  411. //header('Content-Disposition: inline; filename="barcode.png"');
  412. // Draw (or save) the image into PNG format.
  413. $drawing->finish(\BCGDrawing::IMG_FORMAT_PNG);
  414. return 'http://'.$_SERVER['HTTP_HOST'].'/data/img/'.date('Ymd',time()).'/'.$arg_array.'.png';
  415. //return "<img src='".$data."' />";
  416. }
  417. public function _excel()
  418. {
  419. if(isset($_GET['fexcel']))
  420. {
  421. $timetk = $this->input->get('timetk',true);
  422. $timetj = $this->input->get('timetj',true);
  423. $type = $this->input->get('type',true);
  424. $cz = $this->input->get('cz',true);
  425. $number = $this->input->get('number',true);
  426. $timetk = strtotime($timetk.':0:0');
  427. $timetj = strtotime($timetj);
  428. $gctime = "gctime".$cz;
  429. $where = "type != 0 and $gctime like '%-".date('YmdH',$timetk)."'";
  430. if(isset($_SESSION['api']))
  431. {
  432. if($type)
  433. {
  434. $where .= " and type = '$type'";
  435. $warehouse = $this->warehouse->read($type);
  436. $titletype = "---".$warehouse['title'];
  437. }
  438. else
  439. {
  440. $uw = '';
  441. $u = $this->user->get_api($_SESSION['api']);
  442. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  443. foreach ($u['warehouse'] as $v)
  444. {
  445. $uw .= " type = '$v' or";
  446. }
  447. $uw = rtrim($uw,'or');
  448. $uw = " and (".ltrim($uw,' ').")";
  449. $where .= $uw;
  450. $titletype = "";
  451. }
  452. }
  453. else
  454. {
  455. echo json_encode(array('msg'=>'导出失败,请重新登陆!','success'=>false));exit;
  456. }
  457. if($number)
  458. {
  459. $where .= " and number = '$number'";
  460. }
  461. if($cz)
  462. {
  463. $where .= " and cz like '%~".$cz."-%'";
  464. }
  465. $data = array();
  466. $datafy = array();
  467. $j = 0;
  468. $info_list = $this->systemwigsout->find_all($where,'number,shipremarks,printtime,quantity');
  469. foreach ($info_list as $key=>$value)
  470. {
  471. $img = $this->_barcode($value['number']);
  472. $info_list[$key]['number'] = ".<img width='260' src='".$img."' />";
  473. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['shipremarks']);
  474. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  475. }
  476. $title = date('Y-m-d H-i',time()).'扫码统计表'.$titletype;
  477. $titlename = "<table border=1 >
  478. <tr><th colspan='4' align='left'><h3>".$title."<h3></th></tr>
  479. <tr>
  480. <td>编号</td>
  481. <td>仓库品名</td>
  482. <td>打印时间</td>
  483. <td>数量</td>
  484. </tr></table><table><tr></tr>";
  485. $filename = $title.".xls";
  486. $tail = "\n";
  487. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  488. <head>
  489. </head><body>";
  490. $str .= $titlename;
  491. foreach ($info_list as $key=>$value)
  492. {
  493. $str .= "<tr style=' border-bottom:1 double #000;'>";
  494. foreach ($value as $ke=>$va)
  495. {
  496. $tj = '';
  497. if($ke == 'number')
  498. {
  499. $str .= "<td style='padding-left:400px;'>".$va."</td>";//使用文本格式
  500. }
  501. else
  502. {
  503. $str .= "<td>".$va."</td>";//使用文本格式
  504. }
  505. }
  506. $str .= "</tr><tr></tr><tr></tr>\n";
  507. }
  508. $str .= $tail;
  509. $str .= "</table></body></html>";
  510. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  511. header( "Content-type: application/octet-stream" );
  512. header( "Content-Disposition: attachment; filename=".$filename );
  513. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  514. header( "Pragma: no-cache" );
  515. header( "Expires: 0" );
  516. exit($str);
  517. //echo "<pre>";
  518. //print_r($info_list);
  519. }
  520. }
  521. public function _xz()
  522. {
  523. if(isset($_GET['fexcel']))
  524. {
  525. if(isset($_SESSION['api']))
  526. {
  527. $user = $this->user->get_api($_SESSION['api']);
  528. $wid="";
  529. $userwh = explode('|',trim($user['warehouse'],'|'));
  530. foreach ($userwh as $value)
  531. {
  532. $wid .= " type = ".$value." or";
  533. }
  534. }
  535. $tc = $this->typeclass->find_all();
  536. $typeclass = array();
  537. foreach ($tc as $v)
  538. {
  539. $tcjm[$v['id']] = array($v['jm'],$v['classid']);
  540. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  541. }
  542. $timetk = $this->input->get('timetk',true);
  543. $timetj = $this->input->get('timetj',true);
  544. $cz = $this->input->get('cz',true);
  545. if(!$cz)
  546. {
  547. $cz = 1;
  548. }
  549. $type = $this->input->get('type',true);
  550. $czwarehouse = $this->input->get('czwarehouse',true);
  551. $timetk = strtotime($timetk);
  552. $timetj = strtotime($timetj);
  553. $where = "type != '0'";
  554. $cxctime = "ctime".$cz;
  555. if($timetk)
  556. {
  557. $where .= " and $cxctime > '$timetk' and $cxctime < '$timetj'";
  558. }
  559. if($cz)
  560. {
  561. $where .= " and cz like '%|".$cz."|%'";
  562. }
  563. if($czwarehouse != '')
  564. {
  565. $where .= " and czwarehouse = '$czwarehouse'";
  566. }
  567. $data = array();
  568. $datafy = array();
  569. $j = 0;
  570. $wh = array();
  571. $w = $this->warehouse->find_all('1=1','id,title');
  572. foreach ($w as $v)
  573. {
  574. $wh[$v['id']] = $v['title'];
  575. }
  576. $info_list = $this->systemwigsout->find_all($where.' and ('.rtrim($wid,'or').')','type,number,shipremarks,printtime,fg');
  577. foreach ($info_list as $key=>$value)
  578. {
  579. $info_list[$key]['type'] = $wh[$value['type']];
  580. if($value['fg'] > 0)
  581. {
  582. $info_list[$key]['fg'] = '返工';
  583. }
  584. else
  585. {
  586. $info_list[$key]['fg'] = '';
  587. }
  588. $dd = $this->fullordersmt->get_number($value['number']);
  589. if(!$dd)
  590. {
  591. $dd = $this->fullorder->get_number($value['number']);
  592. }
  593. if(!$dd)
  594. {
  595. $dd = $this->fullordertt->get_number($value['number']);
  596. }
  597. $classid = $this->classid->sku();
  598. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  599. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['shipremarks']);
  600. //$this->systemwigsout->save(array('xz'=>1),$value['id']);
  601. $fpdata = array();$bm = '03';
  602. if(stripos($dd['fpdata'],';') !== false)
  603. {
  604. $fpdata = explode(';',rtrim($dd['fpdata'],';'));
  605. foreach ($fpdata as $ke=>$va)
  606. {
  607. $pm = $classid;
  608. $jm = $classid;
  609. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  610. $title = '';
  611. $va = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  612. $fg = explode('|',$va);
  613. if(stripos($fg[0],',') !== false)
  614. {
  615. $ft = explode(',',$fg[0]);
  616. $features = explode('-',trim($ft[1],'-'));
  617. $features[] = $ft[0];
  618. }
  619. else
  620. {
  621. $features = explode('-',trim($fg[0],'-'));
  622. }
  623. foreach ($features as $v)
  624. {
  625. if(isset($typeclass[$v]))
  626. {
  627. if($typeclass[$v]['bm'] != '')
  628. {
  629. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  630. }
  631. }
  632. if($v != 0)
  633. {
  634. if(isset($typeclass[$v]))
  635. {
  636. if($typeclass[$v]['title'] == '9A')
  637. {
  638. $pm[$typeclass[$v]['classid']] = '9A';
  639. }
  640. else if($typeclass[$v]['title'] == '10A')
  641. {
  642. $pm[$typeclass[$v]['classid']] = '10A';
  643. }
  644. else
  645. {
  646. $clzh = $typeclass[$v]['zh'];
  647. if(stripos($typeclass[$v]['zh'],'|') !== false)
  648. {
  649. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  650. $clzh = $clzh[0];
  651. }
  652. $pm[$typeclass[$v]['classid']] = $clzh;
  653. }
  654. }
  655. if(isset($typeclass[$v]))
  656. {
  657. if($typeclass[$v]['jm'])
  658. {
  659. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  660. }
  661. }
  662. }
  663. }
  664. $jm = array_filter($jm);//去除空值
  665. $jm = implode("-",$jm);
  666. $pm = array_filter($pm);//去除空值
  667. $zh = implode(" ",$pm);
  668. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  669. $dtnr = explode('-',trim($fg[0],'-'));
  670. $dj = '';$md = '';$ys = '';$title = '';
  671. foreach ($dtnr as $v)
  672. {
  673. if(isset($typeclass[$v]))
  674. {
  675. if($typeclass[$v]['classid'] == '15')
  676. {
  677. $title = $typeclass[$v]['title'];
  678. }
  679. else if($typeclass[$v]['classid'] == '8')
  680. {
  681. $ys = $typeclass[$v]['title'];
  682. }
  683. else if($typeclass[$v]['classid'] == '13')
  684. {
  685. $dj = $typeclass[$v]['title'];
  686. }
  687. else if($typeclass[$v]['classid'] == '10')
  688. {
  689. $md = $typeclass[$v]['title'];
  690. }
  691. }
  692. }
  693. $fpdata[$ke] = array($zh,$fg[5],$dj,$ys,$title,$md,$jm,$bm.implode("",$bmpx),$fg[2]);//内容,尺寸,等级,颜色,数量,密度
  694. }
  695. }
  696. $info_list[$key]['fpdata'] = $fpdata;
  697. }
  698. $transfer = $this->transfer->read($cz);
  699. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' '.$transfer['title'].'仓统计表';
  700. $titlename = "<table border=1>
  701. <tr>
  702. <td>仓库</td>
  703. <td>编号</td>
  704. <td>仓库品名</td>
  705. <td>打印时间</td>
  706. <td>状态</td>
  707. <td>
  708. <table border=1>
  709. <tr><td colspan='10' align='center'>订单产品信息</td></tr>
  710. <tr>
  711. <td>产品名称</td>
  712. <td>尺寸</td>
  713. <td>等级</td>
  714. <td>颜色</td>
  715. <td>花型</td>
  716. <td>密度</td>
  717. <td>用友料号</td>
  718. <td>用友编码</td>
  719. <td>数量</td>
  720. <td>总数量</td>
  721. </tr>
  722. </table>
  723. </td>
  724. </tr>
  725. </table>";
  726. $filename = $title.".xls";
  727. $tail = "\n";
  728. $this->excel->get_fz($info_list,$titlename,$filename,$tail);
  729. }
  730. }
  731. public function _add()
  732. {
  733. $post = $this->input->post(NULL, TRUE);
  734. if(isset($post['number']))
  735. {
  736. $where = "gtime = '".date('Ymd',time())."'";
  737. $number = $this->input->post('number',true);
  738. $id = $this->input->post('id',true);
  739. $type = $this->input->post('type',true);
  740. $time = $this->input->post('time',true);
  741. $time = strtotime($time);
  742. if($id)
  743. {
  744. if($type)
  745. {
  746. $where .= " and type = '$type'";
  747. }
  748. else
  749. {
  750. $uw = '';
  751. $u = $this->user->get_api($id);
  752. $u['warehouse'] = explode('|',trim($u['warehouse'],'|'));
  753. foreach ($u['warehouse'] as $v)
  754. {
  755. $uw .= " type = '$v' or";
  756. }
  757. $uw = rtrim($uw,'or');
  758. $uw = " and (".ltrim($uw,' ').")";
  759. $where .= $uw;
  760. }
  761. }
  762. if(!$number)
  763. {
  764. echo json_encode(array('msg'=>'编号不能为空!','success'=>false));exit;
  765. }
  766. if(!$type)
  767. {
  768. echo json_encode(array('msg'=>'请选择需要录入数据的仓库!','success'=>false));exit;
  769. }
  770. $nu = $this->fullorder->get_number($number);
  771. if(!$nu)
  772. {
  773. $nu = $this->fullordersmt->get_number($number);
  774. }
  775. if(!$nu)
  776. {
  777. $nu = $this->fullordertt->get_number($number);
  778. }
  779. if(!$nu)
  780. {
  781. echo json_encode(array('msg'=>'错误!未找到此编号的订单','success'=>false));exit;
  782. }
  783. if($nu['printtime'] == '0')
  784. {
  785. echo json_encode(array('msg'=>'错误,此单没有打印时间!请联系店员核实','success'=>false));exit;
  786. }
  787. $data = 0;
  788. $count = $this->systemwigsout->find_all($where);
  789. foreach ($count as $v)
  790. {
  791. $data += $v['quantity'];
  792. }
  793. $systemwigsout = $this->systemwigsout->get_number($number);
  794. if($systemwigsout)
  795. {
  796. $this->systemwigsout->save(array('quantity'=>$systemwigsout['quantity']+1),$systemwigsout['id']);
  797. echo json_encode(array('title'=>'添加成功','msg'=>$data+1,'music'=>'1','success'=>true));exit;
  798. }
  799. else
  800. {
  801. if($this->systemwigsout->insert(array('type'=>$type,'number'=>$number,'shipremarks'=>$nu['shipremarks'],'printtime'=>$nu['printtime'],'quantity'=>1,'gtime'=>date('YmdH',time()),'time'=>time())))
  802. {
  803. echo json_encode(array('title'=>'添加成功','msg'=>$data+1,'music'=>'1','success'=>true));exit;
  804. }
  805. else
  806. {
  807. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  808. }
  809. }
  810. }
  811. }
  812. public function _del()
  813. {
  814. $post = $this->input->post(NULL, TRUE);
  815. if(isset($_SESSION['api']))
  816. {
  817. $user = $this->user->get_api($_SESSION['api']);
  818. }
  819. if(stripos($user['userid'],'peihuo') !== false)
  820. {
  821. $kx = 1;
  822. }
  823. else if(stripos($user['userid'],'gaozhen') !== false)
  824. {
  825. $kx = 2;
  826. }
  827. else if(stripos($user['userid'],'wancheng') !== false)
  828. {
  829. $kx = 3;
  830. }
  831. else if(stripos($user['userid'],'qvfa') !== false)
  832. {
  833. $kx = 4;
  834. }
  835. else if(stripos($user['userid'],'qianchuli') !== false)
  836. {
  837. $kx = 5;
  838. }
  839. else if(stripos($user['userid'],'houchuli') !== false)
  840. {
  841. $kx = 6;
  842. }
  843. else if(stripos($user['userid'],'faxingshi') !== false)
  844. {
  845. $kx = 7;
  846. }
  847. else if(stripos($user['userid'],'baozhuang') !== false)
  848. {
  849. $kx = 8;
  850. }
  851. else if(stripos($user['userid'],'sheji') !== false)
  852. {
  853. $kx = 9;
  854. }
  855. else if(stripos($user['userid'],'piaokou') !== false)
  856. {
  857. $kx = 10;
  858. }
  859. else if(stripos($user['userid'],'ck') !== false)
  860. {
  861. $kx = 11;
  862. }
  863. if(isset($post['delarr']))
  864. {
  865. $id_arr = $this->input->post('delarr');
  866. $id_arr = explode(',',rtrim($id_arr,','));
  867. if(!$id_arr)
  868. {
  869. echo json_encode(array('msg'=>'未选择需要删除的内容!','success'=>false));exit;
  870. }
  871. if(count($id_arr) > 1)
  872. {
  873. echo json_encode(array('msg'=>'每次只能删除一个!','success'=>false));exit;
  874. }
  875. //循环删除记录
  876. $a=0;
  877. foreach ($id_arr as $v)
  878. {
  879. $systemwigsout = $this->systemwigsout->read($v);
  880. $czarray = explode('|',trim($systemwigsout['cz'],'|'));
  881. $cztimearray = explode('|',trim($systemwigsout['cztime'],'|'));
  882. if(count($czarray) == 1)
  883. {
  884. $this->systemwigsout->remove($v);
  885. continue;
  886. }
  887. foreach ($czarray as $ka=>$va)
  888. {
  889. if($va == $kx)
  890. {
  891. unset($czarray[$ka]);
  892. unset($cztimearray[$ka]);
  893. }
  894. }
  895. $cz = "|".implode("|",$czarray)."|";
  896. $cztime = "|".implode("|",$cztimearray)."|";
  897. $this->systemwigsout->save(array('cz'=>$cz,'cztime'=>$cztime),$v);
  898. }
  899. echo json_encode(array('success'=>true));exit;
  900. }
  901. }
  902. public function _hb()
  903. {
  904. $dataorder = array();
  905. /* 订单加入键值-k */
  906. $fdata = $this->fullorder->find_all('dtime > "'.(time()-50*24*3600).'" and printtime > 0','number,orderinfo,fpdata,shipremarks');
  907. foreach ($fdata as $v)
  908. {
  909. $dataorder[$v['number']] = $v;
  910. }
  911. $sdata = $this->fullordersmt->find_all('dtime > "'.(time()-50*24*3600).'" and printtime > 0','number,orderinfo,fpdata,shipremarks');
  912. foreach ($sdata as $v)
  913. {
  914. $dataorder[$v['number']] = $v;
  915. }
  916. $tdata = $this->fullordertt->find_all('dtime > "'.(time()-50*24*3600).'" and printtime > 0','number,orderinfo,fpdata,shipremarks');
  917. foreach ($sdata as $v)
  918. {
  919. $dataorder[$v['number']] = $v;
  920. }
  921. /* 匹配ID加入 */
  922. $tc = array();$ztc = array();$tclass = array();
  923. $typeclass = $this->typeclass->find_all();
  924. foreach ($typeclass as $v)
  925. {
  926. $ztc[$v['id']] = $v['zh'];
  927. $tc[$v['id']] = $v['title'];
  928. $tclass[$v['id']] = $v['classid'];
  929. }
  930. $dir = '/data/excel/'.date('Ymd',time()).'/';
  931. $config['upload_path'] = '.'.$dir ;
  932. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  933. $config['allowed_types'] = 'xls|xlsx|csv';
  934. $config['max_size'] = 10240;
  935. $this->load->library('upload', $config);
  936. $this->upload->initialize($config);
  937. if ($this->upload->do_upload('userfile'))
  938. {
  939. $full_path = $dir.$this->upload->data('file_name');
  940. $fileName = '.' . $full_path;
  941. if (!file_exists($fileName))
  942. {
  943. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  944. }
  945. else
  946. {
  947. require_once "./data/excel/PHPExcel/IOFactory.php";
  948. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  949. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  950. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  951. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  952. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  953. ++$column;//如果列数大于26行
  954. $list = array();
  955. for ($i = 2; $i <= $row; $i++) // 行数循环
  956. {
  957. $data = array();
  958. for ($c = 'A'; $c != $column; $c++) // 列数循环
  959. {
  960. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  961. }
  962. $list[] = $data;
  963. }
  964. }
  965. $ed = array();$i = 0;$j = 0;$dcdata = array();$yc = '';
  966. $cmf_arr = array_column($list, '1');
  967. array_multisort($cmf_arr, SORT_ASC, $list);
  968. foreach ($list as $key=>$value)
  969. {
  970. $number = $value['1'];
  971. $bbtime = $value['7'];
  972. if(stripos($number,'QM') !== false)
  973. {
  974. continue;
  975. }
  976. if(isset($dataorder[$number]))
  977. {
  978. $thisnumber = $dataorder[$number];$thisshipremarks = array();
  979. if(stripos($thisnumber['fpdata'],';') !== false)
  980. {
  981. $fpdata = explode(';',rtrim($thisnumber['fpdata'],';'));
  982. foreach ($fpdata as $ke=>$va)
  983. {
  984. $title = '';
  985. $fg = explode('|',$va);
  986. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  987. $cp = explode('-',rtrim($fg[0],'-'));
  988. if(isset($cp[5]))
  989. {
  990. $tt = $ztc[$cp[5]];
  991. }
  992. else
  993. {
  994. $tt = '';
  995. }
  996. $md = '';
  997. foreach ($cp as $v)
  998. {
  999. if(!isset($tclass[$v]))
  1000. {
  1001. continue;
  1002. }
  1003. if($tclass[$v] == '10')
  1004. {
  1005. $md = $tc[$v];
  1006. }
  1007. }
  1008. if(isset($cp[4]))
  1009. {
  1010. $dchx = $tc[$cp[4]];
  1011. }
  1012. else
  1013. {
  1014. $dchx = ' ';
  1015. }
  1016. $thisshipremarks[] = array($tt,$tc[$cp[3]],$md,$dchx,$fg[5],$fg[2]);//头套种类,颜色,密度,花型,尺寸,数量
  1017. }
  1018. }
  1019. $thisnumber['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$thisnumber['shipremarks']);
  1020. $dcdata[] = array('number'=>$thisnumber['number'],'time'=>$bbtime,'shipremarks'=>$thisnumber['shipremarks'],'fpdata'=>$thisshipremarks);
  1021. }
  1022. else
  1023. {
  1024. $ed[] = array($number.'-系统未找到此订单信息');
  1025. $i++;
  1026. continue;
  1027. }
  1028. }
  1029. if($i > 0)
  1030. {
  1031. $yc = $i.'条异常';
  1032. }
  1033. $title = date('Y-m-d H:i:s',time())." 产品详细信息";
  1034. $titlename = "<table border=1>
  1035. <tr><th colspan='29' align='left'><h3>".$title."<h3></th></tr>
  1036. <tr>
  1037. <td>订单编号</td>
  1038. <td>配货时间</td>
  1039. <td>仓库品名</td>
  1040. <td>
  1041. <table border=1>
  1042. <tr><td colspan='4' align='center'>订单产品信息</td></tr>
  1043. <tr>
  1044. <td>种类</td>
  1045. <td>颜色</td>
  1046. <td>密度</td>
  1047. <td>花型</td>
  1048. <td>尺寸</td>
  1049. <td>数量</td>
  1050. </tr>
  1051. </table>
  1052. </td>
  1053. <td>总条数</td>
  1054. </tr>
  1055. </table>";
  1056. $filename = $title.".xls";
  1057. $tail = "\n";
  1058. $downexcel = $this->get_fz($dcdata,$titlename,$filename,$tail);
  1059. $time = date('Ymd',time());
  1060. $dir = '/data/excel/'.$time.'/';
  1061. $file_name = $title;
  1062. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  1063. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  1064. fwrite($myfile,$downexcel);
  1065. fclose($myfile);
  1066. $goexcel = $dir.$file_name.'.xls';
  1067. echo json_encode(array('msg'=>'操作成功 '.$yc,'goexcel'=>$goexcel,'success'=>true));exit;
  1068. }
  1069. else
  1070. {
  1071. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1072. }
  1073. }
  1074. public function get_fz($info_list,$titlename,$filename,$tail)
  1075. {
  1076. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1077. <head>
  1078. <!--[if gte mso 9]><xml>
  1079. <x:ExcelWorkbook>
  1080. <x:ExcelWorksheets>
  1081. <x:ExcelWorksheet>
  1082. <x:Name>EXCEL</x:Name>
  1083. <x:WorksheetOptions>
  1084. <x:Print>
  1085. <x:ValidPrinterInfo />
  1086. </x:Print>
  1087. </x:WorksheetOptions>
  1088. </x:ExcelWorksheet>
  1089. </x:ExcelWorksheets>
  1090. </x:ExcelWorkbook>
  1091. </xml>
  1092. <![endif]-->
  1093. </head><body>";
  1094. $str .= $titlename;
  1095. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1096. foreach ($info_list as $key=>$value)
  1097. {
  1098. if($value['fpdata'] == '')
  1099. {
  1100. continue;
  1101. }
  1102. $str .= "<tr>";
  1103. foreach ($value as $ke=>$va)
  1104. {
  1105. if($ke == 'orderinfo' || $ke == 'waybill')
  1106. {
  1107. $str .= "<td align='left' style='vnd.ms-excel.numberformat:@'>".$va."</td>";
  1108. }
  1109. else if($ke != 'fpdata' && $ke != 'hl' && $ke != 'currencytitle')
  1110. {
  1111. $str .= "<td align='left'>".$va."</td>";
  1112. }
  1113. }
  1114. $str .= "<td><table border=1>";
  1115. $a = 0;
  1116. foreach ($value['fpdata'] as $k=>$v)
  1117. {
  1118. $vd = '';
  1119. foreach ($v as $vv)
  1120. {
  1121. $vd .= "<td>".$vv."</td>";
  1122. }
  1123. $str .= "<tr>".$vd."</tr>";
  1124. $endv = is_numeric(end($v))?end($v):0;
  1125. $a = $a + $endv;
  1126. }
  1127. $str .= "</table></td>";
  1128. $str .= "<td>".$a."</td>";
  1129. $str .= "</tr>\n";
  1130. }
  1131. $str .= $tail;
  1132. $str .= "</table></body></html>";
  1133. return $str;
  1134. //return $str;
  1135. }
  1136. }