Whlabelfz1.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. }
  15. //定义方法的调用规则 获取URI第二段值
  16. public function _remap($arg, $arg_array)
  17. {
  18. if ($arg == 'scam_mgxx') //
  19. {
  20. $this->_scanMgxx();
  21. }
  22. else if($arg =='scam_mgxx_post')
  23. {
  24. $this->_scanMgxxPost();
  25. }else if($arg == 'mgxxindex'){
  26. $this->_mgxxindex();
  27. }
  28. else if($arg == 'get_scan_info'){
  29. $this->_getScanInfo();
  30. }
  31. else {
  32. $this->_index();
  33. }
  34. }
  35. private function _index(){
  36. die('No direct script access allowed');
  37. }
  38. private function _mgxxindex(){
  39. $post = $this->input->post();
  40. if(!empty($post)){
  41. $rows = array('total'=>0,'over'=>1,'pagenum'=>1,'rows'=>([]));
  42. echo json_encode($rows);exit;
  43. }
  44. $this->_Template('whlabelfz1_mgxxindex', $this->data);
  45. }
  46. //美国销售 扫描出库的
  47. private function _scanMgxx(){
  48. $post = $this->input->post();
  49. if(!empty($post)){
  50. $type = $this->input->post('type',true);
  51. $orderinfo = $this->input->post('orderinfo',true);
  52. $page = $this->input->post('page',true);
  53. $perpage = $this->input->post('perpage',true);
  54. $where = " type = ".$type." and orderinfo = '".(string)$orderinfo."' ";
  55. if(empty($page))
  56. {
  57. $start = 0;
  58. $perpage = 1;
  59. }
  60. else
  61. {
  62. $start = ($page - 1)*$perpage;
  63. }
  64. $order_str = 'id desc';
  65. $info_list = $this->whlabel_bh_scan->find_all($where,'id,orderinfo,pm,label,sl,scantime',$order_str,$start,$perpage);
  66. $total = $this->whlabel_bh_scan->find_count($where);
  67. $pagenum = ceil($total/$perpage);
  68. $over = $total-($start+$perpage);
  69. foreach($info_list as $k=>$v){
  70. $info_list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  71. }
  72. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  73. echo json_encode($rows);exit;
  74. }else{
  75. $orderinfo = $this->input->get('orderinfo',true);
  76. $type = $this->input->get('type',true);
  77. $this->data['orderinfo'] = $orderinfo;
  78. $this->data['type'] = $type;
  79. $this->_Template('whlabelfz1_scammgxx', $this->data);
  80. }
  81. }
  82. private function _getScanInfo(){
  83. $post = $this->input->post();
  84. $label = $post['label'];
  85. if(empty($label)){
  86. die(json_encode(['code'=>-1,'msg'=>'请输入标签号','data'=>[]]));
  87. }
  88. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  89. if(empty($info)){
  90. die(json_encode(['code'=>-1,'msg'=>'标签号不存在','data'=>[]]));
  91. }
  92. echo "<pre>";
  93. print_r($info);
  94. die;
  95. }
  96. //接收美店销售的post提交
  97. private function _scanMgxxPost(){
  98. $post = $this->input->post();
  99. $type = $post['type'];
  100. $orderinfo = $post['orderinfo'];
  101. $label = $post['scanlabel'];
  102. $num = (int)$post['num'];
  103. if(empty($type)){
  104. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[]],JSON_UNESCAPED_UNICODE));
  105. }
  106. if(empty($orderinfo)){
  107. exit(json_encode(['code'=>-1,'msg'=>'美国销售单号未输入','data'=>[]],JSON_UNESCAPED_UNICODE));
  108. }
  109. if(empty($label)){
  110. exit(json_encode(['code'=>-1,'msg'=>'标签号不能为空','data'=>[]],JSON_UNESCAPED_UNICODE));
  111. }
  112. if(!in_array($type,[1,2])){
  113. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[],JSON_UNESCAPED_UNICODE]));
  114. }
  115. if($type == 1){
  116. $num = 1;
  117. }
  118. if($type == 2){
  119. if($num > 200){
  120. exit(json_encode(['code'=>-1,'msg'=>'扫描数量不能大于200','data'=>[],JSON_UNESCAPED_UNICODE]));
  121. }
  122. }
  123. $info = $this->whlabel_bh_scan->find("label ='".$label."'");
  124. if(!empty($info)){
  125. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  126. }
  127. if($type == 1){
  128. $res = $this->_bbscan($orderinfo,$label);
  129. }elseif($type == 2){
  130. $res = $this->_bqscan($orderinfo,$label,$num);
  131. }
  132. exit(json_encode($res));
  133. }
  134. //生产布标扫描
  135. private function _bbscan($orderinfo,$label){
  136. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  137. if(empty($info)){
  138. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  139. }
  140. if($info['label'] != $label){
  141. return ['code'=>-1,'msg'=>'条码对应的美国销售单号不一致','data'=>[]];
  142. }
  143. $arr = [
  144. 'orderinfo'=>(string)$orderinfo,
  145. 'type'=>1,
  146. 'label'=>(string)$label,
  147. 'features'=>(string)$info['features'],
  148. 'fid'=>$info['id'],
  149. 'jm'=>$info['jm'],
  150. 'pm'=>$info['pm'],
  151. 'sl'=>1,
  152. 'scantime'=>time(),
  153. 'status'=>0,
  154. ];
  155. $this->whlabel_bh_scan->insert($arr);
  156. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  157. }
  158. //标签扫描
  159. private function _bqscan($orderinfo,$label,$num){
  160. $info = $this->whlabellabel->find("label ='".$label."'");
  161. if(empty($info)){
  162. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  163. }
  164. $list = [
  165. [
  166. 'sku2'=>$info['features'],
  167. ]
  168. ];
  169. $res = $this->logic_u9tools->getU9bm($list,'sku2');
  170. if(empty($res[0])){
  171. return ['code'=>-1,'msg'=>'u9条码编辑错误-1','data'=>[]];
  172. }
  173. if(empty($res[0]['jm'])){
  174. return ['code'=>-1,'msg'=>'u9条码编辑异常-2','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'=>$res[0]['jm'],
  183. 'pm'=>$res[0]['zh'],
  184. 'sl'=>$num,
  185. 'scantime'=>time(),
  186. 'status'=>0,
  187. ];
  188. $this->whlabel_bh_scan->insert($arr);
  189. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  190. }
  191. }