Transfer.php 63 KB

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