Whlabelfz1.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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_whlabeltransport","whlabeltransport");
  19. }
  20. //定义方法的调用规则 获取URI第二段值
  21. public function _remap($arg, $arg_array)
  22. {
  23. if ($arg == 'scam_mgxx') //
  24. {
  25. $this->_scanMgxx();
  26. }
  27. else if($arg =='scam_mgxx_post')
  28. {
  29. $this->_scanMgxxPost();
  30. }else if($arg == 'mgxxindex'){
  31. $this->_mgxxindex();
  32. }
  33. else if($arg == 'get_scan_info'){
  34. $this->_getScanInfo();
  35. }
  36. else if($arg =='typedy'){
  37. $this->_typedy($arg_array);
  38. }
  39. else {
  40. $this->_index();
  41. }
  42. }
  43. private function _index(){
  44. die('No direct script access allowed');
  45. }
  46. private function _mgxxindex(){
  47. $post = $this->input->post();
  48. if(!empty($post)){
  49. $timetk = $this->input->post('timetk',true);
  50. $timetj = $this->input->post('timetj',true);
  51. $type = $this->input->post('type',true);
  52. $timetk = strtotime($timetk);
  53. $timetj = strtotime($timetj);
  54. $page = $this->input->post('page', true);
  55. $perpage = $this->input->post('perpage', true);
  56. $where_sql = " 1=1 ";
  57. if($timetk&&$timetj){
  58. $where_sql .= " and scantime >= ".$timetk ." and scantime <= ".$timetj." ";
  59. }
  60. if(!empty($post['orderinfo'])){
  61. $where_sql .=" and orderinfo = '".$post['orderinfo']."' ";
  62. }
  63. if($type){
  64. $where_sql .=" and type = ".$type." ";
  65. }
  66. $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();
  67. $total = $this->db->from("whlabel_bh_scan")->where($where_sql)->count_all_results();
  68. $pagenum = ceil($total/$perpage);
  69. $over = $total-($page*$perpage);
  70. foreach($list as $k=>$v){
  71. $list[$k]['type'] = ($v['type']== 1)?"工厂布标":"仓库标签";
  72. $list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  73. }
  74. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  75. echo json_encode($rows);exit;
  76. }
  77. $this->_Template('whlabelfz1_mgxxindex', $this->data);
  78. }
  79. //美国销售 扫描出库的
  80. private function _scanMgxx(){
  81. $post = $this->input->post();
  82. if(!empty($post)){
  83. $type = $this->input->post('type',true);
  84. $orderinfo = $this->input->post('orderinfo',true);
  85. $page = $this->input->post('page',true);
  86. $perpage = $this->input->post('perpage',true);
  87. $where = " type = ".$type." and orderinfo = '".(string)$orderinfo."' ";
  88. if(empty($page))
  89. {
  90. $start = 0;
  91. $perpage = 1;
  92. }
  93. else
  94. {
  95. $start = ($page - 1)*$perpage;
  96. }
  97. $order_str = 'id desc';
  98. $info_list = $this->whlabel_bh_scan->find_all($where,'id,orderinfo,pm,label,sl,scantime',$order_str,$start,$perpage);
  99. $total = $this->whlabel_bh_scan->find_count($where);
  100. $pagenum = ceil($total/$perpage);
  101. $over = $total-($start+$perpage);
  102. foreach($info_list as $k=>$v){
  103. $info_list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  104. }
  105. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  106. echo json_encode($rows);exit;
  107. }else{
  108. $orderinfo = $this->input->get('orderinfo',true);
  109. $type = $this->input->get('type',true);
  110. $this->data['orderinfo'] = $orderinfo;
  111. $this->data['type'] = $type;
  112. $this->_Template('whlabelfz1_scammgxx', $this->data);
  113. }
  114. }
  115. private function _getScanInfo(){
  116. $post = $this->input->post();
  117. $label = $post['label'];
  118. if(empty($label)){
  119. die(json_encode(['code'=>-1,'msg'=>'请输入标签号','data'=>[]]));
  120. }
  121. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  122. if(empty($info)){
  123. die(json_encode(['code'=>-1,'msg'=>'标签号不存在','data'=>[]]));
  124. }
  125. echo "<pre>";
  126. print_r($info);
  127. die;
  128. }
  129. //接收美店销售的post提交
  130. private function _scanMgxxPost(){
  131. $post = $this->input->post();
  132. $type = $post['type'];
  133. $orderinfo = $post['orderinfo'];
  134. $label = $post['scanlabel'];
  135. $num = (int)$post['num'];
  136. if(empty($type)){
  137. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[]],JSON_UNESCAPED_UNICODE));
  138. }
  139. if(empty($orderinfo)){
  140. exit(json_encode(['code'=>-1,'msg'=>'美国销售单号未输入','data'=>[]],JSON_UNESCAPED_UNICODE));
  141. }
  142. if(empty($label)){
  143. exit(json_encode(['code'=>-1,'msg'=>'标签号不能为空','data'=>[]],JSON_UNESCAPED_UNICODE));
  144. }
  145. if(!in_array($type,[1,2])){
  146. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[],JSON_UNESCAPED_UNICODE]));
  147. }
  148. if($type == 1){
  149. $num = 1;
  150. }
  151. if($type == 2){
  152. if($num > 2000){
  153. exit(json_encode(['code'=>-1,'msg'=>'扫描数量不能大于2000','data'=>[],JSON_UNESCAPED_UNICODE]));
  154. }
  155. }
  156. if($type == 1){
  157. $info = $this->whlabel_bh_scan->find("label ='".$label."'");
  158. if(!empty($info)){
  159. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  160. }
  161. $res = $this->_bbscan($orderinfo,$label);
  162. }elseif($type == 2){
  163. $start_time = strtotime(date("Y-m-d"),time());
  164. $info = $this->whlabel_bh_scan->find("label ='".$label."' and scantime >= ".$start_time);
  165. if(!empty($info)){
  166. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  167. }
  168. $res = $this->_bqscan($orderinfo,$label,$num);
  169. }
  170. exit(json_encode($res));
  171. }
  172. //生产布标扫描
  173. private function _bbscan($orderinfo,$label){
  174. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  175. if(empty($info)){
  176. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  177. }
  178. if($info['label'] != $label){
  179. return ['code'=>-1,'msg'=>'条码对应的美国销售单号不一致','data'=>[]];
  180. }
  181. $arr = [
  182. 'orderinfo'=>(string)$orderinfo,
  183. 'type'=>1,
  184. 'label'=>(string)$label,
  185. 'features'=>(string)$info['features'],
  186. 'fid'=>$info['id'],
  187. 'jm'=>$info['jm'],
  188. 'pm'=>$info['pm'],
  189. 'sl'=>1,
  190. 'scantime'=>time(),
  191. 'status'=>0,
  192. ];
  193. $this->whlabel_bh_scan->insert($arr);
  194. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  195. }
  196. //标签扫描
  197. private function _bqscan($orderinfo,$label,$num){
  198. $info = $this->whlabellabel->find("label ='".$label."'");
  199. if(empty($info)){
  200. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  201. }
  202. $list = [
  203. [
  204. 'sku2'=>$info['features'],
  205. ]
  206. ];
  207. $res = $this->logic_u9tools->getU9bm($list,'sku2');
  208. if(empty($res[0])){
  209. return ['code'=>-1,'msg'=>'u9条码编辑错误-1','data'=>[]];
  210. }
  211. if(empty($res[0]['jm'])){
  212. return ['code'=>-1,'msg'=>'u9条码编辑异常-2','data'=>[]];
  213. }
  214. $arr = [
  215. 'orderinfo'=>(string)$orderinfo,
  216. 'type'=>2,
  217. 'label'=>(string)$label,
  218. 'features'=>(string)$info['features'],
  219. 'fid'=>$info['id'],
  220. 'jm'=>$res[0]['jm'],
  221. 'pm'=>$res[0]['zh'],
  222. 'sl'=>$num,
  223. 'scantime'=>time(),
  224. 'status'=>0,
  225. ];
  226. $this->whlabel_bh_scan->insert($arr);
  227. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  228. }
  229. // 可以排序的仓库数量
  230. private function _typedy($arg_array){
  231. $prc = array();
  232. $purchase = $this->purchase->find_all();
  233. foreach ($purchase as $k => $v) {
  234. $prc[$v['id']] = $v['title'];
  235. }
  236. $post = $this->input->post(NULL, TRUE);
  237. if (isset($post['page'])) {
  238. $page = $this->input->post('page', true);
  239. $perpage = $this->input->post('perpage', true);
  240. $category = $this->input->post('category', true);
  241. $warehouse = $this->input->post('warehouse', true);
  242. //这里的仓库是隐藏传递的所以不需要判断
  243. $where_sql = " state = 0 and warehouse = ".$warehouse." ";
  244. if(!empty($post['purchase'])){
  245. $where_sql .= " and purchase = ".$post['purchase']." ";
  246. }
  247. if(!empty($post['type'])){
  248. $where_sql .= " and type = ".$post['type']." ";
  249. }
  250. if(!empty($post['category'])){//类目
  251. $where_sql .= " and features like '%-".$post['category']."-%' ";
  252. }
  253. if(!empty($post['grade'])){//等级
  254. $where_sql .= " and features like '%-".$post['grade']."-%' ";
  255. }
  256. if(!empty($post['color'])){//颜色
  257. $where_sql .= " and features like '%-".$post['color']."-%' ";
  258. }
  259. if(!empty($post['lowe'])){//曲度
  260. $where_sql .= " and features like '%-".$post['lowe']."-%' ";
  261. }
  262. if(!empty($post['lacetype'])){//头套种类
  263. $where_sql .= " and features like '%-".$post['lacetype']."-%' ";
  264. }
  265. if(!empty($post['lacecolor'])){//头套颜色
  266. $where_sql .= " and features like '%-".$post['lacecolor']."-%' ";
  267. }
  268. if(!empty($post['size'])){//尺寸
  269. $where_sql .= " and features like '%-".$post['size']."-%' ";
  270. }
  271. if(!empty($post['density'])){//密度
  272. $where_sql .= " and features like '%-".$post['density']."-%' ";
  273. }
  274. if(!empty($post['haircap'])){
  275. $where_sql .= " and features like '%-".$post['haircap']."-%' ";
  276. }
  277. if(!empty($post['hairnumber'])){
  278. $where_sql .= " and features like '%-".$post['hairnumber']."-%' ";
  279. }
  280. if(!empty($post['cklx'])){
  281. $shop_info = $this->shop->read($post['cklx']);
  282. if(!empty($shop_info)){
  283. $where_sql .= " and zd like '%-".$shop_info['shortname']."-%' ";
  284. }
  285. }
  286. if(!empty($post['sku'])){
  287. $sku = trim($post['sku'], ' ');
  288. $sku = trim($sku, ' ');
  289. $where_sql .= " and sku like '%".$sku."%' ";
  290. }
  291. if(!empty($post['title'])){
  292. $title = trim($post['title']);
  293. $where_sql .= " and title like '%". $title ."%' ";
  294. }
  295. if(!empty($post['cpbz'])){
  296. $cpbz = trim($post['cpbz']);
  297. $where_sql .= " and cpbz like '%". $cpbz ."%' ";
  298. }
  299. if(!empty($post['sm'])){
  300. $sm = trim($post['sm']);
  301. $where_sql .= " and sm like '%". $sm ."%' ";
  302. }
  303. if (empty($page)) {
  304. $start = 0;
  305. $perpage = 1;
  306. } else {
  307. $start = ($page - 1) * $perpage;
  308. }
  309. $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');
  310. if(!empty($post['dopx'])){
  311. if($post['dopx'] == 1){
  312. $get_model = $get_model->order_by("total_num",'ASC');
  313. }
  314. if($post['dopx'] == 2){
  315. $get_model = $get_model->order_by("total_num",'DESC');
  316. }
  317. }
  318. // $list = $get_model->limit($perpage,$start)->get_compiled_select();
  319. // echo $list;
  320. // die;
  321. $list = $get_model->limit($perpage,$start)->get()->result_array();
  322. $warehouse_info = $this->warehouse->read($warehouse);
  323. $final_list = [];
  324. $sku_list = array_column($list,'sku');
  325. // $zd_list = ;
  326. foreach($list as $k => $v){
  327. $final_list[$k]['id'] = $v['id'];
  328. $final_list[$k]['warehous'] = $warehouse_info['title'];
  329. $final_list[$k]['purchase'] = $prc[$v['purchase']];
  330. $final_list[$k]['sku'] = $v['sku'];
  331. $final_list[$k]['title'] = $v['title'];
  332. $tmp_deatil = "";
  333. if(!empty($v['details'])){
  334. $tmp_deatil = $v['details'];
  335. }
  336. if(!empty($v['cpid'])){
  337. $tmp_deatil .= "<br/>".$v['cpid'];
  338. }
  339. $final_list[$k]['details'] = $tmp_deatil;
  340. $final_list[$k]['total_num'] = $v['total_num'];
  341. $zt = $this->whlabeltransport->find_all('sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '" and features = "' . $v['features'] . '" and cz = "0"');
  342. $ztdata = '';
  343. if (count($zt) > 0) {
  344. foreach ($zt as $vv) {
  345. $ztdata .= '<p>' . $vv['num'] . ' - ' . date('Y-m-d', $vv['stime']) . '</p>';
  346. }
  347. }
  348. $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();
  349. $final_list[$k]['zt'] = $ztdata;
  350. $final_list[$k]['zd'] = $z;
  351. }
  352. $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();
  353. $pagenum = ceil($total / $perpage);
  354. $over = $total - ($start + $perpage);
  355. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($final_list), 'CS' => $warehouse);
  356. echo json_encode($rows);
  357. exit;
  358. }
  359. $this->data['warehouse'] = (isset($arg_array[0])) ? $arg_array[0] : 5;
  360. $this->_Template('whlabelfz1_typedy', $this->data);
  361. }
  362. }