Whlabelfz.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. }
  19. //定义方法的调用规则 获取URI第二段值
  20. public function _remap($arg, $arg_array)
  21. {
  22. if ($arg == 'bqckexcel') //
  23. {
  24. //获取标签出库的按条件导出的excel
  25. $this->_bqck_excel();
  26. }
  27. elseif ($arg == 'bqrkexcel') //
  28. {
  29. //获取标签出库的按条件导出的excel
  30. $this->_bqrk_excel();
  31. }
  32. elseif ($arg == 'whlabel_cprk_excel') //
  33. {
  34. $this->_whlabel_cprk_excel();
  35. }
  36. else {
  37. $this->_index();
  38. }
  39. }
  40. private function _index(){
  41. die('No direct script access allowed');
  42. }
  43. private function _bqck_excel(){
  44. if (isset($_GET['excel'])) {
  45. //统计时间
  46. $timetk = $this->input->get('timetk', true);
  47. $timetj = $this->input->get('timetj', true);
  48. $timetk = strtotime($timetk);
  49. $timetj = strtotime($timetj);
  50. $category = $this->input->get('category',true); //类目
  51. $size = $this->input->get('size',true);//长度
  52. $grade = $this->input->get('grade',true);//等级
  53. $color = $this->input->get('color',true);//颜色
  54. $lowe = $this->input->get('lowe',true);//曲度
  55. $sku = $this->input->get('sku',true);//sku
  56. $warehouse = $this->input->get('warehouse',true);//仓库
  57. $purchase = $this->input->get('purchase',true);//供应商
  58. $where = "state=1 ";
  59. if ($timetk && $timetj) {
  60. $where .= " and outk > '$timetk' and outk < '$timetj'";
  61. }
  62. if ($sku) {
  63. $where .= " and sku = '$sku'";
  64. }
  65. if ($warehouse) {
  66. $where .= " and warehouse = '$warehouse'";
  67. }
  68. if ($purchase) {
  69. $where .= " and purchase = '$purchase'";
  70. }
  71. if ($category) {
  72. $where .= " and features like '%-$category-%'";
  73. }
  74. if ($size) {
  75. $where .= " and features like '%-$size-%'";
  76. }
  77. if ($grade) {
  78. $where .= " and features like '%-$grade-%'";
  79. }
  80. if ($color) {
  81. $where .= " and features like '%-$color-%'";
  82. }
  83. if ($lowe) {
  84. $where .= " and features like '%-$lowe-%'";
  85. }
  86. $ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
  87. $order_str = "outk desc";
  88. //取得信息列表
  89. $info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,outk,details', $order_str);
  90. $classid = $this->classid->sku();
  91. $tcall = $this->typeclass->find_all();
  92. $typeclass = array();
  93. foreach ($tcall as $v)
  94. {
  95. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  96. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  97. }
  98. $prc = array();
  99. $purchase = $this->purchase->find_all();
  100. foreach ($purchase as $k => $v) {
  101. $prc[$v['id']] = $v['title'];
  102. }
  103. foreach ($info_list as $key => $value) {
  104. $warehouse = $this->warehouse->read($value['warehouse']);
  105. $info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
  106. $info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
  107. $u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
  108. $info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  109. if ($value['state'] == 0) {
  110. $info_list[$key]['state'] = "在库";
  111. } else if ($value['state'] == 1) {
  112. $info_list[$key]['state'] = "出库";
  113. } else if ($value['state'] == 2) {
  114. $info_list[$key]['state'] = "退库";
  115. } else if ($value['state'] == 3) {
  116. $info_list[$key]['state'] = "调拨中";
  117. } else if ($value['state'] == 4) {
  118. $info_list[$key]['state'] = "再加工";
  119. } else if ($value['state'] == 5) {
  120. $info_list[$key]['state'] = "维修中";
  121. } else if ($value['state'] == 6) {
  122. $info_list[$key]['state'] = "盘亏";
  123. } else if ($value['state'] == 7) {
  124. $info_list[$key]['state'] = "更换标签";
  125. } else if ($value['state'] == 8) {
  126. $info_list[$key]['state'] = "其它";
  127. } else if ($value['state'] == 9) {
  128. $info_list[$key]['state'] = "预设";
  129. } else if ($value['state'] == 10) {
  130. $info_list[$key]['state'] = "美店零售";
  131. }
  132. $info_list[$key]['outk'] = date('Y-m-d H:i:s', $value['outk']);
  133. }
  134. //生成excel
  135. $filename = date("Y-m-d")."标签出库导出.xls";
  136. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  137. <head>
  138. <!--[if gte mso 9]><xml>
  139. <x:ExcelWorkbook>
  140. <x:ExcelWorksheets>
  141. <x:ExcelWorksheet>
  142. <x:Name>EXCEL</x:Name>
  143. <x:WorksheetOptions>
  144. <x:Print>
  145. <x:ValidPrinterInfo />
  146. </x:Print>
  147. </x:WorksheetOptions>
  148. </x:ExcelWorksheet>
  149. </x:ExcelWorksheets>
  150. </x:ExcelWorkbook>
  151. </xml>
  152. <![endif]-->
  153. </head><body>";
  154. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  155. $str .= "<tr><td>仓库</td><td>供应商</td><td>SKU</td><td>名称</td><td>料号</td><td>状态</td><td>出库时间</td><td>所在位置</td></tr>";
  156. foreach ($info_list as $key=>$value)
  157. {
  158. $str .= "<tr>";
  159. $str .= "<td>". $value['warehouse']. "</td>";
  160. $str .= "<td>". $value['purchase']. "</td>";
  161. $str .= "<td>". $value['sku']. "</td>";
  162. $str .= "<td>". $value['title']. "</td>";
  163. $str .= "<td>". $value['features']. "</td>";
  164. $str .= "<td>". $value['state']. "</td>";
  165. $str .= "<td>". $value['outk']. "</td>";
  166. $str .= "<td>". $value['details']. "</td>";
  167. $str .= "</tr>";
  168. }
  169. $str .= "</table></body></html>";
  170. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  171. header( "Content-type: application/octet-stream" );
  172. header( "Content-Disposition: attachment; filename=".$filename );
  173. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  174. header( "Pragma: no-cache" );
  175. header( "Expires: 0" );
  176. exit($str);
  177. }else{
  178. }
  179. }
  180. public function _bqrk_excel(){
  181. if (isset($_GET['excel'])) {
  182. $sku = $this->input->get('sku', true);
  183. $bs = $this->input->get('bs', true);
  184. $number = $this->input->get('number', true);
  185. $warehouse = $this->input->get('warehouse', true);
  186. $purchase = $this->input->get('purchase', true);
  187. $orderinfo = $this->input->get('orderinfo', true);
  188. $waybill = $this->input->get('waybill', true);
  189. $category = $this->input->get('category', true);
  190. $size = $this->input->get('size', true);
  191. $grade = $this->input->get('grade', true);
  192. $color = $this->input->get('color', true);
  193. $lowe = $this->input->get('lowe', true);
  194. $state = $this->input->get('state', true);
  195. $label = $this->input->get('label', true);
  196. $timetk = $this->input->get('ktime', true);
  197. $timetj = $this->input->get('jtime', true);
  198. $timetk = strtotime($timetk);
  199. $timetj = strtotime($timetj);
  200. $where = "1=1 ";
  201. if ($timetk && $timetj) {
  202. $where .= " and enter > '$timetk' and enter < '$timetj'";
  203. }
  204. if ($sku) {
  205. $where .= " and sku = '$sku'";
  206. }
  207. if ($bs != '') {
  208. $where .= " and bs = '$bs'";
  209. }
  210. if ($number) {
  211. $where .= " and number = '$number'";
  212. }
  213. if ($warehouse) {
  214. $where .= " and warehouse = '$warehouse'";
  215. }
  216. if ($purchase) {
  217. $where .= " and purchase = '$purchase'";
  218. }
  219. if ($orderinfo) {
  220. $where .= " and orderinfo = '$orderinfo'";
  221. }
  222. if ($waybill) {
  223. $where .= " and waybill = '$waybill'";
  224. }
  225. if ($category) {
  226. $where .= " and features like '%-$category-%'";
  227. }
  228. if ($size) {
  229. $where .= " and features like '%-$size-%'";
  230. }
  231. if ($grade) {
  232. $where .= " and features like '%-$grade-%'";
  233. }
  234. if ($color) {
  235. $where .= " and features like '%-$color-%'";
  236. }
  237. if ($lowe) {
  238. $where .= " and features like '%-$lowe-%'";
  239. }
  240. if ($label) {
  241. $where .= " and label = '$label'";
  242. }
  243. if ($state || $state == 0) {
  244. $where .= " and state = '$state'";
  245. }
  246. $ck = ($warehouse == '12') ? 'specialstock' : 'whlabel';
  247. //数据排序
  248. $order_str = "enter desc";
  249. //取得信息列表
  250. $info_list = $this->$ck->find_all($where, 'id,warehouse,purchase,sku,title,features,state,enter,details', $order_str);
  251. $prc = array();
  252. $purchase = $this->purchase->find_all();
  253. foreach ($purchase as $k => $v) {
  254. $prc[$v['id']] = $v['title'];
  255. }
  256. $classid = $this->classid->sku();
  257. $tcall = $this->typeclass->find_all();
  258. foreach ($tcall as $v)
  259. {
  260. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  261. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  262. }
  263. foreach ($info_list as $key => $value) {
  264. $warehouse = $this->warehouse->read($value['warehouse']);
  265. $info_list[$key]['warehouse'] = ($ck == 'specialstock') ? '特殊仓' : $warehouse['title'];
  266. $info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
  267. $u9_info = $this->logic_u9tools->getOneU9bm($value['features'],$classid,$typeclass);
  268. $info_list[$key]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  269. if ($value['state'] == 0) {
  270. $info_list[$key]['state'] = "在库";
  271. } else if ($value['state'] == 1) {
  272. $info_list[$key]['state'] = "出库";
  273. } else if ($value['state'] == 2) {
  274. $info_list[$key]['state'] = "退库";
  275. } else if ($value['state'] == 3) {
  276. $info_list[$key]['state'] = "调拨中";
  277. } else if ($value['state'] == 4) {
  278. $info_list[$key]['state'] = "再加工";
  279. } else if ($value['state'] == 5) {
  280. $info_list[$key]['state'] = "维修中";
  281. } else if ($value['state'] == 6) {
  282. $info_list[$key]['state'] = "盘亏";
  283. } else if ($value['state'] == 7) {
  284. $info_list[$key]['state'] = "更换标签";
  285. } else if ($value['state'] == 8) {
  286. $info_list[$key]['state'] = "其它";
  287. } else if ($value['state'] == 9) {
  288. $info_list[$key]['state'] = "预设";
  289. } else if ($value['state'] == 10) {
  290. $info_list[$key]['state'] = "美店零售";
  291. }
  292. $info_list[$key]['enter'] = date('Y-m-d H:i:s', $value['enter']);
  293. }
  294. //生成excel
  295. $filename = date("Y-m-d")."标签入库导出.xls";
  296. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  297. <head>
  298. <!--[if gte mso 9]><xml>
  299. <x:ExcelWorkbook>
  300. <x:ExcelWorksheets>
  301. <x:ExcelWorksheet>
  302. <x:Name>EXCEL</x:Name>
  303. <x:WorksheetOptions>
  304. <x:Print>
  305. <x:ValidPrinterInfo />
  306. </x:Print>
  307. </x:WorksheetOptions>
  308. </x:ExcelWorksheet>
  309. </x:ExcelWorksheets>
  310. </x:ExcelWorkbook>
  311. </xml>
  312. <![endif]-->
  313. </head><body>";
  314. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  315. $str .= "<tr><td>仓库</td><td>供应商</td><td>SKU</td><td>名称</td><td>料号</td><td>状态</td><td>入库时间</td><td>所在位置</td></tr>";
  316. foreach ($info_list as $key=>$value)
  317. {
  318. $str .= "<tr>";
  319. $str .= "<td>". $value['warehouse']. "</td>";
  320. $str .= "<td>". $value['purchase']. "</td>";
  321. $str .= "<td>". $value['sku']. "</td>";
  322. $str .= "<td>". $value['title']. "</td>";
  323. $str .= "<td>". $value['features']. "</td>";
  324. $str .= "<td>". $value['state']. "</td>";
  325. $str .= "<td>". $value['enter']. "</td>";
  326. $str .= "<td>". $value['details']. "</td>";
  327. $str .= "</tr>";
  328. }
  329. $str .= "</table></body></html>";
  330. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  331. header( "Content-type: application/octet-stream" );
  332. header( "Content-Disposition: attachment; filename=".$filename );
  333. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  334. header( "Pragma: no-cache" );
  335. header( "Expires: 0" );
  336. exit($str);
  337. }
  338. }
  339. public function _whlabel_cprk_excel(){
  340. if (empty($_SESSION['api'])) {
  341. exit('No direct script access allowed');
  342. }
  343. $user = $this->user->get_api($_SESSION['api']);
  344. $warehouses = $user['warehouse'];
  345. if(empty($warehouses)){
  346. exit('没有仓库权限!!!');
  347. }
  348. $warehouses = explode('|',trim($warehouses,'|'));
  349. $ware_list = [];
  350. foreach ($warehouses as $v) {
  351. if(!empty($v)){
  352. $ware_list[] = $v;
  353. }
  354. }
  355. $category = $this->input->get('category', true);
  356. $size = $this->input->get('size', true);
  357. $grade = $this->input->get('grade', true);
  358. $color = $this->input->get('color', true);
  359. $lowe = $this->input->get('lowe', true);
  360. $sku = $this->input->get('sku', true);
  361. $warehouse = $this->input->get('warehouse', true);
  362. $purchase = $this->input->get('purchase', true);
  363. $ktime = $this->input->get('ktime', true);
  364. $jtime = $this->input->get('jtime', true);
  365. $ktime = strtotime($ktime);
  366. $jtime = strtotime($jtime);
  367. $where = "";
  368. if ($warehouse) {
  369. if(in_array($warehouse,$ware_list)){
  370. $where .= " warehouse = '$warehouse' ";
  371. }else{
  372. $where .= " warehouse = 0 ";
  373. }
  374. }else{
  375. $where .= " warehouse in (".implode(',',$ware_list).")";
  376. }
  377. if ($category) {
  378. $where .= " and features like '%-$category-%'";
  379. }
  380. if ($size) {
  381. $where .= " and features like '%-$size-%'";
  382. }
  383. if ($grade) {
  384. $where .= " and features like '%-$grade-%'";
  385. }
  386. if ($color) {
  387. $where .= " and features like '%-$color-%'";
  388. }
  389. if ($lowe) {
  390. $where .= " and features like '%-$lowe-%'";
  391. }
  392. if ($purchase) {
  393. $where .= " and purchase = '$purchase'";
  394. }
  395. if ($sku) {
  396. $where .= " and sku like '%$sku%'";
  397. }
  398. if ($ktime && $jtime) {
  399. $where .= " and enter > '$ktime' and enter < '$jtime'";
  400. }
  401. //取得信息列表
  402. $info_list = $this->whlabel->find_pc($where, 'enter,warehouse,sku', 'id,warehouse,sku,title,enter,features');
  403. if(!empty($info_list)){
  404. $wh = array();
  405. $w = $this->warehouse->find_all('1=1', 'id,title');
  406. foreach ($w as $v) {
  407. $wh[$v['id']] = $v['title'];
  408. }
  409. $classid = $this->classid->sku();
  410. $tcall = $this->typeclass->find_all();
  411. foreach ($tcall as $v)
  412. {
  413. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  414. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  415. }
  416. foreach ($info_list as $k => $v) {
  417. $info_list[$k]['warehouse'] = $wh[$v['warehouse']];
  418. $info_list[$k]['enter'] = date('Y-m-d H:i:s', $v['enter']);
  419. $g = $this->whlabel->find_count($where . ' and enter = "' . $v['enter'] . '" and sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '"');
  420. $info_list[$k]['g'] = $g;
  421. $u9_info = $this->logic_u9tools->getOneU9bm($v['features'],$classid,$typeclass);
  422. $info_list[$k]['features'] = empty($u9_info['jm'])?"?**?":$u9_info['jm'];
  423. }
  424. }
  425. //生成excel
  426. $filename = date("Y-m-d")."产品入库导出.xls";
  427. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  428. <head>
  429. <!--[if gte mso 9]><xml>
  430. <x:ExcelWorkbook>
  431. <x:ExcelWorksheets>
  432. <x:ExcelWorksheet>
  433. <x:Name>EXCEL</x:Name>
  434. <x:WorksheetOptions>
  435. <x:Print>
  436. <x:ValidPrinterInfo />
  437. </x:Print>
  438. </x:WorksheetOptions>
  439. </x:ExcelWorksheet>
  440. </x:ExcelWorksheets>
  441. </x:ExcelWorkbook>
  442. </xml>
  443. <![endif]-->
  444. </head><body>";
  445. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  446. $str .= "<tr><td>仓库</td><td>SKU</td><td>产品名称</td><td>入库时间</td><td>数量</td><td>料号</td></tr>";
  447. foreach ($info_list as $key=>$value)
  448. {
  449. $str .= "<tr>";
  450. $str .= "<td>". $value['warehouse']. "</td>";
  451. $str .= "<td>". $value['sku']. "</td>";
  452. $str .= "<td>". $value['title']. "</td>";
  453. $str .= "<td>". $value['enter']. "</td>";
  454. $str .= "<td>". $value['g']. "</td>";
  455. $str .= "<td>". $value['features']. "</td>";
  456. $str .= "</tr>";
  457. }
  458. $str .= "</table></body></html>";
  459. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  460. header( "Content-type: application/octet-stream" );
  461. header( "Content-Disposition: attachment; filename=".$filename );
  462. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  463. header( "Pragma: no-cache" );
  464. header( "Expires: 0" );
  465. exit($str);
  466. }
  467. }