예제 #1
0
파일: View.php 프로젝트: jackycgq/bzfshop
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|View';
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_view'));
     // 缓存页面
     if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 查询商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,退出
     if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品 [' . $goods_id . '] 不存在');
         goto out_fail;
     }
     // 取商品推广信息设置
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     // 取商品图片集
     $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id);
     foreach ($goodsGalleryArray as &$galleryItem) {
         $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']);
         $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']);
     }
     unset($galleryItem);
     // 设置商品页面的 SEO 信息
     $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]'));
     $smarty->assign('seo_description', $goodsInfo['seo_description']);
     $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']);
     // 给模板赋值
     $smarty->assign('goodsInfo', $goodsInfo);
     $smarty->assign('goodsPromote', $goodsPromote);
     if (!Utils::isEmpty($goodsGalleryArray)) {
         $smarty->assign('goodsGalleryArray', $goodsGalleryArray);
     }
     // 设置商品规格
     if (!empty($goodsInfo['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $smarty->assign('goodsSpec', $goodsSpecService->getGoodsSpecDataArray());
     }
     out_display:
     $smarty->display('goods_view.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }
예제 #2
0
파일: Admin.php 프로젝트: jackycgq/bzfshop
 /**
  * 更新用户信息到数据库
  *
  * @return object 更新之后的 user 对象
  *
  * @param object $admin  user对象
  * @param array  $input  需要更新的字段
  *
  * */
 public function updateAdmin($admin, array $input)
 {
     if (Utils::isEmpty($admin) || Utils::isEmpty($input)) {
         throw new \InvalidArgumentException('$admin, $input can not be empty');
     }
     // 去除掉一些关键的字段,不允许更新
     $password = null;
     if (isset($input['password']) && !Utils::isBlank($input['password'])) {
         $password = $input['password'];
     }
     unset($input['id']);
     unset($input['user_id']);
     unset($input['password']);
     $admin->copyFrom($input);
     if (!Utils::isBlank($password)) {
         $admin->ec_salt = substr(uniqid(), -10);
         //修改密码同时修改 salt,增强安全性
         $admin->password = $this->encryptPassword($password, $admin->ec_salt);
     }
     $admin->save();
     return $admin;
 }
예제 #3
0
파일: SqlMapper.php 프로젝트: swcug/bzfshop
 /**
  *
  * @param mixed $table 数据表的名字,如果是单个表,可以是 'user',多个表可以是 array('user', 'user_info' => 'ui')
  * @param int   $ttl   缓存多少秒
  *
  * */
 function __construct($table, $ttl = 600)
 {
     $dbEngine = static::getDbEngine();
     // 检查数据库连接
     if (Utils::isEmpty($dbEngine)) {
         throw new \InvalidArgumentException('can not find dbEngine');
     }
     if (null == $table) {
         return parent::__construct($dbEngine, null, null, $ttl);
     }
     // 多表联合查询
     if (is_array($table)) {
         $tableArray = array();
         foreach ($table as $key => $value) {
             if (is_string($key)) {
                 $tableArray[] = static::tableName($key);
                 continue;
             }
             $tableArray[] = static::tableName($value);
         }
         return parent::__construct($dbEngine, $tableArray, null, $ttl);
     }
     // 单表查询
     if (is_string($table)) {
         parent::__construct($dbEngine, static::tableName($table), null, $ttl);
     }
 }
예제 #4
0
파일: View.php 프로젝트: jackycgq/bzfshop
 public function get($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 生成 smarty 的缓存 id
     $smartyCacheId = 'Goods|' . $goods_id . '|View';
     // 开启并设置 smarty 缓存时间
     enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view'));
     if ($smarty->isCached('goods_view.tpl', $smartyCacheId)) {
         goto out_display;
     }
     // 查询商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,退出
     if ($goodsInfo->isEmpty() || !Utils::isTagExist(PluginHelper::SYSTEM_SHOP, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品 [' . $goods_id . '] 不存在');
         goto out_fail;
     }
     // 取得商品的分类层级
     $goodsCategoryLevelArray = array();
     $goodsCategoryService = new GoodsCategoryService();
     $categoryLevel = 5;
     // 最多取 5 层分类
     $currentCategoryId = $goodsInfo['cat_id'];
     for (; $categoryLevel > 0; $categoryLevel--) {
         $category = $goodsCategoryService->loadCategoryById($currentCategoryId, 1800);
         if ($category->isEmpty()) {
             break;
         }
         array_unshift($goodsCategoryLevelArray, $category);
         if ($category['parent_meta_id'] <= 0) {
             break;
         }
         $currentCategoryId = $category['parent_meta_id'];
     }
     // 取商品推广信息设置
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     // 取商品图片集
     $goodsGalleryArray = GoodsGalleryCache::getGoodsGallery($goods_id);
     foreach ($goodsGalleryArray as &$galleryItem) {
         $galleryItem['img_original'] = RouteHelper::makeImageUrl($galleryItem['img_original']);
         $galleryItem['img_url'] = RouteHelper::makeImageUrl($galleryItem['img_url']);
         $galleryItem['thumb_url'] = RouteHelper::makeImageUrl($galleryItem['thumb_url']);
     }
     unset($galleryItem);
     // 取相互关联的商品
     $linkGoodsArray = $goodsBasicService->fetchLinkGoodsArray($goods_id);
     // 相同供货商的商品,一起购买只收一份邮费
     $goodsSupplierService = new GoodsSupplierService();
     // 取得供货商下面的商品总数,总数只缓存 10 分钟
     $supplierTotalGoodsCount = $goodsSupplierService->countSupplierGoodsArray($goodsInfo['suppliers_id'], 600);
     // 随机挑选 10 个商品
     $supplierGoodsSize = 10;
     $supplierGoodsOffset = $supplierTotalGoodsCount <= $supplierGoodsSize ? 0 : mt_rand(0, $supplierTotalGoodsCount - $supplierGoodsSize);
     $supplierGoodsArray = $goodsSupplierService->fetchSupplierGoodsArray($goodsInfo['suppliers_id'], $supplierGoodsOffset, $supplierGoodsSize);
     // 把自己去除掉
     $supplierGoodsKeyExcludeArray = array();
     foreach ($supplierGoodsArray as $supplierGoodsKey => $supplierGoodsItem) {
         if ($supplierGoodsItem['goods_id'] == $goods_id) {
             $supplierGoodsKeyExcludeArray[] = $supplierGoodsKey;
         }
     }
     foreach ($supplierGoodsKeyExcludeArray as $supplierGoodsKey) {
         unset($supplierGoodsArray[$supplierGoodsKey]);
     }
     // 设置商品页面的 SEO 信息
     $smarty->assign('seo_title', $goodsInfo['seo_title'] . ',' . $f3->get('sysConfig[site_name]'));
     $smarty->assign('seo_description', $goodsInfo['seo_description']);
     $smarty->assign('seo_keywords', $goodsInfo['seo_keyword']);
     // 给模板赋值
     $smarty->assign('goodsInfo', $goodsInfo);
     $smarty->assign('goodsPromote', $goodsPromote);
     // 商品购买选择的规格
     if (!empty($goodsInfo['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         // 只显示有库存的商品规格
         $goodsSpecData = $goodsSpecService->getBuyableData();
         $smarty->assign($goodsSpecData);
         $smarty->assign('goodsSpecJson', json_encode($goodsSpecData));
     }
     // 商品的类型属性
     if ($goodsInfo['type_id'] > 0) {
         $goodsTypeService = new GoodsTypeService();
         $goodsAttrTreeTable = $goodsTypeService->fetchGoodsAttrItemValueTreeTable($goodsInfo['goods_id'], $goodsInfo['type_id']);
         $smarty->assign('goodsAttrTreeTable', $goodsAttrTreeTable);
     }
     if (!empty($goodsCategoryLevelArray)) {
         $smarty->assign('goodsCategoryLevelArray', $goodsCategoryLevelArray);
     }
     if (!Utils::isEmpty($goodsGalleryArray)) {
         $smarty->assign('goodsGalleryArray', $goodsGalleryArray);
     }
     if (!Utils::isEmpty($linkGoodsArray)) {
         $smarty->assign('linkGoodsArray', $linkGoodsArray);
     }
     if (!Utils::isEmpty($supplierGoodsArray)) {
         $smarty->assign('supplierGoodsArray', $supplierGoodsArray);
     }
     // 滑动图片广告
     $goods_view_adv_slider = json_decode(bzf_get_option_value('goods_view_adv_slider'), true);
     if (!empty($goods_view_adv_slider)) {
         $smarty->assign('goods_view_adv_slider', $goods_view_adv_slider);
     }
     // 移动端对应的 URL,用于百度页面适配
     $smarty->assign('currentPageMobileUrl', RouteHelper::makeShopSystemUrl(PluginHelper::SYSTEM_MOBILE, '/Goods/View', array('goods_id' => $goods_id)));
     out_display:
     $smarty->display('goods_view.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     RouteHelper::reRoute($this, '/');
     // 返回首页
 }