|
@@ -0,0 +1,120 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: stanley-king
|
|
|
+ * Date: 2016/12/28
|
|
|
+ * Time: 下午12:31
|
|
|
+ */
|
|
|
+
|
|
|
+require_once(BASE_ROOT_PATH . '/helper/time_interval.php');
|
|
|
+
|
|
|
+
|
|
|
+class brand_helper
|
|
|
+{
|
|
|
+ static private $stInstance = null;
|
|
|
+ private $mBrandPageResult;
|
|
|
+ private $mTimeInterval;
|
|
|
+ private $mCountries;
|
|
|
+
|
|
|
+ private function __construct()
|
|
|
+ {
|
|
|
+ $this->mTimeInterval = new time_interval(60);
|
|
|
+ }
|
|
|
+
|
|
|
+ static public function instance()
|
|
|
+ {
|
|
|
+ if (self::$stInstance == null) {
|
|
|
+ self::$stInstance = new brand_helper();
|
|
|
+ }
|
|
|
+ if (self::$stInstance->mTimeInterval->need_init()) {
|
|
|
+ self::$stInstance->init();
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::$stInstance;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function country($brand_id)
|
|
|
+ {
|
|
|
+ $brand_id = intval($brand_id);
|
|
|
+ if(array_key_exists($brand_id,$this->mCountries)) {
|
|
|
+ return $this->mCountries[$brand_id];
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function init()
|
|
|
+ {
|
|
|
+ $prefix = 'mb_';
|
|
|
+ $ret = rcache('brandex', $prefix);
|
|
|
+ if (empty($ret)) {
|
|
|
+ $model = Model('brand');
|
|
|
+ $items = $model->field('brand_id,brand_logo,brand_name,brand_country')->where(array('brand_apply' => '1'))->order('brand_sort asc')->limit(false)->select();
|
|
|
+
|
|
|
+ $this->mCountries = [];
|
|
|
+ $brands = [];
|
|
|
+ foreach ($items as $brand) {
|
|
|
+ $image = UPLOAD_SITE_URL . $brand['brand_logo'];
|
|
|
+ $ret = getimagesize($image, $info);
|
|
|
+ if ($ret != false) {
|
|
|
+ $brand['brand_logo'] = $image;
|
|
|
+ $brands[] = $brand;
|
|
|
+ }
|
|
|
+ $brand_id = intval($brand['brand_id']);
|
|
|
+ $this->mCountries[$brand_id] = $brand['brand_country'];
|
|
|
+ }
|
|
|
+ $block = special_helper::format_grid_brands($brands);
|
|
|
+ wcache("brandex", array("brands" => serialize($brands), "block" => serialize($block)), $prefix);
|
|
|
+
|
|
|
+ $result = array("brands" => $brands, "block" => $block);
|
|
|
+ } else {
|
|
|
+ $brands = unserialize($ret['brands']);
|
|
|
+ $block = unserialize($ret['block']);
|
|
|
+ $result = array("brands" => $brands, "block" => $block);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->mBrandPageResult = $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function brandex()
|
|
|
+ {
|
|
|
+ return $this->mBrandPageResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ //////////for old interface/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
+ static function brands()
|
|
|
+ {
|
|
|
+ $prefix = 'mb_';
|
|
|
+ $ret = rcache('brand', $prefix);
|
|
|
+ if (empty($ret)) {
|
|
|
+ $model = Model();
|
|
|
+ $brand_area_list = $model->table('brand_area')->order('area_sort asc')->limit(false)->select();
|
|
|
+ $filed = 'brand_id,brand_name,brand_pic,brand_img_bg,brand_img_logo,brand_area_id';
|
|
|
+ $brand_c_list = $model->table('brand')->field($filed)->where(array('brand_apply' => '1'))->order('brand_sort asc')->limit(false)->select();
|
|
|
+
|
|
|
+ $brands = array();
|
|
|
+ foreach ($brand_area_list as $brand_area) {
|
|
|
+ foreach ($brand_c_list as $brand) {
|
|
|
+ $brand['brand_pic'] = image_helper::format_brand_img_rect($brand['brand_pic']);
|
|
|
+ $brand['brand_img_bg'] = image_helper::format_brand_img_bg($brand['brand_img_bg']);
|
|
|
+ $brand['brand_img_logo'] = image_helper::format_brand_img_circle($brand['brand_img_logo']);
|
|
|
+ if ($brand['brand_area_id'] == $brand_area['area_id']) {
|
|
|
+ if (empty($brand_area['data'])) {
|
|
|
+ $brand_area['data'] = array();
|
|
|
+ }
|
|
|
+ array_push($brand_area['data'], $brand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($brand_area['data'])) {
|
|
|
+ array_push($brands, $brand_area);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ wcache("brand", array("brands" => serialize($brands)), $prefix);
|
|
|
+ } else {
|
|
|
+ $brands = unserialize($ret['brands']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $brands;
|
|
|
+ }
|
|
|
+}
|