Whlabeltransport.php 23 KB

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