Whlabeltransport.php 23 KB

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