Bh.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. echo "bh do action...";
  175. if(isset($_GET['xr']))
  176. {
  177. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,title,number');
  178. $this->db->trans_begin();
  179. foreach ($info_list as $key=>$value)
  180. {
  181. $c = $this->whlabel->find_count('warehouse = "5" and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and number = "'.$value['number'].'"');
  182. $info_list[$key]['t1'] = 0;
  183. $info_list[$key]['t3'] = 0;
  184. $info_list[$key]['t7'] = 0;
  185. $info_list[$key]['t14'] = 0;
  186. $info_list[$key]['t30'] = 0;
  187. $info_list[$key]['t60'] = 0;
  188. $info_list[$key]['t90'] = 0;
  189. $fullorder = $this->fullorder->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');
  190. $fullordersmt = $this->fullordersmt->find_all("whlabel like '%".$value['number']."%' and librarytime > '".(strtotime(date("Y-m-d",time()))-90*24*3600)."'",'whlabel,librarytime');
  191. $data = array_merge($fullorder,$fullordersmt);
  192. foreach ($data as $val)
  193. {
  194. $dt = explode('|',trim($val['whlabel'],'|'));
  195. foreach ($dt as $v)
  196. {
  197. $v = explode('-',$v);
  198. if($v[0] == $value['number'])
  199. {
  200. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-24*3600))
  201. {
  202. $info_list[$key]['t1'] += $v[1];
  203. }
  204. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-3*24*3600))
  205. {
  206. $info_list[$key]['t3'] += $v[1];
  207. }
  208. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-7*24*3600))
  209. {
  210. $info_list[$key]['t7'] += $v[1];
  211. }
  212. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-14*24*3600))
  213. {
  214. $info_list[$key]['t14'] += $v[1];
  215. }
  216. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-30*24*3600))
  217. {
  218. $info_list[$key]['t30'] += $v[1];
  219. }
  220. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-60*24*3600))
  221. {
  222. $info_list[$key]['t60'] += $v[1];
  223. }
  224. if($val['librarytime'] > (strtotime(date("Y-m-d",time()))-90*24*3600))
  225. {
  226. $info_list[$key]['t90'] += $v[1];
  227. }
  228. }
  229. }
  230. }
  231. if($info_list[$key]['t30'] > 0)
  232. {
  233. $mt = $info_list[$key]['t30']/30;
  234. $info_list[$key]['ksts'] = intval($c/$mt);
  235. $info_list[$key]['jybh'] = ($info_list[$key]['ksts'] < 30)?($info_list[$key]['t30'] - $c):0;
  236. }
  237. else
  238. {
  239. $info_list[$key]['ksts'] = 0;
  240. $info_list[$key]['jybh'] = 0;
  241. }
  242. $this->bh->insert($info_list[$key]);
  243. }
  244. if ($this->db->trans_status() === TRUE)
  245. {
  246. $this->db->trans_commit();
  247. echo 'OK';
  248. }
  249. else
  250. {
  251. $this->db->trans_rollback();
  252. echo 'orver';
  253. }
  254. }
  255. }
  256. public function _exceljs()
  257. {
  258. if(isset($_GET['excel']))
  259. {
  260. $page = $this->input->get('page',true);
  261. $perpage = $this->input->get('perpage',true);
  262. $category = $this->input->get('category',true);
  263. $size = $this->input->get('size',true);
  264. $grade = $this->input->get('grade',true);
  265. $color = $this->input->get('color',true);
  266. $lowe = $this->input->get('lowe',true);
  267. $sku = $this->input->get('sku',true);
  268. $warehouse = $this->input->get('warehouse',true);
  269. $usa = $this->input->get('usa',true);
  270. $purchase = $this->input->get('purchase',true);
  271. $lacetype = $this->input->get('lacetype',true);
  272. $state = $this->input->get('state',true);
  273. $px = $this->input->get('px',true);
  274. $ktime = $this->input->get('ktime',true);
  275. $jtime = $this->input->get('jtime',true);
  276. //$ktime = strtotime($ktime);
  277. //$jtime = strtotime($jtime);
  278. $where = "1=1";$gj = "";$ck = "";
  279. if($lacetype)
  280. {
  281. $where .= " and features like '%-$lacetype-%'";
  282. }
  283. if($category)
  284. {
  285. $where .= " and features like '%-$category-%'";
  286. }
  287. if($size)
  288. {
  289. $where .= " and features like '%-$size-%'";
  290. }
  291. if($grade)
  292. {
  293. $where .= " and features like '%-$grade-%'";
  294. }
  295. if($color)
  296. {
  297. $where .= " and features like '%-$color-%'";
  298. }
  299. if($lowe)
  300. {
  301. $where .= " and features like '%-$lowe-%'";
  302. }
  303. if($usa)
  304. {
  305. if(!$warehouse)
  306. {
  307. $where .= " and (warehouse = '5' or warehouse = '8')";
  308. }
  309. }
  310. if($warehouse)
  311. {
  312. $where .= " and warehouse = '$warehouse'";
  313. }
  314. if($purchase)
  315. {
  316. $where .= " and purchase = '$purchase'";
  317. }
  318. if($state)
  319. {
  320. $where .= " and state = '$state'";
  321. }
  322. if($ktime && $jtime)
  323. {
  324. $gj = " and enter > '$ktime' and enter < '$jtime'";
  325. $ck = " and outk > '$ktime' and outk < '$jtime'";
  326. }
  327. //数据排序
  328. if($px == 'ksts')
  329. {
  330. $order_str = "ksts asc,jybh desc";
  331. $where .= " and jybh > 0";
  332. }
  333. else
  334. {
  335. $order_str = $px." desc";
  336. }
  337. if(empty($page))
  338. {
  339. $start = 0;
  340. $perpage = 1;
  341. }
  342. else
  343. {
  344. $start = ($page - 1)*$perpage;
  345. }
  346. if($sku)
  347. {
  348. $where .= " and sku like '%$sku%'";
  349. $info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);
  350. }
  351. else
  352. {
  353. $info_list = $this->bh->find_all($where,'sku,title,t1,t3,t7,t14,t30,t60,t90,jybh,ksts',$order_str);
  354. }
  355. /**
  356. foreach ($info_list as $key=>$value)
  357. {
  358. $warehouse = $this->warehouse->read($value['warehouse']);
  359. $info_list[$key]['warehouse'] = $warehouse['title'];
  360. }
  361. **/
  362. foreach ($info_list as $key=>$value)
  363. {
  364. if($value['jybh'] == '0')
  365. {
  366. $info_list[$key]['jybh'] = '无';
  367. }
  368. }
  369. $title = "备货详情 ".date("Y-m-d",time());
  370. $titlename = "<table border=1>
  371. <tr align='center'>
  372. <td>SKU</td>
  373. <td>产品名称</td>
  374. <td>昨天销量</td>
  375. <td>3天销量</td>
  376. <td>7天销量</td>
  377. <td>14天销量</td>
  378. <td>30天销量</td>
  379. <td>60天销量</td>
  380. <td>90天销量</td>
  381. <td>建议备货</td>
  382. <td>可售天数</td>
  383. </tr>
  384. </table>";
  385. $filename = $title.".xls";
  386. $tail = "";
  387. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  388. }
  389. }
  390. public function _uck()
  391. {
  392. if(isset($_GET['excel']))
  393. {
  394. $tc = array();
  395. $typeclass = $this->typeclass->find_all();
  396. foreach ($typeclass as $v)
  397. {
  398. $tc[$v['id']] = $v['zh'];
  399. }
  400. $data = array();$t = array();$rq = '';
  401. $ts = strtotime(date("Y-m-d",time()))-strtotime(date("Y-m",time()));
  402. $ts = $ts/(24*3600);
  403. for($i=0;$i<$ts;$i++)
  404. {
  405. $t[] = date("Y-m-d",strtotime('-'.($ts-$i).' day'));
  406. $rq .= "<td>".date("Y-m-d",strtotime('-'.($ts-$i).' day'))."</td>";
  407. }
  408. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku','warehouse,sku,features');
  409. foreach ($info_list as $k=>$v)
  410. {
  411. $features = explode('-',trim($v['features'],'-'));
  412. if(!isset($features[3]) || !isset($features[4]))
  413. {
  414. continue;
  415. }
  416. $data[$k][0] = $tc[$features[0]];//类型
  417. $data[$k][1] = ($features[3] != 57)?$tc[$features[3]]:'';//颜色,自然色不显示
  418. $data[$k][2] = $tc[$features[4]];//曲度
  419. $data[$k][3] = '';
  420. if(isset($data[$k][1]))
  421. {
  422. $data[$k][3] .= $data[$k][1];
  423. }
  424. if(isset($data[$k][2]))
  425. {
  426. $data[$k][3] .= $data[$k][2];
  427. }
  428. if(isset($features[5]))
  429. {
  430. $data[$k][3] .= $tc[$features[5]];
  431. }
  432. if(isset($features[2]))
  433. {
  434. $data[$k][3] .= $tc[$features[2]];
  435. }
  436. //$data[$k][3] 颜色,曲度,头套种类,尺寸
  437. $data[$k][4] = $v['sku'];
  438. $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())).'))');//月初库存
  439. $data[$k][] = $this->whlabel->find_count('warehouse = "5" and sku = "'.$v['sku'].'" and state = 0 and warehouse = "'.$v['warehouse'].'" and features = "'.$v['features'].'"');//剩余库存
  440. $data[$k][] = '';
  441. $data[$k][] = '';
  442. $byck = 0;
  443. foreach ($t as $vv)
  444. {
  445. $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));
  446. $data[$k][] = ($sl > 0)?'<b>'.$sl.'</b>':'';
  447. $byck += $sl;
  448. }
  449. $data[$k][] = ($byck > 0)?$byck:'';
  450. }
  451. $title = "详情 ".date("Y-m-d",time());
  452. $titlename = "<table border=1>
  453. <tr align='center'>
  454. <td>类别</td>
  455. <td>颜色</td>
  456. <td>曲度</td>
  457. <td>名称</td>
  458. <td>SKU</td>
  459. <td>月初库存</td>
  460. <td>剩余库存</td>
  461. <td>在途数量</td>
  462. <td>预达日期</td>".
  463. $rq
  464. ."<td>本月出库</td></tr>
  465. </table>";
  466. $filename = $title.".xls";
  467. $tail = "";
  468. $this->excel->get_fz2($data,$titlename,$filename,$tail);
  469. }
  470. }
  471. }