Whlabeltransport.php 24 KB

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