123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2016/10/19
- * Time: 下午4:45
- */
- require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
- class act_formater
- {
- private $mActivities;
- private $mGoodsActContainer;
- public function __construct($activities)
- {
- $this->mActivities = $activities;
- $this->mGoodsActContainer = [];
- }
- public function format_acting(bonus\IPriceCalculate $price_calc)
- {
- $specials = [];
- $goods_ids = [];
- $cur_type = -1;
- foreach ($this->mActivities as $act)
- {
- $gids =[];
- $block = false;
- if(array_key_exists('xianshi_id',$act))
- {
- $block = $this->format_limit($act,$gids);
- if($block != false) {
- $time_type = intval($act['xianshi_type']);
- }
- }
- elseif(array_key_exists('groupbuy_id',$act))
- {
- $block = $this->format_groupbuy($act,$gids);
- if($block != false) {
- $time_type = intval($act['groupbuy_type']);
- }
- }
- else {
- $time_type = false;
- Log::record("an error activity.",Log::ERR);
- }
- if($block != false)
- {
- if($time_type !== false)
- {
- if($cur_type != $time_type)
- {
- $banners = $this->type_banner($time_type);
- if(!empty($banners))
- {
- foreach ($banners as $banner) {
- $specials[] = $banner;
- }
- }
- $cur_type = $time_type;
- }
- }
- $specials[]= $block;
- self::array_copy($goods_ids,$gids);
- }
- }
- $goods_ids = array_unique($goods_ids);
- if(!empty($goods_ids))
- {
- $helper = new goods_helper($price_calc);
- $ret = $helper->online_summary($goods_ids,$related);
- return array('special_list' => $specials,
- 'summary' => $ret['summary'],
- 'groupbuy' => $ret['groupbuy'],
- 'limitime' => $ret['limitime'],
- 'bundling' => $ret['bundling'],
- 'mobile_page' => mobile_page(1));
- }
- else {
- return array('special_list' => null,
- 'summary' => null,
- 'groupbuy' => null,
- 'limitime' => null,
- 'bundling' => null,
- 'mobile_page' => mobile_page(1));
- }
- }
- public function format_unstart(bonus\IPriceCalculate $price_calc)
- {
- $specials = [];
- $goods_ids = [];
- $group_ids = [];
- $limit_ids = [];
- $cur_type = -1;
- foreach ($this->mActivities as $act)
- {
- $gids = [];
- $block = false;
- if(array_key_exists('xianshi_id',$act))
- {
- $block = $this->format_limit($act,$gids);
- if($block != false) {
- $limit_ids[] = intval($act['xianshi_id']);
- $time_type = intval($act['xianshi_type']);
- }
- }
- elseif(array_key_exists('groupbuy_id',$act))
- {
- $block = $this->format_groupbuy($act,$gids);
- if($block != false) {
- $group_ids[] = intval($act['groupbuy_id']);
- $time_type = intval($act['groupbuy_type']);
- }
- }
- else {
- $time_type = false;
- Log::record("an error activity.",Log::ERR);
- }
- if($block != false)
- {
- if($time_type !== false)
- {
- if($cur_type != $time_type)
- {
- $banners = $this->type_banner($time_type);
- if(!empty($banners))
- {
- foreach ($banners as $banner) {
- $specials[] = $banner;
- }
- }
- $cur_type = $time_type;
- }
- }
- $specials[]= $block;
- self::array_copy($goods_ids,$gids);
- }
- }
- $goods_ids = array_unique($goods_ids);
- if(!empty($goods_ids))
- {
- $helper = new goods_helper($price_calc);
- $ret = $helper->online_summary($goods_ids,$related);
- $summarys = $ret['summary'];
- foreach ($summarys as &$summary)
- {
- $goods_id = $summary['goods_id'];
- $act = $this->mGoodsActContainer[$goods_id];
- $summary['act_id'] = $act['act_id'];
- $summary['act_type'] = $act['act_type'];
- if($act['act_type'] == activity_helper::ACTIVITY_GROUPBUY) {
- $ret = activity_helper::groupbuy_price($act['act_id'],$price);
- } else {
- $ret = activity_helper::limit_price($act['act_id'],$goods_id,$price);
- }
- if($ret == true) {
- $summary['goods_promotion_price'] = $price;
- } else {
- Log::record("can not get : goods_promotion_price",Log::ERR);
- }
- }
- $groups = [];
- foreach ($group_ids as $group_id)
- {
- $item = activity\groupbuy::instance()->get_info($group_id);
- if($item != false) {
- $groups[] = $item;
- } else {
- Log::record("cannot get group id={$group_id}",Log::ERR);
- }
- }
- $limits = [];
- foreach ($limit_ids as $limit_id)
- {
- $item = activity\limitime::instance()->get_info($limit_id);
- if($item != false) {
- $limits[] = $item;
- } else {
- Log::record("cannot get group id={$limit_id}",Log::ERR);
- }
- }
- return array('special_list' => $specials,
- 'summary' => $summarys,
- 'groupbuy' => $groups,
- 'limitime' => $limits,
- 'bundling' => $ret['bundling'],
- 'mobile_page' => mobile_page(1));
- }
- else
- {
- return array('special_list' => null,
- 'summary' => null,
- 'groupbuy' => null,
- 'limitime' => null,
- 'bundling' => null,
- 'mobile_page' => mobile_page(1));
- }
- }
- private function type_banner($time_type)
- {
- static $stTimeBanner = array(12 => 345,20 => 347,24 => 348);
- //static $stTimeBanner = array(12 => 60);
- if(array_key_exists($time_type,$stTimeBanner))
- {
- $banners = special_manager::instance()->special($stTimeBanner[$time_type],$gids);
- if(empty($banners))
- return null;
- else
- return $banners;
- }
- return null;
- }
- private function format_limit($limt, &$goods_ids)
- {
- $result =[];
- $limt_id = intval($limt['xianshi_id']);
- $result['item_title'] = strval($limt_id);
- $result['item_type'] = 'home_limit';
- $goods_ids = activity_helper::limit_goods($limt_id);
- if(empty($goods_ids)) return false;
- foreach ($goods_ids as $gid) {
- $item['type'] = 'goods';
- $item['data'] = strval($gid);
- $item['image'] = '';
- $item['title'] = '';
- $result['items'][] = $item;
- $this->mGoodsActContainer[$gid] = array('act_id' => $limt_id,
- 'act_type' => activity_helper::ACTIVITY_LIMITTIME);
- }
- return $result;
- }
- private function format_groupbuy($group, &$goods_ids)
- {
- $result =[];
- $act_id = intval($group['groupbuy_id']);
- $result['item_title'] = strval($act_id);
- $result['item_type'] = 'home_group';
- $goods_ids = activity_helper::groupbuy_goods($act_id);
- if(empty($goods_ids)) return false;
- foreach ($goods_ids as $gid) {
- $item['type'] = 'goods';
- $item['data'] = strval($gid);
- $item['image'] = '';
- $item['title'] = '';
- $result['items'][] = $item;
- $this->mGoodsActContainer[$gid] = array('act_id' => $act_id,
- 'act_type' => activity_helper::ACTIVITY_GROUPBUY,
- 'goods_promotion_price' => $group['promotion_price']);
- }
- return $result;
- }
- private static function array_copy(&$dest,$src)
- {
- if(empty($src)) return $dest;
- foreach ($src as $value) {
- array_push($dest,$value);
- }
- return $dest;
- }
- }
- class limit_outer
- {
- const WAIT_START = 0;
- const WAIT_END = 1;
- private $mAct;
- private $mType;
- public function __construct($type,$act)
- {
- $this->mAct = $act;
- $this->mType = $type;
- }
- public function format(bonus\IPriceCalculate $price_calc)
- {
- if(array_key_exists('xianshi_id',$this->mAct)) {
- $result = $this->format_limit($price_calc);
- }
- elseif(array_key_exists('groupbuy_id',$this->mAct)) {
- $result = $this->format_group($price_calc);
- }
- else {
- $result = false;
- }
- return $result;
- }
- private function format_limit(bonus\IPriceCalculate $price_calc)
- {
- $result = [];
- $act = $this->mAct;
- $act_id = $act['xianshi_id'];
- $gids = activity_helper::limit_goods($act_id);
- if(empty($gids)) return false;
- $goods_ids = array($gids[0]);
- $helper = new goods_helper($price_calc);
- $ret = $helper->online_summary($goods_ids,$related);
- if(!empty($ret['summary']))
- {
- $summary = $ret['summary'][0];
- if($this->mType == limit_outer::WAIT_START) {
- $result['act_time'] = $act['start_time'];
- } else {
- $result['act_time'] = $act['end_time'];
- }
- $result['goods_name'] = $summary['goods_mobile_name'];
- $result['goods_price'] = $summary['goods_price'];
- $result['goods_promotion_price'] = $summary['goods_promotion_price'];
- $result['goods_image_url'] = $summary['goods_image_url'];
- $result['local_time'] = time();
- return $result;
- }
- else {
- return false;
- }
- }
- private function format_group(bonus\IPriceCalculate $price_calc)
- {
- $result = [];
- $act = $this->mAct;
- $act_id = $act['groupbuy_id'];
- $gids = activity_helper::groupbuy_goods($act_id);
- if(empty($gids)) return false;
- $goods_ids = array($gids[0]);
- $helper = new goods_helper($price_calc);
- $ret = $helper->online_summary($goods_ids,$related);
- if(!empty($ret['summary']))
- {
- $summary = $ret['summary'][0];
- if($this->mType == limit_outer::WAIT_START) {
- $result['act_time'] = $act['start_time'];
- } else {
- $result['act_time'] = $act['end_time'];
- }
- $result['goods_name'] = $summary['goods_mobile_name'];
- $result['goods_price'] = $summary['goods_price'];
- $result['goods_promotion_price'] = $act['promotion_price'];
- $result['goods_image_url'] = $summary['goods_image_url'];
- $result['local_time'] = time();
- return $result;
- }
- else {
- return false;
- }
- }
- }
- class activityControl extends mobileControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function actingOp()
- {
- $actings = activity_helper::acting();
- $formater = new act_formater($actings);
- $result = $formater->format_acting($this->price_calcer());
- return self::outsuccess($result);
- }
- public function unstartOp()
- {
- $actings = activity_helper::unstart();
- $formater = new act_formater($actings);
- $result = $formater->format_unstart($this->price_calcer());
- return self::outsuccess($result);
- }
- public function limit_entraOp()
- {
- $_SESSION['client_type'] = "wap";
- $acts = activity_helper::acting();
- $price_calcer = $this->price_calcer();
- if(!empty($acts)) {
- $act = $acts[0];
- $outer = new limit_outer(limit_outer::WAIT_END,$act);
- $result = $outer->format($price_calcer);
- if($result != false) {
- return self::outsuccess($result,"activity/limit_entra");
- }
- }
- $unstarts = activity_helper::unstart();
- if(!empty($unstarts)) {
- $act = $unstarts[0];
- $outer = new limit_outer(limit_outer::WAIT_START,$act);
- $result = $outer->format($price_calcer);
- if($result != false) {
- return self::outsuccess($result,"activity/limit_entra");
- }
- }
- return self::outsuccess(null,"activity/limit_entra");
- }
- }
|