Whlabelfz1.php 22 KB

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