Systemtransfer.php 31 KB

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