1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/5/9
- * Time: 下午10:35
- */
- namespace fcode;
- require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
- require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
- use StatesHelper;
- use Log;
- use special_manager;
- use special_formater;
- class turn_manager
- {
- public static $stInstance;
- private $mGoodsBlock;
- private $mAmountGoods;
- private function __construct()
- {
- }
- static public function instance()
- {
- if(self::$stInstance == null) {
- self::$stInstance = new turn_manager();
- }
- // if(StatesHelper::fetch_state('fcode')) {
- // Log::record("fcode reinit data.",Log::DEBUG);
- // self::$stInstance->init();
- // }
- self::$stInstance->init();
- return self::$stInstance;
- }
- private function init()
- {
- $this->mAmountGoods = [];
- $this->mGoodsBlock = [];
- //$blocks = special_manager::instance()->special(62,$goods_ids);
- $formater = new special_formater(62,false);
- $blocks = $formater->format($goods_ids);
- foreach ($blocks as $block)
- {
- $item_type = $block['item_type'];
- $item_title = $block['item_title'];
- $amount = intval($item_title);
- if($item_type == 'home_goods' && $amount > 0)
- {
- $items = $block['items'];
- foreach ($items as $item) {
- $this->add($amount,$item);
- }
- }
- }
- krsort($this->mAmountGoods);
- }
- private function add($amount,$item)
- {
- $goods_id = intval($item['data']);
- if($goods_id <= 0) return;
- if(array_key_exists($amount,$this->mAmountGoods) == false) {
- $this->mAmountGoods[$amount] = [];
- }
- $this->mAmountGoods[$amount][] = $goods_id;
- $this->mGoodsBlock[$goods_id] = $item;
- }
- public function fetch($amount,$count)
- {
- $amount = intval($amount);
- if($amount <=0) return false;
- $gids = [];
- foreach ($this->mAmountGoods as $key => $val)
- {
- if($key <= $amount) {
- $gids = array_merge($gids,$val);
- }
- }
- return $gids;
- }
- }
|