Whlabeltransport.php 24 KB

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