Transfer.php 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  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. $this->load->_model('Model_systemtransfer_cr','systemtransfer_cr');
  21. }
  22. //定义方法的调用规则 获取URI第二段值
  23. public function _remap($arg,$arg_array)
  24. {
  25. if($arg == 'add')
  26. {
  27. $this->_add();
  28. }
  29. else if($arg == 'edit')
  30. {
  31. $this->_edit($arg_array);
  32. }
  33. else if($arg == 'del')
  34. {
  35. $this->_del();
  36. }
  37. else if($arg == 'print')
  38. {
  39. $this->_print();
  40. }
  41. else if($arg == 'number')
  42. {
  43. $this->_number();
  44. }
  45. else if($arg == 'numberprint')
  46. {
  47. $this->_numberprint();
  48. }
  49. else if($arg == 'operate')
  50. {
  51. $this->_operate();
  52. }
  53. else if($arg == 'out')
  54. {
  55. $this->_out();
  56. }
  57. else if($arg == 'excel')
  58. {
  59. $this->_excel();
  60. }
  61. else if($arg == 'bdbb')
  62. {
  63. $this->_bdbb();
  64. }
  65. else if($arg == 'rk')
  66. {
  67. $this->_rk();
  68. }
  69. else if($arg == 'ck')
  70. {
  71. $this->_ck();
  72. }
  73. else if($arg == 'jgl')//交工率
  74. {
  75. $this->_jgl();
  76. }
  77. else if($arg == 'linqi')
  78. {
  79. $this->_linqi();
  80. }
  81. else if($arg == 'overtime_export'){
  82. $this->_overtime_export();
  83. }
  84. else
  85. {
  86. $this->_index();
  87. }
  88. }
  89. //管理
  90. public function _index()
  91. {
  92. $t = array();
  93. $typeclass = $this->typeclass->find_all();
  94. foreach ($typeclass as $v)
  95. {
  96. $t[$v['id']] = $v['title'];
  97. }
  98. $post = $this->input->post(NULL, TRUE);
  99. if(isset($post['page']))
  100. {
  101. $page = $this->input->post('page',true);
  102. $perpage = $this->input->post('perpage',true);
  103. $type = $this->input->post('type',true);
  104. $where = "1=1 ";
  105. //数据排序
  106. $order_str = "id asc";
  107. if($type)
  108. {
  109. $where .= "and type = '$type'";
  110. }
  111. if(empty($page))
  112. {
  113. $start = 0;
  114. $perpage = 1;
  115. }
  116. else
  117. {
  118. $start = ($page - 1)*$perpage;
  119. }
  120. //取得信息列表
  121. $info_list = $this->transfer->find_all($where,'id,title,orvertime,overtime_one,overtime_two',$order_str,$start,$perpage);
  122. $total = $this->transfer->find_count($where);
  123. $pagenum = ceil($total/$perpage);
  124. $over = $total-($start+$perpage);
  125. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  126. echo json_encode($rows);exit;
  127. }
  128. $this->_Template('transfer',$this->data);
  129. }
  130. //添加
  131. public function _add()
  132. {
  133. $post = $this->input->post(NULL, TRUE);
  134. if(isset($post['title']))
  135. {
  136. $title = $this->input->post('title',true);
  137. if($this->transfer->find_all("title = '$title'"))
  138. {
  139. echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;
  140. }
  141. if($this->transfer->insert($post))
  142. {
  143. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  144. }
  145. else
  146. {
  147. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  148. }
  149. }
  150. $this->_Template('transfer_add',$this->data);
  151. }
  152. //修改
  153. public function _edit($arg_array)
  154. {
  155. $post = $this->input->post(NULL, TRUE);
  156. if(isset($post['id']))
  157. {
  158. $id = $this->input->post('id',true);
  159. $title = $this->input->post('title',true);
  160. if($this->transfer->find_all("title = '$title' and id != '".$id."'"))
  161. {
  162. echo json_encode(array('msg'=>'名称重复!','success'=>false));exit;
  163. }
  164. if($this->transfer->save($post,$id))
  165. {
  166. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  167. }
  168. else
  169. {
  170. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  171. }
  172. }
  173. $arg_array = $arg_array[0];
  174. $transfer = $this->transfer->read($arg_array);
  175. $this->data['transfer'] = $transfer;
  176. $this->_Template('transfer_edit',$this->data);
  177. }
  178. //删除
  179. public function _del()
  180. {
  181. $post = $this->input->post(NULL, TRUE);
  182. if(isset($post['s']))
  183. {
  184. $id_arr = $this->input->post('s');
  185. $id_arr = explode(',',$id_arr);
  186. if(!$id_arr)
  187. {
  188. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  189. }
  190. //循环删除记录
  191. foreach ($id_arr as $v)
  192. {
  193. $this->transfer->remove($v);
  194. }
  195. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  196. }
  197. }
  198. public function _print()
  199. {
  200. if(isset($_SESSION['api']))
  201. {
  202. $user = $this->user->get_api($_SESSION['api']);
  203. $usp = $user;
  204. $sid = "";$wid="";$wtype="";
  205. $userwh = explode('|',trim($user['warehouse'],'|'));
  206. foreach ($userwh as $value)
  207. {
  208. $wid .= " id = ".$value." or";
  209. $wtype .= " type = ".$value." or";
  210. }
  211. }
  212. $post = $this->input->post(NULL, TRUE);
  213. $classid = $this->classid->sku();
  214. $pm = $classid;
  215. $scsku = $classid;
  216. if(isset($post['category']))
  217. {
  218. $list = array();$num = "";$title = "";$features = "";
  219. $order = 0;
  220. $xbqnum = $this->input->post('xbqnum',true);//打印数量
  221. $t = $this->input->post('t',true);//打印数量
  222. if($xbqnum > 99)
  223. {
  224. echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;
  225. }
  226. if($xbqnum < 1)
  227. {
  228. echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;
  229. }
  230. $post['purchase'] = $this->input->post('purchase',true);//所属工厂
  231. $category = $this->input->post('category',true);
  232. $list['category'] = $category;
  233. $list['hairtype'] = $this->input->post('hairtype',true);
  234. $list['grade'] = $this->input->post('grade',true);
  235. $size = $this->input->post('size',true);
  236. $xzsku = $this->input->post('xzsku',true);
  237. $list['size'] = rtrim($size,',');
  238. $list['hairnumber'] = $this->input->post('hairnumber',true);
  239. $list['extension'] = $this->input->post('extension',true);
  240. if($category == 1297)
  241. {
  242. $list['sywignumber'] = $this->input->post('sywignumber',true);
  243. }
  244. if($category == 1702)
  245. {
  246. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  247. $list['syother'] = $this->input->post('syother',true);
  248. }
  249. if($category == 133)
  250. {
  251. $list['fittype'] = $this->input->post('fittype',true);
  252. $list['acother'] = $this->input->post('acother',true);
  253. }
  254. $list['color'] = $this->input->post('color',true);
  255. $list['lowe'] = $this->input->post('lowe',true);
  256. if($category == 127)
  257. {
  258. $list['type'] = $this->input->post('type',true);
  259. $list['headroad'] = $this->input->post('headroad',true);
  260. $list['density'] = $this->input->post('density',true);
  261. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  262. {
  263. $list['lacesize'] = $this->input->post('lacesize',true);
  264. }
  265. $list['lacecolor'] = $this->input->post('lacecolor',true);
  266. $list['lacetypes'] = $this->input->post('lacetypes',true);
  267. }
  268. if($category == 128)
  269. {
  270. $list['lacetype'] = $this->input->post('lacetype',true);
  271. $list['haircap'] = $this->input->post('haircap',true);
  272. $list['density'] = $this->input->post('density',true);
  273. $list['lacecolor'] = $this->input->post('lacecolor',true);
  274. $list['lacetypes'] = $this->input->post('lacetypes',true);
  275. $list['wigother'] = $this->input->post('wigother',true);
  276. $list['wigother2'] = $this->input->post('wigother2',true);
  277. }
  278. if($category == 129)
  279. {
  280. $list['wide'] = $this->input->post('wide',true);
  281. }
  282. if($category == 131)
  283. {
  284. $list['gifttype'] = $this->input->post('gifttype',true);
  285. $list['giftother'] = $this->input->post('giftother',true);
  286. }
  287. if($category == 134)
  288. {
  289. $list['pieceweight'] = $this->input->post('pieceweight',true);
  290. }
  291. if($category == 1297)
  292. {
  293. $list['synthetictype'] = $this->input->post('synthetictype',true);
  294. $list['sywigother'] = $this->input->post('sywigother',true);
  295. }
  296. if($category == 130 || $category == 133 || $category == 1702)
  297. {
  298. $list['items'] = $this->input->post('items',true);
  299. }
  300. if($category == 1702)
  301. {
  302. $list['syhairther'] = $this->input->post('syhairther',true);
  303. }
  304. foreach($list as $k=>$v)
  305. {
  306. if($v != 0)
  307. {
  308. $num .=$v;
  309. $features .=$v.'-';
  310. $post[$k] = $v;
  311. $typeclass = $this->typeclass->read($v);
  312. if(isset($pm[$typeclass['classid']]))
  313. {
  314. $pm[$typeclass['classid']] = $typeclass['zh'];
  315. }
  316. $scsku[$typeclass['classid']] = $typeclass['bqsku'];
  317. if($k != 'size')
  318. {
  319. $title .= $typeclass['title']." ";
  320. }
  321. }
  322. }
  323. $typeclass = $this->typeclass->read($list['size']);
  324. $title .= $typeclass['title'];
  325. $time = time();
  326. $post['printtime'] = $time;
  327. $post['title'] = rtrim($title,' ');
  328. $post['number'] = $num;
  329. $post['features'] = '-'.$features;
  330. $featurespp = str_replace(array('-163-','-164-','-165-','-166-'),'-',$features);
  331. $featurespp = explode('-',trim($featurespp,'-'));
  332. if(isset($featurespp[5]))
  333. {
  334. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4].'-'.$featurespp[5];
  335. }
  336. else
  337. {
  338. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4];
  339. }
  340. $post['time'] = $time;//操作时间
  341. $scsku = implode("-",$scsku);
  342. $zh = implode(" ",$pm);
  343. $zh = str_replace('自然色 ','',trim($zh,' '));
  344. $zh = str_replace(array(' ',' ',' ',' ',' ',' ',' '),' ',$zh);
  345. $post['shipremarks'] = $zh;
  346. $scsku = str_replace('- ','-',trim($scsku,'-'));
  347. $scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
  348. $bqsku = (isset($b['title']))?$b['title'].'-'.$scsku:$scsku;
  349. $post['sku'] = $bqsku;
  350. $post['rk'] = "|1|";//默认配货 打印后直接入库
  351. $post['rktime'] = "|".$time."|";
  352. $rows = array();
  353. $this->db->trans_begin();
  354. for($i=0;$i<$xbqnum;$i++)
  355. {
  356. $label = substr($time,1)*100;
  357. $post['label'] = $label+$i;
  358. $rows[] = array('num'=>$post['label'],'number'=>'','shipremarks'=>$zh,'ex'=>'','t'=>$t,'time'=>'布标打印时间:'.date('Y-m-d H:i:s',$time),'s'=>'('.($i+1).'/'.$xbqnum.')');
  359. $this->systemtransfer->insert($post);
  360. }
  361. if ($this->db->trans_status() === TRUE)
  362. {
  363. $this->db->trans_commit();
  364. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  365. }
  366. else
  367. {
  368. $this->db->trans_rollback();
  369. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  370. }
  371. }
  372. $purchase = $this->purchase->find_all("yyid != ''");
  373. $this->data['purchase'] = $purchase;
  374. $this->_Template('transfer_print',$this->data);
  375. }
  376. public function _number()
  377. {
  378. if(isset($_SESSION['api']))
  379. {
  380. $user = $this->user->get_api($_SESSION['api']);
  381. $pid = "";$tid="";$sid="";$wid="";
  382. $purchase = explode('|',trim($user['purchase'],'|'));
  383. $transfer = explode('|',trim($user['transfer'],'|'));
  384. foreach ($purchase as $value)
  385. {
  386. $pid .= " id = ".$value." or";
  387. }
  388. foreach ($transfer as $value)
  389. {
  390. $tid .= " id = ".$value." or";
  391. }
  392. }
  393. else
  394. {
  395. header('Location: /');exit;
  396. }
  397. $post = $this->input->post(NULL, TRUE);
  398. if(isset($post['number']))
  399. {
  400. $number = $this->input->post('number',true);
  401. $type = $this->input->post('type',true);
  402. $xbqnum = $this->input->post('xbqnum',true);//打印数量
  403. $purchase = $this->input->post('purchase',true);
  404. $f = 'fullorder';
  405. $y = $this->fullorder->get_number($number);
  406. if(!$y)
  407. {
  408. $f = 'fullordersmt';
  409. $y = $this->fullordersmt->get_number($number);
  410. if(!$y)
  411. {
  412. $f = 'fullordertt';
  413. $y = $this->fullordertt->get_number($number);
  414. if(!$y)
  415. {
  416. echo json_encode(array('msg'=>'没有找到此订单,请检查是否扫描错误','success'=>false));exit;
  417. }
  418. }
  419. }
  420. if($y['librarytime'] > 0)
  421. {
  422. echo json_encode(array('msg'=>'错误,此订单已出库!','success'=>false));exit;
  423. }
  424. $cp = array();$i = 0;$x=0;$byz = array();$znum = 0;$typeclass = array();
  425. $classid = $this->classid->sku();
  426. $tc = $this->typeclass->find_all();
  427. foreach($tc as $v)
  428. {
  429. $typeclass[$v['id']] = $v;
  430. }
  431. $bm = '03';
  432. $fpdata = explode(';',trim($y['fpdata'],';'));
  433. $whlabelsc = explode('|',trim($y['whlabel'],'|'));
  434. foreach($fpdata as $key=>$val)
  435. {
  436. $pm = $classid;
  437. $jm = $classid;
  438. $sku = $classid;
  439. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  440. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$val);
  441. $jvnr = explode('|',trim($features,'|'));
  442. if(stripos($jvnr[0],',') !== false)
  443. {
  444. $ft = explode(',',$jvnr[0]);
  445. $features = explode('-',trim($ft[1],'-'));
  446. array_splice($features,2,0,$ft[0]);
  447. }
  448. else
  449. {
  450. $features = explode('-',trim($jvnr[0],'-'));
  451. }
  452. $title = $jvnr[1];
  453. foreach($features as $k=>$v)
  454. {
  455. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  456. {
  457. if($typeclass[$v]['bm'] != '')
  458. {
  459. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  460. }
  461. }
  462. if($v != 0)
  463. {
  464. $sku[$typeclass[$v]['classid']] = $typeclass[$v]['bqsku'];
  465. if(isset($pm[$typeclass[$v]['classid']]))
  466. {
  467. if($typeclass[$v]['title'] == '9A')
  468. {
  469. $pm[$typeclass[$v]['classid']] = '9A';
  470. }
  471. else if($typeclass[$v]['title'] == '10A')
  472. {
  473. $pm[$typeclass[$v]['classid']] = '10A';
  474. }
  475. else
  476. {
  477. $clzh = $typeclass[$v]['zh'];
  478. if(stripos($typeclass[$v]['zh'],'|') !== false)
  479. {
  480. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  481. $clzh = $clzh[0];
  482. }
  483. $pm[$typeclass[$v]['classid']] = $clzh;
  484. }
  485. }
  486. if(isset($jm[$typeclass[$v]['classid']]))
  487. {
  488. if($typeclass[$v]['jm'])
  489. {
  490. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  491. }
  492. }
  493. }
  494. }
  495. $jm = array_filter($jm);//去除空值
  496. $jm = implode("-",$jm);
  497. $sku = array_filter($sku);//去除空值
  498. $sku = implode("-",$sku);
  499. $pm = array_filter($pm);//去除空值
  500. $zh = implode(" ",$pm);
  501. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  502. $features = implode("-",$features);
  503. $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))));
  504. }
  505. echo json_encode(array('rows'=>$cp,'success'=>true));exit;
  506. }
  507. $purchase = $this->purchase->find_all("yyid != ''");
  508. $this->data['purchase'] = $purchase;
  509. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  510. $this->data['transfer'] = $transfer;
  511. $this->_Template('transfer_number',$this->data);
  512. }
  513. public function _numberprint()
  514. {
  515. $time = time();
  516. $post = $this->input->post(NULL);
  517. $classid = $this->classid->sku();
  518. $pm = $classid;
  519. $scsku = $classid;
  520. if(isset($post['data']))
  521. {
  522. $data = json_decode($post['data'],true);
  523. $f = 'fullorder';
  524. $y = $this->fullorder->get_number($data['ordernumber']);
  525. if(!$y)
  526. {
  527. $f = 'fullordersmt';
  528. $y = $this->fullordersmt->get_number($data['ordernumber']);
  529. if(!$y)
  530. {
  531. $f = 'fullordertt';
  532. $y = $this->fullordertt->get_number($data['ordernumber']);
  533. if(!$y)
  534. {
  535. echo json_encode(array('msg'=>$data['ordernumber'].'没有找到此订单,请检查是否扫描错误'.$data['ordernumber'],'success'=>false));exit;
  536. }
  537. }
  538. }
  539. if($y['printtime'] == 0)
  540. {
  541. echo json_encode(array('msg'=>'此单已重置,请询问梦体','success'=>false));exit;
  542. }
  543. $order = 0;$time = time();
  544. $xbqnum = $this->input->post('n',true);//打印数量
  545. if($xbqnum > 99)
  546. {
  547. echo json_encode(array('msg'=>'打印数量不可超过99!','success'=>false));exit;
  548. }
  549. if($xbqnum < 1)
  550. {
  551. echo json_encode(array('msg'=>'打印数量错误!','success'=>false));exit;
  552. }
  553. $transfer = $this->input->post('transfer',true);
  554. $post['type'] = $this->input->post('type',true);
  555. $post['shipremarks'] = $this->input->post('b',true);
  556. $post['ph'] = $this->input->post('ph',true);
  557. $is_jiaji = $this->input->post('is_jiaji',true);
  558. if($is_jiaji == 2){
  559. $post['is_jiaji'] = 2;
  560. }else{
  561. $post['is_jiaji'] = 0;
  562. }
  563. $zps = $this->input->post('zps',true);
  564. $post['purchase'] = $this->input->post('purchase',true);//供应商
  565. $post['time'] = $time;//操作时间
  566. $post['jm'] = $data['jm'];
  567. $post['bm'] = $data['bm'];
  568. $post['pm'] = $data['pm'];
  569. $post['features'] = $data['features'];
  570. $post['number'] = $data['number'];
  571. $post['title'] = $data['title'];
  572. $post['sku'] = $data['sku'];
  573. $post['printtime'] = $y['printtime'];
  574. $post['rk'] = "|12|";//默认订单中心 打印后直接入库
  575. $post['ck'] = "|12|";
  576. $post['rktime'] = "|".$time."|";
  577. $post['cktime'] = $post['rktime'];
  578. $post['ctime12'] = $time;
  579. $express = $this->express->read($y['express']);
  580. $rows = array();$t='';
  581. $this->db->trans_begin();
  582. $post['xbqnum'] = $xbqnum;
  583. $kh = $this->shop->read($y['shop']);
  584. $yy = $this->apiyy->_peihuo($post,$kh['yyid'],$y['number'],$post['xbqnum']);
  585. if($yy['c'] == 0)
  586. {
  587. $post['scapi'] = '99';
  588. $post['scid'] = $yy['scid'];
  589. if(!$post['purchase'])
  590. {
  591. $post['purchase'] = '';
  592. }
  593. $mqsl = $this->systemtransfer->find_count("number = '".$data['number']."'");
  594. //able_ext 实在打印小单布标时判断是否可以打印备货单
  595. $able_ext = 0;
  596. $tmp_fetaures = explode('-',$data['features']);
  597. //只有头套和马尾才会要配货单
  598. if(in_array(128, $tmp_fetaures)){
  599. $able_ext = 1;
  600. }
  601. if(in_array(133, $tmp_fetaures)){
  602. if(in_array(673, $tmp_fetaures)){
  603. $able_ext = 1;
  604. }
  605. }
  606. for($i=0;$i<$xbqnum;$i++)
  607. {
  608. if($post['zps'])
  609. {
  610. if($post['zps'] > 0)
  611. {
  612. $t = '总量:'.($mqsl+$i+1).'/'.$zps;
  613. }
  614. }
  615. $label = substr($time,1)*100;
  616. $post['label'] = $label+$i;
  617. $rows[] = array('num'=>$post['label'],'number'=>$post['number'],'shipremarks'=>$post['shipremarks'],'ph'=>$post['ph'],'ex'=>$express['servicename'],'time'=>''.date('Y-m-d',$post['printtime']),'gtime'=>date('YmdH',time()),'s'=>'('.($i+1).'/'.$xbqnum.')','t'=>$t,'able_ext'=>$able_ext,'is_jiaji'=>$is_jiaji);
  618. $this->systemtransfer->insert($post);
  619. }
  620. }
  621. else
  622. {
  623. $this->db->trans_rollback();
  624. echo json_encode(array('msg'=>$yy['error'],'a'=>1,'success'=>false));exit;
  625. }
  626. if($this->db->trans_status() === TRUE)
  627. {
  628. $this->db->trans_commit();
  629. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  630. }
  631. else
  632. {
  633. $this->db->trans_rollback();
  634. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  635. }
  636. }
  637. }
  638. public function _operate()
  639. {
  640. $post = $this->input->post(NULL, TRUE);
  641. if(isset($post['page']))
  642. {
  643. $api = $this->input->post('api',true);
  644. $page = $this->input->post('page',true);
  645. $perpage = $this->input->post('perpage',true);
  646. $number = $this->input->post('number',true);
  647. $color = $this->input->post('color',true);
  648. $purchase = $this->input->post('purchase',true);
  649. $transfer = $this->input->post('transfer',true);
  650. $lx = $this->input->post('lx',true);
  651. $type = $this->input->post('type',true);
  652. $jiaji = $this->input->post('jiaji',true);
  653. $xztime = $this->input->post('xztime',true);
  654. $timetk = $this->input->post('timetk',true);
  655. $timetj = $this->input->post('timetj',true);
  656. $timetk = strtotime($timetk);
  657. $timetj = strtotime($timetj);
  658. $where = '1=1';
  659. if($number)
  660. {
  661. $where .= " and number = '$number'";
  662. }
  663. if($purchase)
  664. {
  665. $where .= " and purchase = '$purchase'";
  666. }
  667. if($color)
  668. {
  669. $where .= " and fpdata like '%-".$color."-%'";
  670. }
  671. if($lx)
  672. {
  673. if($lx == 1)
  674. {
  675. $where .= " and ordernumber = ''";
  676. }
  677. else
  678. {
  679. $where .= " and ordernumber != ''";
  680. }
  681. }
  682. if($jiaji){
  683. if($jiaji == 1){
  684. $where .= " and is_jiaji = 0";
  685. }
  686. if($jiaji == 2){
  687. $where .= " and is_jiaji = 2";
  688. }
  689. }
  690. //数据排序
  691. $order_str = "id desc";
  692. if(empty($page))
  693. {
  694. $start = 0;
  695. $perpage = 1;
  696. }
  697. else
  698. {
  699. $start = ($page - 1)*$perpage;
  700. }
  701. if($xztime == 'printtime')
  702. {
  703. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  704. if($type)
  705. {
  706. $type = ($type==1)?'rk':'ck';
  707. if($transfer)
  708. {
  709. $where .= " and $type like '%|".$transfer."|%'";
  710. }
  711. }
  712. else
  713. {
  714. if($transfer)
  715. {
  716. $where .= " and rk like '%|".$transfer."|%'";
  717. }
  718. }
  719. }
  720. else
  721. {
  722. $cr = "time > '$timetk' and time < '$timetj'";
  723. if($transfer)
  724. {
  725. $cr .= " and lx = '".$transfer."'";
  726. }
  727. if($type)
  728. {
  729. $cr .= " and type = '".$type."'";
  730. }
  731. $fid = '';
  732. $info_list_cr = $this->systemtransfer_cr->find_all($cr);
  733. foreach ($info_list_cr as $v)
  734. {
  735. $fid .= "id = '".$v['fid']."' or ";
  736. }
  737. if($fid)
  738. {
  739. $where .= ' and ('.trim($fid,'or ').')';
  740. }
  741. else
  742. {
  743. $where .= ' and id = 0';
  744. }
  745. }
  746. //取得信息列表
  747. $info_list = $this->systemtransfer->find_all($where,'id,number,is_jiaji,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  748. $transfer = $this->transfer->find_all();
  749. $t = array();
  750. foreach ($transfer as $v)
  751. {
  752. $t[$v['id']] = $v['title'];
  753. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  754. }
  755. //格式化数据
  756. foreach ($info_list as $key=>$value)
  757. {
  758. if($value['is_jiaji'] == 2){
  759. $info_list[$key]['is_jiaji'] = "<a href='javascript:void(0)' style='color:red'>加急</a>";
  760. }else{
  761. $info_list[$key]['is_jiaji'] = "常规";
  762. }
  763. $dd = $this->systemtransfer->read($value['id']);
  764. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  765. $rk = explode('|',trim($dd['rk'],'|'));
  766. $rktime = explode('|',trim($dd['rktime'],'|'));
  767. $ck = explode('|',trim($dd['ck'],'|'));
  768. $cktime = explode('|',trim($dd['cktime'],'|'));
  769. $info_list[$key]['time'] = '';
  770. $data = $this->systemtransfer_cr->find_all("fid = '".$value['id']."'");
  771. /**
  772. for($i=0;$i<count($rk);$i++)
  773. {
  774. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  775. {
  776. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  777. }
  778. else
  779. {
  780. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  781. }
  782. $info_list[$key]['time'] .= $d;
  783. if(isset($ck[$i]) && $ck[$i] != '')
  784. {
  785. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  786. }
  787. }
  788. **/
  789. $info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$value['printtime']).'<br>';
  790. foreach ($data as $k=>$v)
  791. {
  792. // $type = ($v['type']==1)?'入库':'出库';
  793. // $info_list[$key]['time'] .= $t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']).'<br>';
  794. $type = ($v['type']==1)?'入库':'出库';
  795. if($v['orver_flag'] == 1){
  796. if($v['is_over'] == 0){
  797. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#90f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='font-weight:900;'>即将超时 </l></a>".'<br>';
  798. // $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';
  799. }else{
  800. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';
  801. }
  802. }elseif($v['orver_flag'] == 2){
  803. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#f33'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l font-weight:900'>超时! </l></a>".'<br>';
  804. }elseif($v['orver_flag'] == 3){
  805. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#06f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l font-weight:900'>【该单已取消】 </l></a>".'<br>';
  806. }else{
  807. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';
  808. }
  809. }
  810. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  811. }
  812. $total = $this->systemtransfer->find_count($where);
  813. $pagenum = ceil($total/$perpage);
  814. $over = $total-($start+$perpage);
  815. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  816. echo json_encode($rows);exit;
  817. }
  818. if(isset($_SESSION['api']))
  819. {
  820. $user = $this->user->get_api($_SESSION['api']);
  821. $usp = $user;
  822. $pid = "";$tid="";$sid="";$wid="";
  823. $purchase = explode('|',trim($user['purchase'],'|'));
  824. $transfer = explode('|',trim($user['transfer'],'|'));
  825. $warehouse = explode('|',trim($user['warehouse'],'|'));
  826. foreach ($purchase as $value)
  827. {
  828. $pid .= " id = ".$value." or";
  829. }
  830. foreach ($transfer as $value)
  831. {
  832. $tid .= " id = ".$value." or";
  833. }
  834. foreach ($warehouse as $value)
  835. {
  836. $wid .= " id = ".$value." or";
  837. }
  838. }
  839. else
  840. {
  841. header('Location: /');exit;
  842. }
  843. $kx = '';$zjtab = '';
  844. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  845. $this->data['warehouse'] = $warehouse;
  846. $purchase = $this->purchase->find_all("yyid != ''");
  847. $this->data['purchase'] = $purchase;
  848. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  849. $this->data['transfer'] = $transfer;
  850. $this->data['vip'] = $user['vip'];
  851. $transfer_ids = array_column($transfer,'id');
  852. $transfer_str = implode(",",$transfer_ids);
  853. $this->data['cz_1_num'] = $this->systemtransfer_cr->find_count("orver_flag = 1 and is_over = 0 and time > ".(time()-3600*24*7) ." and lx in (".$transfer_str.")");
  854. $this->data['cz_2_num'] = $this->systemtransfer_cr->find_count("orver_flag = 2 and is_over = 0 and time > ".(time()-3600*24*7) ." and lx in (".$transfer_str.")");
  855. $jiaji_num = 0;
  856. $jiaji_num = $this->systemtransfer->find_count(" is_jiaji = 2 and time > ".(time()-3600*24*7)." and rk not like '%|11|%'" );
  857. $this->data['jiaji_num'] = $jiaji_num;
  858. $this->_Template('transfer_operate',$this->data);
  859. }
  860. public function _out()
  861. {
  862. $post = $this->input->post(NULL, TRUE);
  863. if(isset($post['label']))
  864. {
  865. $time = time();
  866. $label = $this->input->post('label',true);
  867. $cz = $this->input->post('cz',true);
  868. $transfer = $this->input->post('transfer',true);
  869. if(!$label)
  870. {
  871. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  872. }
  873. if(!$transfer)
  874. {
  875. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  876. }
  877. $lb = $this->systemtransfer->get_label($label);
  878. if(!$lb)
  879. {
  880. echo json_encode(array('msg'=>'错误!未找到此条码','success'=>false));exit;
  881. }
  882. if($lb['number']!='')
  883. {
  884. $nu = $this->fullorder->get_number($lb['number']);
  885. if(!$nu)
  886. {
  887. $nu = $this->fullordersmt->get_number($lb['number']);
  888. if(!$nu)
  889. {
  890. $nu = $this->fullordertt->get_number($lb['number']);
  891. }
  892. }
  893. //取消的订单还是要继续生产的 所以还允许继续扫入扫出 只是后续的出入库中不在限定时间
  894. // if($nu['state'] == '214' || $nu['state'] == '217')
  895. // {
  896. // echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;
  897. // }
  898. }
  899. $tdata = $this->transfer->find_all();
  900. $t = array();
  901. foreach ($tdata as $v)
  902. {
  903. $t[$v['id']] = $v['title'];
  904. }
  905. /**
  906. if($cz == 1 && stripos($lb['rk'],'|'.$transfer.'|') !== false)
  907. {
  908. echo json_encode(array('msg'=>'此条码已有入库操作!','success'=>false));exit;
  909. }
  910. if($cz == 2 && stripos($lb['ck'],'|'.$transfer.'|') !== false)
  911. {
  912. echo json_encode(array('msg'=>'此条码已有出库操作!','success'=>false));exit;
  913. }
  914. **/
  915. // if(stripos($lb['ck'],'|1|') === false && $transfer != 1 && stripos($nu['fpdata'],'-128-') !== false)
  916. // {
  917. // echo json_encode(array('msg'=>'必须有配货出库才可后续操作!','success'=>false));exit;
  918. // }
  919. //重新定义配货的原则问题
  920. //先检测订单是否含有 128 头套 或者配件 如果有 133 进行下一步检测
  921. $sku_arr = explode("-",$lb['features']);
  922. if(in_array(128,$sku_arr)||in_array(133,$sku_arr)){
  923. // 145 Full Lace Wig
  924. // 1170 HDFullLaceWig
  925. // 1249 FullLaceBobwithBang
  926. // 1484 FullLaceBob
  927. //如果是这4中全蕾丝那么配货就不处理
  928. if(in_array(145,$sku_arr) || in_array(1170,$sku_arr) || in_array(1249,$sku_arr) || in_array(1484,$sku_arr)){
  929. }else{
  930. if(stripos($lb['ck'],'|1|') === false && $transfer != 1 )
  931. {
  932. echo json_encode(array('msg'=>'头套和配件除了全蕾丝外必须走配货!','success'=>false));exit;
  933. }
  934. }
  935. }
  936. if($cz == 2 && stripos($lb['rk'],'|'.$transfer.'|') === false)
  937. {
  938. echo json_encode(array('msg'=>'此条码还未入库!','success'=>false));exit;
  939. }
  940. $lbrk = array_reverse(explode('|',trim($lb['rk'],'|')));
  941. $lbck = array_reverse(explode('|',trim($lb['ck'],'|')));
  942. if($transfer != 3 && $transfer != 11 && $transfer != 2)
  943. {
  944. if($cz == 1)
  945. {
  946. if($lb['rk'] != $lb['ck'])//判断是否没走完流程就拿到下一步奏
  947. {
  948. echo json_encode(array('msg'=>$t[$lbrk[0]].'还未出库,无法入库!','success'=>false));exit;
  949. }
  950. }
  951. if($cz == 2 && $lbrk[0] != $transfer)//判断是否没走完流程就拿到下一步奏
  952. {
  953. echo json_encode(array('msg'=>$t[$transfer].'还未入库,无法出库!','success'=>false));exit;
  954. }
  955. }
  956. if($cz == 1)
  957. {
  958. $lb['rk'] .= $transfer.'|';
  959. $lb['rktime'] .= $time.'|';
  960. if($lbrk[0] == $transfer)
  961. {
  962. echo json_encode(array('msg'=>'已有入库记录,不可连续重复录入!','success'=>false));exit;
  963. }
  964. }
  965. else if($cz == 2)
  966. {
  967. $lb['ck'] .= $transfer.'|';
  968. $lb['cktime'] .= $time.'|';
  969. if($lbck[0] == $transfer)
  970. {
  971. echo json_encode(array('msg'=>'已有出库记录,不可连续重复录入!','success'=>false));exit;
  972. }
  973. }
  974. $cztime = 'ctime'.$transfer;
  975. if(($transfer == 3 && $lb['dbapi'] < 99 && $cz == 2) || ($transfer == 13 && $lb['dbapi'] < 99 && $cz == 1))//出入库用这个
  976. //if(($transfer == 8 || $transfer == 13) && $lb['dbapi'] < 99 && $cz == 1)//单入库
  977. {
  978. if($lb['type'] == 0)
  979. {
  980. $s = $this->shop->read($nu['shop']);
  981. $lb['kh'] = $s['yyid'];
  982. $lb['ts'] = 1;
  983. $rk = $this->apiyy->_newrk($lb);
  984. if($rk['c'] == 0)
  985. {
  986. $this->db->trans_begin();
  987. $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']);
  988. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  989. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  990. if($cz == 2){
  991. $this->_doCheckIsOverTime($lb['id'],$transfer);
  992. }
  993. if ($this->db->trans_status() === TRUE)
  994. {
  995. $this->db->trans_commit();
  996. if($nu['state'] == '216')
  997. {
  998. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  999. }
  1000. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  1001. //标记订单已经取消
  1002. $this->_doCheckCancelFlag($lb['id']);
  1003. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  1004. }
  1005. else
  1006. {
  1007. if($lb['is_jiaji'] == 2){
  1008. echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;
  1009. }else{
  1010. echo json_encode(array('music'=>'1','success'=>true));exit;
  1011. }
  1012. }
  1013. }
  1014. else
  1015. {
  1016. $this->db->trans_rollback();
  1017. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1018. }
  1019. }
  1020. else
  1021. {
  1022. if(stripos($rk['error'],'DocNo') !== false)
  1023. {
  1024. $rk['error'] = '未找到对应的生产订单 '.$lb['scid'];
  1025. }
  1026. $this->systemtransfer->save(array('dbapi'=>$rk['dbapi'],'scid'=>$rk['scid']),$lb['id']);
  1027. echo json_encode(array('msg'=>'订单号:'.$lb['number'].' 用友报错:'.$rk['error'],'success'=>false));exit;
  1028. }
  1029. }
  1030. else
  1031. {
  1032. $scid = explode('~',$lb['scid']);
  1033. $rkdata = array('od'=>$scid[1],'ts'=>1,'title'=>$lb['title']);
  1034. $rk = $this->apiyy->get_bzsh($rkdata);
  1035. if(isset($rk['Data'][0]))
  1036. {
  1037. if($rk['Data'][0]['IsSucess'] == 1)
  1038. {
  1039. $this->db->trans_begin();
  1040. $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']);
  1041. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  1042. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  1043. if($cz == 2){
  1044. $this->_doCheckIsOverTime($lb['id'],$transfer);
  1045. }
  1046. if ($this->db->trans_status() === TRUE)
  1047. {
  1048. $this->db->trans_commit();
  1049. if($nu['state'] == '216')
  1050. {
  1051. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  1052. }
  1053. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  1054. //标记订单已经取消
  1055. $this->_doCheckCancelFlag($lb['id']);
  1056. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  1057. }
  1058. else
  1059. {
  1060. if($lb['is_jiaji'] == 2){
  1061. echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;
  1062. }else{
  1063. echo json_encode(array('music'=>'1','success'=>true));exit;
  1064. }
  1065. }
  1066. }
  1067. else
  1068. {
  1069. $this->db->trans_rollback();
  1070. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1071. }
  1072. }
  1073. else
  1074. {
  1075. echo json_encode(array('msg'=>$rk['Data'][0]['ErrorMsg'],'success'=>false));exit;
  1076. }
  1077. }
  1078. else
  1079. {
  1080. echo json_encode(array('msg'=>$rk,'success'=>false));exit;
  1081. }
  1082. }
  1083. }
  1084. //if($transfer == 11 && stripos($lb['rk'],'|8|') === false && stripos($lb['ck'],'|3|') === false && stripos($lb['rk'],'|13|') === false)//只入库
  1085. if($transfer == 11 && stripos($lb['ck'],'|3|') === false && stripos($lb['rk'],'|13|') === false)//改出入库
  1086. {
  1087. echo json_encode(array('msg'=>'工厂未出库,请退回工厂!','success'=>false));exit;
  1088. }
  1089. $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']);
  1090. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  1091. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  1092. if($cz == 2){
  1093. $this->_doCheckIsOverTime($lb['id'],$transfer);
  1094. }
  1095. if ($this->db->trans_status() === TRUE)
  1096. {
  1097. $this->db->trans_commit();
  1098. if($nu['state'] == '216')
  1099. {
  1100. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  1101. }
  1102. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  1103. //标记订单已经取消
  1104. $this->_doCheckCancelFlag($lb['id']);
  1105. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  1106. }
  1107. else
  1108. {
  1109. if($lb['is_jiaji'] == 2){
  1110. echo json_encode(array('music'=>'1','is_jiaji'=>2,'success'=>true));exit;
  1111. }else{
  1112. echo json_encode(array('music'=>'1','success'=>true));exit;
  1113. }
  1114. }
  1115. }
  1116. else
  1117. {
  1118. $this->db->trans_rollback();
  1119. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1120. }
  1121. }
  1122. }
  1123. //检测取消标记是否添加 同时也检查下 该流转单是否被标记为取消单
  1124. private function _doCheckCancelFlag($fid){
  1125. $info = $this->systemtransfer->read($fid);
  1126. if($info['status'] != 11){
  1127. $this->systemtransfer->save(['status'=>11],$fid);
  1128. }
  1129. $list = $this->systemtransfer_cr->find_all("fid = ".$fid,'*','id desc');
  1130. if(empty($list)){
  1131. return;
  1132. }
  1133. $is_cancel = false;
  1134. foreach($list as $val){
  1135. if($val['orver_flag'] == 3){
  1136. $is_cancel = true;
  1137. }
  1138. }
  1139. if($is_cancel){
  1140. return ;
  1141. }
  1142. $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);
  1143. }
  1144. //检测是否超时 车间流转环节
  1145. private function _doCheckIsOverTime($fid,$transfer){
  1146. $list = $this->systemtransfer_cr->find_all("fid = ".$fid." and lx = ".$transfer." and is_over = 0","*",'id desc',0,2);
  1147. if(count($list) < 2){
  1148. return ;
  1149. }
  1150. if($list[0]['type'] != 2){
  1151. return;
  1152. }
  1153. if($list[1]['type'] != 1){
  1154. return;
  1155. }
  1156. if($list[1]['orver_flag'] == 2){
  1157. $this->systemtransfer_cr->save(array('is_over'=>1,'orver_flag'=>2),$list[0]['id']);
  1158. }else{
  1159. $this->systemtransfer_cr->save(array('is_over'=>1),$list[0]['id']);
  1160. }
  1161. $this->systemtransfer_cr->save(array('is_over'=>1),$list[1]['id']);
  1162. }
  1163. public function _bdbb()
  1164. {
  1165. $post = $this->input->post(NULL, TRUE);
  1166. if(isset($post['s']))
  1167. {
  1168. $id_arr = $this->input->post('s');
  1169. $id_arr = explode(',',trim($id_arr,','));
  1170. if(!$id_arr)
  1171. {
  1172. echo json_encode(array('msg'=>$v.' - 未查询到需要补打信息!','success'=>false));exit;
  1173. }
  1174. //循环删除记录
  1175. foreach ($id_arr as $v)
  1176. {
  1177. $t = $this->systemtransfer->read($v);
  1178. if(!isset($t['number']))
  1179. {
  1180. echo json_encode(array('msg'=>$v.' - 补打信息已被删除!','success'=>false));exit;
  1181. }
  1182. $y = $this->fullorder->get_number($t['number']);
  1183. if(!$y)
  1184. {
  1185. $y = $this->fullordersmt->get_number($t['number']);
  1186. if(!$y)
  1187. {
  1188. $y = $this->fullordertt->get_number($t['number']);
  1189. if(!$y)
  1190. {
  1191. echo json_encode(array('msg'=>$t['number'].'没有找到此订单','success'=>false));exit;
  1192. }
  1193. }
  1194. }
  1195. $express = $this->express->read($y['express']);
  1196. $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'=>"补打");
  1197. }
  1198. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  1199. }
  1200. }
  1201. public function _excel()
  1202. {
  1203. if(isset($_GET['fexcel']))
  1204. {
  1205. $tc = array();$zh = array();
  1206. $typeclass = $this->typeclass->find_all();
  1207. foreach ($typeclass as $v)
  1208. {
  1209. $tc[$v['id']] = $v;
  1210. }
  1211. $number = $this->input->get('number',true);
  1212. $color = $this->input->get('color',true);
  1213. $gs = $this->input->get('gs',true);
  1214. $transfer = $this->input->get('transfer',true);
  1215. $type = $this->input->get('type',true);
  1216. $timetk = $this->input->get('timetk',true);
  1217. $timetj = $this->input->get('timetj',true);
  1218. $purchase = $this->input->get('purchase',true);
  1219. $lx = $this->input->get('lx',true);
  1220. $timetk = strtotime($timetk);
  1221. $timetj = strtotime($timetj);
  1222. $where = "1=1";
  1223. $cr = "time > '$timetk' and time < '$timetj'";
  1224. if($number)
  1225. {
  1226. $where .= " and number = '$number'";
  1227. }
  1228. if($transfer)
  1229. {
  1230. $cr .= " and lx = '".$transfer."'";
  1231. }
  1232. if($type)
  1233. {
  1234. $cr .= " and type = '".$type."'";
  1235. }
  1236. if($purchase)
  1237. {
  1238. $where .= " and purchase = '$purchase'";
  1239. }
  1240. if($color)
  1241. {
  1242. $where .= " and fpdata like '%-".$color."-%'";
  1243. }
  1244. if($lx)
  1245. {
  1246. if($lx == 1)
  1247. {
  1248. $where .= " and ordernumber = ''";
  1249. }
  1250. else
  1251. {
  1252. $where .= " and ordernumber != ''";
  1253. }
  1254. }
  1255. $fid = '';
  1256. $info_list_cr = $this->systemtransfer_cr->find_all($cr);
  1257. foreach ($info_list_cr as $v)
  1258. {
  1259. $fid .= "id = '".$v['fid']."' or ";
  1260. }
  1261. if($fid)
  1262. {
  1263. $where .= ' and ('.trim($fid,'or ').')';
  1264. }
  1265. else
  1266. {
  1267. $where .= ' and id = 0';
  1268. }
  1269. $data = array();
  1270. $datafy = array();
  1271. $j = 0;
  1272. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,jm,shipremarks,printtime');
  1273. $lzbm = $this->transfer->find_all();
  1274. foreach ($info_list as $key=>$value)
  1275. {
  1276. $dj = '';$ys = '';$cc = '';$hx = '';$md = '';
  1277. $d = $this->systemtransfer->read($value['id']);
  1278. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1279. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$d['shipremarks']);
  1280. $d['features'] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$d['features']);
  1281. $cp = explode('-',trim($d['features'],'-'));
  1282. $rk = explode('|',trim($d['rk'],'|'));
  1283. $rktime = explode('|',trim($d['rktime'],'|'));
  1284. foreach ($cp as $v)
  1285. {
  1286. if(isset($tc[$v]))
  1287. {
  1288. if($tc[$v]['classid'] == 13)
  1289. {
  1290. $dj = $tc[$v]['title'];
  1291. }
  1292. else if($tc[$v]['classid'] == 8)
  1293. {
  1294. $ys = $tc[$v]['title'];
  1295. }
  1296. else if($tc[$v]['classid'] == 14)
  1297. {
  1298. $cc = $tc[$v]['title'];
  1299. }
  1300. else if($tc[$v]['classid'] == 15)
  1301. {
  1302. $hx = $tc[$v]['title'];
  1303. }
  1304. else if($tc[$v]['classid'] == 10)
  1305. {
  1306. $md = $tc[$v]['title'];
  1307. }
  1308. }
  1309. }
  1310. $rt = array();
  1311. foreach ($rk as $k=>$v)
  1312. {
  1313. $rt[$v+5] = date('Y-m-d H:i:s',$rktime[$k]);
  1314. }
  1315. $fpdata = array(array('0'=>$d['title'],'1'=>$cc,'2'=>$dj,'3'=>$ys,'4'=>$hx,'5'=>$md));
  1316. foreach ($lzbm as $v)
  1317. {
  1318. if(isset($rt[count($fpdata[0])]))
  1319. {
  1320. //$fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1321. $num = $this->systemtransfer_cr->find_count("fid = ".$value['id']." and lx = ".$v['id']." and orver_flag = 2");
  1322. if($num > 0){
  1323. $fpdata[0][count($fpdata[0])] = "<span style='color:red;font-weight:bold;'>".$rt[count($fpdata[0])]."<span>";
  1324. }else{
  1325. $fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1326. }
  1327. }
  1328. else
  1329. {
  1330. $fpdata[0][count($fpdata[0])] = '';
  1331. }
  1332. }
  1333. $info_list[$key]['fpdata'] = $fpdata;//名称,尺寸,等级,颜色,花型,密度
  1334. unset($info_list[$key]['id']);
  1335. }
  1336. //echo "<pre>";print_r($info_list);exit;
  1337. $lzxq = '';
  1338. foreach ($lzbm as $v)
  1339. {
  1340. $lzxq .= '<td>'.$v['title'].'</td>';
  1341. }
  1342. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 统计表';
  1343. $titlename = "<table border=1>
  1344. <tr>
  1345. <td>订单编号</td>
  1346. <td>品名</td>
  1347. <td>简码</td>
  1348. <td>备注</td>
  1349. <td>打印时间</td>
  1350. <td>
  1351. <table border=1>
  1352. <tr><td colspan='6' align='center'>订单产品信息</td><td colspan='".count($lzbm)."' align='center'>货物流转时间</td></tr>
  1353. <tr>
  1354. <td>产品名称</td>
  1355. <td>尺寸</td>
  1356. <td>等级</td>
  1357. <td>颜色</td>
  1358. <td>花型</td>
  1359. <td>密度</td>
  1360. ".$lzxq."
  1361. </tr>
  1362. </table>
  1363. </td>
  1364. </tr>
  1365. </table>";
  1366. $filename = $title.".xls";
  1367. $tail = "\n";
  1368. $this->excel->get_fz($info_list,$titlename,$filename,$tail,1);
  1369. }
  1370. }
  1371. public function _rk()
  1372. {
  1373. $post = $this->input->post(NULL, TRUE);
  1374. if(isset($post['page']))
  1375. {
  1376. $api = $this->input->post('api',true);
  1377. $page = $this->input->post('page',true);
  1378. $perpage = $this->input->post('perpage',true);
  1379. $number = $this->input->post('number',true);
  1380. $color = $this->input->post('color',true);
  1381. $purchase = $this->input->post('purchase',true);
  1382. $transfer = $this->input->post('transfer',true);
  1383. $lx = $this->input->post('lx',true);
  1384. $timetk = $this->input->post('timetk',true);
  1385. $timetj = $this->input->post('timetj',true);
  1386. $timetk = strtotime($timetk);
  1387. $timetj = strtotime($timetj);
  1388. $where = "1=1";
  1389. if($transfer)
  1390. {
  1391. $ctime = 'ctime'.$transfer;
  1392. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  1393. }
  1394. else
  1395. {
  1396. $where .= " and time > '$timetk' and time < '$timetj'";
  1397. }
  1398. if($number)
  1399. {
  1400. $where .= " and number = '$number'";
  1401. }
  1402. if($transfer)
  1403. {
  1404. $where .= " and rk like '%|".$transfer."|%'";
  1405. }
  1406. if($purchase)
  1407. {
  1408. $where .= " and purchase = '$purchase'";
  1409. }
  1410. if($color)
  1411. {
  1412. $where .= " and fpdata like '%-".$color."-%'";
  1413. }
  1414. if($lx)
  1415. {
  1416. if($lx == 1)
  1417. {
  1418. $where .= " and ordernumber = ''";
  1419. }
  1420. else
  1421. {
  1422. $where .= " and ordernumber != ''";
  1423. }
  1424. }
  1425. //数据排序
  1426. $order_str = "id desc";
  1427. if(empty($page))
  1428. {
  1429. $start = 0;
  1430. $perpage = 1;
  1431. }
  1432. else
  1433. {
  1434. $start = ($page - 1)*$perpage;
  1435. }
  1436. //取得信息列表
  1437. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  1438. $transfer = $this->transfer->find_all();
  1439. $t = array();
  1440. foreach ($transfer as $v)
  1441. {
  1442. $t[$v['id']] = $v['title'];
  1443. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  1444. }
  1445. //格式化数据
  1446. foreach ($info_list as $key=>$value)
  1447. {
  1448. $dd = $this->systemtransfer->read($value['id']);
  1449. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1450. $rk = explode('|',trim($dd['rk'],'|'));
  1451. $rktime = explode('|',trim($dd['rktime'],'|'));
  1452. $ck = explode('|',trim($dd['ck'],'|'));
  1453. $cktime = explode('|',trim($dd['cktime'],'|'));
  1454. $info_list[$key]['time'] = '';
  1455. for($i=0;$i<count($rk);$i++)
  1456. {
  1457. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  1458. {
  1459. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  1460. }
  1461. else
  1462. {
  1463. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  1464. }
  1465. $info_list[$key]['time'] .= $d;
  1466. if(isset($ck[$i]) && $ck[$i] != '')
  1467. {
  1468. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  1469. }
  1470. }
  1471. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1472. }
  1473. $total = $this->systemtransfer->find_count($where);
  1474. $pagenum = ceil($total/$perpage);
  1475. $over = $total-($start+$perpage);
  1476. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);
  1477. echo json_encode($rows);exit;
  1478. }
  1479. if(isset($_SESSION['api']))
  1480. {
  1481. $user = $this->user->get_api($_SESSION['api']);
  1482. $usp = $user;
  1483. $pid = "";$tid="";$sid="";$wid="";
  1484. $purchase = explode('|',trim($user['purchase'],'|'));
  1485. $transfer = explode('|',trim($user['transfer'],'|'));
  1486. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1487. foreach ($purchase as $value)
  1488. {
  1489. $pid .= " id = ".$value." or";
  1490. }
  1491. foreach ($transfer as $value)
  1492. {
  1493. $tid .= " id = ".$value." or";
  1494. }
  1495. foreach ($warehouse as $value)
  1496. {
  1497. $wid .= " id = ".$value." or";
  1498. }
  1499. }
  1500. else
  1501. {
  1502. header('Location: /');exit;
  1503. }
  1504. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1505. $this->data['transfer'] = $transfer;
  1506. $this->_Template('transfer_rk',$this->data);
  1507. }
  1508. public function _ck()
  1509. {
  1510. $post = $this->input->post(NULL, TRUE);
  1511. if(isset($post['page']))
  1512. {
  1513. $api = $this->input->post('api',true);
  1514. $page = $this->input->post('page',true);
  1515. $perpage = $this->input->post('perpage',true);
  1516. $number = $this->input->post('number',true);
  1517. $color = $this->input->post('color',true);
  1518. $purchase = $this->input->post('purchase',true);
  1519. $transfer = $this->input->post('transfer',true);
  1520. $lx = $this->input->post('lx',true);
  1521. $timetk = $this->input->post('timetk',true);
  1522. $timetj = $this->input->post('timetj',true);
  1523. $timetk = strtotime($timetk);
  1524. $timetj = strtotime($timetj);
  1525. $where = "1=1";
  1526. if($transfer)
  1527. {
  1528. $ctime = 'ctime'.$transfer;
  1529. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  1530. }
  1531. else
  1532. {
  1533. $where .= " and time > '$timetk' and time < '$timetj'";
  1534. }
  1535. if($number)
  1536. {
  1537. $where .= " and number = '$number'";
  1538. }
  1539. if($transfer)
  1540. {
  1541. $where .= " and ck like '%|".$transfer."|%'";
  1542. }
  1543. if($purchase)
  1544. {
  1545. $where .= " and purchase = '$purchase'";
  1546. }
  1547. if($color)
  1548. {
  1549. $where .= " and fpdata like '%-".$color."-%'";
  1550. }
  1551. if($lx)
  1552. {
  1553. if($lx == 1)
  1554. {
  1555. $where .= " and ordernumber = ''";
  1556. }
  1557. else
  1558. {
  1559. $where .= " and ordernumber != ''";
  1560. }
  1561. }
  1562. //数据排序
  1563. $order_str = "id desc";
  1564. if(empty($page))
  1565. {
  1566. $start = 0;
  1567. $perpage = 1;
  1568. }
  1569. else
  1570. {
  1571. $start = ($page - 1)*$perpage;
  1572. }
  1573. //取得信息列表
  1574. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  1575. $transfer = $this->transfer->find_all();
  1576. $t = array();
  1577. foreach ($transfer as $v)
  1578. {
  1579. $t[$v['id']] = $v['title'];
  1580. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  1581. }
  1582. //格式化数据
  1583. foreach ($info_list as $key=>$value)
  1584. {
  1585. $dd = $this->systemtransfer->read($value['id']);
  1586. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1587. $rk = explode('|',trim($dd['rk'],'|'));
  1588. $rktime = explode('|',trim($dd['rktime'],'|'));
  1589. $ck = explode('|',trim($dd['ck'],'|'));
  1590. $cktime = explode('|',trim($dd['cktime'],'|'));
  1591. $info_list[$key]['time'] = '';
  1592. for($i=0;$i<count($rk);$i++)
  1593. {
  1594. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  1595. {
  1596. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  1597. }
  1598. else
  1599. {
  1600. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  1601. }
  1602. $info_list[$key]['time'] .= $d;
  1603. if(isset($ck[$i]) && $ck[$i] != '')
  1604. {
  1605. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  1606. }
  1607. }
  1608. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1609. }
  1610. $total = $this->systemtransfer->find_count($where);
  1611. $pagenum = ceil($total/$perpage);
  1612. $over = $total-($start+$perpage);
  1613. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);
  1614. echo json_encode($rows);exit;
  1615. }
  1616. if(isset($_SESSION['api']))
  1617. {
  1618. $user = $this->user->get_api($_SESSION['api']);
  1619. $usp = $user;
  1620. $pid = "";$tid="";$sid="";$wid="";
  1621. $purchase = explode('|',trim($user['purchase'],'|'));
  1622. $transfer = explode('|',trim($user['transfer'],'|'));
  1623. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1624. foreach ($purchase as $value)
  1625. {
  1626. $pid .= " id = ".$value." or";
  1627. }
  1628. foreach ($transfer as $value)
  1629. {
  1630. $tid .= " id = ".$value." or";
  1631. }
  1632. foreach ($warehouse as $value)
  1633. {
  1634. $wid .= " id = ".$value." or";
  1635. }
  1636. }
  1637. else
  1638. {
  1639. header('Location: /');exit;
  1640. }
  1641. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1642. $this->data['transfer'] = $transfer;
  1643. $this->_Template('transfer_ck',$this->data);
  1644. }
  1645. public function _jgl()
  1646. {
  1647. $post = $this->input->post(NULL, TRUE);
  1648. if(isset($post['printtime']))
  1649. {
  1650. $pt = $this->input->post('printtime',true);
  1651. $wt = $this->input->post('wgtime',true);
  1652. $printtime = strtotime($pt);
  1653. $wgtime = strtotime($wt);
  1654. $sy = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."'");
  1655. $wg = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."' and ctime11 < '$wgtime' and ctime11 != '0'");
  1656. if($printtime == $wgtime || $printtime > $wgtime)
  1657. {
  1658. echo json_encode(array('msg'=>"<p style='height:140px;line-height:140px'>时间选择错误</p>",'success'=>true));exit;
  1659. }
  1660. echo json_encode(array('msg'=>"<p style='height:140px;line-height:140px'>".(($wgtime-$printtime)/86400)."天 完工数量:".$wg.", 总数量:".$sy.", 完工率:".number_format(($wg/$sy*100),2)."%</p>",'success'=>true));exit;
  1661. }
  1662. $this->_Template('transfer_wgl',$this->data);
  1663. }
  1664. public function _linqi(){
  1665. $post = $this->input->post(NULL, TRUE);
  1666. if(isset($post['page']))
  1667. {
  1668. $api = $this->input->post('api',true);
  1669. $page = $this->input->post('page',true);
  1670. $perpage = $this->input->post('perpage',true);
  1671. $transfer = $this->input->post('transfer',true);
  1672. $transfer_ids = $this->input->post('transfer_ids',true);
  1673. $orver_flag = $this->input->post('orver_flag',true);
  1674. $timetk = $this->input->post('timetk',true);
  1675. $timetj = $this->input->post('timetj',true);
  1676. $timetk = strtotime($timetk);
  1677. $timetj = strtotime($timetj);
  1678. $transfer_list = $this->transfer->find_all();
  1679. $t = $transfer_list = array_column($transfer_list, 'title', 'id');
  1680. $where = 'type = 1 ';
  1681. $where .= " and is_over = 0 and orver_flag = ".$orver_flag." ";
  1682. //数据排序
  1683. $order_str = "id desc";
  1684. if(empty($page))
  1685. {
  1686. $start = 0;
  1687. $perpage = 1;
  1688. }
  1689. else
  1690. {
  1691. $start = ($page - 1)*$perpage;
  1692. }
  1693. if($transfer){
  1694. $where .= " and lx = '$transfer'";
  1695. }else{
  1696. $where .= " and lx in (".$transfer_ids.") ";
  1697. }
  1698. $where .= " and time > '$timetk' and time < '$timetj'";
  1699. $list = $this->systemtransfer_cr->find_all($where,'*',$order_str,$start,$perpage);
  1700. $final_list = [];
  1701. foreach ($list as $key => $value) {
  1702. $info = $this->systemtransfer->read($value['fid']);
  1703. $final_list[$key]['id'] = $value['id'];
  1704. $final_list[$key]['number'] = isset($info['number'])?$info['number']:'';
  1705. if($info['is_jiaji'] == 2){
  1706. $final_list[$key]['is_jiaji'] = "<a href='javascript:void(0)' style='color:red'>加急</a>";
  1707. }else{
  1708. $final_list[$key]['is_jiaji'] = "常规";
  1709. }
  1710. $final_list[$key]['pm'] = $info['pm'];
  1711. $final_list[$key]['shipremarks'] = $info['shipremarks'];
  1712. $final_list[$key]['printtime'] = date('Y-m-d H:i:s',$info['printtime']);
  1713. $data = $this->systemtransfer_cr->find_all("fid = '".$info['id']."'");
  1714. $info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$info['printtime']).'<br>';
  1715. foreach ($data as $k=>$v)
  1716. {
  1717. $type = ($v['type']==1)?'入库':'出库';
  1718. if($v['orver_flag'] == 1){
  1719. if($v['is_over'] == 0){
  1720. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#90f'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='padding-left:10px;font-weight:900;'> 即将超时 </l></a>".'<br>';
  1721. // $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';
  1722. }else{
  1723. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';
  1724. }
  1725. }elseif($v['orver_flag'] == 2){
  1726. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#f33'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ." <l style='padding-left:10px;font-weight:900'> 超 时 ! </l></a>".'<br>';
  1727. }else{
  1728. $info_list[$key]['time'] .= "<a href='javascript:void(0);' style='color:#000'>".$t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']) ."</a>".'<br>';
  1729. }
  1730. }
  1731. $final_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1732. }
  1733. $total = $this->systemtransfer_cr->find_count($where);
  1734. $pagenum = ceil($total/$perpage);
  1735. $over = $total-($start+$perpage);
  1736. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($final_list));
  1737. echo json_encode($rows);exit;
  1738. }
  1739. if(isset($_SESSION['api']))
  1740. {
  1741. $user = $this->user->get_api($_SESSION['api']);
  1742. $usp = $user;
  1743. $pid = "";$tid="";$sid="";$wid="";
  1744. $purchase = explode('|',trim($user['purchase'],'|'));
  1745. $transfer = explode('|',trim($user['transfer'],'|'));
  1746. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1747. foreach ($purchase as $value)
  1748. {
  1749. $pid .= " id = ".$value." or";
  1750. }
  1751. foreach ($transfer as $value)
  1752. {
  1753. $tid .= " id = ".$value." or";
  1754. }
  1755. foreach ($warehouse as $value)
  1756. {
  1757. $wid .= " id = ".$value." or";
  1758. }
  1759. }
  1760. else
  1761. {
  1762. header('Location: /');exit;
  1763. }
  1764. $kx = '';$zjtab = '';
  1765. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1766. $this->data['transfer'] = $transfer;
  1767. $transfer_ids = array_column($transfer, 'id');
  1768. $this->data['transfer_ids'] =implode(",",$transfer_ids) ;
  1769. $this->data['vip'] = $user['vip'];
  1770. $this->data['orver_flag'] = $this->input->get('orver_flag', TRUE);
  1771. $this->_Template('transfer_linqi',$this->data);
  1772. }
  1773. //按照条件导出超时车间
  1774. public function _overtime_export(){
  1775. $transfer_id = $this->input->get('transfer', TRUE);
  1776. $timetk = $this->input->get('timetk', TRUE);
  1777. $timetj = $this->input->get('timetj', TRUE);
  1778. $timetk = strtotime($timetk);
  1779. $timetj = strtotime($timetj);
  1780. if(isset($_SESSION['api']))
  1781. {
  1782. $user = $this->user->get_api($_SESSION['api']);
  1783. $transfer_ids = explode('|',trim($user['transfer'],'|'));
  1784. $tmp_transfer_list = $this->transfer->find_all();
  1785. $transfer_list = array_column($tmp_transfer_list, 'title', 'id');
  1786. }
  1787. else
  1788. {
  1789. header('Location: /');exit;
  1790. }
  1791. $where = " orver_flag = 2 and type = 1";
  1792. if(empty($transfer_id)){
  1793. $where .= " and lx in (".implode(',',$transfer_ids).") ";
  1794. }else{
  1795. $where .= " and lx = ".$transfer_id." ";
  1796. }
  1797. $where .= " and time > '$timetk' and time < '$timetj'";
  1798. $list = $this->systemtransfer_cr->find_all($where,'*');
  1799. $fid_list = array_column($list, 'fid');
  1800. if(empty($fid_list)){
  1801. echo "没有数据" ;
  1802. die ;
  1803. }
  1804. $order_list = $this->systemtransfer->find_all("id in (".implode(',',$fid_list).")");
  1805. $where_two = " orver_flag = 2 and type = 2";
  1806. if(empty($transfer_id)){
  1807. $where_two .= " and lx in (".implode(',',$transfer_ids).") ";
  1808. }else{
  1809. $where_two .= " and lx = ".$transfer_id." ";
  1810. }
  1811. $where_two .= " and time > '$timetk' and time < '$timetj'";
  1812. $list_two = $this->systemtransfer_cr->find_all($where_two,'*');
  1813. $final_list = [];
  1814. // foreach($list as $k => $v){
  1815. // $final_list[$v['fid']]['fid'] = $v['fid'];
  1816. // $final_list[$v['fid']]['lx'] = $v['lx'];
  1817. // $final_list[$v['fid']]['start_type'] = $v['type'];
  1818. // $final_list[$v['fid']]['start_time'] = date('Y-m-d H:i:s',$v['time']);
  1819. // $final_list[$v['fid']]['condition'] = json_decode($v['limit_time_str'],true);
  1820. // $final_list[$v['fid']]['end_time'] = "";
  1821. // $final_list[$v['fid']]['lx_name'] = isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'';
  1822. // }
  1823. // foreach($order_list as $k=>$v){
  1824. // if(isset($final_list[$v['id']])){
  1825. // $final_list[$v['id']]['number'] = $v['number'];
  1826. // $final_list[$v['id']]['pm'] = $v['pm'];
  1827. // }
  1828. // }
  1829. // foreach($list_two as $k => $v){
  1830. // if(isset($final_list[$v['fid']])){
  1831. // if($v['lx'] ==$final_list[$v['fid']]['lx']){
  1832. // $final_list[$v['fid']]['end_time'] = date('Y-m-d H:i:s',$v['time']);
  1833. // }
  1834. // }
  1835. // }
  1836. foreach($list as $k => $v){
  1837. $final_list[] = [
  1838. 'fid' => $v['fid'],
  1839. 'lx' => $v['lx'],
  1840. 'start_type' => $v['type'],
  1841. 'start_time' => date('Y-m-d H:i:s',$v['time']),
  1842. 'condition' => json_decode($v['limit_time_str'],true),
  1843. 'end_time' => "",
  1844. 'lx_name' => isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'',
  1845. ];
  1846. }
  1847. foreach($order_list as $k=>$v){
  1848. foreach($final_list as $kk => $vv){
  1849. if($v['id'] == $vv['fid']){
  1850. $final_list[$kk]['number'] = $v['number'];
  1851. $final_list[$kk]['pm'] = $v['pm'];
  1852. }
  1853. }
  1854. }
  1855. foreach($list_two as $k => $v){
  1856. foreach($final_list as $kk => $vv){
  1857. if(($v['fid'] == $vv['fid']) && ($v['lx'] == $vv['lx'])){
  1858. $final_list[$kk]['end_time'] = date('Y-m-d H:i:s',$v['time']);
  1859. }
  1860. }
  1861. }
  1862. $filename = date("Y-m-d")."超时单导出.xls";
  1863. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1864. <head>
  1865. <!--[if gte mso 9]><xml>
  1866. <x:ExcelWorkbook>
  1867. <x:ExcelWorksheets>
  1868. <x:ExcelWorksheet>
  1869. <x:Name>EXCEL</x:Name>
  1870. <x:WorksheetOptions>
  1871. <x:Print>
  1872. <x:ValidPrinterInfo />
  1873. </x:Print>
  1874. </x:WorksheetOptions>
  1875. </x:ExcelWorksheet>
  1876. </x:ExcelWorksheets>
  1877. </x:ExcelWorkbook>
  1878. </xml>
  1879. <![endif]-->
  1880. </head><body>";
  1881. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1882. $str .= "<tr><td>订单编号</td><td>品名</td><td>车间</td><td>入库日期</td><td>出库日期</td></tr>";
  1883. foreach ($final_list as $key=>$value)
  1884. {
  1885. $str .= "<tr>";
  1886. $str .= "<td>". $value['number']. "</td>";
  1887. $str .= "<td>". $value['pm']. "</td>";
  1888. $str .= "<td>". $value['lx_name']. "</td>";
  1889. $str .= "<td>". $value['start_time']. "</td>";
  1890. $str .= "<td>". $value['end_time']. "</td>";
  1891. $str .= "</tr>";
  1892. }
  1893. $str .= "</table></body></html>";
  1894. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1895. header( "Content-type: application/octet-stream" );
  1896. header( "Content-Disposition: attachment; filename=".$filename );
  1897. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1898. header( "Pragma: no-cache" );
  1899. header( "Expires: 0" );
  1900. exit($str);
  1901. }
  1902. }