Transfer.php 71 KB

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