Whlabelfz1.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. }
  16. //定义方法的调用规则 获取URI第二段值
  17. public function _remap($arg, $arg_array)
  18. {
  19. if ($arg == 'scam_mgxx') //
  20. {
  21. $this->_scanMgxx();
  22. }
  23. else if($arg =='scam_mgxx_post')
  24. {
  25. $this->_scanMgxxPost();
  26. }else if($arg == 'mgxxindex'){
  27. $this->_mgxxindex();
  28. }
  29. else if($arg == 'get_scan_info'){
  30. $this->_getScanInfo();
  31. }
  32. else if($arg =='typedy'){
  33. $this->_typedy();
  34. }
  35. else {
  36. $this->_index();
  37. }
  38. }
  39. private function _index(){
  40. die('No direct script access allowed');
  41. }
  42. private function _mgxxindex(){
  43. $post = $this->input->post();
  44. if(!empty($post)){
  45. $rows = array('total'=>0,'over'=>1,'pagenum'=>1,'rows'=>([]));
  46. echo json_encode($rows);exit;
  47. }
  48. $this->_Template('whlabelfz1_mgxxindex', $this->data);
  49. }
  50. //美国销售 扫描出库的
  51. private function _scanMgxx(){
  52. $post = $this->input->post();
  53. if(!empty($post)){
  54. $type = $this->input->post('type',true);
  55. $orderinfo = $this->input->post('orderinfo',true);
  56. $page = $this->input->post('page',true);
  57. $perpage = $this->input->post('perpage',true);
  58. $where = " type = ".$type." and orderinfo = '".(string)$orderinfo."' ";
  59. if(empty($page))
  60. {
  61. $start = 0;
  62. $perpage = 1;
  63. }
  64. else
  65. {
  66. $start = ($page - 1)*$perpage;
  67. }
  68. $order_str = 'id desc';
  69. $info_list = $this->whlabel_bh_scan->find_all($where,'id,orderinfo,pm,label,sl,scantime',$order_str,$start,$perpage);
  70. $total = $this->whlabel_bh_scan->find_count($where);
  71. $pagenum = ceil($total/$perpage);
  72. $over = $total-($start+$perpage);
  73. foreach($info_list as $k=>$v){
  74. $info_list[$k]['scantime'] = date('Y-m-d H:i:s',$v['scantime']);
  75. }
  76. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  77. echo json_encode($rows);exit;
  78. }else{
  79. $orderinfo = $this->input->get('orderinfo',true);
  80. $type = $this->input->get('type',true);
  81. $this->data['orderinfo'] = $orderinfo;
  82. $this->data['type'] = $type;
  83. $this->_Template('whlabelfz1_scammgxx', $this->data);
  84. }
  85. }
  86. private function _getScanInfo(){
  87. $post = $this->input->post();
  88. $label = $post['label'];
  89. if(empty($label)){
  90. die(json_encode(['code'=>-1,'msg'=>'请输入标签号','data'=>[]]));
  91. }
  92. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  93. if(empty($info)){
  94. die(json_encode(['code'=>-1,'msg'=>'标签号不存在','data'=>[]]));
  95. }
  96. echo "<pre>";
  97. print_r($info);
  98. die;
  99. }
  100. //接收美店销售的post提交
  101. private function _scanMgxxPost(){
  102. $post = $this->input->post();
  103. $type = $post['type'];
  104. $orderinfo = $post['orderinfo'];
  105. $label = $post['scanlabel'];
  106. $num = (int)$post['num'];
  107. if(empty($type)){
  108. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[]],JSON_UNESCAPED_UNICODE));
  109. }
  110. if(empty($orderinfo)){
  111. exit(json_encode(['code'=>-1,'msg'=>'美国销售单号未输入','data'=>[]],JSON_UNESCAPED_UNICODE));
  112. }
  113. if(empty($label)){
  114. exit(json_encode(['code'=>-1,'msg'=>'标签号不能为空','data'=>[]],JSON_UNESCAPED_UNICODE));
  115. }
  116. if(!in_array($type,[1,2])){
  117. exit(json_encode(['code'=>-1,'msg'=>'数据类型异常,请联系技术','data'=>[],JSON_UNESCAPED_UNICODE]));
  118. }
  119. if($type == 1){
  120. $num = 1;
  121. }
  122. if($type == 2){
  123. if($num > 200){
  124. exit(json_encode(['code'=>-1,'msg'=>'扫描数量不能大于200','data'=>[],JSON_UNESCAPED_UNICODE]));
  125. }
  126. }
  127. $info = $this->whlabel_bh_scan->find("label ='".$label."'");
  128. if(!empty($info)){
  129. exit(json_encode(['code'=>-1,'msg'=>'该标签已被扫描','data'=>[],JSON_UNESCAPED_UNICODE]));
  130. }
  131. if($type == 1){
  132. $res = $this->_bbscan($orderinfo,$label);
  133. }elseif($type == 2){
  134. $res = $this->_bqscan($orderinfo,$label,$num);
  135. }
  136. exit(json_encode($res));
  137. }
  138. //生产布标扫描
  139. private function _bbscan($orderinfo,$label){
  140. $info = $this->whlabel_bh_transfer->find("label ='".$label."'");
  141. if(empty($info)){
  142. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  143. }
  144. if($info['label'] != $label){
  145. return ['code'=>-1,'msg'=>'条码对应的美国销售单号不一致','data'=>[]];
  146. }
  147. $arr = [
  148. 'orderinfo'=>(string)$orderinfo,
  149. 'type'=>1,
  150. 'label'=>(string)$label,
  151. 'features'=>(string)$info['features'],
  152. 'fid'=>$info['id'],
  153. 'jm'=>$info['jm'],
  154. 'pm'=>$info['pm'],
  155. 'sl'=>1,
  156. 'scantime'=>time(),
  157. 'status'=>0,
  158. ];
  159. $this->whlabel_bh_scan->insert($arr);
  160. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  161. }
  162. //标签扫描
  163. private function _bqscan($orderinfo,$label,$num){
  164. $info = $this->whlabellabel->find("label ='".$label."'");
  165. if(empty($info)){
  166. return ['code'=>-1,'msg'=>'标签号不存在','data'=>[]];
  167. }
  168. $list = [
  169. [
  170. 'sku2'=>$info['features'],
  171. ]
  172. ];
  173. $res = $this->logic_u9tools->getU9bm($list,'sku2');
  174. if(empty($res[0])){
  175. return ['code'=>-1,'msg'=>'u9条码编辑错误-1','data'=>[]];
  176. }
  177. if(empty($res[0]['jm'])){
  178. return ['code'=>-1,'msg'=>'u9条码编辑异常-2','data'=>[]];
  179. }
  180. $arr = [
  181. 'orderinfo'=>(string)$orderinfo,
  182. 'type'=>1,
  183. 'label'=>(string)$label,
  184. 'features'=>(string)$info['features'],
  185. 'fid'=>$info['id'],
  186. 'jm'=>$res[0]['jm'],
  187. 'pm'=>$res[0]['zh'],
  188. 'sl'=>$num,
  189. 'scantime'=>time(),
  190. 'status'=>0,
  191. ];
  192. $this->whlabel_bh_scan->insert($arr);
  193. return ['code'=>1,'msg'=>'标签扫描成功','data'=>[]];
  194. }
  195. // 可以排序的仓库数量
  196. private function _typedy(){
  197. $prc = array();
  198. $purchase = $this->purchase->find_all();
  199. foreach ($purchase as $k => $v) {
  200. $prc[$v['id']] = $v['title'];
  201. }
  202. $post = $this->input->post(NULL, TRUE);
  203. if (isset($post['page'])) {
  204. $page = $this->input->post('page', true);
  205. $perpage = $this->input->post('perpage', true);
  206. $category = $this->input->post('category', true);
  207. $size = $this->input->post('size', true);
  208. $grade = $this->input->post('grade', true);
  209. $color = $this->input->post('color', true);
  210. $lowe = $this->input->post('lowe', true);
  211. $sku = $this->input->post('sku');
  212. $title = $this->input->post('title');
  213. $warehouse = $this->input->post('warehouse', true);
  214. $usa = $this->input->post('usa', true);
  215. $purchase = $this->input->post('purchase', true);
  216. $lacetype = $this->input->post('lacetype', true);
  217. $haircap = $this->input->post('haircap', true);
  218. $density = $this->input->post('density', true);
  219. $details = $this->input->post('details', true);
  220. $state = $this->input->post('state', true);
  221. $lacecolor = $this->input->post('lacecolor', true);
  222. $hairnumber = $this->input->post('hairnumber', true);
  223. $cklx = $this->input->post('cklx', true);
  224. $ktime = $this->input->post('ktime', true);
  225. $jtime = $this->input->post('jtime', true);
  226. $sm = $this->input->post('sm', true);
  227. $cpbz = $this->input->post('cpbz', true);
  228. $type = $this->input->post('type', true);
  229. $ktime = strtotime($ktime);
  230. $jtime = strtotime($jtime);
  231. $where = "1=1";
  232. if ($usa) {
  233. if (!$warehouse) {
  234. $where .= " and (warehouse = '5' or warehouse = '8')";
  235. }
  236. }
  237. if ($warehouse) {
  238. $where .= " and warehouse = '$warehouse'";
  239. }
  240. if ($details) {
  241. $where .= " and details = '$details'";
  242. }
  243. if ($purchase) {
  244. $where .= " and purchase = '$purchase'";
  245. }
  246. if (isset($state)) {
  247. if($state >-1){
  248. $where .= " and state = '$state'";
  249. }
  250. }
  251. if ($lacetype) {
  252. $where .= " and features like '%-$lacetype-%'";
  253. }
  254. if ($category) {
  255. $where .= " and features like '%-$category-%'";
  256. }
  257. if ($size) {
  258. $where .= " and features like '%-$size-%'";
  259. }
  260. if ($grade) {
  261. $where .= " and features like '%-$grade-%'";
  262. }
  263. if ($color) {
  264. $where .= " and features like '%-$color-%'";
  265. }
  266. if ($lowe) {
  267. $where .= " and features like '%-$lowe-%'";
  268. }
  269. if ($haircap) {
  270. $where .= " and features like '%-$haircap-%'";
  271. }
  272. if ($density) {
  273. $where .= " and features like '%-$density-%'";
  274. }
  275. if ($lacecolor) {
  276. $where .= " and features like '%-$lacecolor-%'";
  277. }
  278. if($sm){
  279. $where .= " and sm like '%".$sm."%'";
  280. }
  281. if($cpbz){
  282. $where .= " and cpbz like '%".$cpbz."%'";
  283. }
  284. if($type){
  285. $where .= " and type = ".$type."";
  286. }
  287. if (!empty($hairnumber)) {
  288. $where .= " and features like '%-128-%' ";
  289. if ($hairnumber < 0) {
  290. $class_list = $this->typeclass->find_all('classid = 43');
  291. foreach ($class_list as $v) {
  292. $where .= " and features not like '%-" . $v['id'] . "-%'";
  293. }
  294. } else {
  295. $where .= " and features like '%-$hairnumber-%'";
  296. }
  297. }
  298. $where_add = '';
  299. if ($cklx) {
  300. $shop = $this->shop->read($cklx);
  301. $where_add .= " and zd like '" . $shop['shortname'] . "%' and state = 0";
  302. }
  303. //数据排序
  304. $order_str = "id desc";
  305. if (empty($page)) {
  306. $start = 0;
  307. $perpage = 1;
  308. } else {
  309. $start = ($page - 1) * $perpage;
  310. }
  311. //这里为了对应前端界面的字段 新添加了label字段 后续代码会替换为sm字段
  312. if ($sku) {
  313. $sku = trim($sku, ' ');
  314. $sku = trim($sku, ' ');
  315. $where .= " and sku like '%$sku%'";
  316. $info_list = $this->whlabel->find_pc($where . $where_add, 'sku,features,warehouse', 'id,warehouse,purchase,sku,title,details,shop,cpbz,label,features,number,sm', $order_str, $start, $perpage);
  317. } else if ($title) {
  318. $title = trim($title, ' ');
  319. $title = trim($title, ' ');
  320. $where .= " and title like '%$title%'";
  321. $info_list = $this->whlabel->find_pc($where . $where_add, 'sku,features,warehouse', 'id,warehouse,purchase,sku,title,details,shop,cpbz,label,features,number,sm', $order_str, $start, $perpage);
  322. } else {
  323. //$where .= " and time > '$ktime' and time < '$jtime'";
  324. $info_list = $this->whlabel->find_pc($where . $where_add, 'sku,features,warehouse', 'id,warehouse,purchase,sku,title,details,shop,cpbz,label,features,number,sm', $order_str, $start, $perpage);
  325. }
  326. //$this->logic_ding->sendToDing("仓库查询:".$where . $where_add);
  327. $info_list = $this->logic_whlabel->dataTran($info_list, ['pm']);
  328. foreach ($info_list as $k => $v) {
  329. $info_list[$k]['title'] = $v['title'] . "<br/>" . $v['pm'];
  330. unset($info_list[$k]['pm']);
  331. unset($info_list[$k]['jm']);
  332. unset($info_list[$k]['bm']);
  333. }
  334. //取得信息列表
  335. $rows = array();
  336. $list = array();
  337. foreach ($info_list as $key => $value) {
  338. $warehouse = $this->warehouse->read($value['warehouse']);
  339. $info_list[$key]['purchase'] = (isset($prc[$value['purchase']])) ? $prc[$value['purchase']] : '未知';
  340. $c = $this->whlabel->find_all($where . ' and sku = "' . $value['sku'] . '" and state = 0 and warehouse = "' . $value['warehouse'] . '" and features = "' . $value['features'] . '"', 'details,cpid');
  341. $z = $this->whlabel->find_all($where . ' and sku = "' . $value['sku'] . '" and zd != "" and state = 0 and warehouse = "' . $value['warehouse'] . '" and features = "' . $value['features'] . '"');
  342. $info_list[$key]['cpbz'] = $value['cpbz'] ;
  343. $info_list[$key]['label'] = $value['sm'];
  344. $number = $value['number'];
  345. $ftime = time() - 15 * 24 * 3600;
  346. $info_list[$key]['warehouse'] = $warehouse['title'];
  347. $info_list[$key]['features'] = count($c);
  348. $z = count($z); //查看订单号
  349. $zt = $this->whlabeltransport->find_all('sku = "' . $value['sku'] . '" and warehouse = "' . $value['warehouse'] . '" and features = "' . $value['features'] . '" and cz = "0"');
  350. $ztdata = '';
  351. if (count($zt) > 0) {
  352. foreach ($zt as $vv) {
  353. $ztdata .= '<p>' . $vv['num'] . ' - ' . date('Y-m-d', $vv['stime']) . '</p>';
  354. }
  355. }
  356. $info_list[$key]['number'] = $ztdata;
  357. $info_list[$key]['sm'] = $z;
  358. $details = array();
  359. $cpid = array();
  360. foreach ($c as $k => $v) {
  361. $details[$v['details']] = $v['details'];
  362. if ($v['cpid'] != 0) {
  363. $cpid[$v['cpid']] = $v['cpid'];
  364. }
  365. }
  366. $info_list[$key]['details'] = ($cpid) ? implode(" ", $details) . '<p>' . implode(" ", $cpid) . '</p>' : implode(" ", $details);
  367. if ($value['shop'] != '') {
  368. $shop = explode(',', trim($value['shop'], ','));
  369. $shop = $this->shop->read($shop[0]);
  370. $info_list[$key]['shop'] = $shop['shopname'];
  371. }
  372. }
  373. $total = count($this->whlabel->find_pc($where . $where_add, 'sku,features,warehouse', 'id,warehouse,sku,title,features,number'));
  374. $pagenum = ceil($total / $perpage);
  375. $over = $total - ($start + $perpage);
  376. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list), 'CS' => $warehouse);
  377. echo json_encode($rows);
  378. exit;
  379. }
  380. $this->data['warehouse'] = (isset($arg_array[0])) ? $arg_array[0] : 5;
  381. $this->_Template('whlabelfz1_typedy', $this->data);
  382. }
  383. }