Whlabelfz1.php 10 KB

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