Whlabeltransport.php 22 KB

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