Transfer.php 66 KB

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