Whlabeltransport.php 23 KB

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