Whlabelfz1.php 11 KB

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