Whlabeltransport.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. $this->zzquque_u9->insert( [
  348. 'platform'=>'',
  349. 'warehouse'=>0,
  350. 'type'=>2, //将在途库存调入到美仓
  351. 'order_no'=>$data['order_no'],
  352. 'status'=>0,
  353. 'create_time'=>time(),
  354. 'update_time'=>time(),
  355. ]);
  356. }
  357. if ($this->db->trans_status() === TRUE)
  358. {
  359. $this->db->trans_commit();
  360. echo json_encode(array('msg'=>'入库成功!','id'=>$id,'time'=>date('Y-m-d H:i:s',$time),'success'=>true));exit;
  361. }
  362. else
  363. {
  364. $this->db->trans_rollback();
  365. echo json_encode(array('msg'=>'入库失败,请重试!','success'=>false));exit;
  366. }
  367. }
  368. else
  369. {
  370. echo json_encode(array('msg'=>'错误!已操作入库','success'=>false));exit;
  371. }
  372. }
  373. }
  374. //导出模板
  375. public function _presetout()
  376. {
  377. if(isset($_GET['excel']))
  378. {
  379. $where = "sku != 'Preset'";
  380. //数据排序
  381. $order_str = "id desc";
  382. if(empty($page))
  383. {
  384. $start = 0;
  385. $perpage = 1;
  386. }
  387. else
  388. {
  389. $start = ($page - 1)*$perpage;
  390. }
  391. $warehouse = $this->input->get('warehouse',true);
  392. if($warehouse)
  393. {
  394. $where .= " and warehouse = '".$warehouse."'";
  395. }
  396. //取得信息列表
  397. $info_list = $this->whlabel->find_pc($where,'warehouse,sku','*');
  398. $rows = array();$list = array();
  399. foreach ($info_list as $value)
  400. {
  401. $warehouse = $this->warehouse->read($value['warehouse']);
  402. $number = $value['number'];$ftime = time()-15*24*3600;
  403. $list[] = array($warehouse['title'],$value['sku'],'0','','');
  404. }
  405. $title = "在途模板";
  406. $titlename = "<table border=1>
  407. <tr align='center'>
  408. <td>仓库</td>
  409. <td>SKU</td>
  410. <td>数量</td>
  411. <td>预达日期(格式:2022-01-01)</td>
  412. <td>备注</td>
  413. </tr>
  414. </table>";
  415. $filename = $title.".xls";
  416. $tail = "";
  417. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  418. }
  419. }
  420. public function _excel()
  421. {
  422. if(isset($_GET['excel']))
  423. {
  424. $warehouse = $this->input->get('warehouse',true);
  425. $sku = $this->input->get('sku',true);
  426. $cz = $this->input->get('cz',true);
  427. $text = $this->input->post('text',true);
  428. $xztime = $this->input->get('xztime',true);
  429. $timetk = $this->input->get('timetk',true);
  430. $timetj = $this->input->get('timetj',true);
  431. $timetk = strtotime($timetk);
  432. $timetj = strtotime($timetj);
  433. $where = "1=1 ";
  434. if($warehouse)
  435. {
  436. $where .= " and warehouse = '$warehouse'";
  437. }
  438. if($sku)
  439. {
  440. $where .= " and sku = '$sku'";
  441. }
  442. if($text)
  443. {
  444. $where .= " and text like '%$text%'";
  445. }
  446. if($cz != '')
  447. {
  448. $where .= " and cz = '$cz'";
  449. }
  450. if($timetk && $timetj)
  451. {
  452. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  453. }
  454. //数据排序
  455. $order_str = $xztime." desc";
  456. //取得信息列表
  457. $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,enter,stime,time,text,features');
  458. //转化为用友的编码 不为空在执行 为空了啥都不说了
  459. if(!empty($info_list)){
  460. $info_list = $this->logic_u9tools->getU9bm($info_list,'features');
  461. }
  462. $final_list = [];
  463. $warehouse_list = $this->warehouse->find_all("1=1",'id,title');
  464. $warehouse_list = array_column($warehouse_list,'title','id');
  465. foreach($info_list as $key=>$value){
  466. $final_list[$key] = [
  467. 'warehouse'=>isset($warehouse_list[$value['warehouse']])?$warehouse_list[$value['warehouse']]:"",
  468. "sku"=>$value['sku'],
  469. 'title'=>$value['title'],
  470. 'jm'=>$value['jm'],
  471. 'num'=>$value['num'],
  472. 'enter'=>date('Y-m-d H:i:s',$value['enter']),
  473. 'stime'=>date('Y-m-d',$value['stime']),
  474. 'time'=>(($value['time'] > 0))?date('Y-m-d H:i:s',$value['time']):"<p class='wc'><p>",
  475. 'text'=>$value['text']
  476. ];
  477. }
  478. // foreach ($info_list as $key=>$value)
  479. // {
  480. // $warehouse = $this->warehouse->read($value['warehouse']);
  481. // $info_list[$key]['warehouse'] = $warehouse['title'];
  482. // $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
  483. // $info_list[$key]['stime'] = date('Y-m-d',$value['stime']);
  484. // if($value['time'] > 0)
  485. // {
  486. // $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  487. // }
  488. // else
  489. // {
  490. // $info_list[$key]['time'] = "<p class='wc'><p>";
  491. // }
  492. // }
  493. $title = "在途数据".date('Y-m-d',time());
  494. $titlename = "<table border=1>
  495. <tr align='center'>
  496. <td>仓库</td>
  497. <td>SKU</td>
  498. <td>名称</td>
  499. <td>料号</td>
  500. <td>数量</td>
  501. <td>添加日期</td>
  502. <td>预达日期</td>
  503. <td>完成日期</td>
  504. <td>备注</td>
  505. </tr>
  506. </table>";
  507. $filename = $title.".xls";
  508. $tail = "";
  509. $this->excel->get_fz2($final_list,$titlename,$filename,$tail);
  510. }
  511. }
  512. public function _excelzh()
  513. {
  514. if(isset($_GET['excel']))
  515. {
  516. $warehouse = $this->input->get('warehouse',true);
  517. $sku = $this->input->get('sku',true);
  518. $cz = $this->input->get('cz',true);
  519. $text = $this->input->post('text',true);
  520. $xztime = $this->input->get('xztime',true);
  521. $timetk = $this->input->get('timetk',true);
  522. $timetj = $this->input->get('timetj',true);
  523. $timetk = strtotime($timetk);
  524. $timetj = strtotime($timetj);
  525. $where = "time = '0' ";
  526. if($warehouse)
  527. {
  528. $where .= " and warehouse = '$warehouse'";
  529. }
  530. if($sku)
  531. {
  532. $where .= " and sku = '$sku'";
  533. }
  534. if($text)
  535. {
  536. $where .= " and text like '%$text%'";
  537. }
  538. if($cz != '')
  539. {
  540. $where .= " and cz = '$cz'";
  541. }
  542. if($timetk && $timetj)
  543. {
  544. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  545. }
  546. //数据排序
  547. $order_str = $xztime." desc";
  548. //取得信息列表
  549. $zh = array();
  550. $info_list = $this->whlabeltransport->find_all($where,'warehouse,sku,title,num,features,enter,stime,text');
  551. //转化为用友的编码 不为空在执行 为空了啥都不说了
  552. if(!empty($info_list)){
  553. $info_list = $this->logic_u9tools->getU9bm($info_list,'features');
  554. }
  555. $final_list = [];
  556. $warehouse_list = $this->warehouse->find_all("1=1",'id,title');
  557. $warehouse_list = array_column($warehouse_list,'title','id');
  558. foreach($info_list as $key=>$value){
  559. $final_list[$key] = [
  560. 'warehouse'=>$value['warehouse'],
  561. "sku"=>$value['sku'],
  562. 'title'=>$value['title'],
  563. 'jm'=>$value['jm'],
  564. 'num'=>$value['num'],
  565. 'features'=>$value['features'],
  566. 'enter'=>date('Y-m-d H:i:s',$value['enter']),
  567. 'stime'=>date('Y-m-d',$value['stime']),
  568. 'text'=>$value['text']
  569. ];
  570. }
  571. foreach ($final_list as $v)
  572. {
  573. $c = $this->whlabel->find_count('state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');
  574. // $warehouse = $this->warehouse->read($v['warehouse']);
  575. // $v['warehouse'] = $warehouse['title'];
  576. // $v['enter'] = date('Y-m-d H:i:s',$v['enter']);
  577. // $v['stime'] = date('Y-m-d',$v['stime']);
  578. $v['warehouse'] = isset($warehouse_list[$value['warehouse']])?$warehouse_list[$value['warehouse']]:"";
  579. if(isset($zh[$v['features']]))
  580. {
  581. $zh[$v['features']]['num'] += $v['num'];
  582. }
  583. else
  584. {
  585. $zh[$v['features']] = $v;
  586. }
  587. $zh[$v['features']]['features'] = $c;
  588. }
  589. $title = "在途数据".date('Y-m-d',time());
  590. $titlename = "<table border=1>
  591. <tr align='center'>
  592. <td>仓库</td>
  593. <td>SKU</td>
  594. <td>名称</td>
  595. <td>料号</td>
  596. <td>在途数量</td>
  597. <td>库存数量</td>
  598. <td>添加在途日期</td>
  599. <td>预达日期</td>
  600. <td>备注</td>
  601. </tr>
  602. </table>";
  603. $filename = $title.".xls";
  604. $tail = "";
  605. $this->excel->get_fz2($zh,$titlename,$filename,$tail);
  606. }
  607. }
  608. //批量完成
  609. public function _list()
  610. {
  611. $post = $this->input->post(NULL, TRUE);
  612. if(isset($post['s']))
  613. {
  614. $cw = '';$i = 0;
  615. $id_arr = $this->input->post('s');
  616. $id_arr = explode(',',$id_arr);
  617. if(!$id_arr)
  618. {
  619. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  620. }
  621. //循环删除记录
  622. foreach ($id_arr as $v)
  623. {
  624. $id = $v;
  625. $data = $this->whlabeltransport->read($id);
  626. if($data['cz'] == '0')
  627. {
  628. $list = array();$num = "";$title = "";$features = "";
  629. $order = $this->input->post('order',true);
  630. $shop = $this->input->post('shop',true);
  631. $label['shop'] = $data['shop'];
  632. $label['sku'] = $data['sku'];
  633. $label['warehouse'] = $data['warehouse'];
  634. $label['purchase'] = $data['purchase'];
  635. $label['retreatwarehouse'] = $data['retreatwarehouse'];
  636. $label['state'] = 0;
  637. $time = time();
  638. $label['title'] = $data['title'];
  639. $label['number'] = $data['number'];
  640. $label['features'] = $data['features'];
  641. $label['enter'] = $time;
  642. $label['time'] = $time;//操作时间
  643. if($label['warehouse'] == '5')
  644. {
  645. $yza = $this->whlabel->find_all("sku = '".$label['sku']."' and warehouse = '".$label['warehouse']."'");
  646. if($yza)
  647. {
  648. if($label['features'] != $yza[0]['features'])
  649. {
  650. echo json_encode(array('msg'=>'此SKU的产品信息和现有不一致!','success'=>false));exit;
  651. }
  652. }
  653. $yzb = $this->whlabel->find_all("features = '".$label['features']."' and warehouse = '".$label['warehouse']."'");
  654. if($yzb)
  655. {
  656. if($label['sku'] != $yzb[0]['sku'])
  657. {
  658. echo json_encode(array('msg'=>'此产品信息的SKU和现有不一致!','success'=>false));exit;
  659. }
  660. }
  661. }
  662. $this->db->trans_begin();
  663. for($i=0;$i<$data['num'];$i++)
  664. {
  665. $label['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
  666. $label['cs'] = 1;//前期增加这个是在途库存添加的数据
  667. $label['rktype'] = 1;
  668. $this->whlabel->insert($label);
  669. }
  670. $this->whlabeltransport->save(array('time'=>$time,'cz'=>1),$data['id']);
  671. if ($this->db->trans_status() === TRUE)
  672. {
  673. $this->db->trans_commit();
  674. $i++;
  675. }
  676. else
  677. {
  678. $this->db->trans_rollback();
  679. $cw .= $data['sku'].' | ';
  680. }
  681. }
  682. }
  683. if(count($id_arr) == $i)
  684. {
  685. echo json_encode(array('msg'=>'入库成功!','success'=>true));exit;
  686. }
  687. else
  688. {
  689. echo json_encode(array('msg'=>'有入库失败数据:'.$cw,'success'=>false));exit;
  690. }
  691. }
  692. }
  693. //删除
  694. public function _del()
  695. {
  696. $post = $this->input->post(NULL, TRUE);
  697. if(isset($post['s']))
  698. {
  699. $id_arr = $this->input->post('s');
  700. $id_arr = explode(',',$id_arr);
  701. if(!$id_arr)
  702. {
  703. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  704. }
  705. //循环删除记录
  706. foreach ($id_arr as $v)
  707. {
  708. $data = $this->whlabeltransport->read($v);
  709. if($data['cz'] == '0')
  710. {
  711. $this->whlabeltransport->remove($v);
  712. }
  713. else
  714. {
  715. echo json_encode(array('msg'=>'有已完成数据!无法继续删除','success'=>false));exit;
  716. }
  717. }
  718. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  719. }
  720. }
  721. }