Bh.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Bh extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_whlabel','whlabel');
  7. $this->load->_model('Model_warehouse','warehouse');
  8. $this->load->_model('Model_purchase','purchase');
  9. $this->load->_model('Model_excel','excel');
  10. $this->load->_model('Model_fullorder','fullorder');
  11. $this->load->_model('Model_fullordertt','fullordertt');
  12. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  13. $this->load->_model('Model_fullordersmt','fullordersmt');
  14. $this->load->_model('Model_express','express');
  15. $this->load->_model('Model_shop','shop');
  16. $this->load->_model('Model_typeclass','typeclass');
  17. $this->load->_model('Model_country','country');
  18. $this->load->_model('Model_warehouse','warehouse');
  19. $this->load->_model('Model_kdniao','kdniao');
  20. $this->load->_model('Model_notice','notice');
  21. $this->load->_model('Model_dhl','dhl');
  22. $this->load->_model('Model_shop','shop');
  23. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  24. $this->load->_model('Model_ljg','ljg');
  25. $this->load->_model('Model_usps','usps');
  26. $this->load->_model('Model_specialstock','specialstock');
  27. $this->load->_model('Model_whlabellabel','whlabellabel');
  28. $this->load->_model('Model_whlabelwz','whlabelwz');
  29. $this->load->_model('Model_whlabelbarcode','whlabelbarcode');
  30. $this->load->_model('Model_bh','bh');
  31. }
  32. //定义方法的调用规则 获取URI第二段值
  33. public function _remap($arg,$arg_array)
  34. {
  35. if($arg == 'xr')//在库标签
  36. {
  37. $this->_xr();
  38. }
  39. else if($arg == 'exceljs')
  40. {
  41. $this->_exceljs();
  42. }
  43. else if($arg == 'uck')
  44. {
  45. $this->_uck();
  46. }
  47. else
  48. {
  49. $this->_index();
  50. }
  51. }
  52. //进销存浏览
  53. public function _index()
  54. {
  55. $post = $this->input->post(NULL, TRUE);
  56. if(isset($post['page']))
  57. {
  58. $page = $this->input->post('page',true);
  59. $perpage = $this->input->post('perpage',true);
  60. $category = $this->input->post('category',true);
  61. $size = $this->input->post('size',true);
  62. $grade = $this->input->post('grade',true);
  63. $color = $this->input->post('color',true);
  64. $lowe = $this->input->post('lowe',true);
  65. $sku = $this->input->post('sku',true);
  66. $warehouse = $this->input->post('warehouse',true);
  67. $usa = $this->input->post('usa',true);
  68. $purchase = $this->input->post('purchase',true);
  69. $lacetype = $this->input->post('lacetype',true);
  70. $state = $this->input->post('state',true);
  71. $px = $this->input->post('px',true);
  72. $ktime = $this->input->post('ktime',true);
  73. $jtime = $this->input->post('jtime',true);
  74. //$ktime = strtotime($ktime);
  75. //$jtime = strtotime($jtime);
  76. $where = "1=1";$gj = "";$ck = "";
  77. if($lacetype)
  78. {
  79. $where .= " and features like '%-$lacetype-%'";
  80. }
  81. if($category)
  82. {
  83. $where .= " and features like '%-$category-%'";
  84. }
  85. if($size)
  86. {
  87. $where .= " and features like '%-$size-%'";
  88. }
  89. if($grade)
  90. {
  91. $where .= " and features like '%-$grade-%'";
  92. }
  93. if($color)
  94. {
  95. $where .= " and features like '%-$color-%'";
  96. }
  97. if($lowe)
  98. {
  99. $where .= " and features like '%-$lowe-%'";
  100. }
  101. if($usa)
  102. {
  103. if(!$warehouse)
  104. {
  105. $where .= " and (warehouse = '5' or warehouse = '8')";
  106. }
  107. }
  108. if($warehouse)
  109. {
  110. $where .= " and warehouse = '$warehouse'";
  111. }
  112. if($purchase)
  113. {
  114. $where .= " and purchase = '$purchase'";
  115. }
  116. if($state)
  117. {
  118. $where .= " and state = '$state'";
  119. }
  120. if($ktime && $jtime)
  121. {
  122. $gj = " and enter > '$ktime' and enter < '$jtime'";
  123. $ck = " and outk > '$ktime' and outk < '$jtime'";
  124. }
  125. //数据排序
  126. if($px == 'ksts')
  127. {
  128. $order_str = "ksts asc,jybh desc";
  129. $where .= " and jybh > 0";
  130. }
  131. else
  132. {
  133. $order_str = $px." desc";
  134. }
  135. if(empty($page))
  136. {
  137. $start = 0;
  138. $perpage = 1;
  139. }
  140. else
  141. {
  142. $start = ($page - 1)*$perpage;
  143. }
  144. if($sku)
  145. {
  146. $where .= " and sku like '%$sku%'";
  147. $info_list = $this->bh->find_all($where,'id,sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str,$start,$perpage);
  148. }
  149. else
  150. {
  151. $info_list = $this->bh->find_all($where,'id,sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str,$start,$perpage);
  152. }
  153. foreach ($info_list as $key=>$value)
  154. {
  155. if($value['jybh'] == '0')
  156. {
  157. $info_list[$key]['jybh'] = '无';
  158. }
  159. }
  160. $rows = array();$list = array();
  161. $total = count($this->bh->find_all($where));
  162. $pagenum = ceil($total/$perpage);
  163. $over = $total-($start+$perpage);
  164. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  165. echo json_encode($rows);exit;
  166. }
  167. $this->_Template('bh',$this->data);
  168. }
  169. //进销存浏览
  170. public function _xr()//数据写入
  171. {
  172. $this->db->query("delete from crowd_bh");
  173. $post = $this->input->post(NULL, TRUE);
  174. if(isset($_GET['xr']))
  175. {
  176. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,title,number');
  177. $this->db->trans_begin();
  178. foreach ($info_list as $key=>$value)
  179. {
  180. $c = $this->whlabel->find_count('warehouse = "5" and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and number = "'.$value['number'].'"');
  181. $info_list[$key]['t1'] = 0;
  182. $info_list[$key]['t3'] = 0;
  183. $info_list[$key]['t7'] = 0;
  184. $info_list[$key]['t14'] = 0;
  185. $info_list[$key]['t30'] = 0;
  186. $info_list[$key]['t60'] = 0;
  187. $info_list[$key]['t90'] = 0;
  188. $fullorder = $this->fullorder->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');
  189. $fullordersmt = $this->fullordersmt->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');
  190. $data = array_merge($fullorder,$fullordersmt);
  191. foreach ($data as $val)
  192. {
  193. $dt = explode('|',trim($val['whlabel'],'|'));
  194. foreach ($dt as $v)
  195. {
  196. $v = explode('-',$v);
  197. if($v[0] == $value['number'])
  198. {
  199. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-24*3600))
  200. {
  201. $info_list[$key]['t1'] += $v[1];
  202. }
  203. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-3*24*3600))
  204. {
  205. $info_list[$key]['t3'] += $v[1];
  206. }
  207. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-7*24*3600))
  208. {
  209. $info_list[$key]['t7'] += $v[1];
  210. }
  211. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-14*24*3600))
  212. {
  213. $info_list[$key]['t14'] += $v[1];
  214. }
  215. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-30*24*3600))
  216. {
  217. $info_list[$key]['t30'] += $v[1];
  218. }
  219. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-60*24*3600))
  220. {
  221. $info_list[$key]['t60'] += $v[1];
  222. }
  223. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-90*24*3600))
  224. {
  225. $info_list[$key]['t90'] += $v[1];
  226. }
  227. }
  228. }
  229. }
  230. if($info_list[$key]['t30'] > 0)
  231. {
  232. $mt = $info_list[$key]['t30']/30;
  233. $info_list[$key]['ksts'] = intval($c/$mt);
  234. $info_list[$key]['jybh'] = ($info_list[$key]['ksts'] < 30)?($info_list[$key]['t30'] - $c):0;
  235. }
  236. else
  237. {
  238. $info_list[$key]['ksts'] = 0;
  239. $info_list[$key]['jybh'] = 0;
  240. }
  241. $this->bh->insert($info_list[$key]);
  242. }
  243. if ($this->db->trans_status() === TRUE)
  244. {
  245. $this->db->trans_commit();
  246. echo 'OK';
  247. }
  248. else
  249. {
  250. $this->db->trans_rollback();
  251. echo 'orver';
  252. }
  253. }
  254. }
  255. public function _exceljs()
  256. {
  257. if(isset($_GET['excel']))
  258. {
  259. $page = $this->input->get('page',true);
  260. $perpage = $this->input->get('perpage',true);
  261. $category = $this->input->get('category',true);
  262. $size = $this->input->get('size',true);
  263. $grade = $this->input->get('grade',true);
  264. $color = $this->input->get('color',true);
  265. $lowe = $this->input->get('lowe',true);
  266. $sku = $this->input->get('sku',true);
  267. $warehouse = $this->input->get('warehouse',true);
  268. $usa = $this->input->get('usa',true);
  269. $purchase = $this->input->get('purchase',true);
  270. $lacetype = $this->input->get('lacetype',true);
  271. $state = $this->input->get('state',true);
  272. $px = $this->input->get('px',true);
  273. $ktime = $this->input->get('ktime',true);
  274. $jtime = $this->input->get('jtime',true);
  275. //$ktime = strtotime($ktime);
  276. //$jtime = strtotime($jtime);
  277. $where = "1=1";$gj = "";$ck = "";
  278. if($lacetype)
  279. {
  280. $where .= " and features like '%-$lacetype-%'";
  281. }
  282. if($category)
  283. {
  284. $where .= " and features like '%-$category-%'";
  285. }
  286. if($size)
  287. {
  288. $where .= " and features like '%-$size-%'";
  289. }
  290. if($grade)
  291. {
  292. $where .= " and features like '%-$grade-%'";
  293. }
  294. if($color)
  295. {
  296. $where .= " and features like '%-$color-%'";
  297. }
  298. if($lowe)
  299. {
  300. $where .= " and features like '%-$lowe-%'";
  301. }
  302. if($usa)
  303. {
  304. if(!$warehouse)
  305. {
  306. $where .= " and (warehouse = '5' or warehouse = '8')";
  307. }
  308. }
  309. if($warehouse)
  310. {
  311. $where .= " and warehouse = '$warehouse'";
  312. }
  313. if($purchase)
  314. {
  315. $where .= " and purchase = '$purchase'";
  316. }
  317. if($state)
  318. {
  319. $where .= " and state = '$state'";
  320. }
  321. if($ktime && $jtime)
  322. {
  323. $gj = " and enter > '$ktime' and enter < '$jtime'";
  324. $ck = " and outk > '$ktime' and outk < '$jtime'";
  325. }
  326. //数据排序
  327. if($px == 'ksts')
  328. {
  329. $order_str = "ksts asc,jybh desc";
  330. $where .= " and jybh > 0";
  331. }
  332. else
  333. {
  334. $order_str = $px." desc";
  335. }
  336. if(empty($page))
  337. {
  338. $start = 0;
  339. $perpage = 1;
  340. }
  341. else
  342. {
  343. $start = ($page - 1)*$perpage;
  344. }
  345. if($sku)
  346. {
  347. $where .= " and sku like '%$sku%'";
  348. $info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);
  349. }
  350. else
  351. {
  352. $info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);
  353. }
  354. /**
  355. foreach ($info_list as $key=>$value)
  356. {
  357. $warehouse = $this->warehouse->read($value['warehouse']);
  358. $info_list[$key]['warehouse'] = $warehouse['title'];
  359. }
  360. **/
  361. foreach ($info_list as $key=>$value)
  362. {
  363. if($value['jybh'] == '0')
  364. {
  365. $info_list[$key]['jybh'] = '无';
  366. }
  367. }
  368. $title = "备货详情 ".date("Y-m-d",time());
  369. $titlename = "<table border=1>
  370. <tr align='center'>
  371. <td>SKU</td>
  372. <td>产品名称</td>
  373. <td>昨天销量</td>
  374. <td>3天销量</td>
  375. <td>7天销量</td>
  376. <td>14天销量</td>
  377. <td>30天销量</td>
  378. <td>60天销量</td>
  379. <td>90天销量</td>
  380. <td>建议备货</td>
  381. <td>可售天数</td>
  382. </tr>
  383. </table>";
  384. $filename = $title.".xls";
  385. $tail = "";
  386. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  387. }
  388. }
  389. public function _uck()
  390. {
  391. if(isset($_GET['excel']))
  392. {
  393. $tc = array();
  394. $typeclass = $this->typeclass->find_all();
  395. foreach ($typeclass as $v)
  396. {
  397. $tc[$v['id']] = $v['zh'];
  398. }
  399. $data = array();$t = array();$rq = '';
  400. $ts = strtotime(date("Y-m-d",time()))-strtotime(date("Y-m",time()));
  401. $ts = $ts/(24*3600);
  402. for($i=0;$i<$ts;$i++)
  403. {
  404. $t[] = date("Y-m-d",strtotime('-'.($ts-$i).' day'));
  405. $rq .= "<td>".date("Y-m-d",strtotime('-'.($ts-$i).' day'))."</td>";
  406. }
  407. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,features');
  408. foreach ($info_list as $k=>$v)
  409. {
  410. $features = explode('-',trim($v['features'],'-'));
  411. if(!isset($features[3]) || !isset($features[4]))
  412. {
  413. continue;
  414. }
  415. $data[$k][0] = $tc[$features[0]];//类型
  416. $data[$k][1] = ($features[3] != 57)?$tc[$features[3]]:'';//颜色,自然色不显示
  417. $data[$k][2] = $tc[$features[4]];//曲度
  418. $data[$k][3] = '';
  419. if(isset($data[$k][1]))
  420. {
  421. $data[$k][3] .= $data[$k][1];
  422. }
  423. if(isset($data[$k][2]))
  424. {
  425. $data[$k][3] .= $data[$k][2];
  426. }
  427. if(isset($features[5]))
  428. {
  429. $data[$k][3] .= $tc[$features[5]];
  430. }
  431. if(isset($features[2]))
  432. {
  433. $data[$k][3] .= $tc[$features[2]];
  434. }
  435. //$data[$k][3] 颜色,曲度,头套种类,尺寸
  436. $data[$k][4] = $v['sku'];
  437. $data[$k][5] = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and (state = 0 or (state = 1 and outk > '.strtotime(date("Y-m",time())).'))');//月初库存
  438. $data[$k][] = $this->whlabel->find_count('warehouse = "5" and sku = "'.$v['sku'].'" and state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');//剩余库存
  439. $data[$k][] = '';
  440. $data[$k][] = '';
  441. $byck = 0;
  442. foreach ($t as $vv)
  443. {
  444. $sl = $this->whlabel->find_count('sku = "'.$v['sku'].'" and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'" and state = 1 and outk > '.strtotime($vv).' and outk < '.(strtotime($vv)+24*3600));
  445. $data[$k][] = ($sl > 0)?'<b>'.$sl.'</b>':'';
  446. $byck += $sl;
  447. }
  448. $data[$k][] = ($byck > 0)?$byck:'';
  449. }
  450. $title = "详情 ".date("Y-m-d",time());
  451. $titlename = "<table border=1>
  452. <tr align='center'>
  453. <td>类别</td>
  454. <td>颜色</td>
  455. <td>曲度</td>
  456. <td>名称</td>
  457. <td>SKU</td>
  458. <td>月初库存</td>
  459. <td>剩余库存</td>
  460. <td>在途数量</td>
  461. <td>预达日期</td>".
  462. $rq
  463. ."<td>本月出库</td></tr>
  464. </table>";
  465. $filename = $title.".xls";
  466. $tail = "";
  467. $this->excel->get_fz2($data,$titlename,$filename,$tail);
  468. }
  469. }
  470. }