Whlabelfz1.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. $info = $this->whlabel_bh_scan->find("label ='".$label."'");
  157. if(!empty($info)){
  158. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  159. }
  160. if($type == 1){
  161. $res = $this->_bbscan($orderinfo,$label);
  162. }elseif($type == 2){
  163. $res = $this->_bqscan($orderinfo,$label,$num);
  164. }
  165. exit(json_encode($res));
  166. }
  167. //生产布标扫描
  168. private function _bbscan($orderinfo,$label){
  169. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  170. if(empty($info)){
  171. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  172. }
  173. if($info['label'] != $label){
  174. return ['code'=>-1,'msg'=>'条码对应的美国销售单号不一致','data'=>[]];
  175. }
  176. $arr = [
  177. 'orderinfo'=>(string)$orderinfo,
  178. 'type'=>1,
  179. 'label'=>(string)$label,
  180. 'features'=>(string)$info['features'],
  181. 'fid'=>$info['id'],
  182. 'jm'=>$info['jm'],
  183. 'pm'=>$info['pm'],
  184. 'sl'=>1,
  185. 'scantime'=>time(),
  186. 'status'=>0,
  187. ];
  188. $this->whlabel_bh_scan->insert($arr);
  189. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  190. }
  191. //标签扫描
  192. private function _bqscan($orderinfo,$label,$num){
  193. $info = $this->whlabellabel->find("label ='".$label."'");
  194. if(empty($info)){
  195. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  196. }
  197. $list = [
  198. [
  199. 'sku2'=>$info['features'],
  200. ]
  201. ];
  202. $res = $this->logic_u9tools->getU9bm($list,'sku2');
  203. if(empty($res[0])){
  204. return ['code'=>-1,'msg'=>'u9条码编辑错误-1','data'=>[]];
  205. }
  206. if(empty($res[0]['jm'])){
  207. return ['code'=>-1,'msg'=>'u9条码编辑异常-2','data'=>[]];
  208. }
  209. $arr = [
  210. 'orderinfo'=>(string)$orderinfo,
  211. 'type'=>2,
  212. 'label'=>(string)$label,
  213. 'features'=>(string)$info['features'],
  214. 'fid'=>$info['id'],
  215. 'jm'=>$res[0]['jm'],
  216. 'pm'=>$res[0]['zh'],
  217. 'sl'=>$num,
  218. 'scantime'=>time(),
  219. 'status'=>0,
  220. ];
  221. $this->whlabel_bh_scan->insert($arr);
  222. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  223. }
  224. // 可以排序的仓库数量
  225. private function _typedy($arg_array){
  226. $prc = array();
  227. $purchase = $this->purchase->find_all();
  228. foreach ($purchase as $k => $v) {
  229. $prc[$v['id']] = $v['title'];
  230. }
  231. $post = $this->input->post(NULL, TRUE);
  232. if (isset($post['page'])) {
  233. $page = $this->input->post('page', true);
  234. $perpage = $this->input->post('perpage', true);
  235. $category = $this->input->post('category', true);
  236. $warehouse = $this->input->post('warehouse', true);
  237. //这里的仓库是隐藏传递的所以不需要判断
  238. $where_sql = " state = 0 and warehouse = ".$warehouse." ";
  239. if(!empty($post['purchase'])){
  240. $where_sql .= " and purchase = ".$post['purchase']." ";
  241. }
  242. if(!empty($post['type'])){
  243. $where_sql .= " and type = ".$post['type']." ";
  244. }
  245. if(!empty($post['category'])){//类目
  246. $where_sql .= " and features like '%-".$post['category']."-%' ";
  247. }
  248. if(!empty($post['grade'])){//等级
  249. $where_sql .= " and features like '%-".$post['grade']."-%' ";
  250. }
  251. if(!empty($post['color'])){//颜色
  252. $where_sql .= " and features like '%-".$post['color']."-%' ";
  253. }
  254. if(!empty($post['lowe'])){//曲度
  255. $where_sql .= " and features like '%-".$post['lowe']."-%' ";
  256. }
  257. if(!empty($post['lacetype'])){//头套种类
  258. $where_sql .= " and features like '%-".$post['lacetype']."-%' ";
  259. }
  260. if(!empty($post['lacecolor'])){//头套颜色
  261. $where_sql .= " and features like '%-".$post['lacecolor']."-%' ";
  262. }
  263. if(!empty($post['size'])){//尺寸
  264. $where_sql .= " and features like '%-".$post['size']."-%' ";
  265. }
  266. if(!empty($post['density'])){//密度
  267. $where_sql .= " and density like '%-".$post['density']."-%' ";
  268. }
  269. if(!empty($post['haircap'])){
  270. $where_sql .= " and features like '%-".$post['haircap']."-%' ";
  271. }
  272. if(!empty($post['hairnumber'])){
  273. $where_sql .= " and features like '%-".$post['hairnumber']."-%' ";
  274. }
  275. if(!empty($post['cklx'])){
  276. $shop_info = $this->shop->read($post['cklx']);
  277. if(!empty($shop_info)){
  278. $where_sql .= " and zd like '%-".$shop_info['shortname']."-%' ";
  279. }
  280. }
  281. if(!empty($post['sku'])){
  282. $sku = trim($post['sku'], ' ');
  283. $sku = trim($sku, ' ');
  284. $where_sql .= " and sku like '%".$sku."%' ";
  285. }
  286. if(!empty($post['title'])){
  287. $title = trim($post['title']);
  288. $where_sql .= " and title like '%". $title ."%' ";
  289. }
  290. if(!empty($post['cpbz'])){
  291. $cpbz = trim($post['cpbz']);
  292. $where_sql .= " and cpbz like '%". $cpbz ."%' ";
  293. }
  294. if(!empty($post['sm'])){
  295. $sm = trim($post['sm']);
  296. $where_sql .= " and sm like '%". $sm ."%' ";
  297. }
  298. if (empty($page)) {
  299. $start = 0;
  300. $perpage = 1;
  301. } else {
  302. $start = ($page - 1) * $perpage;
  303. }
  304. $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');
  305. if(!empty($post['dopx'])){
  306. if($post['dopx'] == 1){
  307. $get_model = $get_model->order_by("total_num",'ASC');
  308. }
  309. if($post['dopx'] == 2){
  310. $get_model = $get_model->order_by("total_num",'DESC');
  311. }
  312. }
  313. // $list = $get_model->limit($perpage,$start)->get_compiled_select();
  314. // echo $list;
  315. // die;
  316. $list = $get_model->limit($perpage,$start)->get()->result_array();
  317. $warehouse_info = $this->warehouse->read($warehouse);
  318. $final_list = [];
  319. $sku_list = array_column($list,'sku');
  320. // $zd_list = ;
  321. foreach($list as $k => $v){
  322. $final_list[$k]['id'] = $v['id'];
  323. $final_list[$k]['warehous'] = $warehouse_info['title'];
  324. $final_list[$k]['purchase'] = $prc[$v['purchase']];
  325. $final_list[$k]['sku'] = $v['sku'];
  326. $final_list[$k]['title'] = $v['title'];
  327. $tmp_deatil = "";
  328. if(!empty($v['details'])){
  329. $tmp_deatil = $v['details'];
  330. }
  331. if(!empty($v['cpid'])){
  332. $tmp_deatil .= "<br/>".$v['cpid'];
  333. }
  334. $final_list[$k]['details'] = $tmp_deatil;
  335. $final_list[$k]['total_num'] = $v['total_num'];
  336. $zt = $this->whlabeltransport->find_all('sku = "' . $v['sku'] . '" and warehouse = "' . $v['warehouse'] . '" and features = "' . $v['features'] . '" and cz = "0"');
  337. $ztdata = '';
  338. if (count($zt) > 0) {
  339. foreach ($zt as $vv) {
  340. $ztdata .= '<p>' . $vv['num'] . ' - ' . date('Y-m-d', $vv['stime']) . '</p>';
  341. }
  342. }
  343. $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();
  344. $final_list[$k]['zt'] = $ztdata;
  345. $final_list[$k]['zd'] = $z;
  346. }
  347. $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();
  348. $pagenum = ceil($total / $perpage);
  349. $over = $total - ($start + $perpage);
  350. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($final_list), 'CS' => $warehouse);
  351. echo json_encode($rows);
  352. exit;
  353. }
  354. $this->data['warehouse'] = (isset($arg_array[0])) ? $arg_array[0] : 5;
  355. $this->_Template('whlabelfz1_typedy', $this->data);
  356. }
  357. }