1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/6/16
- * Time: 下午2:07
- */
- //将乱七八糟的格式输出,整合成统一的格式输出
- require_once(BASE_ROOT_PATH . '/helper/util_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
- class brands_special
- {
- const publish_brands_special = 56;
- const local_brands_special = 50;
- const test_brands_special = 56;
- static private $stBImgContianers;
- public function brands_special()
- {
- if(self::$stBImgContianers == null) {
- self::$stBImgContianers = [];
- $this->init();
- }
- }
- public function info($brand_id)
- {
- if(isset(self::$stBImgContianers[$brand_id])) {
- return self::$stBImgContianers[$brand_id];
- } else {
- return false;
- }
- }
- private function init()
- {
- $special_id = self::special_id();
- if($special_id == false) return false;
- $helper = new special_formater($special_id);
- $blocks = $helper->format($goods_ids);
- foreach ($blocks as $block)
- {
- $items = $block['items'];
- if(empty($items) || is_array($items) == false) continue;
- foreach ($items as $item)
- {
- $brand_id = intval($item['data']);
- $data = $item;
- $data['scale'] = $block['scale'];
- self::$stBImgContianers[$brand_id] = $data;
- }
- if(!empty($items) && is_array($items)) {
- }
- }
- }
- private static function special_id()
- {
- if (is_pushoms()) {
- return self::publish_brands_special;
- }
- elseif(is_localdebug()) {
- return self::local_brands_special;
- }
- else {
- return self::test_brands_special;
- }
- }
- }
- class special_formater
- {
- const def_item_bg_color = '#F7F7F7';
- const def_item_bg_type = 'color';
- const def_divider_bg_img= '/mobile/defimg/divider_bg.png';
- private $special_id;
- private $filter_data;
- private $goods_ids;
- private $special_info;
- private $sender_info;
- private $tabs;
- private $old_version;
- public function __construct($special_id,$old_version = false)
- {
- $this->special_id = $special_id;
- $this->old_version = $old_version;
- $this->special_info = [];
- $this->sender_info = [];
- $this->read_cache();
- }
- public function special_info() {
- return $this->special_info;
- }
- public function sender_info() {
- return $this->sender_info;
- }
- public function tabs() {
- return $this->tabs;
- }
- public static function def_divider()
- {
- static $block = [];
- if(empty($block))
- {
- $block['item_type'] = 'divider';
- $block['item_title'] = '';
- $block['bg_type'] = 'image';
- $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
- $block['bg_data'] = $image;
- $block['has_margin'] = false;
- $block['scale'] = self::scale($image);
- }
- return $block;
- }
- public static function format_brand_sale($brand_id,$can_click)
- {
- if($brand_id <= 0) return array();
- $helper = new brands_special();
- $info = $helper->info($brand_id);
- if($info == false) return array();
- $result['item_title'] = '';
- $result['item_type'] = 'home1';
- $result['scale'] = $info['scale'];
- $item['image'] = $info['image'];
- $item['type'] = $info['type'];
- if($can_click == true) {
- $item['data'] = $info['data'];
- } else {
- $item['data'] = 0;
- }
- $item['title'] = $info['title'];
- $result['items'][] = $item;
- return $result;
- }
- public static function format_grid_brands($brands)
- {
- $result = [];
- $result['item_title'] = '';
- $result['item_type'] = 'home_grid';
- $result['scale'] = 3;
- $items = [];
- foreach ($brands as $brand) {
- $item['image'] = $brand['brand_logo'];
- $item['type'] = 'brand';
- $item['data'] = $brand['brand_id'];
- $item['title'] = $brand['brand_name'];
- $items[] = $item;
- }
- $result['items'] = $items;
- return $result;
- }
- public static function format_comments($comments)
- {
- $blocks = [];
- foreach ($comments as $val)
- {
- $block = [];
- $block['item_title'] = '';
- $block['item_type'] = 'home_comment';
- $block['scale'] = 1;
- $item['image'] = '';
- $item['type'] = 'comment';
- $item['data'] = intval($val['geval_id']);
- $item['title'] = $val['geval_goodsname'];
- $items[] = $item;
- $block['items'] = $items;
- $blocks[] = $block;
- }
- return $blocks;
- }
- public static function format_brand($brands)
- {
- if(empty($brands)) return array();
- if(count($brands) == 1)
- {
- $brand_id = intval($brands[0]['data']);
- return self::format_brand_sale($brand_id,true);
- }
- else
- {
- $result = [];
- $result['item_title'] = '';
- $result['item_type'] = 'homewords';
- foreach ($brands as $val) {
- $item['image'] = "";
- $item['type'] = $val['type'];
- $item['data'] = strval($val['data']);
- $item['title'] = $val['title'];
- $result['items'][] = $item;
- }
- return $result;
- }
- }
- public static function format_category($cats,$title = '')
- {
- if(empty($cats)) return array();
- $result = [];
- $result['item_title'] = $title;
- $result['item_type'] = 'homewords';
- foreach ($cats as $val) {
- $item['image'] = "";
- $item['type'] = $val['type'];
- $item['data'] = strval($val['data']);
- $item['title'] = $val['title'];
- $result['items'][] = $item;
- }
- return $result;
- }
- public static function format_keyword($words,$title='')
- {
- $result = [];
- $result['item_title'] = $title;
- $result['item_type'] = 'homewords';
- foreach ($words as $word) {
- $item['image'] = "";
- $item['type'] = 'keyword';
- $item['data'] = $word;
- $item['title'] = $word;
- $result['items'][] = $item;
- }
- return $result;
- }
- public static function format_ugc(ugc\special $special)
- {
- $special_id = $special->special_id();
- $url = BASE_SITE_URL . "/mobile/index.php?act=special&op=index&client_type=wap&special_id={$special_id}";
- $result = [];
- $result['item_title'] = $special->share_title();
- $result['item_type'] = 'home1';
- $item['show_type'] = 'ugc';
- $item['show_data'] = $special_id;
- $item['image'] = $special->share_img();
- $item['type'] = 'url';
- $item['data'] = $url;
- $item['title'] = $special->share_title();
- $result['items'][] = $item;
- return $result;
- }
- public static function format_bonus($bonuses,$title='')
- {
- $result = [];
- $result['item_title'] = $title;
- $result['item_type'] = 'home_bonus';
- foreach ($bonuses as $bonus) {
- $item['image'] = "";
- $item['type'] = 'bonus';
- $item['data'] = $bonus['bonus_sn'];
- $item['title'] = '';
- $result['items'][] = $item;
- }
- return $result;
- }
- public static function format_type($type_infos,$title='')
- {
- $result = [];
- $result['item_title'] = $title;
- $result['item_type'] = 'home_type';
- foreach ($type_infos as $type) {
- $item['image'] = "";
- $item['type'] = 'bonus_type';
- $item['data'] = $type['type_sn'];
- $item['title'] = '';
- $result['items'][] = $item;
- }
- return $result;
- }
- public static function format_goods($goods_ids,$title,$sort_summary)
- {
- $result = [];
- $result['item_title'] = empty($title) ? '' : $title;
- $result['item_type'] = 'home_goods';
- foreach ($goods_ids as $goods_id)
- {
- $summary = $sort_summary[$goods_id];
- $item['image'] = $summary['goods_image_url'];
- $item['show_type'] = 'goods';
- $item['show_data'] = strval($goods_id);
- $item['type'] = 'goods';
- $item['data'] = strval($goods_id);
- $item['title'] = $summary['goods_mobile_name'];
- $result['items'][] = $item;
- }
- return $result;
- }
- public static function format_ugc_goods($goods_ids,$title,$sort_summary)
- {
- $blocks = [];
- $count = count($goods_ids);
- $i = 1;
- foreach ($goods_ids as $goods_id)
- {
- $block = [];
- $block['item_title'] = empty($title) ? '' : $title;
- $block['item_type'] = 'home1';
- $summary = $sort_summary[$goods_id];
- $item['image'] = $summary['goods_image_url'];
- $item['show_type'] = 'goods_ugc';
- $item['show_data'] = strval($goods_id);
- $item['type'] = 'goods';
- $item['data'] = strval($goods_id);
- $item['title'] = $summary['goods_mobile_name'];
- $block['items'][] = $item;
- $blocks[] = $block;
- if($i != $count) {
- $blocks[] = self::def_divider();
- }
- }
- return $blocks;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public function format(&$goods_ids)
- {
- $goods_ids = $this->goods_ids;
- return $this->filter_data;
- }
- private function read_cache()
- {
- $mod_special = Model('mb_special');
- if($this->special_id > 0)
- {
- $special = $mod_special->getMbSpecialByID($this->special_id);
- if(empty($special)) {
- return false;
- }
- }
- $sp_items = $mod_special->getMbSpecialItemUsableListByID($this->special_id);
- if(empty($sp_items)) {
- Log::record("getMbSpecialItemUsableListByID is empty",Log::ERR);
- return false;
- }
- $from_user = spid_helper::instance()->special($this->special_id)->from_user();
- if(array_key_exists('tabs',$sp_items)) {
- $this->tabs = $sp_items['tabs'];
- } else {
- $this->tabs = [];
- }
- if(isset($sp_items["mobile_filter_data"]))
- {
- $this->filter_data = $sp_items['mobile_filter_data'];
- $this->goods_ids = $sp_items['mobile_goods_ids'];
- if($from_user) {
- $this->special_info = $sp_items['special_info'];
- $this->sender_info = $sp_items['sender_info'];
- }
- }
- else
- {
- $this->filter_data = $this->filter($sp_items['blocks'],$goods_ids);
- $this->goods_ids = $goods_ids;
- $sp_items['mobile_filter_data'] = $this->filter_data;
- $sp_items['mobile_goods_ids'] = $goods_ids;
- if($from_user)
- {
- $special_info = $mod_special->getMbSpecialByID($this->special_id);
- $sp_items['special_info'] = $special_info;
- $userid = $special_info['member_id'];
- if($userid > 0) {
- $mod_member = Model('member');
- $sender_info = $mod_member->getMemberInfoByID($userid);
- $sp_items['sender_info'] = $sender_info;
- $this->sender_info = $sp_items['sender_info'];
- }
- $this->special_info = $sp_items['special_info'];
- }
- $cache = array('special' => serialize($sp_items));
- wcache($this->special_id, $cache, 'mb_special');
- }
- }
- private function filter($specials,&$goods_ids)
- {
- $blocks = [];
- $goods_ids = [];
- foreach($specials as $special)
- {
- $ids = [];
- $block = $this->filter_item($special,$ids,$scale);
- if($scale != false && !empty($block)) {
- $blocks[] = $block;
- $goods_ids = array_merge($goods_ids,$ids);
- }
- }
- $goods_ids = array_unique($goods_ids);
- return $blocks;
- }
- private function filter_item($special,&$goods_ids,&$scale)
- {
- $block = [];
- $block['item_title'] = empty($special['title']) ? '' : $special['title'];
- $block['item_type'] = $special['item_type'];
- $block['bg_image'] = $special['bg_image'];
- $block['bg_type'] = $special['bg_type'];
- $block['bg_data'] = $special['bg_data'];
- $block['has_margin'] = $special['has_margin'];
- $block_scale = false;
- $this->format_property($block,$block_scale);
- $key = $special['item_type'];
- if ($key == 'divider') {
- $scale = $block_scale;
- $block['scale'] = $scale;
- return $block;
- }
- $org_items = $special['items'];
- if($key != 'divider' && empty($org_items)) {
- return false;
- }
- $scale = false;
- if($key == 'adv_list' || $key == 'home3' || $key == 'home5' || $key =='home6' || $key == 'home7' || $key == 'goods')
- {
- $items = $this->filter_normal($key,$org_items,$goods_ids,$scale);
- if($key == 'goods') {
- $block['item_type'] = 'home_goods';
- }
- elseif($key == 'home3') {
- if($this->old_version == false) $scale = $block_scale;
- }
- elseif($key == 'home6') {
- $block['item_type'] = 'horizon';
- $scale = $block_scale;
- }
- elseif($key == 'home7') {
- $block['item_type'] = 'horizon_goods';
- $scale = $block_scale;
- }
- }
- elseif($key == 'home1') {
- $items = $this->filter_home1($org_items,$goods_ids,$scale);
- }
- elseif($key == 'home2') {
- $items = $this->filter_home2($org_items,$goods_ids,$scale);
- }
- elseif($key == 'home4') {
- $items = $this->filter_home4($org_items,$goods_ids,$scale);
- }
- elseif($key == 'home_ugc')
- {
- $items = $this->filter_home_ugc($org_items,$goods_ids);
- $block['items'] = $items;
- $scale = 1;
- return $block;
- }
- else {
- return false;
- }
- if($items == false && $key != 'divider') {
- return false;
- }
- $this->decode($items);
- foreach ($items as &$item)
- {
- if($this->image_wh($item['image'],$w,$h)) {
- $item['width'] = $w;
- $item['height'] = $h;
- }
- }
- $block['items'] = $items;
- if($block_scale) {
- $block['scale'] = $scale;
- }
- else {
- $block['scale'] = $scale;
- }
- return $block;
- }
- /**
- * 处理type=url 时的&字符转义问题
- * @param array $data
- * @return array|bool
- */
- private function decode(&$items)
- {
- foreach($items as &$item)
- {
- static $action_types = array('url','innerurl','video','appjump');
- static $show_types = array('webview','video');
- if(in_array($item['type'],$action_types)){
- $item['data'] = htmlspecialchars_decode($item['data']);
- }
- if(in_array($item['show_type'],$show_types)){
- $item['show_data'] = htmlspecialchars_decode($item['show_data']);
- }
- }
- }
- public static function scale($image)
- {
- $image = trim($image);
- if(empty($image)) {
- Log::record("special scale error {$image}",Log::ERR);
- return false;
- }
- $ret = util::imgsize($image);
- if($ret != false) {
- $scale = doubleval($ret[0]) / doubleval($ret[1]);
- return $scale;
- } else {
- Log::record("special scale getimagesize error {$image}",Log::ERR);
- return false;
- }
- }
- private function safe_string($str)
- {
- if($str == null || empty($str)) {
- return "";
- }
- else {
- return $str;
- }
- }
- private function check_goods($ids)
- {
- if(empty($ids)) return true;
- $ids = array_unique($ids);
- $mod = Model('goods');
- $goods = $mod->getGoodsOnlineList(array("goods_id" => array("in",$ids)));
- $gids = [];
- foreach ($goods as $item) {
- $gids[] = intval($item['goods_id']);
- }
- if(count($ids) == count($gids)) {
- return true;
- } else {
- return false;
- }
- }
- private function filter_home1($val,&$goods_ids,&$scale)
- {
- $items = [];
- $item['image'] = $val['image'];
- $item['type'] = $val['type'];
- $item['data'] = $val['data'];
- $item['show_type'] = $val['show_type'];
- $item['show_data'] = $val['show_data'];
- $item['reserved'] = $this->safe_string($val['reserved']);
- $item['title'] = $this->safe_string($val['title']);
- $scale = self::scale($item['image']);
- $ids = [];
- if($item['type'] == 'goods') {
- $ids[] = intval($item['data']);
- }
- if(self::check_goods($ids)) {
- $goods_ids = array_merge($goods_ids,$ids);
- $items[] = $item;
- return $items;
- } else {
- return false;
- }
- }
- private function filter_home_ugc($val,&$goods_ids)
- {
- $items = [];
- $item['image'] = $val['image'];
- $item['type'] = $val['type'];
- $item['data'] = $val['data'];
- $item['show_type'] = $val['show_type'];
- $item['show_data'] = $val['show_data'];
- $item['reserved'] = $this->safe_string($val['reserved']);
- $item['title'] = $this->safe_string($val['title']);
- $ids = [];
- if($item['type'] == 'goods') {
- $ids[] = intval($item['data']);
- }
- if(self::check_goods($ids)) {
- $goods_ids = array_merge($goods_ids,$ids);
- $items[] = $item;
- return $items;
- } else {
- return false;
- }
- }
- private function filter_home2($val,&$goods_ids,&$scale)
- {
- $items = [];
- {
- $item['image'] = $val['square_image'];
- $item['type'] = $val['square_type'];
- $item['data'] = $val['square_data'];
- $item['show_type'] = $val['square_show_type'];
- $item['show_data'] = $val['square_show_data'];
- $item['title'] = $this->safe_string($val['square_title']);
- $item['reserved'] = $this->safe_string($val['square_reserved']);
- $items[] = $item;
- }
- {
- $item['image'] = $val['rectangle1_image'];
- $item['type'] = $val['rectangle1_type'];
- $item['data'] = $val['rectangle1_data'];
- $item['show_type'] = $val['rectangle1_show_type'];
- $item['show_data'] = $val['rectangle1_show_data'];
- $item['title'] = $this->safe_string($val['rectangle1_title']);
- $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
- $items[] = $item;
- $scale = self::scale($item['image']);
- }
- {
- $item['image'] = $val['rectangle2_image'];
- $item['type'] = $val['rectangle2_type'];
- $item['data'] = $val['rectangle2_data'];
- $item['show_type'] = $val['rectangle2_show_type'];
- $item['show_data'] = $val['rectangle2_show_data'];
- $item['title'] = $this->safe_string($val['rectangle2_title']);
- $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
- $items[] = $item;
- }
- $ids = [];
- foreach ($items as $item)
- {
- if($item['type'] == 'goods') {
- $ids[] = intval($item['data']);
- }
- }
- if(self::check_goods($ids)) {
- $goods_ids = array_merge($goods_ids,$ids);
- return $items;
- } else {
- Log::record("check_goods error {$ids}",Log::ERR);
- return false;
- }
- }
- private function filter_home4($val,&$goods_ids,&$scale)
- {
- $items = [];
- {
- $item['image'] = $val['rectangle1_image'];
- $item['type'] = $val['rectangle1_type'];
- $item['data'] = $val['rectangle1_data'];
- $item['show_type'] = $val['rectangle1_show_type'];
- $item['show_data'] = $val['rectangle1_show_data'];
- $item['title'] = $this->safe_string($val['rectangle1_title']);
- $item['reserved'] = $this->safe_string($val['rectangle1_reserved']);
- $items[] = $item;
- }
- {
- $item['image'] = $val['rectangle2_image'];
- $item['type'] = $val['rectangle2_type'];
- $item['data'] = $val['rectangle2_data'];
- $item['show_type'] = $val['rectangle2_show_type'];
- $item['show_data'] = $val['rectangle2_show_data'];
- $item['title'] = $this->safe_string($val['rectangle2_title']);
- $item['reserved'] = $this->safe_string($val['rectangle2_reserved']);
- $scale = self::scale($item['image']);
- $items[] = $item;
- }
- {
- $item['image'] = $val['square_image'];
- $item['type'] = $val['square_type'];
- $item['data'] = $val['square_data'];
- $item['show_type'] = $val['square_show_type'];
- $item['show_data'] = $val['square_show_data'];
- $item['title'] = $this->safe_string($val['square_title']);
- $item['reserved'] = $this->safe_string($val['square_reserved']);
- $items[] = $item;
- }
- $ids = [];
- foreach ($items as $item)
- {
- if($item['type'] == 'goods') {
- $ids[] = intval($item['data']);
- }
- }
- if(self::check_goods($ids)) {
- $goods_ids = array_merge($goods_ids,$ids);
- return $items;
- } else {
- return false;
- }
- }
- private function image_wh($image,&$width,&$height)
- {
- $ret = util::imgsize($image);
- if ($ret != false) {
- $width = $ret[0];
- $height = $ret[1];
- return true;
- } else {
- Log::record("cannt find image imgurl={$image}",Log::ERR);
- return false;
- }
- }
- private function format_property(&$block,&$block_scale)
- {
- $image = $block['bg_image'];
- if(empty($image))
- {
- if($block['item_type'] == 'divider') {
- $image = RESOURCE_SITE_URL . self::def_divider_bg_img;
- }
- }
- else {
- $image = getMbSpecialImageUrl($image);
- }
- $block['bg_image'] = $image;
- if(!empty($image)) {
- $block_scale = self::scale($image);
- } else {
- $block_scale = false;
- }
- if($block['bg_type'] == 'image')
- {
- if($block_scale != false) {
- $block['bg_data'] = $image;
- } else {
- $block['bg_data'] = '';
- }
- }
- else
- {
- if(empty($block['bg_data'])) {
- $block['bg_data'] = self::def_item_bg_color;
- }
- }
- unset($block['bg_image']);
- }
- private function filter_normal($block_type,$items, &$goods_ids, &$scale)
- {
- $result = [];
- $has_set = false;
- foreach($items as $item)
- {
- $item['title'] = $this->safe_string($item['title']);
- if($has_set == false) {
- $scale = self::scale($item['image']);
- $has_set = true;
- }
- if($item['type'] == 'goods')
- {
- $goods_id = intval($item['data']);
- if(self::check_goods(array($goods_id))) {
- array_push($goods_ids,$goods_id);
- $result[] = $item;
- } else {
- Log::record("block_type={$block_type} cannt find goods ,goods_id={$goods_id}",Log::ERR);
- continue;
- }
- }
- else {
- $result[] = $item;
- }
- }
- if($has_set == true)
- {
- if($block_type == 'home3') {
- $scale = $scale * 2;
- }
- elseif($block_type == 'goods') {
- $scale = 1;
- }
- }
- if(empty($result)) {
- return false;
- } else {
- return $result;
- }
- }
- }
- class spid_item
- {
- private $mFromUser;
- private $mHasVote;
- private $mShareImage;
- private $mShareTitle;
- public function __construct($item)
- {
- $special = new ugc\special($item);
- $this->mFromUser = $special->from_user();
- $this->mHasVote = $special->has_vote();
- $this->mShareImage = $special->share_img();
- $this->mShareTitle = $special->share_title();
- }
- public function from_user() {
- return $this->mFromUser;
- }
- public function has_vote() {
- return $this->mHasVote;
- }
- public function share_image() {
- return $this->mShareImage;
- }
- public function share_title() {
- return $this->mShareTitle;
- }
- }
- class spid_helper
- {
- private static $stInstance = null;
- private $mContents;
- public function __construct() {
- $this->mContents = [];
- $this->add_home();
- }
- public static function instance() {
- if(self::$stInstance == null) {
- self::$stInstance = new spid_helper();
- }
- return self::$stInstance;
- }
- //home page is not in mb_special table.
- private function add_home()
- {
- $item['from_user'] = 0;
- $item['share_image'] = "";
- $item['share_title'] = "";
- $spitem = new spid_item($item);
- $this->mContents[0] = $spitem;
- }
- public function special($spid)
- {
- $spid = intval($spid);
- if(array_key_exists($spid,$this->mContents)) {
- return $this->mContents[$spid];
- }
- else
- {
- $item = $this->read($spid);
- if($item == false) {
- return false;
- } else {
- $this->mContents[$spid] = $item;
- return $item;
- }
- }
- }
- private function read($spid)
- {
- $mod_special = Model('mb_special');
- $item = $mod_special->getMbSpecialByID($spid);
- if(empty($item)) {
- return false;
- }
- else
- {
- $spitem = new spid_item($item);
- return $spitem;
- }
- }
- }
- class special_manager
- {
- private static $stInstance = null;
- private $mContents;
- public function __construct()
- {
- $this->mContents = [];
- }
- public static function instance() {
- if(self::$stInstance == null) {
- self::$stInstance = new special_manager();
- }
- return self::$stInstance;
- }
- public function tabs($special_id)
- {
- if (array_key_exists($special_id, $this->mContents)) {
- return $this->mContents[$special_id]['tabs'];
- } else {
- return [];
- }
- }
- public function special($special_id,&$goods_ids,$pub=true)
- {
- if($pub)
- {
- if(StatesHelper::fetch_state('special')) {
- $this->mContents = [];
- }
- $special_id = intval($special_id);
- if(array_key_exists($special_id,$this->mContents)) {
- $data = $this->mContents[$special_id]['data'];
- $goods_ids = $this->mContents[$special_id]['gids'];
- return $data;
- }
- else
- {
- $formater = new special_formater($special_id,$this->old_version($special_id));
- $data = $formater->format($goods_ids);
- $this->mContents[$special_id]['data'] = $data;
- $this->mContents[$special_id]['gids'] = $goods_ids;
- $this->mContents[$special_id]['tabs'] = $formater->tabs();
- return $data;
- }
- }
- else
- {
- $formater = new special_formater($special_id,$this->old_version($special_id));
- $specials = $formater->format($goods_ids);
- $result['specials'] = $specials;
- $result['sender_info'] = $formater->sender_info();
- $result['special_info'] = $formater->special_info();
- return $result;
- }
- }
- private function old_version($special_id)
- {
- global $config;
- if($_SESSION['is_lasted'] || empty($config['old_specials'])) return false;
- return in_array($special_id,$config['old_specials']);
- }
- }
|