Transfer.php 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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,orvertime',$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' and id != '".$id."'"))
  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['ck'] = "|12|";
  548. $post['rktime'] = "|".$time."|";
  549. $post['cktime'] = $post['rktime'];
  550. $post['ctime12'] = $time;
  551. $express = $this->express->read($y['express']);
  552. $rows = array();$t='';
  553. $this->db->trans_begin();
  554. $post['xbqnum'] = $xbqnum;
  555. $kh = $this->shop->read($y['shop']);
  556. $yy = $this->apiyy->_peihuo($post,$kh['yyid'],$y['number'],$post['xbqnum']);
  557. if($yy['c'] == 0)
  558. {
  559. $post['scapi'] = '99';
  560. $post['scid'] = $yy['scid'];
  561. if(!$post['purchase'])
  562. {
  563. $post['purchase'] = '';
  564. }
  565. $mqsl = $this->systemtransfer->find_count("number = '".$data['number']."'");
  566. for($i=0;$i<$xbqnum;$i++)
  567. {
  568. if($post['zps'])
  569. {
  570. if($post['zps'] > 0)
  571. {
  572. $t = '总量:'.($mqsl+$i+1).'/'.$zps;
  573. }
  574. }
  575. $label = substr($time,1)*100;
  576. $post['label'] = $label+$i;
  577. $rows[] = array('num'=>$post['label'],'number'=>$post['number'],'shipremarks'=>$post['shipremarks'],'ex'=>$express['servicename'],'time'=>''.date('Y-m-d',$post['printtime']),'gtime'=>date('YmdH',time()),'s'=>'('.($i+1).'/'.$xbqnum.')','t'=>$t);
  578. $this->systemtransfer->insert($post);
  579. }
  580. }
  581. else
  582. {
  583. $this->db->trans_rollback();
  584. echo json_encode(array('msg'=>$yy['error'],'a'=>1,'success'=>false));exit;
  585. }
  586. if($this->db->trans_status() === TRUE)
  587. {
  588. $this->db->trans_commit();
  589. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  590. }
  591. else
  592. {
  593. $this->db->trans_rollback();
  594. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  595. }
  596. }
  597. }
  598. public function _operate()
  599. {
  600. $post = $this->input->post(NULL, TRUE);
  601. if(isset($post['page']))
  602. {
  603. $api = $this->input->post('api',true);
  604. $page = $this->input->post('page',true);
  605. $perpage = $this->input->post('perpage',true);
  606. $number = $this->input->post('number',true);
  607. $color = $this->input->post('color',true);
  608. $purchase = $this->input->post('purchase',true);
  609. $transfer = $this->input->post('transfer',true);
  610. $lx = $this->input->post('lx',true);
  611. $timetk = $this->input->post('timetk',true);
  612. $timetj = $this->input->post('timetj',true);
  613. $timetk = strtotime($timetk);
  614. $timetj = strtotime($timetj);
  615. $where = "1=1";
  616. if($transfer)
  617. {
  618. $ctime = 'ctime'.$transfer;
  619. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  620. }
  621. else
  622. {
  623. $where .= " and time > '$timetk' and time < '$timetj'";
  624. }
  625. if($number)
  626. {
  627. $where .= " and number = '$number'";
  628. }
  629. if($transfer)
  630. {
  631. $where .= " and rk like '%|".$transfer."|%'";
  632. }
  633. if($purchase)
  634. {
  635. $where .= " and purchase = '$purchase'";
  636. }
  637. if($color)
  638. {
  639. $where .= " and fpdata like '%-".$color."-%'";
  640. }
  641. if($lx)
  642. {
  643. if($lx == 1)
  644. {
  645. $where .= " and ordernumber = ''";
  646. }
  647. else
  648. {
  649. $where .= " and ordernumber != ''";
  650. }
  651. }
  652. //数据排序
  653. $order_str = "id desc";
  654. if(empty($page))
  655. {
  656. $start = 0;
  657. $perpage = 1;
  658. }
  659. else
  660. {
  661. $start = ($page - 1)*$perpage;
  662. }
  663. //取得信息列表
  664. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  665. $transfer = $this->transfer->find_all();
  666. $t = array();
  667. foreach ($transfer as $v)
  668. {
  669. $t[$v['id']] = $v['title'];
  670. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  671. }
  672. //格式化数据
  673. foreach ($info_list as $key=>$value)
  674. {
  675. $dd = $this->systemtransfer->read($value['id']);
  676. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  677. $rk = explode('|',trim($dd['rk'],'|'));
  678. $rktime = explode('|',trim($dd['rktime'],'|'));
  679. $ck = explode('|',trim($dd['ck'],'|'));
  680. $cktime = explode('|',trim($dd['cktime'],'|'));
  681. $info_list[$key]['time'] = '';
  682. for($i=0;$i<count($rk);$i++)
  683. {
  684. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  685. {
  686. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  687. }
  688. else
  689. {
  690. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  691. }
  692. $info_list[$key]['time'] .= $d;
  693. if(isset($ck[$i]) && $ck[$i] != '')
  694. {
  695. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  696. }
  697. }
  698. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  699. }
  700. $total = $this->systemtransfer->find_count($where);
  701. $pagenum = ceil($total/$perpage);
  702. $over = $total-($start+$perpage);
  703. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  704. echo json_encode($rows);exit;
  705. }
  706. if(isset($_SESSION['api']))
  707. {
  708. $user = $this->user->get_api($_SESSION['api']);
  709. $usp = $user;
  710. $pid = "";$tid="";$sid="";$wid="";
  711. $purchase = explode('|',trim($user['purchase'],'|'));
  712. $transfer = explode('|',trim($user['transfer'],'|'));
  713. $warehouse = explode('|',trim($user['warehouse'],'|'));
  714. foreach ($purchase as $value)
  715. {
  716. $pid .= " id = ".$value." or";
  717. }
  718. foreach ($transfer as $value)
  719. {
  720. $tid .= " id = ".$value." or";
  721. }
  722. foreach ($warehouse as $value)
  723. {
  724. $wid .= " id = ".$value." or";
  725. }
  726. }
  727. else
  728. {
  729. header('Location: /');exit;
  730. }
  731. $kx = '';$zjtab = '';
  732. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  733. $this->data['warehouse'] = $warehouse;
  734. $purchase = $this->purchase->find_all("yyid != ''");
  735. $this->data['purchase'] = $purchase;
  736. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  737. $this->data['transfer'] = $transfer;
  738. $this->data['vip'] = $user['vip'];
  739. $this->_Template('transfer_operate',$this->data);
  740. }
  741. public function _out()
  742. {
  743. $post = $this->input->post(NULL, TRUE);
  744. if(isset($post['label']))
  745. {
  746. $time = time();
  747. $label = $this->input->post('label',true);
  748. $cz = $this->input->post('cz',true);
  749. $transfer = $this->input->post('transfer',true);
  750. if(!$label)
  751. {
  752. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  753. }
  754. if(!$transfer)
  755. {
  756. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  757. }
  758. $lb = $this->systemtransfer->get_label($label);
  759. if(!$lb)
  760. {
  761. echo json_encode(array('msg'=>'错误!未找到此条码','success'=>false));exit;
  762. }
  763. if($lb['number']!='')
  764. {
  765. $nu = $this->fullorder->get_number($lb['number']);
  766. if(!$nu)
  767. {
  768. $nu = $this->fullordersmt->get_number($lb['number']);
  769. if(!$nu)
  770. {
  771. $nu = $this->fullordertt->get_number($lb['number']);
  772. }
  773. }
  774. if($nu['state'] == '214' || $nu['state'] == '217')
  775. {
  776. echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;
  777. }
  778. }
  779. /**
  780. if($cz == 1 && stripos($lb['rk'],'|'.$transfer.'|') !== false)
  781. {
  782. echo json_encode(array('msg'=>'此条码已有入库操作!','success'=>false));exit;
  783. }
  784. if($cz == 2 && stripos($lb['ck'],'|'.$transfer.'|') !== false)
  785. {
  786. echo json_encode(array('msg'=>'此条码已有出库操作!','success'=>false));exit;
  787. }
  788. if($cz == 2 && stripos($lb['rk'],'|'.$transfer.'|') === false)
  789. {
  790. echo json_encode(array('msg'=>'此条码还未入库!','success'=>false));exit;
  791. }
  792. if($lb['printtime'] > 1705939200)
  793. {
  794. if($cz == 1 && $lb['rk'] != $lb['ck'] && stripos($lb['rk'],'|'.$transfer.'|') === false && stripos($lb['ck'],'|'.$transfer.'|') === false)//判断是否没走完流程就拿到下一步奏
  795. {
  796. echo json_encode(array('msg'=>'上个流程还未出库,无法入库!','success'=>false));exit;
  797. }
  798. }
  799. **/
  800. $lbrk = array_reverse(explode('|',trim($lb['rk'],'|')));
  801. $lbck = array_reverse(explode('|',trim($lb['ck'],'|')));
  802. if($cz == 1)
  803. {
  804. $lb['rk'] .= $transfer.'|';
  805. $lb['rktime'] .= $time.'|';
  806. if($lbrk[0] == $transfer)
  807. {
  808. echo json_encode(array('msg'=>'已有入库记录,不可连续重复录入!','success'=>false));exit;
  809. }
  810. }
  811. else if($cz == 2)
  812. {
  813. $lb['ck'] .= $transfer.'|';
  814. $lb['cktime'] .= $time.'|';
  815. if($lbck[0] == $transfer)
  816. {
  817. echo json_encode(array('msg'=>'已有出库记录,不可连续重复录入!','success'=>false));exit;
  818. }
  819. }
  820. $cztime = 'ctime'.$transfer;
  821. //if(($transfer == 3 && $lb['dbapi'] < 99 && $cz == 2) || ($transfer == 13 && $lb['dbapi'] < 99 && $cz == 1))//出入库用这个
  822. if(($transfer == 8 || $transfer == 13) && $lb['dbapi'] < 99 && $cz == 1)
  823. {
  824. if($lb['type'] == 0)
  825. {
  826. $s = $this->shop->read($nu['shop']);
  827. $lb['kh'] = $s['yyid'];
  828. $lb['ts'] = 1;
  829. $rk = $this->apiyy->_newrk($lb);
  830. if($rk['c'] == 0)
  831. {
  832. 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']))
  833. {
  834. if($nu['state'] == '216')
  835. {
  836. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  837. }
  838. else
  839. {
  840. echo json_encode(array('music'=>'1','success'=>true));exit;
  841. }
  842. }
  843. else
  844. {
  845. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  846. }
  847. }
  848. else
  849. {
  850. if(stripos($rk['error'],'DocNo') !== false)
  851. {
  852. $rk['error'] = '未找到对应的生产订单 '.$lb['scid'];
  853. }
  854. $this->systemtransfer->save(array('dbapi'=>$rk['dbapi'],'scid'=>$rk['scid']),$lb['id']);
  855. echo json_encode(array('msg'=>'订单号:'.$lb['number'].' 用友报错:'.$rk['error'],'success'=>false));exit;
  856. }
  857. }
  858. else
  859. {
  860. $scid = explode('~',$lb['scid']);
  861. $rkdata = array('od'=>$scid[1],'ts'=>1,'title'=>$lb['title']);
  862. $rk = $this->apiyy->get_bzsh($rkdata);
  863. if(isset($rk['Data'][0]))
  864. {
  865. if($rk['Data'][0]['IsSucess'] == 1)
  866. {
  867. 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']))
  868. {
  869. if($nu['state'] == '216')
  870. {
  871. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  872. }
  873. else
  874. {
  875. echo json_encode(array('music'=>'1','success'=>true));exit;
  876. }
  877. }
  878. else
  879. {
  880. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  881. }
  882. }
  883. else
  884. {
  885. echo json_encode(array('msg'=>$rk['Data'][0]['ErrorMsg'],'success'=>false));exit;
  886. }
  887. }
  888. else
  889. {
  890. echo json_encode(array('msg'=>$rk,'success'=>false));exit;
  891. }
  892. }
  893. }
  894. if($transfer == 11 && stripos($lb['rk'],'|8|') === false && stripos($lb['ck'],'|3|') === false && stripos($lb['rk'],'|13|') === false)//改出入库 需要调整8为3 由完成出库检测
  895. {
  896. echo json_encode(array('msg'=>'工厂未出库,请退回工厂!','success'=>false));exit;
  897. }
  898. 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']))
  899. {
  900. if($nu['state'] == '216')
  901. {
  902. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  903. }
  904. else
  905. {
  906. echo json_encode(array('music'=>'1','success'=>true));exit;
  907. }
  908. }
  909. else
  910. {
  911. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  912. }
  913. }
  914. }
  915. public function _bdbb()
  916. {
  917. $post = $this->input->post(NULL, TRUE);
  918. if(isset($post['s']))
  919. {
  920. $id_arr = $this->input->post('s');
  921. $id_arr = explode(',',trim($id_arr,','));
  922. if(!$id_arr)
  923. {
  924. echo json_encode(array('msg'=>$v.' - 未查询到需要补打信息!','success'=>false));exit;
  925. }
  926. //循环删除记录
  927. foreach ($id_arr as $v)
  928. {
  929. $t = $this->systemtransfer->read($v);
  930. if(!isset($t['number']))
  931. {
  932. echo json_encode(array('msg'=>$v.' - 补打信息已被删除!','success'=>false));exit;
  933. }
  934. $y = $this->fullorder->get_number($t['number']);
  935. if(!$y)
  936. {
  937. $y = $this->fullordersmt->get_number($t['number']);
  938. if(!$y)
  939. {
  940. $y = $this->fullordertt->get_number($t['number']);
  941. if(!$y)
  942. {
  943. echo json_encode(array('msg'=>$t['number'].'没有找到此订单','success'=>false));exit;
  944. }
  945. }
  946. }
  947. $express = $this->express->read($y['express']);
  948. $rows[] = array('num'=>$t['label'],'number'=>$t['number'],'shipremarks'=>$t['shipremarks'],'ex'=>$express['servicename'],'time'=>''.date('Y-m-d',$t['printtime']),'gtime'=>date('YmdH',time()),'s'=>'1/1','t'=>"补打");
  949. }
  950. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  951. }
  952. }
  953. public function _excel()
  954. {
  955. if(isset($_GET['fexcel']))
  956. {
  957. $tc = array();$zh = array();
  958. $typeclass = $this->typeclass->find_all();
  959. foreach ($typeclass as $v)
  960. {
  961. $tc[$v['id']] = $v;
  962. }
  963. $number = $this->input->get('number',true);
  964. $color = $this->input->get('color',true);
  965. $gs = $this->input->get('gs',true);
  966. $transfer = $this->input->get('transfer',true);
  967. $timetk = $this->input->get('timetk',true);
  968. $timetj = $this->input->get('timetj',true);
  969. $timetk = strtotime($timetk);
  970. $timetj = strtotime($timetj);
  971. $where = "1=1";
  972. if($transfer)
  973. {
  974. if($transfer == 12)
  975. {
  976. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  977. }
  978. else
  979. {
  980. $ctime = 'ctime'.$transfer;
  981. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  982. }
  983. }
  984. else
  985. {
  986. $where .= " and time > '$timetk' and time < '$timetj'";
  987. }
  988. if($transfer)
  989. {
  990. $where .= " and rk like '%|$transfer|%'";
  991. }
  992. if($number)
  993. {
  994. $where .= " and number = '$number'";
  995. }
  996. if($gs)
  997. {
  998. $where .= " and gs = '$gs'";
  999. }
  1000. if($color)
  1001. {
  1002. $where .= " and features like '%$color%'";
  1003. }
  1004. $data = array();
  1005. $datafy = array();
  1006. $j = 0;
  1007. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,jm,shipremarks,printtime');
  1008. $lzbm = $this->transfer->find_all();
  1009. foreach ($info_list as $key=>$value)
  1010. {
  1011. $dj = '';$ys = '';$cc = '';$hx = '';$md = '';
  1012. $d = $this->systemtransfer->read($value['id']);
  1013. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1014. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$d['shipremarks']);
  1015. $d['features'] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$d['features']);
  1016. $cp = explode('-',trim($d['features'],'-'));
  1017. $rk = explode('|',trim($d['rk'],'|'));
  1018. $rktime = explode('|',trim($d['rktime'],'|'));
  1019. foreach ($cp as $v)
  1020. {
  1021. if(isset($tc[$v]))
  1022. {
  1023. if($tc[$v]['classid'] == 13)
  1024. {
  1025. $dj = $tc[$v]['title'];
  1026. }
  1027. else if($tc[$v]['classid'] == 8)
  1028. {
  1029. $ys = $tc[$v]['title'];
  1030. }
  1031. else if($tc[$v]['classid'] == 14)
  1032. {
  1033. $cc = $tc[$v]['title'];
  1034. }
  1035. else if($tc[$v]['classid'] == 15)
  1036. {
  1037. $hx = $tc[$v]['title'];
  1038. }
  1039. else if($tc[$v]['classid'] == 10)
  1040. {
  1041. $md = $tc[$v]['title'];
  1042. }
  1043. }
  1044. }
  1045. $rt = array();
  1046. foreach ($rk as $k=>$v)
  1047. {
  1048. $rt[$v+5] = date('Y-m-d H:i:s',$rktime[$k]);
  1049. }
  1050. $fpdata = array(array('0'=>$d['title'],'1'=>$cc,'2'=>$dj,'3'=>$ys,'4'=>$hx,'5'=>$md));
  1051. foreach ($lzbm as $v)
  1052. {
  1053. if(isset($rt[count($fpdata[0])]))
  1054. {
  1055. $fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1056. }
  1057. else
  1058. {
  1059. $fpdata[0][count($fpdata[0])] = '';
  1060. }
  1061. }
  1062. $info_list[$key]['fpdata'] = $fpdata;//名称,尺寸,等级,颜色,花型,密度
  1063. unset($info_list[$key]['id']);
  1064. }
  1065. //echo "<pre>";print_r($info_list);exit;
  1066. $lzxq = '';
  1067. foreach ($lzbm as $v)
  1068. {
  1069. $lzxq .= '<td>'.$v['title'].'</td>';
  1070. }
  1071. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 统计表';
  1072. $titlename = "<table border=1>
  1073. <tr>
  1074. <td>订单编号</td>
  1075. <td>品名</td>
  1076. <td>简码</td>
  1077. <td>备注</td>
  1078. <td>打印时间</td>
  1079. <td>
  1080. <table border=1>
  1081. <tr><td colspan='6' align='center'>订单产品信息</td><td colspan='".count($lzbm)."' align='center'>货物流转时间</td></tr>
  1082. <tr>
  1083. <td>产品名称</td>
  1084. <td>尺寸</td>
  1085. <td>等级</td>
  1086. <td>颜色</td>
  1087. <td>花型</td>
  1088. <td>密度</td>
  1089. ".$lzxq."
  1090. </tr>
  1091. </table>
  1092. </td>
  1093. </tr>
  1094. </table>";
  1095. $filename = $title.".xls";
  1096. $tail = "\n";
  1097. $this->excel->get_fz($info_list,$titlename,$filename,$tail,1);
  1098. }
  1099. }
  1100. }