Whlabeltransport.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Whlabeltransport extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_whlabel','whlabel');
  6. $this->load->_model('Model_warehouse','warehouse');
  7. $this->load->_model('Model_excel','excel');
  8. $this->load->_model('Model_whlabeltransport','whlabeltransport');
  9. $this->load->_model('Model_logic_u9tools','logic_u9tools');
  10. $this->load->_model("Model_zzquque_u9","zzquque_u9");
  11. $this->load->_model("Model_logic_ding","logic_ding");
  12. }
  13. //定义方法的调用规则 获取URI第二段值
  14. public function _remap($arg,$arg_array)
  15. {
  16. if($arg == 'add')//添加
  17. {
  18. $this->_add();
  19. }
  20. else if($arg == 'edit')//修改
  21. {
  22. $this->_edit($arg_array);
  23. }
  24. else if($arg == 'del')//修改
  25. {
  26. $this->_del();
  27. }
  28. else if($arg == 'zj')//修改
  29. {
  30. $this->_zj();
  31. }
  32. else if($arg == 'list')//修改
  33. {
  34. $this->_list();
  35. }
  36. else if($arg == 'presetou')//修改
  37. {
  38. $this->_presetout($arg_array);
  39. }
  40. else if($arg == 'excel')
  41. {
  42. $this->_excel();
  43. }
  44. else if($arg == 'excelzh')
  45. {
  46. $this->_excelzh();//整合数据
  47. }
  48. else
  49. {
  50. $this->_index();
  51. }
  52. }
  53. //管理
  54. public function _index()
  55. {
  56. $post = $this->input->post(NULL, TRUE);
  57. if(isset($post['page']))
  58. {
  59. $page = $this->input->post('page',true);
  60. $perpage = $this->input->post('perpage',true);
  61. $warehouse = $this->input->post('warehouse',true);
  62. $sku = $this->input->post('sku',true);
  63. $text = $this->input->post('text',true);
  64. $cz = $this->input->post('cz',true);
  65. $order_no = $this->input->post('order_no',true);
  66. $xztime = $this->input->post('xztime',true);
  67. $timetk = $this->input->post('timetk',true);
  68. $timetj = $this->input->post('timetj',true);
  69. $timetk = strtotime($timetk);
  70. $timetj = strtotime($timetj);
  71. $where = "1=1 ";
  72. if($warehouse)
  73. {
  74. $where .= " and warehouse = '$warehouse'";
  75. }
  76. if($order_no){
  77. $where .= " and order_no = '$order_no'";
  78. }
  79. if($sku)
  80. {
  81. $where .= " and sku = '$sku'";
  82. }
  83. if($text)
  84. {
  85. $where .= " and text like '%$text%'";
  86. }
  87. if($cz != '')
  88. {
  89. $where .= " and cz = '$cz'";
  90. }
  91. if($timetk && $timetj)
  92. {
  93. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  94. }
  95. //数据排序
  96. $order_str = $xztime." desc";
  97. if(empty($page))
  98. {
  99. $start = 0;
  100. $perpage = 1;
  101. }
  102. else
  103. {
  104. $start = ($page - 1)*$perpage;
  105. }
  106. $info_list = $this->whlabeltransport->find_all($where,'id,order_no,warehouse,sku,title,num,enter,stime,time,text,cz',$order_str,$start,$perpage);
  107. foreach ($info_list as $key=>$value)
  108. {
  109. $warehouse = $this->warehouse->read($value['warehouse']);
  110. $info_list[$key]['order_no'] = empty($value['order_no'])?"":$value['order_no'];
  111. $info_list[$key]['warehouse'] = $warehouse['title'];
  112. $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
  113. $info_list[$key]['stime'] = date('Y-m-d',$value['stime']);
  114. if($value['time'] > 0)
  115. {
  116. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  117. }
  118. else
  119. {
  120. $info_list[$key]['time'] = "<p class='wc'><p>";
  121. }
  122. if($value['cz'] == '0')
  123. {
  124. $info_list[$key]['cz'] = "<p class='cz'><span class='ztwc' data-id='".$value['id']."'>点击完成</span><p>";
  125. }
  126. else if($value['cz'] == '1')
  127. {
  128. $info_list[$key]['cz'] = "<p class='cz'><font>已完成</font><p>";
  129. }
  130. }
  131. $total = $this->whlabeltransport->find_count($where);
  132. $pagenum = ceil($total/$perpage);
  133. $over = $total-($start+$perpage);
  134. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  135. echo json_encode($rows);exit;
  136. }
  137. $this->_Template('whlabeltransport',$this->data);
  138. }
  139. //添加
  140. public function _add()
  141. {
  142. $post = $this->input->post(NULL, TRUE);
  143. $data_str = $post['data'];
  144. $list = json_decode($data_str,true);
  145. if(empty($list)){
  146. echo json_encode(['smg'=>"在途数据为空",'success'=>false]);
  147. }
  148. $i = 0;$j = 0;$ed = array();
  149. $order_no = "ZT".date("ymdHis");
  150. foreach ($list as $key=>$value)
  151. {
  152. if($key == 0){
  153. if(!empty($value[5])){
  154. if(strpos($value[5], "ZT") !== false){
  155. $order_no = $value[5];
  156. }
  157. }
  158. }
  159. $time = time();
  160. if($value['0'] == "")
  161. {
  162. continue;
  163. }
  164. $warehouse = $this->warehouse->get_title($value['0']);
  165. //$d = $this->whlabel->get_sku($value['1']);//针对各个仓库
  166. if($value['2'] =='' || $value['2'] < 1)
  167. {
  168. continue;
  169. }
  170. $d = $this->whlabel->get_warehousesku(5,$value['1']);//针对各个仓库
  171. if(!$d)//如果没有这个SKU
  172. {
  173. $ed[] = array($value['1'].'-库存中不存在此SKU');
  174. $j++;
  175. continue;
  176. }
  177. if(!isset($warehouse['id']))
  178. {
  179. $ed[] = array($value['1'].'-仓库名错误!');
  180. $j++;
  181. continue;
  182. }
  183. if($value['3'] == '')
  184. {
  185. $ed[] = array($value['1'].'-没有填写预达日期!');
  186. $j++;
  187. continue;
  188. }
  189. $post['sku'] = $value['1'];
  190. $post['num'] = $value['2'];//数量
  191. $post['stime'] = strtotime($value['3']);//预计到达日期
  192. $post['text'] = $value['4'];//备注
  193. $post['enter'] = $time;//添加时间
  194. $post['shop'] = $d['shop'];
  195. $post['warehouse'] = $warehouse['id'];
  196. $post['purchase'] = $d['purchase'];
  197. $post['title'] = $d['title'];
  198. $post['number'] = $d['number'];
  199. $post['features'] = $d['features'];
  200. $post['retreatwarehouse'] = $d['retreatwarehouse'];
  201. $post['order_no'] = $order_no;
  202. $post['u9_tb'] = 0;
  203. $this->whlabeltransport->insert($post);
  204. }
  205. $num = $this->whlabeltransport->find_all("order_no = '".$order_no."'");
  206. if(!empty($num) ){
  207. $num2 = $this->zzquque_u9->find_all("order_no = '".$order_no."'");
  208. if(empty($num2)){
  209. $this->zzquque_u9->insert( [
  210. 'platform'=>'',
  211. 'warehouse'=>0,
  212. 'type'=>1, //成品库到在途库
  213. 'order_no'=>$order_no,
  214. 'status'=>0,
  215. 'create_time'=>time(),
  216. 'update_time'=>time(),
  217. ]);
  218. }
  219. }
  220. if($j > 0)
  221. {
  222. $tt = date('Ymd',time());
  223. $title = '导入错误信息-'.$tt;
  224. $filename = $title.".xlsx";
  225. $eds =[];
  226. foreach($ed as $k=>$v){
  227. $eds[]= [
  228. "错误信息"=>$v[0]
  229. ];
  230. }
  231. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','data'=>['filename'=>$filename,'error'=>$eds],'success'=>true));exit;
  232. }
  233. else
  234. {
  235. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  236. }
  237. }
  238. public function _addbak()
  239. {
  240. $dir = '/data/excel/'.date('Ymd',time()).'/';
  241. $config['upload_path'] = '.'.$dir ;
  242. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  243. $config['allowed_types'] = 'xls|xlsx|csv';
  244. $config['max_size'] = 10240;
  245. $this->load->library('upload', $config);
  246. $this->upload->initialize($config);
  247. if ($this->upload->do_upload('userfile'))
  248. {
  249. $full_path = $dir.$this->upload->data('file_name');
  250. $fileName = '.' . $full_path;
  251. if (!file_exists($fileName))
  252. {
  253. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  254. }
  255. else
  256. {
  257. libxml_use_internal_errors(true);
  258. require_once "./data/excel/PHPExcel/IOFactory.php";
  259. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  260. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  261. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  262. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  263. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  264. ++$column;//如果列数大于26行
  265. $list = array();
  266. for ($i = 2; $i <= $row; $i++) // 行数循环
  267. {
  268. $data = array();
  269. for ($c = 'A'; $c != $column; $c++) // 列数循环
  270. {
  271. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  272. }
  273. $list[] = $data;
  274. }
  275. }
  276. $i = 0;$j = 0;$ed = array();
  277. $order_no = "ZT".date("ymdHis");
  278. foreach ($list as $key=>$value)
  279. {
  280. if($key == 0){
  281. if(!empty($value[5])){
  282. if(strpos($value[5], "ZT") !== false){
  283. $order_no = $value[5];
  284. }
  285. }
  286. }
  287. $time = time();
  288. if($value['0'] == "")
  289. {
  290. continue;
  291. }
  292. $warehouse = $this->warehouse->get_title($value['0']);
  293. //$d = $this->whlabel->get_sku($value['1']);//针对各个仓库
  294. if($value['2'] =='' || $value['2'] < 1)
  295. {
  296. continue;
  297. }
  298. $d = $this->whlabel->get_warehousesku(5,$value['1']);//针对各个仓库
  299. if(!$d)//如果没有这个SKU
  300. {
  301. $ed[] = array($value['1'].'-库存中不存在此SKU');
  302. $j++;
  303. continue;
  304. }
  305. if(!isset($warehouse['id']))
  306. {
  307. $ed[] = array($value['1'].'-仓库名错误!');
  308. $j++;
  309. continue;
  310. }
  311. if($value['3'] == '')
  312. {
  313. $ed[] = array($value['1'].'-没有填写预达日期!');
  314. $j++;
  315. continue;
  316. }
  317. $post['sku'] = $value['1'];
  318. $post['num'] = $value['2'];//数量
  319. $post['stime'] = strtotime($value['3']);//预计到达日期
  320. $post['text'] = $value['4'];//备注
  321. $post['enter'] = $time;//添加时间
  322. $post['shop'] = $d['shop'];
  323. $post['warehouse'] = $warehouse['id'];
  324. $post['purchase'] = $d['purchase'];
  325. $post['title'] = $d['title'];
  326. $post['number'] = $d['number'];
  327. $post['features'] = $d['features'];
  328. $post['retreatwarehouse'] = $d['retreatwarehouse'];
  329. $post['order_no'] = $order_no;
  330. $post['u9_tb'] = 0;
  331. $this->whlabeltransport->insert($post);
  332. }
  333. $num = $this->whlabeltransport->find_all("order_no = '".$order_no."'");
  334. if(!empty($num) ){
  335. $num2 = $this->zzquque_u9->find_all("order_no = '".$order_no."'");
  336. if(empty($num2)){
  337. $this->zzquque_u9->insert( [
  338. 'platform'=>'',
  339. 'warehouse'=>0,
  340. 'type'=>1, //成品库到在途库
  341. 'order_no'=>$order_no,
  342. 'status'=>0,
  343. 'create_time'=>time(),
  344. 'update_time'=>time(),
  345. ]);
  346. }
  347. }
  348. if($j > 0)
  349. {
  350. $tt = date('Ymd',time());
  351. $title = '导入错误信息-'.$tt;
  352. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  353. $tail = "\n";
  354. $filename = $title.".xls";
  355. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  356. $dir = '/data/excel/'.$time.'/';
  357. $file_name = 'error_'.$time.rand(1000,9999);
  358. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  359. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  360. fwrite($myfile,$ecl);
  361. fclose($myfile);
  362. $error = $dir.$file_name.'.xls';
  363. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  364. }
  365. else
  366. {
  367. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  368. }
  369. }
  370. }
  371. //修改
  372. public function _edit($arg_array)
  373. {
  374. $post = $this->input->post(NULL, TRUE);
  375. if(isset($post['id']))
  376. {
  377. $id = $this->input->post('id',true);
  378. $data = $this->whlabeltransport->read($id);
  379. if($data['cz'] == '1')
  380. {
  381. echo json_encode(array('msg'=>'已完成的数据无法修改!','success'=>false));exit;
  382. }
  383. $post['num'] = $this->input->post('num',true);
  384. $post['text'] = $this->input->post('text',true);
  385. $post['sku'] = $this->input->post('sku',true);
  386. $stime = $this->input->post('stime',true);
  387. $post['stime'] = strtotime($stime);
  388. $post['edit'] = time();
  389. $info = $this->whlabeltransport->read($id);
  390. if($post['sku'] !== $info['sku']){
  391. $d = $this->whlabel->get_warehousesku(5,trim($post['sku']));//针对各个仓库
  392. if(!$d)//如果没有这个SKU
  393. {
  394. echo json_encode(array('msg'=>'修改失败,'.$post['sku'].'-库存中不存在此SKU','success'=>false));exit;
  395. }
  396. $post['shop'] = $d['shop'];
  397. $post['purchase'] = $d['purchase'];
  398. $post['title'] = $d['title'];
  399. $post['number'] = $d['number'];
  400. $post['features'] = $d['features'];
  401. $post['retreatwarehouse'] = $d['retreatwarehouse'];
  402. }
  403. if($this->whlabeltransport->save($post,$id))
  404. {
  405. $this->logic_ding->sendToDing("检测在途库存".$info['order_no']."修改前的数据".json_encode($info,JSON_UNESCAPED_UNICODE));
  406. $this->logic_ding->sendToDing("检测在途库存".$info['order_no']."修改的数据".json_encode($post,JSON_UNESCAPED_UNICODE));
  407. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  408. }
  409. else
  410. {
  411. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  412. }
  413. }
  414. $arg_array = $arg_array[0];
  415. $whlabeltransport = $this->whlabeltransport->read($arg_array);
  416. $this->data['whlabeltransport'] = $whlabeltransport;
  417. $this->_Template('whlabeltransport_edit',$this->data);
  418. }
  419. public function _zj()
  420. {
  421. $post = $this->input->post(NULL, TRUE);
  422. if(isset($post['id']))
  423. {
  424. $id = $this->input->post('id',true);
  425. $data = $this->whlabeltransport->read($id);
  426. if($data['cz'] == '0')
  427. {
  428. $list = array();$num = "";$title = "";$features = "";
  429. $order = $this->input->post('order',true);
  430. $shop = $this->input->post('shop',true);
  431. $label['shop'] = $data['shop'];
  432. $label['sku'] = $data['sku'];
  433. $label['warehouse'] = $data['warehouse'];
  434. $label['purchase'] = $data['purchase'];
  435. $label['retreatwarehouse'] = $data['retreatwarehouse'];
  436. $label['state'] = 0;
  437. $time = time();
  438. $label['title'] = $data['title'];
  439. $label['number'] = $data['number'];
  440. $label['features'] = $data['features'];
  441. $label['enter'] = $time;
  442. $label['time'] = $time;//操作时间
  443. if($label['warehouse'] == '5')
  444. {
  445. $yza = $this->whlabel->find_all("sku = '".$label['sku']."' and warehouse = '".$label['warehouse']."'",'*','id desc');
  446. if($yza)
  447. {
  448. if($label['features'] != $yza[0]['features'])
  449. {
  450. echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!- 1','success'=>false));exit;
  451. }
  452. }
  453. /**
  454. $yzb = $this->whlabel->find_all("features = '".$label['features']."' and warehouse = '".$label['warehouse']."'",'*','id desc');
  455. if($yzb)
  456. {
  457. if($label['sku'] != $yzb[0]['sku'])
  458. {
  459. echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致! - 2','success'=>false));exit;
  460. }
  461. }
  462. **/
  463. }
  464. if(empty($data['num'])){
  465. echo json_encode(array('msg'=>'数量不能为空!','success'=>false));exit;
  466. }
  467. $this->db->trans_begin();
  468. for($i=0;$i<$data['num'];$i++)
  469. {
  470. $label['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
  471. $label['cs'] = $id;//前期增加这个是在途库存添加的数据
  472. $label['rktype'] = 1;
  473. $this->whlabel->insert($label);
  474. }
  475. $this->whlabeltransport->save(array('time'=>$time,'cz'=>1),$data['id']);
  476. if ($this->db->trans_status() === TRUE)
  477. {
  478. $this->db->trans_commit();
  479. usleep(5000);
  480. $num = $this->whlabeltransport->find_count("order_no = '".$data['order_no']."' and cz = 0");
  481. if(empty($num)){
  482. if(!empty($data['order_no'])){
  483. $this->zzquque_u9->insert( [
  484. 'platform'=>'',
  485. 'warehouse'=>0,
  486. 'type'=>2, //将在途库存调入到美仓
  487. 'order_no'=>$data['order_no'],
  488. 'status'=>0,
  489. 'create_time'=>time(),
  490. 'update_time'=>time(),
  491. ]);
  492. }
  493. }
  494. echo json_encode(array('msg'=>'入库成功!','id'=>$id,'time'=>date('Y-m-d H:i:s',$time),'success'=>true));exit;
  495. }
  496. else
  497. {
  498. $this->db->trans_rollback();
  499. echo json_encode(array('msg'=>'入库失败,请重试!','success'=>false));exit;
  500. }
  501. }
  502. else
  503. {
  504. echo json_encode(array('msg'=>'错误!已操作入库','success'=>false));exit;
  505. }
  506. }
  507. }
  508. //导出模板
  509. public function _presetout()
  510. {
  511. if(isset($_GET['excel']))
  512. {
  513. $where = "sku != 'Preset'";
  514. //数据排序
  515. $order_str = "id desc";
  516. if(empty($page))
  517. {
  518. $start = 0;
  519. $perpage = 1;
  520. }
  521. else
  522. {
  523. $start = ($page - 1)*$perpage;
  524. }
  525. $warehouse = $this->input->get('warehouse',true);
  526. if($warehouse)
  527. {
  528. $where .= " and warehouse = '".$warehouse."'";
  529. }
  530. //取得信息列表
  531. $info_list = $this->whlabel->find_pc($where,'warehouse,sku','*');
  532. $rows = array();$list = array();
  533. foreach ($info_list as $value)
  534. {
  535. $warehouse = $this->warehouse->read($value['warehouse']);
  536. $number = $value['number'];$ftime = time()-15*24*3600;
  537. $list[] = array($warehouse['title'],$value['sku'],'0','','','');
  538. }
  539. $title = "在途模板";
  540. $titlename = "<table border=1>
  541. <tr align='center'>
  542. <td>仓库</td>
  543. <td>SKU</td>
  544. <td>数量</td>
  545. <td>预达日期(格式:2022-01-01)</td>
  546. <td>备注</td>
  547. <td>在途订单编码</td>
  548. </tr>
  549. </table>";
  550. $filename = $title.".xls";
  551. $tail = "";
  552. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  553. }
  554. }
  555. public function _excel()
  556. {
  557. if(isset($_GET['excel']))
  558. {
  559. $warehouse = $this->input->get('warehouse',true);
  560. $sku = $this->input->get('sku',true);
  561. $cz = $this->input->get('cz',true);
  562. $text = $this->input->post('text',true);
  563. $xztime = $this->input->get('xztime',true);
  564. $timetk = $this->input->get('timetk',true);
  565. $timetj = $this->input->get('timetj',true);
  566. $timetk = strtotime($timetk);
  567. $timetj = strtotime($timetj);
  568. $where = "1=1 ";
  569. if($warehouse)
  570. {
  571. $where .= " and warehouse = '$warehouse'";
  572. }
  573. if($sku)
  574. {
  575. $where .= " and sku = '$sku'";
  576. }
  577. if($text)
  578. {
  579. $where .= " and text like '%$text%'";
  580. }
  581. if($cz != '')
  582. {
  583. $where .= " and cz = '$cz'";
  584. }
  585. if($timetk && $timetj)
  586. {
  587. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  588. }
  589. //数据排序
  590. $order_str = $xztime." desc";
  591. //取得信息列表
  592. $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,enter,stime,time,text,features');
  593. //转化为用友的编码 不为空在执行 为空了啥都不说了
  594. if(!empty($info_list)){
  595. $info_list = $this->logic_u9tools->getU9bm($info_list,'features');
  596. }
  597. $final_list = [];
  598. $warehouse_list = $this->warehouse->find_all("1=1",'id,title');
  599. $warehouse_list = array_column($warehouse_list,'title','id');
  600. foreach($info_list as $key=>$value){
  601. $final_list[$key] = [
  602. 'warehouse'=>isset($warehouse_list[$value['warehouse']])?$warehouse_list[$value['warehouse']]:"",
  603. "sku"=>$value['sku'],
  604. 'title'=>$value['title'],
  605. 'jm'=>$value['jm'],
  606. 'num'=>$value['num'],
  607. 'enter'=>date('Y-m-d H:i:s',$value['enter']),
  608. 'stime'=>date('Y-m-d',$value['stime']),
  609. 'time'=>(($value['time'] > 0))?date('Y-m-d H:i:s',$value['time']):"<p class='wc'><p>",
  610. 'text'=>$value['text']
  611. ];
  612. }
  613. // foreach ($info_list as $key=>$value)
  614. // {
  615. // $warehouse = $this->warehouse->read($value['warehouse']);
  616. // $info_list[$key]['warehouse'] = $warehouse['title'];
  617. // $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
  618. // $info_list[$key]['stime'] = date('Y-m-d',$value['stime']);
  619. // if($value['time'] > 0)
  620. // {
  621. // $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  622. // }
  623. // else
  624. // {
  625. // $info_list[$key]['time'] = "<p class='wc'><p>";
  626. // }
  627. // }
  628. $title = "在途数据".date('Y-m-d',time());
  629. $titlename = "<table border=1>
  630. <tr align='center'>
  631. <td>仓库</td>
  632. <td>SKU</td>
  633. <td>名称</td>
  634. <td>料号</td>
  635. <td>数量</td>
  636. <td>添加日期</td>
  637. <td>预达日期</td>
  638. <td>完成日期</td>
  639. <td>备注</td>
  640. </tr>
  641. </table>";
  642. $filename = $title.".xls";
  643. $tail = "";
  644. $this->excel->get_fz2($final_list,$titlename,$filename,$tail);
  645. }
  646. }
  647. public function _excelzh()
  648. {
  649. if(isset($_GET['excel']))
  650. {
  651. $warehouse = $this->input->get('warehouse',true);
  652. $sku = $this->input->get('sku',true);
  653. $cz = $this->input->get('cz',true);
  654. $text = $this->input->post('text',true);
  655. $xztime = $this->input->get('xztime',true);
  656. $timetk = $this->input->get('timetk',true);
  657. $timetj = $this->input->get('timetj',true);
  658. $timetk = strtotime($timetk);
  659. $timetj = strtotime($timetj);
  660. $where = "time = '0' ";
  661. if($warehouse)
  662. {
  663. $where .= " and warehouse = '$warehouse'";
  664. }
  665. if($sku)
  666. {
  667. $where .= " and sku = '$sku'";
  668. }
  669. if($text)
  670. {
  671. $where .= " and text like '%$text%'";
  672. }
  673. if($cz != '')
  674. {
  675. $where .= " and cz = '$cz'";
  676. }
  677. if($timetk && $timetj)
  678. {
  679. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  680. }
  681. //数据排序
  682. $order_str = $xztime." desc";
  683. //取得信息列表
  684. $zh = array();
  685. $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,features,enter,stime,text');
  686. //转化为用友的编码 不为空在执行 为空了啥都不说了
  687. if(!empty($info_list)){
  688. $info_list = $this->logic_u9tools->getU9bm($info_list,'features');
  689. }
  690. $final_list = [];
  691. $warehouse_list = $this->warehouse->find_all("1=1",'id,title');
  692. $warehouse_list = array_column($warehouse_list,'title','id');
  693. foreach($info_list as $key=>$value){
  694. $final_list[$key] = [
  695. 'warehouse'=>$value['warehouse'],
  696. "sku"=>$value['sku'],
  697. 'title'=>$value['title'],
  698. 'jm'=>$value['jm'],
  699. 'num'=>$value['num'],
  700. 'features'=>$value['features'],
  701. 'enter'=>date('Y-m-d H:i:s',$value['enter']),
  702. 'stime'=>date('Y-m-d',$value['stime']),
  703. 'text'=>$value['text']
  704. ];
  705. }
  706. foreach ($final_list as $v)
  707. {
  708. $c = $this->whlabel->find_count('state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');
  709. // $warehouse = $this->warehouse->read($v['warehouse']);
  710. // $v['warehouse'] = $warehouse['title'];
  711. // $v['enter'] = date('Y-m-d H:i:s',$v['enter']);
  712. // $v['stime'] = date('Y-m-d',$v['stime']);
  713. $v['warehouse'] = isset($warehouse_list[$value['warehouse']])?$warehouse_list[$value['warehouse']]:"";
  714. if(isset($zh[$v['features']]))
  715. {
  716. $zh[$v['features']]['num'] += $v['num'];
  717. }
  718. else
  719. {
  720. $zh[$v['features']] = $v;
  721. }
  722. $zh[$v['features']]['features'] = $c;
  723. }
  724. $title = "在途数据".date('Y-m-d',time());
  725. $titlename = "<table border=1>
  726. <tr align='center'>
  727. <td>仓库</td>
  728. <td>SKU</td>
  729. <td>名称</td>
  730. <td>料号</td>
  731. <td>在途数量</td>
  732. <td>库存数量</td>
  733. <td>添加在途日期</td>
  734. <td>预达日期</td>
  735. <td>备注</td>
  736. </tr>
  737. </table>";
  738. $filename = $title.".xls";
  739. $tail = "";
  740. $this->excel->get_fz2($zh,$titlename,$filename,$tail);
  741. }
  742. }
  743. //批量完成
  744. public function _list()
  745. {
  746. $post = $this->input->post(NULL, TRUE);
  747. if(isset($post['s']))
  748. {
  749. $cw = '';$i = 0;
  750. $id_arr = $this->input->post('s');
  751. $id_arr = explode(',',$id_arr);
  752. if(!$id_arr)
  753. {
  754. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  755. }
  756. //循环删除记录
  757. foreach ($id_arr as $v)
  758. {
  759. $id = $v;
  760. $data = $this->whlabeltransport->read($id);
  761. if($data['cz'] == '0')
  762. {
  763. $list = array();$num = "";$title = "";$features = "";
  764. $order = $this->input->post('order',true);
  765. $shop = $this->input->post('shop',true);
  766. $label['shop'] = $data['shop'];
  767. $label['sku'] = $data['sku'];
  768. $label['warehouse'] = $data['warehouse'];
  769. $label['purchase'] = $data['purchase'];
  770. $label['retreatwarehouse'] = $data['retreatwarehouse'];
  771. $label['state'] = 0;
  772. $time = time();
  773. $label['title'] = $data['title'];
  774. $label['number'] = $data['number'];
  775. $label['features'] = $data['features'];
  776. $label['enter'] = $time;
  777. $label['time'] = $time;//操作时间
  778. if($label['warehouse'] == '5')
  779. {
  780. $yza = $this->whlabel->find_all("sku = '".$label['sku']."' and warehouse = '".$label['warehouse']."'");
  781. if($yza)
  782. {
  783. if($label['features'] != $yza[0]['features'])
  784. {
  785. echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','success'=>false));exit;
  786. }
  787. }
  788. $yzb = $this->whlabel->find_all("features = '".$label['features']."' and warehouse = '".$label['warehouse']."'");
  789. if($yzb)
  790. {
  791. if($label['sku'] != $yzb[0]['sku'])
  792. {
  793. echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致!','success'=>false));exit;
  794. }
  795. }
  796. }
  797. $this->db->trans_begin();
  798. for($i=0;$i<$data['num'];$i++)
  799. {
  800. $label['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
  801. $label['cs'] = 1;//前期增加这个是在途库存添加的数据
  802. $label['rktype'] = 1;
  803. $this->whlabel->insert($label);
  804. }
  805. $this->whlabeltransport->save(array('time'=>$time,'cz'=>1),$data['id']);
  806. if ($this->db->trans_status() === TRUE)
  807. {
  808. $this->db->trans_commit();
  809. $i++;
  810. }
  811. else
  812. {
  813. $this->db->trans_rollback();
  814. $cw .= $data['sku'].' | ';
  815. }
  816. }
  817. }
  818. if(count($id_arr) == $i)
  819. {
  820. echo json_encode(array('msg'=>'入库成功!','success'=>true));exit;
  821. }
  822. else
  823. {
  824. echo json_encode(array('msg'=>'有入库失败数据:'.$cw,'success'=>false));exit;
  825. }
  826. }
  827. }
  828. //删除
  829. public function _del()
  830. {
  831. $post = $this->input->post(NULL, TRUE);
  832. if(isset($post['s']))
  833. {
  834. $id_arr = $this->input->post('s');
  835. $id_arr = explode(',',$id_arr);
  836. if(!$id_arr)
  837. {
  838. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  839. }
  840. //循环删除记录
  841. foreach ($id_arr as $v)
  842. {
  843. $data = $this->whlabeltransport->read($v);
  844. if($data['cz'] == '0')
  845. {
  846. $this->whlabeltransport->remove($v);
  847. }
  848. else
  849. {
  850. echo json_encode(array('msg'=>'有已完成数据!无法继续删除','success'=>false));exit;
  851. }
  852. }
  853. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  854. }
  855. }
  856. }