Transfer.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934
  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. $zps = $this->input->post('zps',true);
  558. $post['purchase'] = $this->input->post('purchase',true);//供应商
  559. $post['time'] = $time;//操作时间
  560. $post['jm'] = $data['jm'];
  561. $post['bm'] = $data['bm'];
  562. $post['pm'] = $data['pm'];
  563. $post['features'] = $data['features'];
  564. $post['number'] = $data['number'];
  565. $post['title'] = $data['title'];
  566. $post['sku'] = $data['sku'];
  567. $post['printtime'] = $y['printtime'];
  568. $post['rk'] = "|12|";//默认订单中心 打印后直接入库
  569. $post['ck'] = "|12|";
  570. $post['rktime'] = "|".$time."|";
  571. $post['cktime'] = $post['rktime'];
  572. $post['ctime12'] = $time;
  573. $express = $this->express->read($y['express']);
  574. $rows = array();$t='';
  575. $this->db->trans_begin();
  576. $post['xbqnum'] = $xbqnum;
  577. $kh = $this->shop->read($y['shop']);
  578. $yy = $this->apiyy->_peihuo($post,$kh['yyid'],$y['number'],$post['xbqnum']);
  579. if($yy['c'] == 0)
  580. {
  581. $post['scapi'] = '99';
  582. $post['scid'] = $yy['scid'];
  583. if(!$post['purchase'])
  584. {
  585. $post['purchase'] = '';
  586. }
  587. $mqsl = $this->systemtransfer->find_count("number = '".$data['number']."'");
  588. //able_ext 实在打印小单布标时判断是否可以打印备货单
  589. $able_ext = 0;
  590. $tmp_fetaures = explode('-',$data['features']);
  591. //只有头套和马尾才会要配货单
  592. if(in_array(128, $tmp_fetaures)){
  593. $able_ext = 1;
  594. }
  595. if(in_array(133, $tmp_fetaures)){
  596. if(in_array(673, $tmp_fetaures)){
  597. $able_ext = 1;
  598. }
  599. }
  600. for($i=0;$i<$xbqnum;$i++)
  601. {
  602. if($post['zps'])
  603. {
  604. if($post['zps'] > 0)
  605. {
  606. $t = '总量:'.($mqsl+$i+1).'/'.$zps;
  607. }
  608. }
  609. $label = substr($time,1)*100;
  610. $post['label'] = $label+$i;
  611. $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);
  612. $this->systemtransfer->insert($post);
  613. }
  614. }
  615. else
  616. {
  617. $this->db->trans_rollback();
  618. echo json_encode(array('msg'=>$yy['error'],'a'=>1,'success'=>false));exit;
  619. }
  620. if($this->db->trans_status() === TRUE)
  621. {
  622. $this->db->trans_commit();
  623. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  624. }
  625. else
  626. {
  627. $this->db->trans_rollback();
  628. echo json_encode(array('msg'=>'错误,请重试!','success'=>false));exit;
  629. }
  630. }
  631. }
  632. public function _operate()
  633. {
  634. $post = $this->input->post(NULL, TRUE);
  635. if(isset($post['page']))
  636. {
  637. $api = $this->input->post('api',true);
  638. $page = $this->input->post('page',true);
  639. $perpage = $this->input->post('perpage',true);
  640. $number = $this->input->post('number',true);
  641. $color = $this->input->post('color',true);
  642. $purchase = $this->input->post('purchase',true);
  643. $transfer = $this->input->post('transfer',true);
  644. $lx = $this->input->post('lx',true);
  645. $type = $this->input->post('type',true);
  646. $xztime = $this->input->post('xztime',true);
  647. $timetk = $this->input->post('timetk',true);
  648. $timetj = $this->input->post('timetj',true);
  649. $timetk = strtotime($timetk);
  650. $timetj = strtotime($timetj);
  651. $where = '1=1';
  652. if($number)
  653. {
  654. $where .= " and number = '$number'";
  655. }
  656. if($purchase)
  657. {
  658. $where .= " and purchase = '$purchase'";
  659. }
  660. if($color)
  661. {
  662. $where .= " and fpdata like '%-".$color."-%'";
  663. }
  664. if($lx)
  665. {
  666. if($lx == 1)
  667. {
  668. $where .= " and ordernumber = ''";
  669. }
  670. else
  671. {
  672. $where .= " and ordernumber != ''";
  673. }
  674. }
  675. //数据排序
  676. $order_str = "id desc";
  677. if(empty($page))
  678. {
  679. $start = 0;
  680. $perpage = 1;
  681. }
  682. else
  683. {
  684. $start = ($page - 1)*$perpage;
  685. }
  686. if($xztime == 'printtime')
  687. {
  688. $where .= " and printtime > '$timetk' and printtime < '$timetj'";
  689. if($type)
  690. {
  691. $type = ($type==1)?'rk':'ck';
  692. if($transfer)
  693. {
  694. $where .= " and $type like '%|".$transfer."|%'";
  695. }
  696. }
  697. else
  698. {
  699. if($transfer)
  700. {
  701. $where .= " and rk like '%|".$transfer."|%'";
  702. }
  703. }
  704. }
  705. else
  706. {
  707. $cr = "time > '$timetk' and time < '$timetj'";
  708. if($transfer)
  709. {
  710. $cr .= " and lx = '".$transfer."'";
  711. }
  712. if($type)
  713. {
  714. $cr .= " and type = '".$type."'";
  715. }
  716. $fid = '';
  717. $info_list_cr = $this->systemtransfer_cr->find_all($cr);
  718. foreach ($info_list_cr as $v)
  719. {
  720. $fid .= "id = '".$v['fid']."' or ";
  721. }
  722. if($fid)
  723. {
  724. $where .= ' and ('.trim($fid,'or ').')';
  725. }
  726. else
  727. {
  728. $where .= ' and id = 0';
  729. }
  730. }
  731. //取得信息列表
  732. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  733. $transfer = $this->transfer->find_all();
  734. $t = array();
  735. foreach ($transfer as $v)
  736. {
  737. $t[$v['id']] = $v['title'];
  738. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  739. }
  740. //格式化数据
  741. foreach ($info_list as $key=>$value)
  742. {
  743. $dd = $this->systemtransfer->read($value['id']);
  744. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  745. $rk = explode('|',trim($dd['rk'],'|'));
  746. $rktime = explode('|',trim($dd['rktime'],'|'));
  747. $ck = explode('|',trim($dd['ck'],'|'));
  748. $cktime = explode('|',trim($dd['cktime'],'|'));
  749. $info_list[$key]['time'] = '';
  750. $data = $this->systemtransfer_cr->find_all("fid = '".$value['id']."'");
  751. /**
  752. for($i=0;$i<count($rk);$i++)
  753. {
  754. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  755. {
  756. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  757. }
  758. else
  759. {
  760. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  761. }
  762. $info_list[$key]['time'] .= $d;
  763. if(isset($ck[$i]) && $ck[$i] != '')
  764. {
  765. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  766. }
  767. }
  768. **/
  769. $info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$value['printtime']).'<br>';
  770. foreach ($data as $k=>$v)
  771. {
  772. // $type = ($v['type']==1)?'入库':'出库';
  773. // $info_list[$key]['time'] .= $t[$v['lx']].$type.' :'.date('Y-m-d H:i',$v['time']).'<br>';
  774. $type = ($v['type']==1)?'入库':'出库';
  775. if($v['orver_flag'] == 1){
  776. if($v['is_over'] == 0){
  777. $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>';
  778. // $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';
  779. }else{
  780. $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>';
  781. }
  782. }elseif($v['orver_flag'] == 2){
  783. $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>';
  784. }elseif($v['orver_flag'] == 3){
  785. $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>';
  786. }else{
  787. $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>';
  788. }
  789. }
  790. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  791. }
  792. $total = $this->systemtransfer->find_count($where);
  793. $pagenum = ceil($total/$perpage);
  794. $over = $total-($start+$perpage);
  795. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  796. echo json_encode($rows);exit;
  797. }
  798. if(isset($_SESSION['api']))
  799. {
  800. $user = $this->user->get_api($_SESSION['api']);
  801. $usp = $user;
  802. $pid = "";$tid="";$sid="";$wid="";
  803. $purchase = explode('|',trim($user['purchase'],'|'));
  804. $transfer = explode('|',trim($user['transfer'],'|'));
  805. $warehouse = explode('|',trim($user['warehouse'],'|'));
  806. foreach ($purchase as $value)
  807. {
  808. $pid .= " id = ".$value." or";
  809. }
  810. foreach ($transfer as $value)
  811. {
  812. $tid .= " id = ".$value." or";
  813. }
  814. foreach ($warehouse as $value)
  815. {
  816. $wid .= " id = ".$value." or";
  817. }
  818. }
  819. else
  820. {
  821. header('Location: /');exit;
  822. }
  823. $kx = '';$zjtab = '';
  824. $warehouse = $this->warehouse->find_all('1=1 and '.rtrim($wid,'or'),"*","px asc");
  825. $this->data['warehouse'] = $warehouse;
  826. $purchase = $this->purchase->find_all("yyid != ''");
  827. $this->data['purchase'] = $purchase;
  828. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  829. $this->data['transfer'] = $transfer;
  830. $this->data['vip'] = $user['vip'];
  831. $transfer_ids = array_column($transfer,'id');
  832. $transfer_str = implode(",",$transfer_ids);
  833. $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.")");
  834. $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.")");
  835. $this->_Template('transfer_operate',$this->data);
  836. }
  837. public function _out()
  838. {
  839. $post = $this->input->post(NULL, TRUE);
  840. if(isset($post['label']))
  841. {
  842. $time = time();
  843. $label = $this->input->post('label',true);
  844. $cz = $this->input->post('cz',true);
  845. $transfer = $this->input->post('transfer',true);
  846. if(!$label)
  847. {
  848. echo json_encode(array('msg'=>'未扫入数据!','success'=>false));exit;
  849. }
  850. if(!$transfer)
  851. {
  852. echo json_encode(array('msg'=>'请选择需对应的部门!','success'=>false));exit;
  853. }
  854. $lb = $this->systemtransfer->get_label($label);
  855. if(!$lb)
  856. {
  857. echo json_encode(array('msg'=>'错误!未找到此条码','success'=>false));exit;
  858. }
  859. if($lb['number']!='')
  860. {
  861. $nu = $this->fullorder->get_number($lb['number']);
  862. if(!$nu)
  863. {
  864. $nu = $this->fullordersmt->get_number($lb['number']);
  865. if(!$nu)
  866. {
  867. $nu = $this->fullordertt->get_number($lb['number']);
  868. }
  869. }
  870. //取消的订单还是要继续生产的 所以还允许继续扫入扫出 只是后续的出入库中不在限定时间
  871. // if($nu['state'] == '214' || $nu['state'] == '217')
  872. // {
  873. // echo json_encode(array('msg'=>'错误,此单已取消!请联系店员核实','success'=>false));exit;
  874. // }
  875. }
  876. $tdata = $this->transfer->find_all();
  877. $t = array();
  878. foreach ($tdata as $v)
  879. {
  880. $t[$v['id']] = $v['title'];
  881. }
  882. /**
  883. if($cz == 1 && stripos($lb['rk'],'|'.$transfer.'|') !== false)
  884. {
  885. echo json_encode(array('msg'=>'此条码已有入库操作!','success'=>false));exit;
  886. }
  887. if($cz == 2 && stripos($lb['ck'],'|'.$transfer.'|') !== false)
  888. {
  889. echo json_encode(array('msg'=>'此条码已有出库操作!','success'=>false));exit;
  890. }
  891. **/
  892. // if(stripos($lb['ck'],'|1|') === false && $transfer != 1 && stripos($nu['fpdata'],'-128-') !== false)
  893. // {
  894. // echo json_encode(array('msg'=>'必须有配货出库才可后续操作!','success'=>false));exit;
  895. // }
  896. //重新定义配货的原则问题
  897. //先检测订单是否含有 128 头套 或者配件 如果有 133 进行下一步检测
  898. $sku_arr = explode("-",$lb['features']);
  899. if(in_array(128,$sku_arr)||in_array(133,$sku_arr)){
  900. // 145 Full Lace Wig
  901. // 1170 HDFullLaceWig
  902. // 1249 FullLaceBobwithBang
  903. // 1484 FullLaceBob
  904. //如果是这4中全蕾丝那么配货就不处理
  905. if(in_array(145,$sku_arr) || in_array(1170,$sku_arr) || in_array(1249,$sku_arr) || in_array(1484,$sku_arr)){
  906. }else{
  907. if(stripos($lb['ck'],'|1|') === false && $transfer != 1 )
  908. {
  909. echo json_encode(array('msg'=>'头套和配件除了全蕾丝外必须走配货!','success'=>false));exit;
  910. }
  911. }
  912. }
  913. if($cz == 2 && stripos($lb['rk'],'|'.$transfer.'|') === false)
  914. {
  915. echo json_encode(array('msg'=>'此条码还未入库!','success'=>false));exit;
  916. }
  917. $lbrk = array_reverse(explode('|',trim($lb['rk'],'|')));
  918. $lbck = array_reverse(explode('|',trim($lb['ck'],'|')));
  919. if($transfer != 3 && $transfer != 11 && $transfer != 2)
  920. {
  921. if($cz == 1)
  922. {
  923. if($lb['rk'] != $lb['ck'])//判断是否没走完流程就拿到下一步奏
  924. {
  925. echo json_encode(array('msg'=>$t[$lbrk[0]].'还未出库,无法入库!','success'=>false));exit;
  926. }
  927. }
  928. if($cz == 2 && $lbrk[0] != $transfer)//判断是否没走完流程就拿到下一步奏
  929. {
  930. echo json_encode(array('msg'=>$t[$transfer].'还未入库,无法出库!','success'=>false));exit;
  931. }
  932. }
  933. if($cz == 1)
  934. {
  935. $lb['rk'] .= $transfer.'|';
  936. $lb['rktime'] .= $time.'|';
  937. if($lbrk[0] == $transfer)
  938. {
  939. echo json_encode(array('msg'=>'已有入库记录,不可连续重复录入!','success'=>false));exit;
  940. }
  941. }
  942. else if($cz == 2)
  943. {
  944. $lb['ck'] .= $transfer.'|';
  945. $lb['cktime'] .= $time.'|';
  946. if($lbck[0] == $transfer)
  947. {
  948. echo json_encode(array('msg'=>'已有出库记录,不可连续重复录入!','success'=>false));exit;
  949. }
  950. }
  951. $cztime = 'ctime'.$transfer;
  952. if(($transfer == 3 && $lb['dbapi'] < 99 && $cz == 2) || ($transfer == 13 && $lb['dbapi'] < 99 && $cz == 1))//出入库用这个
  953. //if(($transfer == 8 || $transfer == 13) && $lb['dbapi'] < 99 && $cz == 1)//单入库
  954. {
  955. if($lb['type'] == 0)
  956. {
  957. $s = $this->shop->read($nu['shop']);
  958. $lb['kh'] = $s['yyid'];
  959. $lb['ts'] = 1;
  960. $rk = $this->apiyy->_newrk($lb);
  961. if($rk['c'] == 0)
  962. {
  963. $this->db->trans_begin();
  964. $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']);
  965. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  966. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  967. if($cz == 2){
  968. $this->_doCheckIsOverTime($lb['id'],$transfer);
  969. }
  970. if ($this->db->trans_status() === TRUE)
  971. {
  972. $this->db->trans_commit();
  973. if($nu['state'] == '216')
  974. {
  975. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  976. }
  977. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  978. //标记订单已经取消
  979. $this->_doCheckCancelFlag($lb['id']);
  980. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  981. }
  982. else
  983. {
  984. echo json_encode(array('music'=>'1','success'=>true));exit;
  985. }
  986. }
  987. else
  988. {
  989. $this->db->trans_rollback();
  990. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  991. }
  992. }
  993. else
  994. {
  995. if(stripos($rk['error'],'DocNo') !== false)
  996. {
  997. $rk['error'] = '未找到对应的生产订单 '.$lb['scid'];
  998. }
  999. $this->systemtransfer->save(array('dbapi'=>$rk['dbapi'],'scid'=>$rk['scid']),$lb['id']);
  1000. echo json_encode(array('msg'=>'订单号:'.$lb['number'].' 用友报错:'.$rk['error'],'success'=>false));exit;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. $scid = explode('~',$lb['scid']);
  1006. $rkdata = array('od'=>$scid[1],'ts'=>1,'title'=>$lb['title']);
  1007. $rk = $this->apiyy->get_bzsh($rkdata);
  1008. if(isset($rk['Data'][0]))
  1009. {
  1010. if($rk['Data'][0]['IsSucess'] == 1)
  1011. {
  1012. $this->db->trans_begin();
  1013. $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']);
  1014. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  1015. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  1016. if($cz == 2){
  1017. $this->_doCheckIsOverTime($lb['id'],$transfer);
  1018. }
  1019. if ($this->db->trans_status() === TRUE)
  1020. {
  1021. $this->db->trans_commit();
  1022. if($nu['state'] == '216')
  1023. {
  1024. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  1025. }
  1026. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  1027. //标记订单已经取消
  1028. $this->_doCheckCancelFlag($lb['id']);
  1029. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  1030. }
  1031. else
  1032. {
  1033. echo json_encode(array('music'=>'1','success'=>true));exit;
  1034. }
  1035. }
  1036. else
  1037. {
  1038. $this->db->trans_rollback();
  1039. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1040. }
  1041. }
  1042. else
  1043. {
  1044. echo json_encode(array('msg'=>$rk['Data'][0]['ErrorMsg'],'success'=>false));exit;
  1045. }
  1046. }
  1047. else
  1048. {
  1049. echo json_encode(array('msg'=>$rk,'success'=>false));exit;
  1050. }
  1051. }
  1052. }
  1053. //if($transfer == 11 && stripos($lb['rk'],'|8|') === false && stripos($lb['ck'],'|3|') === false && stripos($lb['rk'],'|13|') === false)//只入库
  1054. if($transfer == 11 && stripos($lb['ck'],'|3|') === false && stripos($lb['rk'],'|13|') === false)//改出入库
  1055. {
  1056. echo json_encode(array('msg'=>'工厂未出库,请退回工厂!','success'=>false));exit;
  1057. }
  1058. $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']);
  1059. $this->systemtransfer_cr->insert(array('fid'=>$lb['id'],'lx'=>$transfer,'type'=>$cz,'time'=>$time));
  1060. //处理定时任务每三分钟 执行一次的bug 在出库的时候直接同步相关信息
  1061. if($cz == 2){
  1062. $this->_doCheckIsOverTime($lb['id'],$transfer);
  1063. }
  1064. if ($this->db->trans_status() === TRUE)
  1065. {
  1066. $this->db->trans_commit();
  1067. if($nu['state'] == '216')
  1068. {
  1069. echo json_encode(array('msg'=>'数据已录入成功!提示:此订单已出库,可选择终止生产。','success'=>false));exit;
  1070. }
  1071. elseif(($nu['state'] == '217') || ($nu['state'] == '214')){
  1072. //标记订单已经取消
  1073. $this->_doCheckCancelFlag($lb['id']);
  1074. echo json_encode(array('msg'=>'数据已录入成功!提示:【该单已取消】,可选择终止生产。','success'=>false));exit;
  1075. }
  1076. else
  1077. {
  1078. echo json_encode(array('music'=>'1','success'=>true));exit;
  1079. }
  1080. }
  1081. else
  1082. {
  1083. $this->db->trans_rollback();
  1084. echo json_encode(array('msg'=>'数据写入失败,请重试!','success'=>false));exit;
  1085. }
  1086. }
  1087. }
  1088. //检测取消标记是否添加 同时也检查下 该流转单是否被标记为取消单
  1089. private function _doCheckCancelFlag($fid){
  1090. $info = $this->systemtransfer->read($fid);
  1091. if($info['status'] != 11){
  1092. $this->systemtransfer->save(['status'=>11],$fid);
  1093. }
  1094. $list = $this->systemtransfer_cr->find_all("fid = ".$fid,'*','id desc');
  1095. if(empty($list)){
  1096. return;
  1097. }
  1098. $is_cancel = false;
  1099. foreach($list as $val){
  1100. if($val['orver_flag'] == 3){
  1101. $is_cancel = true;
  1102. }
  1103. }
  1104. if($is_cancel){
  1105. return ;
  1106. }
  1107. $this->systemtransfer_cr->save(['orver_flag'=>3],$list[0]['id']);
  1108. }
  1109. //检测是否超时 车间流转环节
  1110. private function _doCheckIsOverTime($fid,$transfer){
  1111. $list = $this->systemtransfer_cr->find_all("fid = ".$fid." and lx = ".$transfer." and is_over = 0","*",'id desc',0,2);
  1112. if(count($list) < 2){
  1113. return ;
  1114. }
  1115. if($list[0]['type'] != 2){
  1116. return;
  1117. }
  1118. if($list[1]['type'] != 1){
  1119. return;
  1120. }
  1121. if($list[1]['orver_flag'] == 2){
  1122. $this->systemtransfer_cr->save(array('is_over'=>1,'orver_flag'=>2),$list[0]['id']);
  1123. }else{
  1124. $this->systemtransfer_cr->save(array('is_over'=>1),$list[0]['id']);
  1125. }
  1126. $this->systemtransfer_cr->save(array('is_over'=>1),$list[1]['id']);
  1127. }
  1128. public function _bdbb()
  1129. {
  1130. $post = $this->input->post(NULL, TRUE);
  1131. if(isset($post['s']))
  1132. {
  1133. $id_arr = $this->input->post('s');
  1134. $id_arr = explode(',',trim($id_arr,','));
  1135. if(!$id_arr)
  1136. {
  1137. echo json_encode(array('msg'=>$v.' - 未查询到需要补打信息!','success'=>false));exit;
  1138. }
  1139. //循环删除记录
  1140. foreach ($id_arr as $v)
  1141. {
  1142. $t = $this->systemtransfer->read($v);
  1143. if(!isset($t['number']))
  1144. {
  1145. echo json_encode(array('msg'=>$v.' - 补打信息已被删除!','success'=>false));exit;
  1146. }
  1147. $y = $this->fullorder->get_number($t['number']);
  1148. if(!$y)
  1149. {
  1150. $y = $this->fullordersmt->get_number($t['number']);
  1151. if(!$y)
  1152. {
  1153. $y = $this->fullordertt->get_number($t['number']);
  1154. if(!$y)
  1155. {
  1156. echo json_encode(array('msg'=>$t['number'].'没有找到此订单','success'=>false));exit;
  1157. }
  1158. }
  1159. }
  1160. $express = $this->express->read($y['express']);
  1161. $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'=>"补打");
  1162. }
  1163. echo json_encode(array('rows'=>($rows),'success'=>true));exit;
  1164. }
  1165. }
  1166. public function _excel()
  1167. {
  1168. if(isset($_GET['fexcel']))
  1169. {
  1170. $tc = array();$zh = array();
  1171. $typeclass = $this->typeclass->find_all();
  1172. foreach ($typeclass as $v)
  1173. {
  1174. $tc[$v['id']] = $v;
  1175. }
  1176. $number = $this->input->get('number',true);
  1177. $color = $this->input->get('color',true);
  1178. $gs = $this->input->get('gs',true);
  1179. $transfer = $this->input->get('transfer',true);
  1180. $type = $this->input->get('type',true);
  1181. $timetk = $this->input->get('timetk',true);
  1182. $timetj = $this->input->get('timetj',true);
  1183. $purchase = $this->input->get('purchase',true);
  1184. $lx = $this->input->get('lx',true);
  1185. $timetk = strtotime($timetk);
  1186. $timetj = strtotime($timetj);
  1187. $where = "1=1";
  1188. $cr = "time > '$timetk' and time < '$timetj'";
  1189. if($number)
  1190. {
  1191. $where .= " and number = '$number'";
  1192. }
  1193. if($transfer)
  1194. {
  1195. $cr .= " and lx = '".$transfer."'";
  1196. }
  1197. if($type)
  1198. {
  1199. $cr .= " and type = '".$type."'";
  1200. }
  1201. if($purchase)
  1202. {
  1203. $where .= " and purchase = '$purchase'";
  1204. }
  1205. if($color)
  1206. {
  1207. $where .= " and fpdata like '%-".$color."-%'";
  1208. }
  1209. if($lx)
  1210. {
  1211. if($lx == 1)
  1212. {
  1213. $where .= " and ordernumber = ''";
  1214. }
  1215. else
  1216. {
  1217. $where .= " and ordernumber != ''";
  1218. }
  1219. }
  1220. $fid = '';
  1221. $info_list_cr = $this->systemtransfer_cr->find_all($cr);
  1222. foreach ($info_list_cr as $v)
  1223. {
  1224. $fid .= "id = '".$v['fid']."' or ";
  1225. }
  1226. if($fid)
  1227. {
  1228. $where .= ' and ('.trim($fid,'or ').')';
  1229. }
  1230. else
  1231. {
  1232. $where .= ' and id = 0';
  1233. }
  1234. $data = array();
  1235. $datafy = array();
  1236. $j = 0;
  1237. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,jm,shipremarks,printtime');
  1238. $lzbm = $this->transfer->find_all();
  1239. foreach ($info_list as $key=>$value)
  1240. {
  1241. $dj = '';$ys = '';$cc = '';$hx = '';$md = '';
  1242. $d = $this->systemtransfer->read($value['id']);
  1243. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1244. $info_list[$key]['shipremarks'] = str_replace(array('<','>'),array('&lt;','&gt;'),$d['shipremarks']);
  1245. $d['features'] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$d['features']);
  1246. $cp = explode('-',trim($d['features'],'-'));
  1247. $rk = explode('|',trim($d['rk'],'|'));
  1248. $rktime = explode('|',trim($d['rktime'],'|'));
  1249. foreach ($cp as $v)
  1250. {
  1251. if(isset($tc[$v]))
  1252. {
  1253. if($tc[$v]['classid'] == 13)
  1254. {
  1255. $dj = $tc[$v]['title'];
  1256. }
  1257. else if($tc[$v]['classid'] == 8)
  1258. {
  1259. $ys = $tc[$v]['title'];
  1260. }
  1261. else if($tc[$v]['classid'] == 14)
  1262. {
  1263. $cc = $tc[$v]['title'];
  1264. }
  1265. else if($tc[$v]['classid'] == 15)
  1266. {
  1267. $hx = $tc[$v]['title'];
  1268. }
  1269. else if($tc[$v]['classid'] == 10)
  1270. {
  1271. $md = $tc[$v]['title'];
  1272. }
  1273. }
  1274. }
  1275. $rt = array();
  1276. foreach ($rk as $k=>$v)
  1277. {
  1278. $rt[$v+5] = date('Y-m-d H:i:s',$rktime[$k]);
  1279. }
  1280. $fpdata = array(array('0'=>$d['title'],'1'=>$cc,'2'=>$dj,'3'=>$ys,'4'=>$hx,'5'=>$md));
  1281. foreach ($lzbm as $v)
  1282. {
  1283. if(isset($rt[count($fpdata[0])]))
  1284. {
  1285. //$fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1286. $num = $this->systemtransfer_cr->find_count("fid = ".$value['id']." and lx = ".$v['id']." and orver_flag = 2");
  1287. if($num > 0){
  1288. $fpdata[0][count($fpdata[0])] = "<span style='color:red;font-weight:bold;'>".$rt[count($fpdata[0])]."<span>";
  1289. }else{
  1290. $fpdata[0][count($fpdata[0])] = $rt[count($fpdata[0])];
  1291. }
  1292. }
  1293. else
  1294. {
  1295. $fpdata[0][count($fpdata[0])] = '';
  1296. }
  1297. }
  1298. $info_list[$key]['fpdata'] = $fpdata;//名称,尺寸,等级,颜色,花型,密度
  1299. unset($info_list[$key]['id']);
  1300. }
  1301. //echo "<pre>";print_r($info_list);exit;
  1302. $lzxq = '';
  1303. foreach ($lzbm as $v)
  1304. {
  1305. $lzxq .= '<td>'.$v['title'].'</td>';
  1306. }
  1307. $title = date('Y-m-d',$timetk).'-'.date('Y-m-d',$timetj).' 统计表';
  1308. $titlename = "<table border=1>
  1309. <tr>
  1310. <td>订单编号</td>
  1311. <td>品名</td>
  1312. <td>简码</td>
  1313. <td>备注</td>
  1314. <td>打印时间</td>
  1315. <td>
  1316. <table border=1>
  1317. <tr><td colspan='6' align='center'>订单产品信息</td><td colspan='".count($lzbm)."' align='center'>货物流转时间</td></tr>
  1318. <tr>
  1319. <td>产品名称</td>
  1320. <td>尺寸</td>
  1321. <td>等级</td>
  1322. <td>颜色</td>
  1323. <td>花型</td>
  1324. <td>密度</td>
  1325. ".$lzxq."
  1326. </tr>
  1327. </table>
  1328. </td>
  1329. </tr>
  1330. </table>";
  1331. $filename = $title.".xls";
  1332. $tail = "\n";
  1333. $this->excel->get_fz($info_list,$titlename,$filename,$tail,1);
  1334. }
  1335. }
  1336. public function _rk()
  1337. {
  1338. $post = $this->input->post(NULL, TRUE);
  1339. if(isset($post['page']))
  1340. {
  1341. $api = $this->input->post('api',true);
  1342. $page = $this->input->post('page',true);
  1343. $perpage = $this->input->post('perpage',true);
  1344. $number = $this->input->post('number',true);
  1345. $color = $this->input->post('color',true);
  1346. $purchase = $this->input->post('purchase',true);
  1347. $transfer = $this->input->post('transfer',true);
  1348. $lx = $this->input->post('lx',true);
  1349. $timetk = $this->input->post('timetk',true);
  1350. $timetj = $this->input->post('timetj',true);
  1351. $timetk = strtotime($timetk);
  1352. $timetj = strtotime($timetj);
  1353. $where = "1=1";
  1354. if($transfer)
  1355. {
  1356. $ctime = 'ctime'.$transfer;
  1357. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  1358. }
  1359. else
  1360. {
  1361. $where .= " and time > '$timetk' and time < '$timetj'";
  1362. }
  1363. if($number)
  1364. {
  1365. $where .= " and number = '$number'";
  1366. }
  1367. if($transfer)
  1368. {
  1369. $where .= " and rk like '%|".$transfer."|%'";
  1370. }
  1371. if($purchase)
  1372. {
  1373. $where .= " and purchase = '$purchase'";
  1374. }
  1375. if($color)
  1376. {
  1377. $where .= " and fpdata like '%-".$color."-%'";
  1378. }
  1379. if($lx)
  1380. {
  1381. if($lx == 1)
  1382. {
  1383. $where .= " and ordernumber = ''";
  1384. }
  1385. else
  1386. {
  1387. $where .= " and ordernumber != ''";
  1388. }
  1389. }
  1390. //数据排序
  1391. $order_str = "id desc";
  1392. if(empty($page))
  1393. {
  1394. $start = 0;
  1395. $perpage = 1;
  1396. }
  1397. else
  1398. {
  1399. $start = ($page - 1)*$perpage;
  1400. }
  1401. //取得信息列表
  1402. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  1403. $transfer = $this->transfer->find_all();
  1404. $t = array();
  1405. foreach ($transfer as $v)
  1406. {
  1407. $t[$v['id']] = $v['title'];
  1408. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  1409. }
  1410. //格式化数据
  1411. foreach ($info_list as $key=>$value)
  1412. {
  1413. $dd = $this->systemtransfer->read($value['id']);
  1414. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1415. $rk = explode('|',trim($dd['rk'],'|'));
  1416. $rktime = explode('|',trim($dd['rktime'],'|'));
  1417. $ck = explode('|',trim($dd['ck'],'|'));
  1418. $cktime = explode('|',trim($dd['cktime'],'|'));
  1419. $info_list[$key]['time'] = '';
  1420. for($i=0;$i<count($rk);$i++)
  1421. {
  1422. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  1423. {
  1424. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  1425. }
  1426. else
  1427. {
  1428. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  1429. }
  1430. $info_list[$key]['time'] .= $d;
  1431. if(isset($ck[$i]) && $ck[$i] != '')
  1432. {
  1433. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  1434. }
  1435. }
  1436. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1437. }
  1438. $total = $this->systemtransfer->find_count($where);
  1439. $pagenum = ceil($total/$perpage);
  1440. $over = $total-($start+$perpage);
  1441. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);
  1442. echo json_encode($rows);exit;
  1443. }
  1444. if(isset($_SESSION['api']))
  1445. {
  1446. $user = $this->user->get_api($_SESSION['api']);
  1447. $usp = $user;
  1448. $pid = "";$tid="";$sid="";$wid="";
  1449. $purchase = explode('|',trim($user['purchase'],'|'));
  1450. $transfer = explode('|',trim($user['transfer'],'|'));
  1451. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1452. foreach ($purchase as $value)
  1453. {
  1454. $pid .= " id = ".$value." or";
  1455. }
  1456. foreach ($transfer as $value)
  1457. {
  1458. $tid .= " id = ".$value." or";
  1459. }
  1460. foreach ($warehouse as $value)
  1461. {
  1462. $wid .= " id = ".$value." or";
  1463. }
  1464. }
  1465. else
  1466. {
  1467. header('Location: /');exit;
  1468. }
  1469. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1470. $this->data['transfer'] = $transfer;
  1471. $this->_Template('transfer_rk',$this->data);
  1472. }
  1473. public function _ck()
  1474. {
  1475. $post = $this->input->post(NULL, TRUE);
  1476. if(isset($post['page']))
  1477. {
  1478. $api = $this->input->post('api',true);
  1479. $page = $this->input->post('page',true);
  1480. $perpage = $this->input->post('perpage',true);
  1481. $number = $this->input->post('number',true);
  1482. $color = $this->input->post('color',true);
  1483. $purchase = $this->input->post('purchase',true);
  1484. $transfer = $this->input->post('transfer',true);
  1485. $lx = $this->input->post('lx',true);
  1486. $timetk = $this->input->post('timetk',true);
  1487. $timetj = $this->input->post('timetj',true);
  1488. $timetk = strtotime($timetk);
  1489. $timetj = strtotime($timetj);
  1490. $where = "1=1";
  1491. if($transfer)
  1492. {
  1493. $ctime = 'ctime'.$transfer;
  1494. $where .= " and $ctime > '$timetk' and $ctime < '$timetj'";
  1495. }
  1496. else
  1497. {
  1498. $where .= " and time > '$timetk' and time < '$timetj'";
  1499. }
  1500. if($number)
  1501. {
  1502. $where .= " and number = '$number'";
  1503. }
  1504. if($transfer)
  1505. {
  1506. $where .= " and ck like '%|".$transfer."|%'";
  1507. }
  1508. if($purchase)
  1509. {
  1510. $where .= " and purchase = '$purchase'";
  1511. }
  1512. if($color)
  1513. {
  1514. $where .= " and fpdata like '%-".$color."-%'";
  1515. }
  1516. if($lx)
  1517. {
  1518. if($lx == 1)
  1519. {
  1520. $where .= " and ordernumber = ''";
  1521. }
  1522. else
  1523. {
  1524. $where .= " and ordernumber != ''";
  1525. }
  1526. }
  1527. //数据排序
  1528. $order_str = "id desc";
  1529. if(empty($page))
  1530. {
  1531. $start = 0;
  1532. $perpage = 1;
  1533. }
  1534. else
  1535. {
  1536. $start = ($page - 1)*$perpage;
  1537. }
  1538. //取得信息列表
  1539. $info_list = $this->systemtransfer->find_all($where,'id,number,pm,shipremarks,printtime,time',$order_str,$start,$perpage);
  1540. $transfer = $this->transfer->find_all();
  1541. $t = array();
  1542. foreach ($transfer as $v)
  1543. {
  1544. $t[$v['id']] = $v['title'];
  1545. $ot[$v['id']] = ($v['orvertime']>0)?$v['orvertime']*24*3600:0;
  1546. }
  1547. //格式化数据
  1548. foreach ($info_list as $key=>$value)
  1549. {
  1550. $dd = $this->systemtransfer->read($value['id']);
  1551. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  1552. $rk = explode('|',trim($dd['rk'],'|'));
  1553. $rktime = explode('|',trim($dd['rktime'],'|'));
  1554. $ck = explode('|',trim($dd['ck'],'|'));
  1555. $cktime = explode('|',trim($dd['cktime'],'|'));
  1556. $info_list[$key]['time'] = '';
  1557. for($i=0;$i<count($rk);$i++)
  1558. {
  1559. if(count($rk)-1 == $i && $ot[$rk[$i]] > 0 && $rktime[$i] + $ot[$rk[$i]] < time())
  1560. {
  1561. $d = ' <em style="color: #fc5454;">'.$t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').' 超</em><br> ';
  1562. }
  1563. else
  1564. {
  1565. $d = $t[$rk[$i]].'入库 :'.((isset($rktime[$i]))?(date('Y-m-d H:i',$rktime[$i])):'').'<br>';
  1566. }
  1567. $info_list[$key]['time'] .= $d;
  1568. if(isset($ck[$i]) && $ck[$i] != '')
  1569. {
  1570. $info_list[$key]['time'] .= $t[$ck[$i]].'出库 :'.date('Y-m-d H:i',$cktime[$i]).'<br>';
  1571. }
  1572. }
  1573. $info_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1574. }
  1575. $total = $this->systemtransfer->find_count($where);
  1576. $pagenum = ceil($total/$perpage);
  1577. $over = $total-($start+$perpage);
  1578. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'cs'=>$where);
  1579. echo json_encode($rows);exit;
  1580. }
  1581. if(isset($_SESSION['api']))
  1582. {
  1583. $user = $this->user->get_api($_SESSION['api']);
  1584. $usp = $user;
  1585. $pid = "";$tid="";$sid="";$wid="";
  1586. $purchase = explode('|',trim($user['purchase'],'|'));
  1587. $transfer = explode('|',trim($user['transfer'],'|'));
  1588. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1589. foreach ($purchase as $value)
  1590. {
  1591. $pid .= " id = ".$value." or";
  1592. }
  1593. foreach ($transfer as $value)
  1594. {
  1595. $tid .= " id = ".$value." or";
  1596. }
  1597. foreach ($warehouse as $value)
  1598. {
  1599. $wid .= " id = ".$value." or";
  1600. }
  1601. }
  1602. else
  1603. {
  1604. header('Location: /');exit;
  1605. }
  1606. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1607. $this->data['transfer'] = $transfer;
  1608. $this->_Template('transfer_ck',$this->data);
  1609. }
  1610. public function _jgl()
  1611. {
  1612. $post = $this->input->post(NULL, TRUE);
  1613. if(isset($post['printtime']))
  1614. {
  1615. $pt = $this->input->post('printtime',true);
  1616. $wt = $this->input->post('wgtime',true);
  1617. $printtime = strtotime($pt);
  1618. $wgtime = strtotime($wt);
  1619. $sy = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."'");
  1620. $wg = $this->systemtransfer->find_count("printtime > '$printtime' and printtime < '".($printtime+24*3600)."' and ctime11 < '$wgtime' and ctime11 != '0'");
  1621. if($printtime == $wgtime || $printtime > $wgtime)
  1622. {
  1623. echo json_encode(array('msg'=>"<p style='height:140px;line-height:140px'>时间选择错误</p>",'success'=>true));exit;
  1624. }
  1625. 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;
  1626. }
  1627. $this->_Template('transfer_wgl',$this->data);
  1628. }
  1629. public function _linqi(){
  1630. $post = $this->input->post(NULL, TRUE);
  1631. if(isset($post['page']))
  1632. {
  1633. $api = $this->input->post('api',true);
  1634. $page = $this->input->post('page',true);
  1635. $perpage = $this->input->post('perpage',true);
  1636. $transfer = $this->input->post('transfer',true);
  1637. $transfer_ids = $this->input->post('transfer_ids',true);
  1638. $orver_flag = $this->input->post('orver_flag',true);
  1639. $timetk = $this->input->post('timetk',true);
  1640. $timetj = $this->input->post('timetj',true);
  1641. $timetk = strtotime($timetk);
  1642. $timetj = strtotime($timetj);
  1643. $transfer_list = $this->transfer->find_all();
  1644. $t = $transfer_list = array_column($transfer_list, 'title', 'id');
  1645. $where = 'type = 1 ';
  1646. $where .= " and is_over = 0 and orver_flag = ".$orver_flag." ";
  1647. //数据排序
  1648. $order_str = "id desc";
  1649. if(empty($page))
  1650. {
  1651. $start = 0;
  1652. $perpage = 1;
  1653. }
  1654. else
  1655. {
  1656. $start = ($page - 1)*$perpage;
  1657. }
  1658. if($transfer){
  1659. $where .= " and lx = '$transfer'";
  1660. }else{
  1661. $where .= " and lx in (".$transfer_ids.") ";
  1662. }
  1663. $where .= " and time > '$timetk' and time < '$timetj'";
  1664. $list = $this->systemtransfer_cr->find_all($where,'*',$order_str,$start,$perpage);
  1665. $final_list = [];
  1666. foreach ($list as $key => $value) {
  1667. $info = $this->systemtransfer->read($value['fid']);
  1668. $final_list[$key]['id'] = $value['id'];
  1669. $final_list[$key]['number'] = isset($info['number'])?$info['number']:'';
  1670. $final_list[$key]['pm'] = $info['pm'];
  1671. $final_list[$key]['shipremarks'] = $info['shipremarks'];
  1672. $final_list[$key]['printtime'] = date('Y-m-d H:i:s',$info['printtime']);
  1673. $data = $this->systemtransfer_cr->find_all("fid = '".$info['id']."'");
  1674. $info_list[$key]['time'] = "订单出库 :".date('Y-m-d H:i',$info['printtime']).'<br>';
  1675. foreach ($data as $k=>$v)
  1676. {
  1677. $type = ($v['type']==1)?'入库':'出库';
  1678. if($v['orver_flag'] == 1){
  1679. if($v['is_over'] == 0){
  1680. $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>';
  1681. // $info_list[$key]['time'] .= '<i style="padding:10px;color:#90f;font-weight:bold;"> 即将超时</i>'.'<br>';
  1682. }else{
  1683. $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>';
  1684. }
  1685. }elseif($v['orver_flag'] == 2){
  1686. $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>';
  1687. }else{
  1688. $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>';
  1689. }
  1690. }
  1691. $final_list[$key]['time'] = trim($info_list[$key]['time'],'<br>');
  1692. }
  1693. $total = $this->systemtransfer_cr->find_count($where);
  1694. $pagenum = ceil($total/$perpage);
  1695. $over = $total-($start+$perpage);
  1696. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($final_list));
  1697. echo json_encode($rows);exit;
  1698. }
  1699. if(isset($_SESSION['api']))
  1700. {
  1701. $user = $this->user->get_api($_SESSION['api']);
  1702. $usp = $user;
  1703. $pid = "";$tid="";$sid="";$wid="";
  1704. $purchase = explode('|',trim($user['purchase'],'|'));
  1705. $transfer = explode('|',trim($user['transfer'],'|'));
  1706. $warehouse = explode('|',trim($user['warehouse'],'|'));
  1707. foreach ($purchase as $value)
  1708. {
  1709. $pid .= " id = ".$value." or";
  1710. }
  1711. foreach ($transfer as $value)
  1712. {
  1713. $tid .= " id = ".$value." or";
  1714. }
  1715. foreach ($warehouse as $value)
  1716. {
  1717. $wid .= " id = ".$value." or";
  1718. }
  1719. }
  1720. else
  1721. {
  1722. header('Location: /');exit;
  1723. }
  1724. $kx = '';$zjtab = '';
  1725. $transfer = $this->transfer->find_all('1=1 and '.rtrim($tid,'or'));
  1726. $this->data['transfer'] = $transfer;
  1727. $transfer_ids = array_column($transfer, 'id');
  1728. $this->data['transfer_ids'] =implode(",",$transfer_ids) ;
  1729. $this->data['vip'] = $user['vip'];
  1730. $this->data['orver_flag'] = $this->input->get('orver_flag', TRUE);
  1731. $this->_Template('transfer_linqi',$this->data);
  1732. }
  1733. //按照条件导出超时车间
  1734. public function _overtime_export(){
  1735. $transfer_id = $this->input->get('transfer', TRUE);
  1736. $timetk = $this->input->get('timetk', TRUE);
  1737. $timetj = $this->input->get('timetj', TRUE);
  1738. $timetk = strtotime($timetk);
  1739. $timetj = strtotime($timetj);
  1740. if(isset($_SESSION['api']))
  1741. {
  1742. $user = $this->user->get_api($_SESSION['api']);
  1743. $transfer_ids = explode('|',trim($user['transfer'],'|'));
  1744. $tmp_transfer_list = $this->transfer->find_all();
  1745. $transfer_list = array_column($tmp_transfer_list, 'title', 'id');
  1746. }
  1747. else
  1748. {
  1749. header('Location: /');exit;
  1750. }
  1751. $where = " orver_flag = 2 and type = 1";
  1752. if(empty($transfer_id)){
  1753. $where .= " and lx in (".implode(',',$transfer_ids).") ";
  1754. }else{
  1755. $where .= " and lx = ".$transfer_id." ";
  1756. }
  1757. $where .= " and time > '$timetk' and time < '$timetj'";
  1758. $list = $this->systemtransfer_cr->find_all($where,'*');
  1759. $fid_list = array_column($list, 'fid');
  1760. if(empty($fid_list)){
  1761. echo "没有数据" ;
  1762. die ;
  1763. }
  1764. $order_list = $this->systemtransfer->find_all("id in (".implode(',',$fid_list).")");
  1765. $where_two = " orver_flag = 2 and type = 2";
  1766. if(empty($transfer_id)){
  1767. $where_two .= " and lx in (".implode(',',$transfer_ids).") ";
  1768. }else{
  1769. $where_two .= " and lx = ".$transfer_id." ";
  1770. }
  1771. $where_two .= " and time > '$timetk' and time < '$timetj'";
  1772. $list_two = $this->systemtransfer_cr->find_all($where_two,'*');
  1773. $final_list = [];
  1774. // foreach($list as $k => $v){
  1775. // $final_list[$v['fid']]['fid'] = $v['fid'];
  1776. // $final_list[$v['fid']]['lx'] = $v['lx'];
  1777. // $final_list[$v['fid']]['start_type'] = $v['type'];
  1778. // $final_list[$v['fid']]['start_time'] = date('Y-m-d H:i:s',$v['time']);
  1779. // $final_list[$v['fid']]['condition'] = json_decode($v['limit_time_str'],true);
  1780. // $final_list[$v['fid']]['end_time'] = "";
  1781. // $final_list[$v['fid']]['lx_name'] = isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'';
  1782. // }
  1783. // foreach($order_list as $k=>$v){
  1784. // if(isset($final_list[$v['id']])){
  1785. // $final_list[$v['id']]['number'] = $v['number'];
  1786. // $final_list[$v['id']]['pm'] = $v['pm'];
  1787. // }
  1788. // }
  1789. // foreach($list_two as $k => $v){
  1790. // if(isset($final_list[$v['fid']])){
  1791. // if($v['lx'] ==$final_list[$v['fid']]['lx']){
  1792. // $final_list[$v['fid']]['end_time'] = date('Y-m-d H:i:s',$v['time']);
  1793. // }
  1794. // }
  1795. // }
  1796. foreach($list as $k => $v){
  1797. $final_list[] = [
  1798. 'fid' => $v['fid'],
  1799. 'lx' => $v['lx'],
  1800. 'start_type' => $v['type'],
  1801. 'start_time' => date('Y-m-d H:i:s',$v['time']),
  1802. 'condition' => json_decode($v['limit_time_str'],true),
  1803. 'end_time' => "",
  1804. 'lx_name' => isset($transfer_list[$v['lx']])?$transfer_list[$v['lx']]:'',
  1805. ];
  1806. }
  1807. foreach($order_list as $k=>$v){
  1808. foreach($final_list as $kk => $vv){
  1809. if($v['id'] == $vv['fid']){
  1810. $final_list[$kk]['number'] = $v['number'];
  1811. $final_list[$kk]['pm'] = $v['pm'];
  1812. }
  1813. }
  1814. }
  1815. foreach($list_two as $k => $v){
  1816. foreach($final_list as $kk => $vv){
  1817. if(($v['fid'] == $vv['fid']) && ($v['lx'] == $vv['lx'])){
  1818. $final_list[$kk]['end_time'] = date('Y-m-d H:i:s',$v['time']);
  1819. }
  1820. }
  1821. }
  1822. $filename = date("Y-m-d")."超时单导出.xls";
  1823. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1824. <head>
  1825. <!--[if gte mso 9]><xml>
  1826. <x:ExcelWorkbook>
  1827. <x:ExcelWorksheets>
  1828. <x:ExcelWorksheet>
  1829. <x:Name>EXCEL</x:Name>
  1830. <x:WorksheetOptions>
  1831. <x:Print>
  1832. <x:ValidPrinterInfo />
  1833. </x:Print>
  1834. </x:WorksheetOptions>
  1835. </x:ExcelWorksheet>
  1836. </x:ExcelWorksheets>
  1837. </x:ExcelWorkbook>
  1838. </xml>
  1839. <![endif]-->
  1840. </head><body>";
  1841. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1842. $str .= "<tr><td>订单编号</td><td>品名</td><td>车间</td><td>入库日期</td><td>出库日期</td></tr>";
  1843. foreach ($final_list as $key=>$value)
  1844. {
  1845. $str .= "<tr>";
  1846. $str .= "<td>". $value['number']. "</td>";
  1847. $str .= "<td>". $value['pm']. "</td>";
  1848. $str .= "<td>". $value['lx_name']. "</td>";
  1849. $str .= "<td>". $value['start_time']. "</td>";
  1850. $str .= "<td>". $value['end_time']. "</td>";
  1851. $str .= "</tr>";
  1852. }
  1853. $str .= "</table></body></html>";
  1854. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1855. header( "Content-type: application/octet-stream" );
  1856. header( "Content-Disposition: attachment; filename=".$filename );
  1857. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1858. header( "Pragma: no-cache" );
  1859. header( "Expires: 0" );
  1860. exit($str);
  1861. }
  1862. }