turn_manager.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/5/9
  6. * Time: 下午10:35
  7. */
  8. namespace fcode;
  9. require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
  10. require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
  11. use StatesHelper;
  12. use Log;
  13. use special_manager;
  14. use special_formater;
  15. class turn_manager
  16. {
  17. public static $stInstance;
  18. private $mGoodsBlock;
  19. private $mAmountGoods;
  20. private function __construct()
  21. {
  22. }
  23. static public function instance()
  24. {
  25. if(self::$stInstance == null) {
  26. self::$stInstance = new turn_manager();
  27. }
  28. // if(StatesHelper::fetch_state('fcode')) {
  29. // Log::record("fcode reinit data.",Log::DEBUG);
  30. // self::$stInstance->init();
  31. // }
  32. self::$stInstance->init();
  33. return self::$stInstance;
  34. }
  35. private function init()
  36. {
  37. $this->mAmountGoods = [];
  38. $this->mGoodsBlock = [];
  39. //$blocks = special_manager::instance()->special(62,$goods_ids);
  40. $formater = new special_formater(62,false);
  41. $blocks = $formater->format($goods_ids);
  42. foreach ($blocks as $block)
  43. {
  44. $item_type = $block['item_type'];
  45. $item_title = $block['item_title'];
  46. $amount = intval($item_title);
  47. if($item_type == 'home_goods' && $amount > 0)
  48. {
  49. $items = $block['items'];
  50. foreach ($items as $item) {
  51. $this->add($amount,$item);
  52. }
  53. }
  54. }
  55. krsort($this->mAmountGoods);
  56. }
  57. private function add($amount,$item)
  58. {
  59. $goods_id = intval($item['data']);
  60. if($goods_id <= 0) return;
  61. if(array_key_exists($amount,$this->mAmountGoods) == false) {
  62. $this->mAmountGoods[$amount] = [];
  63. }
  64. $this->mAmountGoods[$amount][] = $goods_id;
  65. $this->mGoodsBlock[$goods_id] = $item;
  66. }
  67. public function fetch($amount,$count)
  68. {
  69. $amount = intval($amount);
  70. if($amount <=0) return false;
  71. $gids = [];
  72. foreach ($this->mAmountGoods as $key => $val)
  73. {
  74. if($key <= $amount) {
  75. $gids = array_merge($gids,$val);
  76. }
  77. }
  78. return $gids;
  79. }
  80. }