Whlabelfz.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2. /**
  3. * 由于whlabel类下的代码太长了,决定以后非必要代码都放在whlabelfz类中,以便于管理。
  4. */
  5. class Whlabelfz extends Start_Controller
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->_model('Model_whlabel', 'whlabel');
  11. $this->load->_model('Model_warehouse', 'warehouse');
  12. $this->load->_model('Model_specialstock', 'specialstock');
  13. $this->load->_model('Model_logic_u9tools','logic_u9tools');
  14. $this->load->_model('Model_classid','classid');
  15. $this->load->_model('Model_typeclass','typeclass');
  16. $this->load->_model('Model_purchase', 'purchase');
  17. $this->load->_model("Model_shop", "shop");
  18. $this->load->_model("Model_whlabellabel","whlabellabel");
  19. $this->load->_model("Model_logic_zhlp",'logic_zhlp');
  20. $this->load->_model("Model_whlabellabelprint","whlabellabelprint");
  21. }
  22. //定义方法的调用规则 获取URI第二段值
  23. public function _remap($arg, $arg_array)
  24. {
  25. if ($arg == 'bqckexcel') //
  26. {
  27. //获取标签出库的按条件导出的excel
  28. $this->_bqck_excel();
  29. }
  30. elseif ($arg == 'bqrkexcel') //
  31. {
  32. //获取标签出库的按条件导出的excel
  33. $this->_bqrk_excel();
  34. }
  35. elseif ($arg == 'whlabel_cprk_excel') //
  36. {
  37. $this->_whlabel_cprk_excel();
  38. }
  39. elseif($arg == 'bqplindex'){
  40. $this->_bqplindex();
  41. }elseif($arg == 'bqplprint'){
  42. $this->_bqplprint();
  43. }elseif($arg == 'bqpladd'){
  44. $this->_bqpladd();
  45. }
  46. else {
  47. $this->_index();
  48. }
  49. }
  50. private function _index(){
  51. die('No direct script access allowed');
  52. }
  53. private function _bqck_excel(){
  54. if (isset($_GET['excel'])) {
  55. //统计时间
  56. $timetk = $this->input->get('timetk', true);
  57. $timetj = $this->input->get('timetj', true);
  58. $timetk = strtotime($timetk);
  59. $timetj = strtotime($timetj);
  60. $category = $this->input->get('category',true); //类目
  61. $size = $this->input->get('size',true);//长度
  62. $grade = $this->input->get('grade',true);//等级
  63. $color = $this->input->get('color',true);//颜色
  64. $lowe = $this->input->get('lowe',true);//曲度
  65. $sku = $this->input->get('sku',true);//sku
  66. $warehouse = $this->input->get('warehouse',true);//仓库
  67. $purchase = $this->input->get('purchase',true);//供应商
  68. $where = "state=1 ";
  69. if ($timetk && $timetj) {
  70. $where .= " and outk > '$timetk' and outk < '$timetj'";
  71. }
  72. if ($sku) {
  73. $where .= " and sku = '$sku'";
  74. }
  75. if ($warehouse) {
  76. $where .= " and warehouse = '$warehouse'";
  77. }
  78. if ($purchase) {
  79. $where .= " and purchase = '$purchase'";
  80. }
  81. if ($category) {
  82. $where .= " and features like '%-$category-%'";
  83. }
  84. if ($size) {
  85. $where .= " and features like '%-$size-%'";
  86. }
  87. if ($grade) {
  88. $where .= " and features like '%-$grade-%'";
  89. }
  90. if ($color) {
  91. $where .= " and features like '%-$color-%'";
  92. }
  93. if ($lowe) {
  94. $where .= " and features like '%-$lowe-%'";
  95. }
  96. $ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
  97. $order_str = "outk desc";
  98. //取得信息列表
  99. $info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,outk,details', $order_str);
  100. $classid = $this->classid->sku();
  101. $tcall = $this->typeclass->find_all();
  102. $typeclass = array();
  103. foreach ($tcall as $v)
  104. {
  105. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  106. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  107. }
  108. $prc = array();
  109. $purchase = $this->purchase->find_all();
  110. foreach ($purchase as $k => $v) {
  111. $prc[$v['id']] = $v['title'];
  112. }
  113. foreach ($info_list as $key => $value) {
  114. $warehouse = $this->warehouse->read($value['warehouse']);
  115. $info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
  116. $info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
  117. $u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
  118. $info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  119. if ($value['state'] == 0) {
  120. $info_list[$key]['state'] = "在库";
  121. } else if ($value['state'] == 1) {
  122. $info_list[$key]['state'] = "出库";
  123. } else if ($value['state'] == 2) {
  124. $info_list[$key]['state'] = "退库";
  125. } else if ($value['state'] == 3) {
  126. $info_list[$key]['state'] = "调拨中";
  127. } else if ($value['state'] == 4) {
  128. $info_list[$key]['state'] = "再加工";
  129. } else if ($value['state'] == 5) {
  130. $info_list[$key]['state'] = "维修中";
  131. } else if ($value['state'] == 6) {
  132. $info_list[$key]['state'] = "盘亏";
  133. } else if ($value['state'] == 7) {
  134. $info_list[$key]['state'] = "更换标签";
  135. } else if ($value['state'] == 8) {
  136. $info_list[$key]['state'] = "其它";
  137. } else if ($value['state'] == 9) {
  138. $info_list[$key]['state'] = "预设";
  139. } else if ($value['state'] == 10) {
  140. $info_list[$key]['state'] = "美店零售";
  141. }
  142. $info_list[$key]['outk'] = date('Y-m-d H:i:s', $value['outk']);
  143. }
  144. //生成excel
  145. $filename = date("Y-m-d")."标签出库导出.xls";
  146. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  147. <head>
  148. <!--[if gte mso 9]><xml>
  149. <x:ExcelWorkbook>
  150. <x:ExcelWorksheets>
  151. <x:ExcelWorksheet>
  152. <x:Name>EXCEL</x:Name>
  153. <x:WorksheetOptions>
  154. <x:Print>
  155. <x:ValidPrinterInfo />
  156. </x:Print>
  157. </x:WorksheetOptions>
  158. </x:ExcelWorksheet>
  159. </x:ExcelWorksheets>
  160. </x:ExcelWorkbook>
  161. </xml>
  162. <![endif]-->
  163. </head><body>";
  164. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  165. $str .= "<tr><td>仓库</td><td>供应商</td><td>SKU</td><td>名称</td><td>料号</td><td>状态</td><td>出库时间</td><td>所在位置</td></tr>";
  166. foreach ($info_list as $key=>$value)
  167. {
  168. $str .= "<tr>";
  169. $str .= "<td>". $value['warehouse']. "</td>";
  170. $str .= "<td>". $value['purchase']. "</td>";
  171. $str .= "<td>". $value['sku']. "</td>";
  172. $str .= "<td>". $value['title']. "</td>";
  173. $str .= "<td>". $value['features']. "</td>";
  174. $str .= "<td>". $value['state']. "</td>";
  175. $str .= "<td>". $value['outk']. "</td>";
  176. $str .= "<td>". $value['details']. "</td>";
  177. $str .= "</tr>";
  178. }
  179. $str .= "</table></body></html>";
  180. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  181. header( "Content-type: application/octet-stream" );
  182. header( "Content-Disposition: attachment; filename=".$filename );
  183. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  184. header( "Pragma: no-cache" );
  185. header( "Expires: 0" );
  186. exit($str);
  187. }else{
  188. }
  189. }
  190. public function _bqrk_excel(){
  191. if (isset($_GET['excel'])) {
  192. $sku = $this->input->get('sku', true);
  193. $bs = $this->input->get('bs', true);
  194. $number = $this->input->get('number', true);
  195. $warehouse = $this->input->get('warehouse', true);
  196. $purchase = $this->input->get('purchase', true);
  197. $orderinfo = $this->input->get('orderinfo', true);
  198. $waybill = $this->input->get('waybill', true);
  199. $category = $this->input->get('category', true);
  200. $size = $this->input->get('size', true);
  201. $grade = $this->input->get('grade', true);
  202. $color = $this->input->get('color', true);
  203. $lowe = $this->input->get('lowe', true);
  204. $state = $this->input->get('state', true);
  205. $label = $this->input->get('label', true);
  206. $timetk = $this->input->get('ktime', true);
  207. $timetj = $this->input->get('jtime', true);
  208. $timetk = strtotime($timetk);
  209. $timetj = strtotime($timetj);
  210. $where = "1=1 ";
  211. if ($timetk && $timetj) {
  212. $where .= " and enter > '$timetk' and enter < '$timetj'";
  213. }
  214. if ($sku) {
  215. $where .= " and sku = '$sku'";
  216. }
  217. if ($bs != '') {
  218. $where .= " and bs = '$bs'";
  219. }
  220. if ($number) {
  221. $where .= " and number = '$number'";
  222. }
  223. if ($warehouse) {
  224. $where .= " and warehouse = '$warehouse'";
  225. }
  226. if ($purchase) {
  227. $where .= " and purchase = '$purchase'";
  228. }
  229. if ($orderinfo) {
  230. $where .= " and orderinfo = '$orderinfo'";
  231. }
  232. if ($waybill) {
  233. $where .= " and waybill = '$waybill'";
  234. }
  235. if ($category) {
  236. $where .= " and features like '%-$category-%'";
  237. }
  238. if ($size) {
  239. $where .= " and features like '%-$size-%'";
  240. }
  241. if ($grade) {
  242. $where .= " and features like '%-$grade-%'";
  243. }
  244. if ($color) {
  245. $where .= " and features like '%-$color-%'";
  246. }
  247. if ($lowe) {
  248. $where .= " and features like '%-$lowe-%'";
  249. }
  250. if ($label) {
  251. $where .= " and label = '$label'";
  252. }
  253. if ($state || $state == 0) {
  254. $where .= " and state = '$state'";
  255. }
  256. $ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
  257. //数据排序
  258. $order_str = "enter desc";
  259. //取得信息列表
  260. $info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,enter,details', $order_str);
  261. $prc = array();
  262. $purchase = $this->purchase->find_all();
  263. foreach ($purchase as $k => $v) {
  264. $prc[$v['id']] = $v['title'];
  265. }
  266. $classid = $this->classid->sku();
  267. $tcall = $this->typeclass->find_all();
  268. foreach ($tcall as $v)
  269. {
  270. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  271. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  272. }
  273. foreach ($info_list as $key => $value) {
  274. $warehouse = $this->warehouse->read($value['warehouse']);
  275. $info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
  276. $info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
  277. $u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
  278. $info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  279. if ($value['state'] == 0) {
  280. $info_list[$key]['state'] = "在库";
  281. } else if ($value['state'] == 1) {
  282. $info_list[$key]['state'] = "出库";
  283. } else if ($value['state'] == 2) {
  284. $info_list[$key]['state'] = "退库";
  285. } else if ($value['state'] == 3) {
  286. $info_list[$key]['state'] = "调拨中";
  287. } else if ($value['state'] == 4) {
  288. $info_list[$key]['state'] = "再加工";
  289. } else if ($value['state'] == 5) {
  290. $info_list[$key]['state'] = "维修中";
  291. } else if ($value['state'] == 6) {
  292. $info_list[$key]['state'] = "盘亏";
  293. } else if ($value['state'] == 7) {
  294. $info_list[$key]['state'] = "更换标签";
  295. } else if ($value['state'] == 8) {
  296. $info_list[$key]['state'] = "其它";
  297. } else if ($value['state'] == 9) {
  298. $info_list[$key]['state'] = "预设";
  299. } else if ($value['state'] == 10) {
  300. $info_list[$key]['state'] = "美店零售";
  301. }
  302. $info_list[$key]['enter'] = date('Y-m-d H:i:s', $value['enter']);
  303. }
  304. //生成excel
  305. $filename = date("Y-m-d")."标签入库导出.xls";
  306. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  307. <head>
  308. <!--[if gte mso 9]><xml>
  309. <x:ExcelWorkbook>
  310. <x:ExcelWorksheets>
  311. <x:ExcelWorksheet>
  312. <x:Name>EXCEL</x:Name>
  313. <x:WorksheetOptions>
  314. <x:Print>
  315. <x:ValidPrinterInfo />
  316. </x:Print>
  317. </x:WorksheetOptions>
  318. </x:ExcelWorksheet>
  319. </x:ExcelWorksheets>
  320. </x:ExcelWorkbook>
  321. </xml>
  322. <![endif]-->
  323. </head><body>";
  324. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  325. $str .= "<tr><td>仓库</td><td>供应商</td><td>SKU</td><td>名称</td><td>料号</td><td>状态</td><td>入库时间</td><td>所在位置</td></tr>";
  326. foreach ($info_list as $key=>$value)
  327. {
  328. $str .= "<tr>";
  329. $str .= "<td>". $value['warehouse']. "</td>";
  330. $str .= "<td>". $value['purchase']. "</td>";
  331. $str .= "<td>". $value['sku']. "</td>";
  332. $str .= "<td>". $value['title']. "</td>";
  333. $str .= "<td>". $value['features']. "</td>";
  334. $str .= "<td>". $value['state']. "</td>";
  335. $str .= "<td>". $value['enter']. "</td>";
  336. $str .= "<td>". $value['details']. "</td>";
  337. $str .= "</tr>";
  338. }
  339. $str .= "</table></body></html>";
  340. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  341. header( "Content-type: application/octet-stream" );
  342. header( "Content-Disposition: attachment; filename=".$filename );
  343. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  344. header( "Pragma: no-cache" );
  345. header( "Expires: 0" );
  346. exit($str);
  347. }
  348. }
  349. public function _whlabel_cprk_excel(){
  350. if (empty($_SESSION['api'])) {
  351. exit('No direct script access allowed');
  352. }
  353. // $user = $this->user->get_api($_SESSION['api']);
  354. // $warehouses = $user['warehouse'];
  355. // if(empty($warehouses)){
  356. // exit('没有仓库权限!!!');
  357. // }
  358. // $warehouses = explode('|',trim($warehouses,'|'));
  359. // $ware_list = [];
  360. // foreach ($warehouses as $v) {
  361. // if(!empty($v)){
  362. // $ware_list[] = $v;
  363. // }
  364. // }
  365. $category = $this->input->get('category', true);
  366. $size = $this->input->get('size', true);
  367. $grade = $this->input->get('grade', true);
  368. $color = $this->input->get('color', true);
  369. $lowe = $this->input->get('lowe', true);
  370. $sku = $this->input->get('sku', true);
  371. $warehouse = $this->input->get('warehouse', true);
  372. $purchase = $this->input->get('purchase', true);
  373. $ktime = $this->input->get('ktime', true);
  374. $jtime = $this->input->get('jtime', true);
  375. $ktime = strtotime($ktime);
  376. $jtime = strtotime($jtime);
  377. $where = " ";
  378. // if ($warehouse) {
  379. // if(in_array($warehouse,$ware_list)){
  380. // $where .= " warehouse = '$warehouse' ";
  381. // }else{
  382. // $where .= " warehouse = 0 ";
  383. // }
  384. // }else{
  385. // $where .= " warehouse in (".implode(',',$ware_list).")";
  386. // }
  387. if($warehouse){
  388. $where .= " warehouse = '$warehouse' ";
  389. }else{
  390. $where .=" 1 = 1 ";
  391. }
  392. if ($category) {
  393. $where .= " and features like '%-$category-%'";
  394. }
  395. if ($size) {
  396. $where .= " and features like '%-$size-%'";
  397. }
  398. if ($grade) {
  399. $where .= " and features like '%-$grade-%'";
  400. }
  401. if ($color) {
  402. $where .= " and features like '%-$color-%'";
  403. }
  404. if ($lowe) {
  405. $where .= " and features like '%-$lowe-%'";
  406. }
  407. if ($purchase) {
  408. $where .= " and purchase = '$purchase'";
  409. }
  410. if ($sku) {
  411. $where .= " and sku like '%$sku%'";
  412. }
  413. if ($ktime && $jtime) {
  414. $where .= " and enter > '$ktime' and enter < '$jtime'";
  415. }
  416. //取得信息列表
  417. $info_list = $this->whlabel->find_pc($where, 'enter,warehouse,sku', 'id,warehouse,shop,sku,title,enter,features');
  418. if(!empty($info_list)){
  419. $wh = array();
  420. $w = $this->warehouse->find_all('1=1', 'id,title');
  421. foreach ($w as $v) {
  422. $wh[$v['id']] = $v['title'];
  423. }
  424. $classid = $this->classid->sku();
  425. $tcall = $this->typeclass->find_all();
  426. foreach ($tcall as $v)
  427. {
  428. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  429. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  430. }
  431. foreach ($info_list as $k => $v) {
  432. $info_list[$k]['warehouse'] = $wh[$v['warehouse']];
  433. $info_list[$k]['enter'] = date('Y-m-d H:i:s', $v['enter']);
  434. $g = $this->whlabel->find_count($where . ' and enter = "' . $v['enter'] . '" and sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '"');
  435. $info_list[$k]['g'] = $g;
  436. if(!empty($v['features'])){
  437. $u9_info = $this->logic_u9tools->getOneU9bm($v['features'],$classid,$typeclass);
  438. $info_list[$k]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  439. }
  440. }
  441. }
  442. //生成excel
  443. $filename = date("Y-m-d")."产品入库导出.xls";
  444. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  445. <head>
  446. <!--[if gte mso 9]><xml>
  447. <x:ExcelWorkbook>
  448. <x:ExcelWorksheets>
  449. <x:ExcelWorksheet>
  450. <x:Name>EXCEL</x:Name>
  451. <x:WorksheetOptions>
  452. <x:Print>
  453. <x:ValidPrinterInfo />
  454. </x:Print>
  455. </x:WorksheetOptions>
  456. </x:ExcelWorksheet>
  457. </x:ExcelWorksheets>
  458. </x:ExcelWorkbook>
  459. </xml>
  460. <![endif]-->
  461. </head><body>";
  462. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  463. $str .= "<tr><td>仓库</td><td>SKU</td><td>产品名称</td><td>入库时间</td><td>数量</td><td>料号</td></tr>";
  464. foreach ($info_list as $key=>$value)
  465. {
  466. $str .= "<tr>";
  467. $str .= "<td>". $value['warehouse']. "</td>";
  468. $str .= "<td>". $value['sku']. "</td>";
  469. $str .= "<td>". $value['title']. "</td>";
  470. $str .= "<td>". $value['enter']. "</td>";
  471. $str .= "<td>". $value['g']. "</td>";
  472. $str .= "<td>". $value['features']. "</td>";
  473. $str .= "</tr>";
  474. }
  475. $str .= "</table></body></html>";
  476. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  477. header( "Content-type: application/octet-stream" );
  478. header( "Content-Disposition: attachment; filename=".$filename );
  479. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  480. header( "Pragma: no-cache" );
  481. header( "Expires: 0" );
  482. exit($str);
  483. }
  484. private function _bqplindex(){
  485. if($this->input->method() == 'post'){
  486. $rows = array('total'=>0,'over'=>1,'pagenum'=>1,'rows'=>([]));
  487. echo json_encode($rows);exit;
  488. }
  489. $this->_Template('whlabelfz_bqpl', $this->data);
  490. }
  491. private function _getShop($str){
  492. $str = trim($str);
  493. if($str == '无'){
  494. return '';
  495. }else{
  496. $str = strtolower($str);
  497. if($str =='alipearl'){
  498. return 1;
  499. }elseif($str == 'supernova'){
  500. return 2;
  501. }elseif($str == 'asteriahair'){
  502. return 3;
  503. }elseif($str == 'westkiss'){
  504. return 4;
  505. }elseif($str == 'yolissahair'){
  506. return 5;
  507. }elseif($str == 'wiggins'){
  508. return 6;
  509. }
  510. }
  511. }
  512. private function _bqpladd(){
  513. $params = $this->input->post('data',true);
  514. $params = json_decode($params,true);
  515. $list = [];
  516. $error_list= [];
  517. $warehouse_list = $this->warehouse->find_all("1 = 1","id,title");
  518. $warehouse_list = array_column($warehouse_list,'id','title');
  519. $purchase_list = $this->purchase->find_all("1 = 1","id,title");
  520. $purchase_list = array_column($purchase_list,'id','title');
  521. $classid = $this->classid->sku();
  522. foreach($params as $k => $v){
  523. $r = $this->_transferForm($v['0'],$v,$warehouse_list,$purchase_list,$classid,$k);
  524. if($r['code'] != 1){
  525. $error_list[] = [
  526. 'sku'=>$v['0'],
  527. 'msg'=>$r['msg']
  528. ];
  529. }else{
  530. $tmp_data = $r['data'];
  531. $tmp_data['details'] = $v['4'];
  532. $this->whlabellabelprint->insert($tmp_data);
  533. $list[] = $tmp_data['data'];
  534. }
  535. }
  536. if(empty($error_list)){
  537. echo json_encode(['code'=>1,'msg'=>'操作成功','data'=>[],'error'=>[]]);exit;
  538. }else{
  539. echo json_encode(['code'=>-1,'msg'=>'导入数据异常','data'=>[],'error'=>$error_list]);exit;
  540. }
  541. }
  542. /**
  543. * 将数据转化为 批量打印标签需要data格式
  544. */
  545. private function _transferForm($tmsku,$info,$warehouse_list,$purchase_list,$classid,$i){
  546. if (is_numeric($tmsku)) {
  547. $yyh = $this->whlabellabel->get_label($tmsku);
  548. } else {
  549. $yyh = $this->whlabellabel->get_sku($tmsku);
  550. }
  551. if(!empty($yyh)){
  552. return ['code'=>1,'msg'=>"获取标签",'data'=>[
  553. 'sku_shop_id' => 0,
  554. 'sku_master_id' => 0,
  555. 'status' => 0,
  556. 'shop' =>0,
  557. 'purchase' => $yyh['purchase'],
  558. 'warehouse' => $yyh['warehouse'],
  559. 'cpbz' => $yyh['cpbz'],
  560. 'title' => $yyh['title'],
  561. 'number' => $yyh['number'],
  562. 'features' => $yyh['features'],
  563. 'featurespp' => $yyh['featurespp'],
  564. 'time' => time(),
  565. 'dynum' => $info['1'],
  566. 'sku' => $info['sku'],
  567. 'label' => time() . rand(0, 9).$i
  568. ]];
  569. }
  570. $r = $this->logic_u9tools->getErpSkuByU9Lp($tmsku);
  571. if($r['code'] == -1 ){
  572. return ['code'=>-1,'msg'=>"未找到对应的料品"];
  573. }
  574. $str = $r['data'];
  575. $arr = explode("-",trim($str,"-"));
  576. $data = $this->logic_zhlp->transferSku($arr);
  577. $res = $this->logic_zhlp->sortByColume($data);
  578. if($res['code'] == -1){
  579. return $res;
  580. }
  581. $insert_arr = [];
  582. $insert_arr['sku_master_id']= $insert_arr['sku_shop_id'] =0;
  583. $insert_arr['status'] = 0;
  584. $insert_arr['shop'] = '';
  585. $purchase = isset($purchase_list[$info['2']])?$purchase_list[$info['2']]:1;
  586. $insert_arr['purchase'] = $purchase;
  587. $warehouse = isset($warehouse_list[$info['3']])?$warehouse_list[$info['3']]:1;
  588. $insert_arr['warehouse'] = $warehouse;
  589. $insert_arr['cpbz'] = '';
  590. $post = $res['data'];
  591. $list = [];
  592. $category = $post['category'];
  593. $list['category'] = $category;
  594. $list['hairtype'] = empty($post['hairtype'])?'':$post['hairtype'];
  595. $list['grade'] = empty($post['grade'])?'':$post['grade'];
  596. $list['size'] = empty($post['size'])?'':$post['size'];
  597. $list['hairnumber'] = empty($post['hairnumber'])?'':$post['hairnumber'];
  598. $list['extension'] = empty($post['extension'])?'':$post['extension'];
  599. if ($category == 1297) {
  600. $list['sywignumber'] = empty($post['sywignumber'])?'':$post['sywignumber'];
  601. }
  602. if ($category == 1702) {
  603. $list['syhairnumber'] = empty($post['syhairnumber'])?'':$post['syhairnumber'];
  604. $list['syother'] = empty($post['syother'])?'':$post['syother'];
  605. }
  606. if ($category == 133) {
  607. $list['fittype'] = empty($post['fittype'])?'':$post['fittype'];
  608. $list['acother'] = empty($post['acother'])?'':$post['acother'];
  609. }
  610. $list['color'] = empty($post['color'])?'':$post['color'];
  611. $list['lowe'] = empty($post['lowe'])?'':$post['lowe'];
  612. if ($category == 127) {
  613. $list['type'] = empty($post['type'])?'':$post['type'];
  614. $list['headroad'] = empty($post['headroad'])?'':$post['headroad'];
  615. $list['density'] =empty($post['density'])?'':$post['density'];
  616. if ($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199) {
  617. $list['lacesize'] = empty($post['lacesize'])?'':$post['lacesize'];
  618. }
  619. $list['lacecolor'] = empty($post['lacecolor'])?'':$post['lacecolor'];
  620. $list['lacetypes'] = empty($post['lacetypes'])?'':$post['lacetypes'];
  621. }
  622. if ($category == 128) {
  623. $list['lacetype'] =empty($post['lacetype'])?'':$post['lacetype'];
  624. $list['haircap'] = empty($post['haircap'])?'':$post['haircap'];
  625. $list['density'] = empty($post['density'])?'':$post['density'];
  626. $list['lacecolor'] = empty($post['lacecolor'])?'':$post['lacecolor'];
  627. $list['lacetypes'] = empty($post['lacetypes'])?'':$post['lacetypes'];
  628. $list['wigother'] = empty($post['wigother'])?'':$post['wigother'];
  629. $list['wigother1'] = empty($post['wigother1'])?'':$post['wigother1'];
  630. $list['wigother2'] = empty($post['wigother2'])?'':$post['wigother2'];
  631. }
  632. if ($category == 129) {
  633. $list['wide'] = empty($post['wide'])?'':$post['wide'];
  634. }
  635. if ($category == 131) {
  636. $list['gifttype'] = empty($post['gifttype'])?'':$post['gifttype'];
  637. $list['giftother'] = empty($post['giftother'])?'':$post['giftother'];
  638. }
  639. if ($category == 134) {
  640. $list['pieceweight'] = empty($post['pieceweight'])?'':$post['pieceweight'];
  641. }
  642. if ($category == 1297) {
  643. $list['synthetictype'] = empty($post['synthetictype'])?'':$post['synthetictype'];
  644. $list['sywigother'] = empty($post['sywigother'])?'':$post['sywigother'];
  645. }
  646. if ($category == 130 || $category == 133 || $category == 1702) {
  647. $list['items'] = empty($post['items'])?'':$post['items'];
  648. $list['weight'] = empty($post['weight'])?'':$post['weight'];
  649. }
  650. if ($category == 1702) {
  651. $list['syhairther'] = empty($post['syhairther'])?'':$post['syhairther'];
  652. }
  653. $pm = $scsku = $classid;
  654. $number = $features = $title = "";
  655. foreach ($list as $k => $v) {
  656. if ($v != 0) {
  657. $number .= $v;
  658. $features .= $v . '-';
  659. $typeclass = $this->typeclass->read($v);
  660. if (isset($pm[$typeclass['classid']])) {
  661. if (stripos($typeclass['zh'], '|') !== false) {
  662. $exzh = explode('|', $typeclass['zh']);
  663. $pm[$typeclass['classid']] = $exzh[0];
  664. } else {
  665. $pm[$typeclass['classid']] = $typeclass['zh'];
  666. }
  667. }
  668. $scsku[$typeclass['classid']] = $typeclass['bqsku'];
  669. if ($k != 'size') {
  670. $title .= $typeclass['title'] . " ";
  671. }
  672. }
  673. }
  674. $typeclass = $this->typeclass->read($list['size']);
  675. $title .= $typeclass['title'];
  676. $time = time();
  677. $insert_arr['title'] = rtrim($title, ' ');
  678. $insert_arr['number'] = $number;
  679. $insert_arr['features'] = "-".trim($features, '-')."-";
  680. $featurespp = str_replace(array('-163-', '-164-', '-165-', '-166-'), '-', $features);
  681. $featurespp = explode('-', trim($featurespp, '-'));
  682. if (isset($featurespp[5])) {
  683. $insert_arr['featurespp'] = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4] . '-' . $featurespp[5];
  684. } else {
  685. $insert_arr['featurespp'] = $featurespp[0] . '-' . $featurespp[3] . '-' . $featurespp[4];
  686. }
  687. $insert_arr['time'] = $time;
  688. $insert_arr['dynum'] = $info['1'];
  689. $scsku = implode("-", $scsku);
  690. $zh = implode(" ", $pm);
  691. $scsku = str_replace('- ', '-', trim($scsku, '-'));
  692. $scsku = str_replace(array('--------', '-------', '------', '-----', '----', '---', '--'), '-', $scsku);
  693. $bqsku = $scsku;;
  694. $insert_arr['sku'] = $bqsku;
  695. $label = time() . rand(0, 9).$i;
  696. $insert_arr['label'] = $label;
  697. return [
  698. 'code'=>1,
  699. 'msg'=>"success",
  700. 'data'=>$insert_arr
  701. ];
  702. }
  703. private function _bqplprint(){
  704. }
  705. }