Systemtransfer.php 31 KB

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