Whlabeltransport.php 22 KB

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