Whlabelfz1.php 12 KB

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