Transfer.php 64 KB

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