Transfer.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Transfer extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_user','user');
  7. $this->load->_model('Model_transfer','transfer');
  8. $this->load->_model('Model_typeclass','typeclass');
  9. $this->load->_model('Model_warehouse','warehouse');
  10. $this->load->_model('Model_systemtransfer','systemtransfer');
  11. $this->load->_model('Model_excel','excel');
  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_purchase','purchase');
  16. $this->load->_model('Model_classid','classid');
  17. $this->load->_model('Model_express','express');
  18. $this->load->_model('Model_apiyy','apiyy');
  19. $this->load->_model('Model_shop','shop');
  20. }
  21. //定义方法的调用规则 获取URI第二段值
  22. public function _remap($arg,$arg_array)
  23. {
  24. if($arg == 'add')
  25. {
  26. $this->_add();
  27. }
  28. else if($arg == 'edit')
  29. {
  30. $this->_edit($arg_array);
  31. }
  32. else if($arg == 'del')
  33. {
  34. $this->_del();
  35. }
  36. else if($arg == 'print')
  37. {
  38. $this->_print();
  39. }
  40. else if($arg == 'number')
  41. {
  42. $this->_number();
  43. }
  44. else if($arg == 'numberprint')
  45. {
  46. $this->_numberprint();
  47. }
  48. else if($arg == 'operate')
  49. {
  50. $this->_operate();
  51. }
  52. else if($arg == 'out')
  53. {
  54. $this->_out();
  55. }
  56. else if($arg == 'excel')
  57. {
  58. $this->_excel();
  59. }
  60. else if($arg == 'bdbb')
  61. {
  62. $this->_bdbb();
  63. }
  64. else
  65. {
  66. $this->_index();
  67. }
  68. }
  69. //管理
  70. public function _index()
  71. {
  72. $t = array();
  73. $typeclass = $this->typeclass->find_all();
  74. foreach ($typeclass as $v)
  75. {
  76. $t[$v['id']] = $v['title'];
  77. }
  78. $post = $this->input->post(NULL, TRUE);
  79. if(isset($post['page']))
  80. {
  81. $page = $this->input->post('page',true);
  82. $perpage = $this->input->post('perpage',true);
  83. $type = $this->input->post('type',true);
  84. $where = "1=1 ";
  85. //数据排序
  86. $order_str = "id asc";
  87. if($type)
  88. {
  89. $where .= "and type = '$type'";
  90. }
  91. if(empty($page))
  92. {
  93. $start = 0;
  94. $perpage = 1;
  95. }
  96. else
  97. {
  98. $start = ($page - 1)*$perpage;
  99. }
  100. //取得信息列表
  101. $info_list = $this->transfer->find_all($where,'id,title',$order_str,$start,$perpage);
  102. $total = $this->transfer->find_count($where);
  103. $pagenum = ceil($total/$perpage);
  104. $over = $total-($start+$perpage);
  105. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  106. echo json_encode($rows);exit;
  107. }
  108. $this->_Template('transfer',$this->data);
  109. }
  110. //添加
  111. public function _add()
  112. {
  113. $post = $this->input->post(NULL, TRUE);
  114. if(isset($post['title']))
  115. {
  116. $title = $this->input->post('title',true);
  117. if($this->transfer->find_all("title = '$title'"))
  118. {
  119. echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;
  120. }
  121. if($this->transfer->insert($post))
  122. {
  123. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  124. }
  125. else
  126. {
  127. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  128. }
  129. }
  130. $this->_Template('transfer_add',$this->data);
  131. }
  132. //修改
  133. public function _edit($arg_array)
  134. {
  135. $post = $this->input->post(NULL, TRUE);
  136. if(isset($post['id']))
  137. {
  138. $id = $this->input->post('id',true);
  139. $title = $this->input->post('title',true);
  140. if($this->transfer->find_all("title = '$title'"))
  141. {
  142. echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;
  143. }
  144. if($this->transfer->save($post,$id))
  145. {
  146. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  147. }
  148. else
  149. {
  150. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  151. }
  152. }
  153. $arg_array = $arg_array[0];
  154. $transfer = $this->transfer->read($arg_array);
  155. $this->data['transfer'] = $transfer;
  156. $this->_Template('transfer_edit',$this->data);
  157. }
  158. //删除
  159. public function _del()
  160. {
  161. $post = $this->input->post(NULL, TRUE);
  162. if(isset($post['s']))
  163. {
  164. $id_arr = $this->input->post('s');
  165. $id_arr = explode(',',$id_arr);
  166. if(!$id_arr)
  167. {
  168. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  169. }
  170. //循环删除记录
  171. foreach ($id_arr as $v)
  172. {
  173. $this->transfer->remove($v);
  174. }
  175. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  176. }
  177. }
  178. public function _print()
  179. {
  180. if(isset($_SESSION['api']))
  181. {
  182. $user = $this->user->get_api($_SESSION['api']);
  183. $usp = $user;
  184. $sid = "";$wid="";$wtype="";
  185. $userwh = explode('|',trim($user['warehouse'],'|'));
  186. foreach ($userwh as $value)
  187. {
  188. $wid .= " id = ".$value." or";
  189. $wtype .= " type = ".$value." or";
  190. }
  191. }
  192. $post = $this->input->post(NULL, TRUE);
  193. $classid = $this->classid->sku();
  194. $pm = $classid;
  195. $scsku = $classid;
  196. if(isset($post['category']))
  197. {
  198. $list = array();$num = "";$title = "";$features = "";
  199. $order = 0;
  200. $xbqnum = $this->input->post('xbqnum',true);//打印数量
  201. $t = $this->input->post('t',true);//打印数量
  202. if($xbqnum > 99)
  203. {
  204. echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;
  205. }
  206. if($xbqnum < 1)
  207. {
  208. echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;
  209. }
  210. $post['purchase'] = $this->input->post('purchase',true);//所属工厂
  211. $category = $this->input->post('category',true);
  212. $list['category'] = $category;
  213. $list['hairtype'] = $this->input->post('hairtype',true);
  214. $list['grade'] = $this->input->post('grade',true);
  215. $size = $this->input->post('size',true);
  216. $xzsku = $this->input->post('xzsku',true);
  217. $list['size'] = rtrim($size,',');
  218. $list['hairnumber'] = $this->input->post('hairnumber',true);
  219. $list['extension'] = $this->input->post('extension',true);
  220. if($category == 1297)
  221. {
  222. $list['sywignumber'] = $this->input->post('sywignumber',true);
  223. }
  224. if($category == 1702)
  225. {
  226. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  227. $list['syother'] = $this->input->post('syother',true);
  228. }
  229. if($category == 133)
  230. {
  231. $list['fittype'] = $this->input->post('fittype',true);
  232. $list['acother'] = $this->input->post('acother',true);
  233. }
  234. $list['color'] = $this->input->post('color',true);
  235. $list['lowe'] = $this->input->post('lowe',true);
  236. if($category == 127)
  237. {
  238. $list['type'] = $this->input->post('type',true);
  239. $list['headroad'] = $this->input->post('headroad',true);
  240. $list['density'] = $this->input->post('density',true);
  241. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  242. {
  243. $list['lacesize'] = $this->input->post('lacesize',true);
  244. }
  245. $list['lacecolor'] = $this->input->post('lacecolor',true);
  246. $list['lacetypes'] = $this->input->post('lacetypes',true);
  247. }
  248. if($category == 128)
  249. {
  250. $list['lacetype'] = $this->input->post('lacetype',true);
  251. $list['haircap'] = $this->input->post('haircap',true);
  252. $list['density'] = $this->input->post('density',true);
  253. $list['lacecolor'] = $this->input->post('lacecolor',true);
  254. $list['lacetypes'] = $this->input->post('lacetypes',true);
  255. $list['wigother'] = $this->input->post('wigother',true);
  256. }
  257. if($category == 129)
  258. {
  259. $list['wide'] = $this->input->post('wide',true);
  260. }
  261. if($category == 131)
  262. {
  263. $list['gifttype'] = $this->input->post('gifttype',true);
  264. $list['giftother'] = $this->input->post('giftother',true);
  265. }
  266. if($category == 134)
  267. {
  268. $list['pieceweight'] = $this->input->post('pieceweight',true);
  269. }
  270. if($category == 1297)
  271. {
  272. $list['synthetictype'] = $this->input->post('synthetictype',true);
  273. $list['sywigother'] = $this->input->post('sywigother',true);
  274. }
  275. if($category == 130 || $category == 133 || $category == 1702)
  276. {
  277. $list['items'] = $this->input->post('items',true);
  278. }
  279. if($category == 1702)
  280. {
  281. $list['syhairther'] = $this->input->post('syhairther',true);
  282. }
  283. foreach($list as $k=>$v)
  284. {
  285. if($v != 0)
  286. {
  287. $num .=$v;
  288. $features .=$v.'-';
  289. $post[$k] = $v;
  290. $typeclass = $this->typeclass->read($v);
  291. if(isset($pm[$typeclass['classid']]))
  292. {
  293. $pm[$typeclass['classid']] = $typeclass['zh'];
  294. }
  295. $scsku[$typeclass['classid']] = $typeclass['bqsku'];
  296. if($k != 'size')
  297. {
  298. $title .= $typeclass['title']." ";
  299. }
  300. }
  301. }
  302. $typeclass = $this->typeclass->read($list['size']);
  303. $title .= $typeclass['title'];
  304. $time = time();
  305. $post['printtime'] = $time;
  306. $post['title'] = rtrim($title,' ');
  307. $post['number'] = $num;
  308. $post['features'] = '-'.$features;
  309. $featurespp = str_replace(array('-163-','-164-','-165-','-166-'),'-',$features);
  310. $featurespp = explode('-',trim($featurespp,'-'));
  311. if(isset($featurespp[5]))
  312. {
  313. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4].'-'.$featurespp[5];
  314. }
  315. else
  316. {
  317. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4];
  318. }
  319. $post['time'] = $time;//操作时间
  320. $scsku = implode("-",$scsku);
  321. $zh = implode(" ",$pm);
  322. $zh = str_replace('自然色 ','',trim($zh,' '));
  323. $zh = str_replace(array(' ',' ',' ',' ',' ',' ',' '),' ',$zh);
  324. $post['shipremarks'] = $zh;
  325. $scsku = str_replace('- ','-',trim($scsku,'-'));
  326. $scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
  327. $bqsku = (isset($b['title']))?$b['title'].'-'.$scsku:$scsku;
  328. $post['sku'] = $bqsku;
  329. $post['rk'] = "|1|";//默认配货 打印后直接入库
  330. $post['rktime'] = "|".$time."|";
  331. $rows = array();
  332. $this->db->trans_begin();
  333. for($i=0;$i<$xbqnum;$i++)
  334. {
  335. $label = substr($time,1)*100;
  336. $post['label'] = $label+$i;
  337. $rows[] = array('num'=>$post['label'],'number'=>'','shipremarks'=>$zh,'ex'=>'','t'=>$t,'time'=>'布标打印时间:'.date('Y-m-d H:i:s',$time),'s'=>'('.($i+1).'/'.$xbqnum.')');
  338. $this->systemtransfer->insert($post);
  339. }
  340. if ($this->db->trans_status() === TRUE)
  341. {
  342. $this->db->trans_commit();
  343. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  344. }
  345. else
  346. {
  347. $this->db->trans_rollback();
  348. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  349. }
  350. }
  351. $purchase = $this->purchase->find_all("yyid != ''");
  352. $this->data['purchase'] = $purchase;
  353. $this->_Template('transfer_print',$this->data);
  354. }
  355. public function _number()
  356. {
  357. if(isset($_SESSION['api']))
  358. {
  359. $user = $this->user->get_api($_SESSION['api']);
  360. $pid = "";$tid="";$sid="";$wid="";
  361. $purchase = explode('|',trim($user['purchase'],'|'));
  362. $transfer = explode('|',trim($user['transfer'],'|'));
  363. foreach ($purchase as $value)
  364. {
  365. $pid .= " id = ".$value." or";
  366. }
  367. foreach ($transfer as $value)
  368. {
  369. $tid .= " id = ".$value." or";
  370. }
  371. }
  372. else
  373. {
  374. header('Location: /');exit;
  375. }
  376. $post = $this->input->post(NULL, TRUE);
  377. if(isset($post['number']))
  378. {
  379. $number = $this->input->post('number',true);
  380. $type = $this->input->post('type',true);
  381. $xbqnum = $this->input->post('xbqnum',true);//打印数量
  382. $purchase = $this->input->post('purchase',true);
  383. $f = 'fullorder';
  384. $y = $this->fullorder->get_number($number);
  385. if(!$y)
  386. {
  387. $f = 'fullordersmt';
  388. $y = $this->fullordersmt->get_number($number);
  389. if(!$y)
  390. {
  391. $f = 'fullordertt';
  392. $y = $this->fullordertt->get_number($number);
  393. if(!$y)
  394. {
  395. echo json_encode(array('msg'=>'没有找到此订单,请检查是否扫描错误','success'=>false));exit;
  396. }
  397. }
  398. }
  399. if($y['librarytime'] > 0)
  400. {
  401. echo json_encode(array('msg'=>'错误,此订单已出库!','success'=>false));exit;
  402. }
  403. $cp = array();$i = 0;$x=0;$byz = array();$znum = 0;$typeclass = array();
  404. $classid = $this->classid->sku();
  405. $tc = $this->typeclass->find_all();
  406. foreach($tc as $v)
  407. {
  408. $typeclass[$v['id']] = $v;
  409. }
  410. $bm = '03';
  411. $fpdata = explode(';',trim($y['fpdata'],';'));
  412. $whlabelsc = explode('|',trim($y['whlabel'],'|'));
  413. foreach($fpdata as $key=>$val)
  414. {
  415. $pm = $classid;
  416. $jm = $classid;
  417. $sku = $classid;
  418. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  419. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$val);
  420. $jvnr = explode('|',trim($features,'|'));
  421. if(stripos($jvnr[0],',') !== false)
  422. {
  423. $ft = explode(',',$jvnr[0]);
  424. $features = explode('-',trim($ft[1],'-'));
  425. array_splice($features,2,0,$ft[0]);
  426. }
  427. else
  428. {
  429. $features = explode('-',trim($jvnr[0],'-'));
  430. }
  431. $title = $jvnr[1];
  432. foreach($features as $k=>$v)
  433. {
  434. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  435. {
  436. if($typeclass[$v]['bm'] != '')
  437. {
  438. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  439. }
  440. }
  441. if($v != 0)
  442. {
  443. $sku[$typeclass[$v]['classid']] = $typeclass[$v]['bqsku'];
  444. if(isset($pm[$typeclass[$v]['classid']]))
  445. {
  446. if($typeclass[$v]['title'] == '9A')
  447. {
  448. $pm[$typeclass[$v]['classid']] = '9A';
  449. }
  450. else if($typeclass[$v]['title'] == '10A')
  451. {
  452. $pm[$typeclass[$v]['classid']] = '10A';
  453. }
  454. else
  455. {
  456. $clzh = $typeclass[$v]['zh'];
  457. if(stripos($typeclass[$v]['zh'],'|') !== false)
  458. {
  459. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  460. $clzh = $clzh[0];
  461. }
  462. $pm[$typeclass[$v]['classid']] = $clzh;
  463. }
  464. }
  465. if(isset($jm[$typeclass[$v]['classid']]))
  466. {
  467. if($typeclass[$v]['jm'])
  468. {
  469. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  470. }
  471. }
  472. }
  473. }
  474. $jm = array_filter($jm);//去除空值
  475. $jm = implode("-",$jm);
  476. $sku = array_filter($sku);//去除空值
  477. $sku = implode("-",$sku);
  478. $pm = array_filter($pm);//去除空值
  479. $zh = implode(" ",$pm);
  480. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  481. $features = implode("-",$features);
  482. $cp[] = array('ordernumber'=>$number,'title'=>$title,'sku'=>$sku,'jm'=>$jm,'zh'=>$zh,'n'=>$jvnr[2],'b'=>$y['shipremarks'],'data'=>json_encode(array('ordernumber'=>$number,'features'=>$features,'number'=>$number,'title'=>$title,'jm'=>$jm,'sku'=>$sku,'pm'=>$zh,'bm'=>$bm.implode("",$bmpx))));
  483. }
  484. echo json_encode(array('rows'=>$cp,'success'=>true));exit;
  485. }
  486. $purchase = $this->purchase->find_all("yyid != ''");
  487. $this->data['purchase'] = $purchase;
  488. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  489. $this->data['transfer'] = $transfer;
  490. $this->_Template('transfer_number',$this->data);
  491. }
  492. public function _numberprint()
  493. {
  494. $time = time();
  495. $post = $this->input->post(NULL);
  496. $classid = $this->classid->sku();
  497. $pm = $classid;
  498. $scsku = $classid;
  499. if(isset($post['data']))
  500. {
  501. $data = json_decode($post['data'],true);
  502. $f = 'fullorder';
  503. $y = $this->fullorder->get_number($data['ordernumber']);
  504. if(!$y)
  505. {
  506. $f = 'fullordersmt';
  507. $y = $this->fullordersmt->get_number($data['ordernumber']);
  508. if(!$y)
  509. {
  510. $f = 'fullordertt';
  511. $y = $this->fullordertt->get_number($data['ordernumber']);
  512. if(!$y)
  513. {
  514. echo json_encode(array('msg'=>$data['ordernumber'].'没有找到此订单,请检查是否扫描错误'.$data['ordernumber'],'success'=>false));exit;
  515. }
  516. }
  517. }
  518. if($y['printtime'] == 0)
  519. {
  520. echo json_encode(array('msg'=>'此单已重置,请询问梦体','success'=>false));exit;
  521. }
  522. $order = 0;$time = time();
  523. $xbqnum = $this->input->post('n',true);//打印数量
  524. if($xbqnum > 99)
  525. {
  526. echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;
  527. }
  528. if($xbqnum < 1)
  529. {
  530. echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;
  531. }
  532. $transfer = $this->input->post('transfer',true);
  533. $post['type'] = $this->input->post('type',true);
  534. $post['shipremarks'] = $this->input->post('b',true);
  535. $zps = $this->input->post('zps',true);
  536. $post['purchase'] = $this->input->post('purchase',true);//供应商
  537. $post['time'] = $time;//操作时间
  538. $post['jm'] = $data['jm'];
  539. $post['bm'] = $data['bm'];
  540. $post['pm'] = $data['pm'];
  541. $post['features'] = $data['features'];
  542. $post['number'] = $data['number'];
  543. $post['title'] = $data['title'];
  544. $post['sku'] = $data['sku'];
  545. $post['printtime'] = $y['printtime'];
  546. $post['rk'] = "|12|";//默认订单中心 打印后直接入库
  547. $post['rktime'] = "|".$time."|";
  548. $express = $this->express->read($y['express']);
  549. $rows = array();$t='';
  550. $this->db->trans_begin();
  551. $post['xbqnum'] = $xbqnum;
  552. $kh = $this->shop->read($y['shop']);
  553. $yy = $this->apiyy->_peihuo($post,$kh['yyid'],$y['number'],$post['xbqnum']);
  554. if($yy['c'] == 0)
  555. {
  556. $post['scapi'] = '99';
  557. $post['scid'] = $yy['scid'];
  558. if(!$post['purchase'])
  559. {
  560. $post['purchase'] = '';
  561. }
  562. $mqsl = $this->systemtransfer->find_count("number = '".$data['number']."'");
  563. for($i=0;$i<$xbqnum;$i++)
  564. {
  565. if($post['zps'])
  566. {
  567. if($post['zps'] > 0)
  568. {
  569. $t = '订单货物总量:'.($mqsl+$i+1).'/'.$zps;
  570. }
  571. }
  572. $label = substr($time,1)*100;
  573. $post['label'] = $label+$i;
  574. $rows[] = array('num'=>$post['label'],'number'=>$post['number'],'shipremarks'=>$post['shipremarks'],'ex'=>$express['servicename'],'time'=>'发货单打印时间:'.date('Y-m-d H:i:s',$post['printtime']),'gtime'=>date('YmdH',time()),'s'=>'('.($i+1).'/'.$xbqnum.')','t'=>$t);
  575. $this->systemtransfer->insert($post);
  576. }
  577. }
  578. else
  579. {
  580. $this->db->trans_rollback();
  581. echo json_encode(array('msg'=>$yy['error'],'a'=>1,'success'=>false));exit;
  582. }
  583. if($this->db->trans_status() === TRUE)
  584. {
  585. $this->db->trans_commit();
  586. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  587. }
  588. else
  589. {
  590. $this->db->trans_rollback();
  591. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  592. }
  593. }
  594. }
  595. public function _operate()
  596. {
  597. $post = $this->input->post(NULL, TRUE);
  598. if(isset($post['page']))
  599. {
  600. $api = $this->input->post('api',true);
  601. $page = $this->input->post('page',true);
  602. $perpage = $this->input->post('perpage',true);
  603. $number = $this->input->post('number',true);
  604. $color = $this->input->post('color',true);
  605. $purchase = $this->input->post('purchase',true);
  606. $transfer = $this->input->post('transfer',true);
  607. $lx = $this->input->post('lx',true);
  608. $timetk = $this->input->post('timetk',true);
  609. $timetj = $this->input->post('timetj',true);
  610. $timetk = strtotime($timetk);
  611. $timetj = strtotime($timetj);
  612. $where = "1=1";
  613. if($transfer)
  614. {
  615. $ctime = 'ctime'.$transfer;
  616. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  617. }
  618. else
  619. {
  620. $where .= " and time > '$timetk' and time < '$timetj'";
  621. }
  622. if($number)
  623. {
  624. $where .= " and number = '$number'";
  625. }
  626. if($transfer)
  627. {
  628. $where .= " and rk like '%|".$transfer."|%'";
  629. }
  630. if($purchase)
  631. {
  632. $where .= " and purchase = '$purchase'";
  633. }
  634. if($color)
  635. {
  636. $where .= " and fpdata like '%-".$color."-%'";
  637. }
  638. if($lx)
  639. {
  640. if($lx == 1)
  641. {
  642. $where .= " and ordernumber = ''";
  643. }
  644. else
  645. {
  646. $where .= " and ordernumber != ''";
  647. }
  648. }
  649. //数据排序
  650. $order_str = "id desc";
  651. if(empty($page))
  652. {
  653. $start = 0;
  654. $perpage = 1;
  655. }
  656. else
  657. {
  658. $start = ($page - 1)*$perpage;
  659. }
  660. //取得信息列表
  661. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  662. $transfer = $this->transfer->find_all();
  663. $t = array();
  664. foreach ($transfer as $v)
  665. {
  666. $t[$v['id']] = $v['title'];
  667. }
  668. //格式化数据
  669. foreach ($info_list as $key=>$value)
  670. {
  671. $dd = $this->systemtransfer->read($value['id']);
  672. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  673. $rk = explode('|',trim($dd['rk'],'|'));
  674. $rktime = explode('|',trim($dd['rktime'],'|'));
  675. $ck = explode('|',trim($dd['ck'],'|'));
  676. $cktime = explode('|',trim($dd['cktime'],'|'));
  677. $info_list[$key]['time'] = '';
  678. for($i=0;$i<count($rk);$i++)
  679. {
  680. $info_list[$key]['time'] .= $t[$rk[$i]].'入库 :'.date('Y-m-d H:i',$rktime[$i]).'<br>';
  681. if(isset($ck[$i]) && $ck[$i] != '')
  682. {
  683. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  684. }
  685. }
  686. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  687. }
  688. $total = $this->systemtransfer->find_count($where);
  689. $pagenum = ceil($total/$perpage);
  690. $over = $total-($start+$perpage);
  691. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  692. echo json_encode($rows);exit;
  693. }
  694. if(isset($_SESSION['api']))
  695. {
  696. $user = $this->user->get_api($_SESSION['api']);
  697. $usp = $user;
  698. $pid = "";$tid="";$sid="";$wid="";
  699. $purchase = explode('|',trim($user['purchase'],'|'));
  700. $transfer = explode('|',trim($user['transfer'],'|'));
  701. $warehouse = explode('|',trim($user['warehouse'],'|'));
  702. foreach ($purchase as $value)
  703. {
  704. $pid .= " id = ".$value." or";
  705. }
  706. foreach ($transfer as $value)
  707. {
  708. $tid .= " id = ".$value." or";
  709. }
  710. foreach ($warehouse as $value)
  711. {
  712. $wid .= " id = ".$value." or";
  713. }
  714. }
  715. else
  716. {
  717. header('Location: /');exit;
  718. }
  719. $kx = '';$zjtab = '';
  720. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  721. $this->data['warehouse'] = $warehouse;
  722. $purchase = $this->purchase->find_all("yyid != ''");
  723. $this->data['purchase'] = $purchase;
  724. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  725. $this->data['transfer'] = $transfer;
  726. $this->data['vip'] = $user['vip'];
  727. $this->_Template('transfer_operate',$this->data);
  728. }
  729. public function _out()
  730. {
  731. $post = $this->input->post(NULL, TRUE);
  732. if(isset($post['label']))
  733. {
  734. $time = time();
  735. $label = $this->input->post('label',true);
  736. $cz = $this->input->post('cz',true);
  737. $transfer = $this->input->post('transfer',true);
  738. if(!$label)
  739. {
  740. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  741. }
  742. if(!$transfer)
  743. {
  744. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  745. }
  746. $lb = $this->systemtransfer->get_label($label);
  747. if(!$lb)
  748. {
  749. echo json_encode(array('msg'=>'错误!未找到此条码','success'=>false));exit;
  750. }
  751. if($lb['number']!='')
  752. {
  753. $nu = $this->fullorder->get_number($lb['number']);
  754. if(!$nu)
  755. {
  756. $nu = $this->fullordersmt->get_number($lb['number']);
  757. if(!$nu)
  758. {
  759. $nu = $this->fullordertt->get_number($lb['number']);
  760. }
  761. }
  762. if($nu['state'] == '214' || $nu['state'] == '217')
  763. {
  764. echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;
  765. }
  766. }
  767. /**
  768. if($cz == 1 && stripos($lb['rk'],'|'.$transfer.'|') !== false)
  769. {
  770. echo json_encode(array('msg'=>'此条码已有入库操作!','success'=>false));exit;
  771. }
  772. if($cz == 2 && stripos($lb['ck'],'|'.$transfer.'|') !== false)
  773. {
  774. echo json_encode(array('msg'=>'此条码已有出库操作!','success'=>false));exit;
  775. }
  776. if($cz == 2 && stripos($lb['rk'],'|'.$transfer.'|') === false)
  777. {
  778. echo json_encode(array('msg'=>'此条码还未入库!','success'=>false));exit;
  779. }
  780. if($cz == 1 && $lb['rk'] != $lb['ck'] && stripos($lb['rk'],'|'.$transfer.'|') === false && stripos($lb['ck'],'|'.$transfer.'|') === false)//判断是否没走完流程就拿到下一步奏
  781. {
  782. echo json_encode(array('msg'=>'上个流程还未出库,无法入库!','success'=>false));exit;
  783. }
  784. **/
  785. if($cz == 1)
  786. {
  787. $lb['rk'] .= $transfer.'|';
  788. $lb['rktime'] .= $time.'|';
  789. }
  790. else if($cz == 2)
  791. {
  792. $lb['ck'] .= $transfer.'|';
  793. $lb['cktime'] .= $time.'|';
  794. }
  795. $cztime = 'ctime'.$transfer;
  796. if(($transfer == 8 || $transfer == 13) && $lb['dbapi'] < 99)
  797. {
  798. if($lb['type'] == 0)
  799. {
  800. $lb['shipremarks'] = $nu['shipremarks'];
  801. $s = $this->shop->read($nu['shop']);
  802. $lb['kh'] = $s['yyid'];
  803. $lb['ts'] = 1;
  804. $rk = $this->apiyy->_newrk($lb);
  805. if($rk['c'] == 0)
  806. {
  807. if($this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),'dbapi'=>99,'scid'=>$rk['scid'].time(),$cztime=>$time),$lb['id']))
  808. {
  809. if($nu['state'] == '216')
  810. {
  811. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  812. }
  813. else
  814. {
  815. echo json_encode(array('music'=>'1','success'=>true));exit;
  816. }
  817. }
  818. else
  819. {
  820. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  821. }
  822. }
  823. else
  824. {
  825. if(stripos($rk['error'],'DocNo') !== false)
  826. {
  827. $rk['error'] = '未找到对应的生产订单 '.$lb['scid'];
  828. }
  829. $this->systemtransfer->save(array('dbapi'=>$rk['dbapi'],'scid'=>$rk['scid']),$lb['id']);
  830. echo json_encode(array('msg'=>'订单号:'.$lb['number'].' 用友报错:'.$rk['error'],'success'=>false));exit;
  831. }
  832. }
  833. else
  834. {
  835. $scid = explode('~',$lb['scid']);
  836. $rkdata = array('od'=>$scid[1],'ts'=>1,'title'=>$lb['title']);
  837. $rk = $this->apiyy->get_bzsh($rkdata);
  838. if(isset($rk['Data'][0]))
  839. {
  840. if($rk['Data'][0]['IsSucess'] == 1)
  841. {
  842. if($this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),'dbapi'=>99,'scid'=>$lb['scid'].'~'.$rk['Data'][0]['Code'],$cztime=>$time),$lb['id']))
  843. {
  844. if($nu['state'] == '216')
  845. {
  846. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  847. }
  848. else
  849. {
  850. echo json_encode(array('music'=>'1','success'=>true));exit;
  851. }
  852. }
  853. else
  854. {
  855. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  856. }
  857. }
  858. else
  859. {
  860. echo json_encode(array('msg'=>$rk['Data'][0]['ErrorMsg'],'success'=>false));exit;
  861. }
  862. }
  863. else
  864. {
  865. echo json_encode(array('msg'=>$rk,'success'=>false));exit;
  866. }
  867. }
  868. }
  869. /**
  870. if($transfer == 11 && (stripos($lb['rk'],'|8|') === false || stripos($lb['rk'],'|13|') === false))
  871. {
  872. echo json_encode(array('msg'=>'工厂未出库,请退回工厂!','success'=>false));exit;
  873. }
  874. */
  875. if($this->systemtransfer->save(array('rk'=>$lb['rk'],'rktime'=>$lb['rktime'],'ck'=>$lb['ck'],'cktime'=>$lb['cktime'],'time'=>$time,'gtime'=>date('YmdH',$time),$cztime=>$time),$lb['id']))
  876. {
  877. if($nu['state'] == '216')
  878. {
  879. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  880. }
  881. else
  882. {
  883. echo json_encode(array('music'=>'1','success'=>true));exit;
  884. }
  885. }
  886. else
  887. {
  888. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  889. }
  890. }
  891. }
  892. public function _bdbb()
  893. {
  894. $post = $this->input->post(NULL, TRUE);
  895. if(isset($post['s']))
  896. {
  897. $id_arr = $this->input->post('s');
  898. $id_arr = explode(',',trim($id_arr,','));
  899. if(!$id_arr)
  900. {
  901. echo json_encode(array('msg'=>$v.' - 未查询到需要补打信息!','success'=>false));exit;
  902. }
  903. //循环删除记录
  904. foreach ($id_arr as $v)
  905. {
  906. $t = $this->systemtransfer->read($v);
  907. if(!isset($t['number']))
  908. {
  909. echo json_encode(array('msg'=>$v.' - 补打信息已被删除!','success'=>false));exit;
  910. }
  911. $y = $this->fullorder->get_number($t['number']);
  912. if(!$y)
  913. {
  914. $y = $this->fullordersmt->get_number($t['number']);
  915. if(!$y)
  916. {
  917. $y = $this->fullordertt->get_number($t['number']);
  918. if(!$y)
  919. {
  920. echo json_encode(array('msg'=>$t['number'].'没有找到此订单','success'=>false));exit;
  921. }
  922. }
  923. }
  924. $express = $this->express->read($y['express']);
  925. $rows[] = array('num'=>$t['label'],'number'=>$t['number'],'shipremarks'=>$t['shipremarks'],'ex'=>$express['servicename'],'time'=>'发货单打印时间:'.date('Y-m-d H:i:s',$t['printtime']),'gtime'=>date('YmdH',time()),'s'=>'1/1','t'=>"补打");
  926. }
  927. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  928. }
  929. }
  930. public function _excel()
  931. {
  932. if(isset($_GET['fexcel']))
  933. {
  934. $tc = array();$zh = array();
  935. $typeclass = $this->typeclass->find_all();
  936. foreach ($typeclass as $v)
  937. {
  938. $tc[$v['id']] = $v;
  939. }
  940. $number = $this->input->get('number',true);
  941. $color = $this->input->get('color',true);
  942. $gs = $this->input->get('gs',true);
  943. $transfer = $this->input->get('transfer',true);
  944. $timetk = $this->input->get('timetk',true);
  945. $timetj = $this->input->get('timetj',true);
  946. $timetk = strtotime($timetk);
  947. $timetj = strtotime($timetj);
  948. $where = "1=1";
  949. if($transfer)
  950. {
  951. if($transfer == 12)
  952. {
  953. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  954. }
  955. else
  956. {
  957. $ctime = 'ctime'.$transfer;
  958. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  959. }
  960. }
  961. else
  962. {
  963. $where .= " and time > '$timetk' and time < '$timetj'";
  964. }
  965. if($transfer)
  966. {
  967. $where .= " and rk like '%|$transfer|%'";
  968. }
  969. if($number)
  970. {
  971. $where .= " and number = '$number'";
  972. }
  973. if($gs)
  974. {
  975. $where .= " and gs = '$gs'";
  976. }
  977. if($color)
  978. {
  979. $where .= " and features like '%$color%'";
  980. }
  981. $data = array();
  982. $datafy = array();
  983. $j = 0;
  984. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,jm,shipremarks,printtime');
  985. $lzbm = $this->transfer->find_all();
  986. foreach ($info_list as $key=>$value)
  987. {
  988. $dj = '';$ys = '';$cc = '';$hx = '';$md = '';
  989. $d = $this->systemtransfer->read($value['id']);
  990. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  991. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$d['shipremarks']);
  992. $d['features'] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$d['features']);
  993. $cp = explode('-',trim($d['features'],'-'));
  994. $rk = explode('|',trim($d['rk'],'|'));
  995. $rktime = explode('|',trim($d['rktime'],'|'));
  996. foreach ($cp as $v)
  997. {
  998. if(isset($tc[$v]))
  999. {
  1000. if($tc[$v]['classid'] == 13)
  1001. {
  1002. $dj = $tc[$v]['title'];
  1003. }
  1004. else if($tc[$v]['classid'] == 8)
  1005. {
  1006. $ys = $tc[$v]['title'];
  1007. }
  1008. else if($tc[$v]['classid'] == 14)
  1009. {
  1010. $cc = $tc[$v]['title'];
  1011. }
  1012. else if($tc[$v]['classid'] == 15)
  1013. {
  1014. $hx = $tc[$v]['title'];
  1015. }
  1016. else if($tc[$v]['classid'] == 10)
  1017. {
  1018. $md = $tc[$v]['title'];
  1019. }
  1020. }
  1021. }
  1022. $rt = array();
  1023. foreach ($rk as $k=>$v)
  1024. {
  1025. $rt[$v+5] = date('Y-m-d H:i:s',$rktime[$k]);
  1026. }
  1027. $fpdata = array(array('0'=>$d['title'],'1'=>$cc,'2'=>$dj,'3'=>$ys,'4'=>$hx,'5'=>$md));
  1028. foreach ($lzbm as $v)
  1029. {
  1030. if(isset($rt[count($fpdata[0])]))
  1031. {
  1032. $fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1033. }
  1034. else
  1035. {
  1036. $fpdata[0][count($fpdata[0])] = '';
  1037. }
  1038. }
  1039. $info_list[$key]['fpdata'] = $fpdata;//名称,尺寸,等级,颜色,花型,密度
  1040. unset($info_list[$key]['id']);
  1041. }
  1042. //echo "<pre>";print_r($info_list);exit;
  1043. $lzxq = '';
  1044. foreach ($lzbm as $v)
  1045. {
  1046. $lzxq .= '<td>'.$v['title'].'</td>';
  1047. }
  1048. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 统计表';
  1049. $titlename = "<table border=1>
  1050. <tr>
  1051. <td>订单编号</td>
  1052. <td>品名</td>
  1053. <td>简码</td>
  1054. <td>备注</td>
  1055. <td>打印时间</td>
  1056. <td>
  1057. <table border=1>
  1058. <tr><td colspan='6' align='center'>订单产品信息</td><td colspan='".count($lzbm)."' align='center'>货物流转时间</td></tr>
  1059. <tr>
  1060. <td>产品名称</td>
  1061. <td>尺寸</td>
  1062. <td>等级</td>
  1063. <td>颜色</td>
  1064. <td>花型</td>
  1065. <td>密度</td>
  1066. ".$lzxq."
  1067. </tr>
  1068. </table>
  1069. </td>
  1070. </tr>
  1071. </table>";
  1072. $filename = $title.".xls";
  1073. $tail = "\n";
  1074. $this->excel->get_fz($info_list,$titlename,$filename,$tail,1);
  1075. }
  1076. }
  1077. }