Transfer.php 70 KB

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