Whlabelfz1.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <?php defined('BASEPATH') or exit('No direct script access allowed');
  2. /**
  3. * 由于whlabel类下的代码太长了,决定以后非必要代码都放在whlabelfz类中,以便于管理。
  4. */
  5. class Whlabelfz1 extends Start_Controller
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. $this->load->_model("Model_whlabel_bh_transfer",'whlabel_bh_transfer');
  11. $this->load->_model("Model_whlabel_bh_scan",'whlabel_bh_scan');
  12. $this->load->_model("Model_logic_u9tools","logic_u9tools");
  13. $this->load->_model("Model_whlabellabel","whlabellabel");
  14. $this->load->_model('Model_purchase', 'purchase');
  15. $this->load->_model('Model_whlabel_type', 'whlabel_type');
  16. $this->load->_model("Model_shop","shop");
  17. $this->load->_model("Model_warehouse","warehouse");
  18. $this->load->_model("Model_express","express");
  19. $this->load->_model("Model_whlabeltransport","whlabeltransport");
  20. $this->load->_model("Model_logic_order","logic_order");
  21. $this->load->_model("Model_user","user");
  22. $this->load->_model("Model_fullorderexcel","fullorderexcel");
  23. $this->load->_model("Model_power","power");
  24. $this->load->_model("Model_orderurl","orderurl");
  25. }
  26. //定义方法的调用规则 获取URI第二段值
  27. public function _remap($arg, $arg_array)
  28. {
  29. if ($arg == 'scam_mgxx') //
  30. {
  31. $this->_scanMgxx();
  32. }
  33. else if($arg =='scam_mgxx_post')
  34. {
  35. $this->_scanMgxxPost();
  36. }else if($arg == 'mgxxindex'){
  37. $this->_mgxxindex();
  38. }
  39. else if($arg == 'get_scan_info'){
  40. $this->_getScanInfo();
  41. }
  42. else if($arg =='typedy'){
  43. $this->_typedy($arg_array);
  44. }
  45. else if($arg =='scanlogs'){
  46. $this->_scanlogs();
  47. }
  48. else if($arg =='zoutorder'){
  49. $this->_zoutorder();
  50. }
  51. else if($arg == 'mgxxexcel'){
  52. $this->_mgxxexcel();
  53. }
  54. else {
  55. $this->_index();
  56. }
  57. }
  58. private function _index(){
  59. die('No direct script access allowed');
  60. }
  61. private function _mgxxindex(){
  62. $post = $this->input->post();
  63. if(!empty($post)){
  64. $timetk = $this->input->post('timetk',true);
  65. $timetj = $this->input->post('timetj',true);
  66. $type = $this->input->post('type',true);
  67. $timetk = strtotime($timetk);
  68. $timetj = strtotime($timetj);
  69. $page = $this->input->post('page', true);
  70. $perpage = $this->input->post('perpage', true);
  71. $where_sql = " 1=1 ";
  72. if($timetk&&$timetj){
  73. $where_sql .= " and scantime >= ".$timetk ." and scantime <= ".$timetj." ";
  74. }
  75. if(!empty($post['orderinfo'])){
  76. $where_sql .=" and orderinfo = '".$post['orderinfo']."' ";
  77. }
  78. if($type){
  79. $where_sql .=" and type = ".$type." ";
  80. }
  81. $list = $this->db->from("whlabel_bh_scan")->select('id,orderinfo,type,jm,pm,sl,scantime')->where($where_sql)->order_by('id desc')->limit($perpage,($page-1)*$perpage)->get()->result_array();
  82. $total = $this->db->from("whlabel_bh_scan")->where($where_sql)->count_all_results();
  83. $pagenum = ceil($total/$perpage);
  84. $over = $total-($page*$perpage);
  85. foreach($list as $k=>$v){
  86. $list[$k]['type'] = ($v['type']== 1)?"工厂布标":"仓库标签";
  87. $list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  88. }
  89. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  90. echo json_encode($rows);exit;
  91. }
  92. $this->_Template('whlabelfz1_mgxxindex', $this->data);
  93. }
  94. //美国销售 扫描出库的
  95. private function _scanMgxx(){
  96. $post = $this->input->post();
  97. if(!empty($post)){
  98. $type = $this->input->post('type',true);
  99. $orderinfo = $this->input->post('orderinfo',true);
  100. $page = $this->input->post('page',true);
  101. $perpage = $this->input->post('perpage',true);
  102. $where = " type = ".$type." and orderinfo = '".(string)$orderinfo."' ";
  103. if(empty($page))
  104. {
  105. $start = 0;
  106. $perpage = 1;
  107. }
  108. else
  109. {
  110. $start = ($page - 1)*$perpage;
  111. }
  112. $order_str = 'id desc';
  113. $info_list = $this->whlabel_bh_scan->find_all($where,'id,orderinfo,pm,label,sl,scantime',$order_str,$start,$perpage);
  114. $total = $this->whlabel_bh_scan->find_count($where);
  115. $pagenum = ceil($total/$perpage);
  116. $over = $total-($start+$perpage);
  117. foreach($info_list as $k=>$v){
  118. $info_list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  119. }
  120. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  121. echo json_encode($rows);exit;
  122. }else{
  123. $orderinfo = $this->input->get('orderinfo',true);
  124. $type = $this->input->get('type',true);
  125. $this->data['orderinfo'] = $orderinfo;
  126. $this->data['type'] = $type;
  127. $this->_Template('whlabelfz1_scammgxx', $this->data);
  128. }
  129. }
  130. private function _getScanInfo(){
  131. $post = $this->input->post();
  132. $label = $post['label'];
  133. if(empty($label)){
  134. die(json_encode(['code'=>-1,'msg'=>'请输入标签号','data'=>[]]));
  135. }
  136. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  137. if(empty($info)){
  138. die(json_encode(['code'=>-1,'msg'=>'标签号不存在','data'=>[]]));
  139. }
  140. echo "<pre>";
  141. print_r($info);
  142. die;
  143. }
  144. //接收美店销售的post提交
  145. private function _scanMgxxPost(){
  146. $post = $this->input->post();
  147. $type = $post['type'];
  148. $orderinfo = $post['orderinfo'];
  149. $label = $post['scanlabel'];
  150. $num = (int)$post['num'];
  151. if(empty($type)){
  152. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[]],JSON_UNESCAPED_UNICODE));
  153. }
  154. if(empty($orderinfo)){
  155. exit(json_encode(['code'=>-1,'msg'=>'美国销售单号未输入','data'=>[]],JSON_UNESCAPED_UNICODE));
  156. }
  157. if(empty($label)){
  158. exit(json_encode(['code'=>-1,'msg'=>'标签号不能为空','data'=>[]],JSON_UNESCAPED_UNICODE));
  159. }
  160. if(!in_array($type,[1,2])){
  161. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[],JSON_UNESCAPED_UNICODE]));
  162. }
  163. if($type == 1){
  164. $num = 1;
  165. }
  166. if($type == 2){
  167. if($num > 2000){
  168. exit(json_encode(['code'=>-1,'msg'=>'扫描数量不能大于2000','data'=>[],JSON_UNESCAPED_UNICODE]));
  169. }
  170. }
  171. if($type == 1){
  172. $info = $this->whlabel_bh_scan->find("label ='".$label."'");
  173. if(!empty($info)){
  174. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  175. }
  176. $res = $this->_bbscan($orderinfo,$label);
  177. }elseif($type == 2){
  178. $start_time = strtotime(date("Y-m-d"),time());
  179. $info = $this->whlabel_bh_scan->find("label ='".$label."' and scantime >= ".$start_time);
  180. if(!empty($info)){
  181. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  182. }
  183. $res = $this->_bqscan($orderinfo,$label,$num);
  184. }
  185. exit(json_encode($res));
  186. }
  187. //生产布标扫描
  188. private function _bbscan($orderinfo,$label){
  189. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  190. if(empty($info)){
  191. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  192. }
  193. if($info['label'] != $label){
  194. return ['code'=>-1,'msg'=>'条码对应的美国销售单号不一致','data'=>[]];
  195. }
  196. $arr = [
  197. 'orderinfo'=>(string)$orderinfo,
  198. 'type'=>1,
  199. 'label'=>(string)$label,
  200. 'features'=>(string)$info['features'],
  201. 'fid'=>$info['id'],
  202. 'jm'=>$info['jm'],
  203. 'pm'=>$info['pm'],
  204. 'sl'=>1,
  205. 'scantime'=>time(),
  206. 'status'=>0,
  207. ];
  208. $this->whlabel_bh_scan->insert($arr);
  209. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  210. }
  211. //标签扫描
  212. private function _bqscan($orderinfo,$label,$num){
  213. $info = $this->whlabellabel->find("label ='".$label."'");
  214. if(empty($info)){
  215. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  216. }
  217. $list = [
  218. [
  219. 'sku2'=>$info['features'],
  220. ]
  221. ];
  222. $res = $this->logic_u9tools->getU9bm($list,'sku2');
  223. if(empty($res[0])){
  224. return ['code'=>-1,'msg'=>'u9条码编辑错误-1','data'=>[]];
  225. }
  226. if(empty($res[0]['jm'])){
  227. return ['code'=>-1,'msg'=>'u9条码编辑异常-2','data'=>[]];
  228. }
  229. $arr = [
  230. 'orderinfo'=>(string)$orderinfo,
  231. 'type'=>2,
  232. 'label'=>(string)$label,
  233. 'features'=>(string)$info['features'],
  234. 'fid'=>$info['id'],
  235. 'jm'=>$res[0]['jm'],
  236. 'pm'=>$res[0]['zh'],
  237. 'sl'=>$num,
  238. 'scantime'=>time(),
  239. 'status'=>0,
  240. ];
  241. $this->whlabel_bh_scan->insert($arr);
  242. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  243. }
  244. // 可以排序的仓库数量
  245. private function _typedy($arg_array){
  246. $prc = array();
  247. $purchase = $this->purchase->find_all();
  248. foreach ($purchase as $k => $v) {
  249. $prc[$v['id']] = $v['title'];
  250. }
  251. $post = $this->input->post(NULL, TRUE);
  252. if (isset($post['page'])) {
  253. $page = $this->input->post('page', true);
  254. $perpage = $this->input->post('perpage', true);
  255. $category = $this->input->post('category', true);
  256. $warehouse = $this->input->post('warehouse', true);
  257. //这里的仓库是隐藏传递的所以不需要判断
  258. $where_sql = " state = 0 and warehouse = ".$warehouse." ";
  259. if(!empty($post['purchase'])){
  260. $where_sql .= " and purchase = ".$post['purchase']." ";
  261. }
  262. if(!empty($post['type'])){
  263. $where_sql .= " and type = ".$post['type']." ";
  264. }
  265. if(!empty($post['category'])){//类目
  266. $where_sql .= " and features like '%-".$post['category']."-%' ";
  267. }
  268. if(!empty($post['grade'])){//等级
  269. $where_sql .= " and features like '%-".$post['grade']."-%' ";
  270. }
  271. if(!empty($post['color'])){//颜色
  272. $where_sql .= " and features like '%-".$post['color']."-%' ";
  273. }
  274. if(!empty($post['lowe'])){//曲度
  275. $where_sql .= " and features like '%-".$post['lowe']."-%' ";
  276. }
  277. if(!empty($post['lacetype'])){//头套种类
  278. $where_sql .= " and features like '%-".$post['lacetype']."-%' ";
  279. }
  280. if(!empty($post['lacecolor'])){//头套颜色
  281. $where_sql .= " and features like '%-".$post['lacecolor']."-%' ";
  282. }
  283. if(!empty($post['size'])){//尺寸
  284. $where_sql .= " and features like '%-".$post['size']."-%' ";
  285. }
  286. if(!empty($post['density'])){//密度
  287. $where_sql .= " and features like '%-".$post['density']."-%' ";
  288. }
  289. if(!empty($post['haircap'])){
  290. $where_sql .= " and features like '%-".$post['haircap']."-%' ";
  291. }
  292. if(!empty($post['hairnumber'])){
  293. $where_sql .= " and features like '%-".$post['hairnumber']."-%' ";
  294. }
  295. if(!empty($post['cklx'])){
  296. $shop_info = $this->shop->read($post['cklx']);
  297. if(!empty($shop_info)){
  298. $where_sql .= " and zd like '%-".$shop_info['shortname']."-%' ";
  299. }
  300. }
  301. if(!empty($post['sku'])){
  302. $sku = trim($post['sku'], ' ');
  303. $sku = trim($sku, ' ');
  304. $where_sql .= " and sku like '%".$sku."%' ";
  305. }
  306. if(!empty($post['title'])){
  307. $title = trim($post['title']);
  308. $where_sql .= " and title like '%". $title ."%' ";
  309. }
  310. if(!empty($post['cpbz'])){
  311. $cpbz = trim($post['cpbz']);
  312. $where_sql .= " and cpbz like '%". $cpbz ."%' ";
  313. }
  314. if(!empty($post['sm'])){
  315. $sm = trim($post['sm']);
  316. $where_sql .= " and sm like '%". $sm ."%' ";
  317. }
  318. if (empty($page)) {
  319. $start = 0;
  320. $perpage = 1;
  321. } else {
  322. $start = ($page - 1) * $perpage;
  323. }
  324. $get_model = $this->db->from("whlabel")->where($where_sql)->select("id,number,purchase,sku,warehouse,features,title,details,cpid,COUNT(id) AS total_num")->group_by('sku');
  325. if(!empty($post['dopx'])){
  326. if($post['dopx'] == 1){
  327. $get_model = $get_model->order_by("total_num",'ASC');
  328. }
  329. if($post['dopx'] == 2){
  330. $get_model = $get_model->order_by("total_num",'DESC');
  331. }
  332. }
  333. // $list = $get_model->limit($perpage,$start)->get_compiled_select();
  334. // echo $list;
  335. // die;
  336. $list = $get_model->limit($perpage,$start)->get()->result_array();
  337. $warehouse_info = $this->warehouse->read($warehouse);
  338. $final_list = [];
  339. $sku_list = array_column($list,'sku');
  340. // $zd_list = ;
  341. foreach($list as $k => $v){
  342. $final_list[$k]['id'] = $v['id'];
  343. $final_list[$k]['warehous'] = $warehouse_info['title'];
  344. $final_list[$k]['purchase'] = $prc[$v['purchase']];
  345. $final_list[$k]['sku'] = $v['sku'];
  346. $final_list[$k]['title'] = $v['title'];
  347. $tmp_deatil = "";
  348. if(!empty($v['details'])){
  349. $tmp_deatil = $v['details'];
  350. }
  351. if(!empty($v['cpid'])){
  352. $tmp_deatil .= "<br/>".$v['cpid'];
  353. }
  354. $final_list[$k]['details'] = $tmp_deatil;
  355. $final_list[$k]['total_num'] = $v['total_num'];
  356. $zt = $this->whlabeltransport->find_all('sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '" and features = "' . $v['features'] . '" and cz = "0"');
  357. $ztdata = '';
  358. if (count($zt) > 0) {
  359. foreach ($zt as $vv) {
  360. $ztdata .= '<p>' . $vv['num'] . ' - ' . date('Y-m-d', $vv['stime']) . '</p>';
  361. }
  362. }
  363. $z = $this->db->from("whlabel")->where("sku = '".$v['sku']."' and state = 0 and warehouse = '". $v['warehouse']."' and features = '". $v['features']."' and zd != '' ")->count_all_results();
  364. $final_list[$k]['zt'] = $ztdata;
  365. $final_list[$k]['zd'] = $z;
  366. }
  367. $total = $this->db->from("whlabel")->where($where_sql)->select("id,number,sku,warehouse,title,details,cpid,COUNT(id) AS total_num")->group_by('sku')->count_all_results();
  368. $pagenum = ceil($total / $perpage);
  369. $over = $total - ($start + $perpage);
  370. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($final_list), 'CS' => $warehouse);
  371. echo json_encode($rows);
  372. exit;
  373. }
  374. $this->data['warehouse'] = (isset($arg_array[0])) ? $arg_array[0] : 5;
  375. $this->_Template('whlabelfz1_typedy', $this->data);
  376. }
  377. public function _scanlogs(){
  378. $params = $this->input->get(NULL, TRUE);
  379. $timetj = $params['timetj'];
  380. $timetk = $params['timetk'];
  381. $where = [];
  382. $where["scantime >="] = strtotime($timetj);
  383. $where["scantime <="] = strtotime($timetk);
  384. if(!empty($params['orderinfo'])){
  385. $where["orderinfo"] = $params['orderinfo'];
  386. }
  387. $list = $this->db->from("whlabel_bh_scan")->where($where)->get()->result_array();
  388. //生成excel
  389. $filename = date("Y-m-d")."工厂备货扫描记录导出.xls";
  390. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  391. <head>
  392. <!--[if gte mso 9]><xml>
  393. <x:ExcelWorkbook>
  394. <x:ExcelWorksheets>
  395. <x:ExcelWorksheet>
  396. <x:Name>EXCEL</x:Name>
  397. <x:WorksheetOptions>
  398. <x:Print>
  399. <x:ValidPrinterInfo />
  400. </x:Print>
  401. </x:WorksheetOptions>
  402. </x:ExcelWorksheet>
  403. </x:ExcelWorksheets>
  404. </x:ExcelWorkbook>
  405. </xml>
  406. <![endif]-->
  407. </head><body>";
  408. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  409. $str .= "<tr><td>备货单编码</td><td>扫码类型</td><td>SKU</td><td>名称</td><td>料号</td><td>状态</td><td>入库时间</td><td>所在位置</td></tr>";
  410. foreach ($info_list as $key=>$value)
  411. {
  412. $str .= "<tr>";
  413. $str .= "<td>". $value['warehouse']. "</td>";
  414. $str .= "<td>". $value['purchase']. "</td>";
  415. $str .= "<td>". $value['sku']. "</td>";
  416. $str .= "<td>". $value['title']. "</td>";
  417. $str .= "<td>". $value['features']. "</td>";
  418. $str .= "<td>". $value['state']. "</td>";
  419. $str .= "<td>". $value['enter']. "</td>";
  420. $str .= "<td>". $value['details']. "</td>";
  421. $str .= "</tr>";
  422. }
  423. $str .= "</table></body></html>";
  424. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  425. header( "Content-type: application/octet-stream" );
  426. header( "Content-Disposition: attachment; filename=".$filename );
  427. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  428. header( "Pragma: no-cache" );
  429. header( "Expires: 0" );
  430. exit($str);
  431. }
  432. //汇总的出库浏览
  433. private function _zoutorder(){
  434. $fgshop = "";
  435. $sid = "";
  436. if (isset($_SESSION['api'])) {
  437. $user = $this->user->get_api($_SESSION['api']);
  438. $usp = $user;
  439. $user = explode('|', trim($user['shop'], '|'));
  440. foreach ($user as $value) {
  441. $fgshop .= " shop = " . $value . " or";
  442. $sid .= " id = " . $value . " or";
  443. }
  444. } else {
  445. echo "请重新登录";
  446. die;
  447. }
  448. $post = $this->input->post(NULL, TRUE);
  449. if (isset($post['page'])) {
  450. $page = $this->input->post('page', true);
  451. $perpage = $this->input->post('perpage', true);
  452. $warehouse = $this->input->post('warehouse', true);
  453. $xztime = $this->input->post('xztime', true);
  454. $timetk = $this->input->post('timetkk', true);
  455. $timetj = $this->input->post('timetjj', true);
  456. $shop = $this->input->post('shop', true);
  457. $source = $this->input->post('source', true);
  458. $orderinfo = $this->input->post('orderinfo', true);
  459. $number = $this->input->post('number', true);
  460. $sfxh = $this->input->post('sfxh', true);
  461. $express = $this->input->post('express', true);
  462. $waybill = $this->input->post('waybill', true);
  463. $library = $this->input->post('library', true);
  464. $country = $this->input->post('country', true);
  465. $so = $this->input->post('so', true);
  466. $libraryconfirm = $this->input->post('libraryconfirm', true);
  467. $print = $this->input->post('print', true);
  468. $state = $this->input->post('state', true);
  469. $orderurl = $this->input->post('orderurl', true);
  470. $timetk = strtotime($timetk);
  471. $timetj = strtotime($timetj);
  472. $where_arr = [
  473. $xztime.' >' => $timetk,
  474. $xztime.' <' => $timetj,
  475. ];
  476. if ($warehouse) {
  477. $where_arr['type'] = $warehouse;
  478. }
  479. if ($orderinfo) {
  480. $where_arr['orderinfo'] = $orderinfo;
  481. }
  482. if ($number) {
  483. $where_arr['number'] = $number;
  484. }
  485. if ($express) {
  486. $where_arr['express'] = $express;
  487. }
  488. if ($waybill) {
  489. $where_arr['waybill'] = $waybill;
  490. }
  491. if ($library) {
  492. $where_arr['library'] = $library;
  493. }
  494. if ($print) {
  495. $where_arr['print'] = $print;
  496. }
  497. if ($libraryconfirm) {
  498. $where_arr['libraryconfirm'] = $libraryconfirm;
  499. }
  500. if ($state) {
  501. $where_arr['state'] = $state;
  502. }
  503. if ($shop) {
  504. $where_arr['shop'] = $shop;
  505. }
  506. if ($country) {
  507. $where_arr['country'] = $country;
  508. }
  509. if ($sfxh != '') {
  510. $where_arr['sfxh'] = $sfxh;
  511. }
  512. if ($so) {
  513. $where_arr['so like'] = '%'. $so .'%';
  514. }
  515. if ($source) {
  516. if ($source == '2d') {
  517. $where_arr['source >='] = '2';
  518. } else {
  519. $where_arr['source'] = $source;
  520. }
  521. }
  522. if (isset($_SESSION['api'])) {
  523. $shop_select_list = [];
  524. foreach ($user as $value) {
  525. if(!empty($value)){
  526. $shop_select_list[] = $value;
  527. }
  528. }
  529. }
  530. if ($orderurl) {
  531. $url = $this->orderurl->read($orderurl);
  532. $where_arr['link like'] = '%'. $url['url'] . '%';
  533. }
  534. //数据排序
  535. $order_str = "librarytime desc";
  536. if (empty($page)) {
  537. $start = 0;
  538. $perpage = 1;
  539. } else {
  540. $start = ($page - 1) * $perpage;
  541. }
  542. $warehouse_list = $this->warehouse->find_all('1 = 1',"id,title");
  543. $warehouse_arr = array_column($warehouse_list, 'title', 'id');
  544. $express_list = $this->express->find_all('1 = 1',"id,servicename");
  545. $express_arr = array_column($express_list,'servicename', 'id');
  546. $shop_list = $this->shop->find_all('1 = 1',"id,shopname");
  547. $shop_arr = array_column($shop_list,'shopname', 'id');
  548. $total = 0;
  549. $info_list = [];
  550. $r1 = $this->_getData('fullorder', $where_arr, $order_str, 'id,shop,type,orderinfo,number,waybill,express,librarytime', ($page-1)*$perpage, $perpage,$warehouse_arr,$express_arr,$shop_arr,$shop_select_list);
  551. $r2 = $this->_getData('fullordertt', $where_arr, $order_str, 'id,shop,type,orderinfo,number,waybill,express,librarytime', ($page-1)*$perpage, $perpage,$warehouse_arr,$express_arr,$shop_arr,$shop_select_list);
  552. $r3 = $this->_getData('fullordersmt', $where_arr, $order_str, 'id,shop,type,orderinfo,number,waybill,express,librarytime', ($page-1)*$perpage, $perpage,$warehouse_arr,$express_arr,$shop_arr,$shop_select_list);
  553. $r4 = $this->_getData('fullorderamz', $where_arr, $order_str, 'id,shop,type,orderinfo,number,waybill,express,librarytime', ($page-1)*$perpage, $perpage,$warehouse_arr,$express_arr,$shop_arr,$shop_select_list);
  554. $info_list = array_merge($r1['info_list'] , $r2['info_list'] , $r3['info_list'] , $r4['info_list']) ;
  555. $total += $r1['total'] + $r2['total'] + $r3['total'] + $r4['total'];
  556. $pagenum = ceil($total / ($perpage));
  557. $over = $total - ($start + $perpage);
  558. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  559. echo json_encode($rows);
  560. exit;
  561. }
  562. $this->data['express'] = $this->express->find_all();
  563. $wlshop = $this->shop->find_all('1=1 and ' . rtrim($sid, 'or'));
  564. $this->data['wlshop'] = $wlshop;
  565. $user = $this->user->get_api($_SESSION['api']);
  566. $powerid = $this->power->read($user['power']);
  567. $powertext = explode('|', trim($powerid['excelid'], '|'));
  568. $pid = '';
  569. foreach ($powertext as $v) {
  570. $pid .= " id = " . $v . " or";
  571. }
  572. $fullorderexcel = $this->fullorderexcel->find_all("type = '100011' and (" . rtrim($pid, 'or') . ")", '*', 'idorder desc'); //导出模板
  573. $this->data['fullorderexcel'] = $fullorderexcel;
  574. $orderurl = $this->orderurl->find_all(rtrim($fgshop, 'or'));
  575. $this->data['orderurl'] = $orderurl;
  576. $this->_Template('whlabel_zoutorder', $this->data);
  577. }
  578. protected function _getData($tableName, $where, $order, $field, $page, $pagesize,$warehouse_arr,$express_arr,$shop_arr,$shop_select_list){
  579. if(empty($shop_select_list)){
  580. $info_list = $this->db->from($tableName)->where($where)->order_by($order)->select($field)->limit($pagesize, $page)->get()->result_array();
  581. $total = $this->db->from($tableName)->where($where)->count_all_results();
  582. }else{
  583. $info_list = $this->db->from($tableName)->where($where)->where_in('shop', $shop_select_list)->order_by($order)->select($field)->limit($pagesize, $page)->get()->result_array();
  584. $total = $this->db->from($tableName)->where($where)->where_in('shop', $shop_select_list)->count_all_results();
  585. }
  586. //格式化数据
  587. foreach ($info_list as $key => $value) {
  588. $info_list[$key]['shop'] = isset($shop_arr[$value['shop']])? $shop_arr[$value['shop']] : '';
  589. $info_list[$key]['express'] = isset($express_arr[$value['express']])?$express_arr[$value['express']]:'';
  590. $info_list[$key]['type'] = isset($warehouse_arr[$value['type']])? $warehouse_arr[$value['type']] : '';
  591. if ($value['librarytime'] == '0') {
  592. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  593. } else {
  594. $info_list[$key]['librarytime'] = '<em class="t">' . date('Y-m-d H:i:s', $value['librarytime']) . '</em>';
  595. }
  596. }
  597. return [
  598. 'info_list' => $info_list,
  599. 'total' => $total,
  600. ];
  601. }
  602. private function _mgxxexcel(){
  603. $timetk = $this->input->get('timetk',true);
  604. $timetj = $this->input->get('timetj',true);
  605. $type = $this->input->get('type',true);
  606. $timetk = strtotime($timetk);
  607. $timetj = strtotime($timetj);
  608. $where_sql = " 1=1 ";
  609. if($timetk&&$timetj){
  610. $where_sql .= " and scantime >= ".$timetk ." and scantime <= ".$timetj." ";
  611. }
  612. if(!empty($post['orderinfo'])){
  613. $where_sql .=" and orderinfo = '".$post['orderinfo']."' ";
  614. }
  615. if($type){
  616. $where_sql .=" and type = ".$type." ";
  617. }
  618. $list = $this->db->from("whlabel_bh_scan")->select('id,orderinfo,type,jm,pm,sl,scantime')->where($where_sql)->order_by('id desc')->get()->result_array();
  619. foreach($list as $k=>$v){
  620. $list[$k]['type'] = ($v['type']== 1)?"工厂布标":"仓库标签";
  621. $list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  622. }
  623. //生成excel
  624. $filename = date("Y-m-d")."成品库备货扫描记录导出.xls";
  625. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  626. <head>
  627. <!--[if gte mso 9]><xml>
  628. <x:ExcelWorkbook>
  629. <x:ExcelWorksheets>
  630. <x:ExcelWorksheet>
  631. <x:Name>EXCEL</x:Name>
  632. <x:WorksheetOptions>
  633. <x:Print>
  634. <x:ValidPrinterInfo />
  635. </x:Print>
  636. </x:WorksheetOptions>
  637. </x:ExcelWorksheet>
  638. </x:ExcelWorksheets>
  639. </x:ExcelWorkbook>
  640. </xml>
  641. <![endif]-->
  642. </head><body>";
  643. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  644. $str .= "<tr><td>备货单编码</td><td>类型</td><td>u9料号</td><td>品名</td><td>数量</td><td>扫描时间</td></tr>";
  645. foreach ($list as $key=>$value)
  646. {
  647. $str .= "<tr>";
  648. $str .= "<td>". $value['orderinfo']. "</td>";
  649. $str .= "<td>". $value['type']. "</td>";
  650. $str .= "<td>". $value['jm']. "</td>";
  651. $str .= "<td>". $value['pm']. "</td>";
  652. $str .= "<td>". $value['sl']. "</td>";
  653. $str .= "<td>". $value['scantime']. "</td>";
  654. $str .= "</tr>";
  655. }
  656. $str .= "</table></body></html>";
  657. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  658. header( "Content-type: application/octet-stream" );
  659. header( "Content-Disposition: attachment; filename=".$filename );
  660. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  661. header( "Pragma: no-cache" );
  662. header( "Expires: 0" );
  663. exit($str);
  664. }
  665. }