Transfer.php 64 KB

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