コード例 #1
0
ファイル: GoodsSpecPipeline.php プロジェクト: swcug/bzfshop
 public function execute($cartInstance)
 {
     // 使用引用取得内部数据,方便操作
     $cartContext =& $cartInstance->getCartContextRef();
     if ($cartContext->isEmpty()) {
         // 没有数据,不需要计算
         goto out_fail;
     }
     // 计算每个商品的组合选择
     foreach ($cartContext->orderGoodsArray as &$orderGoodsItem) {
         $goodsInfo = $orderGoodsItem->goods;
         if (empty($goodsInfo['goods_spec'])) {
             continue;
             // 普通商品,没有组合选择
         }
         $goodsAttr = $orderGoodsItem->getValue('goods_attr');
         // 计算这个规格对应的价格
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($goodsAttr);
         // 商品的销售价格 = 基础价格 + 规格额外加价
         $shopPrice = $orderGoodsItem->goods['shop_price'] + @$goodsSpecDataArray['goods_spec_add_price'];
         // 设置这个规格对应的价格
         $orderGoodsItem->setValue('shop_price', $shopPrice);
     }
     unset($orderGoodsItem);
     return true;
     out_fail:
     return false;
     // 返回 false,后面的 pipeline 就不会被执行了
 }
コード例 #2
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, '/');
     // 返回首页
 }
コード例 #3
0
ファイル: Goods.php プロジェクト: jackycgq/bzfshop
 /**
  * 更新商品的库存
  *
  * @param int    $goods_id
  * @param string $specStr      商品规格
  * @param int    $goods_number 库存
  */
 public function updateGoodsGoodsNumber($goods_id, $specStr, $goods_number)
 {
     // 参数验证
     $validator = new Validator(array('goods_id' => $goods_id, 'specStr' => $specStr, 'goods_number' => $goods_number));
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     $specStr = $validator->validate('specStr');
     $goods_number = $validator->required()->digits()->min(1)->validate('goods_number');
     $this->validate($validator);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         // 不存在的商品,退出
         return;
     }
     // 商品有规格选择,我们需要计算规格的库存
     if (!empty($goods->goods_spec)) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goods->goods_spec);
         $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($specStr);
         if (empty($goodsSpecDataArray)) {
             goto no_spec_goods_calc;
             // 不正常的商品规格选择,按照普通购买计算库存
         }
         // 计算剩余库存
         $specGoodsNumber = @$goodsSpecDataArray['goods_number'];
         $specGoodsNumber -= $goods_number;
         $specGoodsNumber = $specGoodsNumber >= 0 ? $specGoodsNumber : 0;
         // 确保库存不能为负数
         // 更新商品规格对应的库存
         $goodsSpecService->setGoodsSpecGoodsNumber($specStr, $specGoodsNumber);
         $goods->goods_spec = $goodsSpecService->getJsonStr();
         $goods->save();
         return;
     }
     no_spec_goods_calc:
     // 普通商品,没有商品规格选择
     $goods->goods_number -= $goods_number;
     // 确保库存不能是负数
     $goods->goods_number = $goods->goods_number >= 0 ? $goods->goods_number : 0;
     $goods->save();
 }
コード例 #4
0
ファイル: Cart.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 这里操作加入购物车
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     $goodsChooseSpecListStr = $validator->validate('goods_choose_speclist');
     $goodsChooseBuyCount = $validator->required('商品最少购买 1 件')->digits('商品最少购买 1 件')->min(1, true, '商品最少购买 1 件')->validate('goods_choose_buycount');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,不允许显示等
     if ($goodsInfo->isEmpty() || !$goodsInfo->is_on_sale || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品不存在或者不能购买');
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     // 购物车服务
     $cartBasicService->loadFromStorage();
     // 恢复购物车中已有的数据
     $cartContext =& $cartBasicService->getCartContextRef();
     // 取得 cartContext
     // 商品多组合选择
     if (!empty($goodsChooseSpecListStr)) {
         // 检查商品 Spec 是否合法
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($goodsChooseSpecListStr);
         if (!$goodsSpecDataArray) {
             $this->addFlashMessage('商品选择[' . $goodsChooseSpecListStr . ']非法');
             goto out_fail;
         }
         // 检查商品库存
         if ($goodsChooseBuyCount > @$goodsSpecDataArray['goods_number']) {
             $this->addFlashMessage($goodsChooseSpecListStr . '库存不足,只剩 ' . @$goodsSpecDataArray['goods_number'] . ' 件');
             goto out_fail;
         }
         // 商品加入到购物车
         $cartContext->addGoods($goods_id, $goodsChooseBuyCount, $goodsChooseSpecListStr, @$goodsSpecDataArray['goods_sn']);
     } else {
         // 检查库存
         if ($goodsChooseBuyCount > $goodsInfo['goods_number']) {
             $this->addFlashMessage('库存不足,剩余 ' . $goodsInfo['goods_number'] . ' 件');
             goto out_fail;
         }
         // 普通简单选择,加入购物车
         $cartContext->addGoods($goods_id, $goodsChooseBuyCount);
     }
     $cartBasicService->syncStorage();
     // 保存购物车的数据
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     out_fail:
     // 失败,返回出错信息
     $errorMessage = implode('|', $this->flashMessageArray);
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
コード例 #5
0
 public function execute($cartInstance)
 {
     // 使用引用取得内部数据,方便操作
     $cartContext =& $cartInstance->getCartContextRef();
     if ($cartContext->isEmpty()) {
         // 没有数据,不需要计算
         goto out_fail;
     }
     // 当前主题允许哪些系统的商品被加入到购物车
     $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
     $goodsFilterSystemArray = $currentThemeInstance->getGoodsFilterSystemArray();
     // 从购物车中删除掉的 OrderGoods
     $removeOrderGoods = array();
     // 对每个商品做检查
     foreach ($cartContext->orderGoodsArray as &$orderGoodsItem) {
         // 商品已经下线了,不能购买
         $goodsInfo = $orderGoodsItem->goods;
         if (empty($goodsInfo) || !$goodsInfo['is_on_sale']) {
             $removeOrderGoods[] = array($goodsInfo['goods_id'], null);
             $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '] 已经下线');
             continue;
         }
         $goodsAttr = $orderGoodsItem->getValue('goods_attr');
         // 有规格的商品,用户必须做出选择
         if (!empty($goodsInfo['goods_spec']) && empty($goodsAttr)) {
             $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '] 必须选择规格');
             $removeOrderGoods[] = array($goodsInfo['goods_id'], null);
             continue;
         }
         // 检查商品库存
         if (!empty($goodsAttr)) {
             // 商品有规格选择
             if (empty($goodsInfo['goods_spec'])) {
                 $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '|' . $goodsAttr . '] 选择非法');
                 $removeOrderGoods[] = array($goodsInfo['goods_id'], $goodsAttr);
                 continue;
             }
             // 检查规格是否合法
             $goodsSpecService = new GoodsSpecService();
             $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
             $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($goodsAttr);
             if (empty($goodsSpecDataArray)) {
                 $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '|' . $goodsAttr . '] 选择非法');
                 $removeOrderGoods[] = array($goodsInfo['goods_id'], $goodsAttr);
                 continue;
             }
             // 检查规格对应的库存
             if ($orderGoodsItem->getValue('goods_number') > @$goodsSpecDataArray['goods_number']) {
                 $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '|' . $goodsAttr . '] 库存不足');
                 $removeOrderGoods[] = array($goodsInfo['goods_id'], $goodsAttr);
                 continue;
             }
         } else {
             // 简单商品,没有规格,检查库存
             if ($orderGoodsItem->getValue('goods_number') > $goodsInfo['goods_number']) {
                 $cartContext->addErrorMessage('商品 [' . $goodsInfo['goods_id'] . '] 库存不足');
                 $removeOrderGoods[] = array($goodsInfo['goods_id'], null);
                 continue;
             }
         }
         // 商品不属于当前系统,不能购买
         $goodsSystemArray = Utils::parseTagString($goodsInfo['system_tag_list']);
         $intersectSystem = array_intersect($goodsSystemArray, $goodsFilterSystemArray);
         if (empty($intersectSystem)) {
             $removeOrderGoods[] = array($goodsInfo['goods_id'], null);
             continue;
         }
     }
     unset($orderGoodsItem);
     // 删除不合格的 orderGoods 记录
     foreach ($removeOrderGoods as $removeItem) {
         $cartContext->removeGoods($removeItem[0], $removeItem[1]);
         $cartContext->addErrorMessage('商品 [' . $removeItem[0] . '] 不能购买,移除');
     }
     return true;
     out_fail:
     return false;
     // 返回 false,后面的 pipeline 就不会被执行了
 }
コード例 #6
0
ファイル: Search.php プロジェクト: jackycgq/bzfshop
 public function get($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_search');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 搜索参数数组
     $searchFormQuery = array();
     $searchFormQuery['g.is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale');
     $searchFormQuery['g.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     $searchFormQuery['g.suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id');
     $searchFormQuery['g.goods_name'] = $validator->validate('goods_name');
     $searchFormQuery['g.cat_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('cat_id');
     $searchFormQuery['g.type_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('type_id');
     $searchFormQuery['g.brand_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('brand_id');
     $searchFormQuery['g.goods_sn'] = $validator->validate('goods_sn');
     $searchFormQuery['g.warehouse'] = $validator->validate('warehouse');
     $searchFormQuery['g.shelf'] = $validator->validate('shelf');
     $searchFormQuery['g.admin_user_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('admin_user_id');
     $systemTag = $validator->validate('system_tag');
     if (!empty($systemTag)) {
         $searchFormQuery['g.system_tag_list'] = Utils::makeTagString(array($systemTag));
     }
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 查询条件
     $searchParamArray = array();
     // 根据推广渠道做搜索
     $goods_promote = $validator->validate('goods_promote');
     if (!empty($goods_promote)) {
         switch ($goods_promote) {
             case '360tequan':
                 $searchParamArray[] = array('gp.360tequan_price > 0');
                 break;
             case '360tegong':
                 $searchParamArray[] = array('gp.360tegong_enable = 1');
                 break;
             default:
                 // do nothing
                 break;
         }
     }
     // 建立查询条件
     $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery));
     // 查询商品列表
     $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsPromote, $searchParamArray);
     if ($totalCount <= 0) {
         // 没商品,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Goods/Search');
     }
     // 商品列表
     $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsPromote, 'g.goods_id, g.system_tag_list, g.cat_id, g.admin_user_name, g.goods_name, g.goods_number' . ', g.goods_spec, g.is_on_sale, g.type_id' . ', g.market_price, g.shop_price, g.shipping_fee, g.shipping_free_number' . ', g.suppliers_id, g.suppliers_price, g.suppliers_shipping_fee, g.warehouse, g.shelf', $searchParamArray, array(array('g.goods_id', 'desc')), $pageNo * $pageSize, $pageSize);
     // 取得供货商 id 列表,商品分类 id
     $supplierIdArray = array();
     $categoryIdArray = array();
     $typeIdArray = array();
     foreach ($goodsArray as $goodsItem) {
         $supplierIdArray[] = $goodsItem['suppliers_id'];
         $categoryIdArray[] = $goodsItem['cat_id'];
         $typeIdArray[] = $goodsItem['type_id'];
     }
     $supplierIdArray = array_unique($supplierIdArray);
     $categoryIdArray = array_unique($categoryIdArray);
     //取得供货商信息
     $userSupplierService = new UserSupplierService();
     $supplierArray = $userSupplierService->fetchSupplierArrayBySupplierIdArray($supplierIdArray);
     // 建立 suppliers_id --> supplier 的反查表,方便快速查询
     $supplierIdToSupplierArray = array();
     foreach ($supplierArray as $supplier) {
         $supplierIdToSupplierArray[$supplier['suppliers_id']] = $supplier;
     }
     $system_url_base_array = json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true);
     // 放入供货商信息
     foreach ($goodsArray as &$goodsItem) {
         if (isset($supplierIdToSupplierArray[$goodsItem['suppliers_id']])) {
             // 很老的订单,用户可能被删除了
             $goodsItem['suppliers_name'] = $supplierIdToSupplierArray[$goodsItem['suppliers_id']]['suppliers_name'];
         }
         // 解析 system_tag_list,放入 system_array 的信息
         $systeArray = Utils::parseTagString($goodsItem['system_tag_list']);
         $goodsItem['system_array'] = array();
         foreach ($systeArray as $systemItem) {
             $goodsItem['system_array'][] = @$system_url_base_array[$systemItem]['name'];
         }
         // 商品规格
         if (!empty($goodsItem['goods_spec'])) {
             $goodsSpecService = new GoodsSpecService();
             $goodsSpecService->initWithJson($goodsItem['goods_spec']);
             $goodsItem['goods_spec'] = $goodsSpecService->getGoodsSpecDataArray();
         }
     }
     unset($goodsItem);
     // 取得分类信息
     $categoryBasicService = new CategoryBasicService();
     $categoryArray = $categoryBasicService->fetchCategoryArrayByIdArray($categoryIdArray);
     // 建立 cat_id  ---> cateogry 信息的反查表
     $categoryIdToCategoryArray = array();
     foreach ($categoryArray as $categoryItem) {
         $categoryIdToCategoryArray[$categoryItem['meta_id']] = $categoryItem;
     }
     // 放入分类信息
     foreach ($goodsArray as &$goodsItem) {
         if (isset($categoryIdToCategoryArray[$goodsItem['cat_id']])) {
             // 很老的商品,分类信息可能已经不存在了
             $goodsItem['cat_name'] = $categoryIdToCategoryArray[$goodsItem['cat_id']]['meta_name'];
         }
     }
     unset($goodsItem);
     // 取得商品类型信息
     $goodsTypeService = new GoodsTypeService();
     $goodsTypeArray = $goodsTypeService->fetchGoodsTypeArrayByTypeIdArray($typeIdArray);
     // 建立 type_id ---> type 信息的反查表
     $typeIdToTypeArray = array();
     foreach ($goodsTypeArray as $goodsType) {
         $typeIdToTypeArray[$goodsType['meta_id']] = $goodsType;
     }
     // 放入类型信息
     foreach ($goodsArray as &$goodsItem) {
         if (isset($typeIdToTypeArray[$goodsItem['type_id']])) {
             $goodsItem['type_name'] = $typeIdToTypeArray[$goodsItem['type_id']]['meta_name'];
         }
     }
     unset($goodsItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsArray', $goodsArray);
     $smarty->assign('system_url_base_array', json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true));
     out_display:
     $smarty->display('goods_search.tpl');
 }
コード例 #7
0
ファイル: Copy.php プロジェクト: jackycgq/bzfshop
 public function get($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_create');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('非法商品ID');
         goto out_fail;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 1. 复制 goods 信息
     $goodsArray = $goods->toArray();
     unset($goodsArray['goods_id']);
     // 清除主键
     // 新商品缺省为下线状态
     $goodsArray['is_on_sale'] = 0;
     // 清除购买数量统计
     $goodsArray['user_buy_number'] = 0;
     $goodsArray['user_pay_number'] = 0;
     // 设置复制人
     $goodsArray['admin_user_id'] = $authAdminUser['user_id'];
     $goodsArray['admin_user_name'] = $authAdminUser['user_name'];
     // 处理商品的规格
     if (!empty($goodsArray['goods_spec'])) {
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsArray['goods_spec']);
         $goodsSpecService->clearGoodsSpecImgIdArray();
         // 清除图片 ID 的关联
         $goodsArray['goods_spec'] = $goodsSpecService->getJsonStr();
         unset($goodsSpecService);
     }
     $goodsArray['add_time'] = Time::gmTime();
     $newGoods = $goodsBasicService->loadGoodsById(0);
     $newGoods->copyFrom($goodsArray);
     $newGoods->save();
     // 更新 goods_sn
     $newGoods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $newGoods['goods_id'];
     $newGoods->save();
     unset($goodsArray);
     // 2. 复制 goods_attr 信息
     if ($goods->type_id > 0) {
         $goodsTypeService = new GoodsTypeService();
         $goodsAttrValueArray = $goodsTypeService->fetchGoodsAttrItemValueArray($goods->goods_id, $goods->type_id);
         foreach ($goodsAttrValueArray as $goodsAttrValue) {
             $goodsAttr = $goodsTypeService->loadGoodsAttrById(0);
             $goodsAttr->goods_id = $newGoods->goods_id;
             $goodsAttr->attr_item_id = $goodsAttrValue['meta_id'];
             $goodsAttr->attr_item_value = $goodsAttrValue['attr_item_value'];
             $goodsAttr->save();
             unset($goodsAttr);
         }
         unset($goodsAttrValueArray);
         unset($goodsTypeService);
     }
     // 3. 复制 goods_gallery 信息
     $goodsGalleryService = new GoodsGalleryService();
     $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id);
     foreach ($goodsGalleryArray as $goodsGalleryItem) {
         // 新建一个 goods_gallery 记录
         $goodsGallery = $goodsGalleryService->loadGoodsGalleryById(0);
         unset($goodsGalleryItem['img_id']);
         $goodsGallery->copyFrom($goodsGalleryItem);
         $goodsGallery->goods_id = $newGoods['goods_id'];
         $goodsGallery->save();
         unset($goodsGallery);
     }
     unset($goodsGalleryArray);
     unset($goodsGalleryService);
     // 4. 复制 goods_team 信息
     $goodsTeam = $goodsBasicService->loadGoodsTeamByGoodsId($goods_id);
     if (!$goodsTeam->isEmpty()) {
         $goodsTeamInfo = $goodsTeam->toArray();
         unset($goodsTeamInfo['team_id']);
         $goodsTeamInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodsTeam = new DataMapper('goods_team');
         $newGoodsTeam->copyFrom($goodsTeamInfo);
         $newGoodsTeam->save();
         unset($newGoodsTeam);
         unset($goodsTeamInfo);
         unset($goodsTeam);
     }
     // 5. 复制 link_goods 信息
     $linkGoodsArray = $goodsBasicService->fetchSimpleLinkGoodsArray($goods_id);
     foreach ($linkGoodsArray as $linkGoodsItem) {
         unset($linkGoodsItem['link_id']);
         $linkGoodsItem['goods_id'] = $newGoods['goods_id'];
         $linkGoodsItem['admin_id'] = $authAdminUser['user_id'];
         $linkGoods = new DataMapper('link_goods');
         $linkGoods->copyFrom($linkGoodsItem);
         $linkGoods->save();
         unset($linkGoods);
     }
     unset($linkGoodsArray);
     // 6. 复制 goods_promote 信息
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     if (!$goodsPromote->isEmpty()) {
         $goodsPromoteInfo = $goodsPromote->toArray();
         unset($goodsPromoteInfo['promote_id']);
         $goodsPromoteInfo['goods_id'] = $newGoods['goods_id'];
         $newGoodspromote = new DataMapper('goods_promote');
         $newGoodspromote->copyFrom($goodsPromoteInfo);
         $newGoodspromote->save();
         unset($newGoodspromote);
     }
     unset($goodsPromote);
     // 记录编辑日志
     $goodsLogContent = '从 [' . $goods_id . '] 复制过来';
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($newGoods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], '复制商品', $goodsLogContent);
     $this->addFlashMessage('复制新建商品成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $newGoods['goods_id']), true));
     return;
     //正常返回
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #8
0
ファイル: Spec.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     $goodsLogContent = '';
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id, 1);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('商品 id[' . $goods_id . '] 非法');
         goto out_fail_list_goods;
     }
     // POST 参数验证
     $validator = new Validator($f3->get('POST'));
     $goodsSpecNameArray = $validator->validate('goodsSpecNameArray');
     $goodsSpecValue1Array = $validator->validate('goodsSpecValue1Array');
     $goodsSpecValue2Array = $validator->validate('goodsSpecValue2Array');
     $goodsSpecValue3Array = $validator->validate('goodsSpecValue3Array');
     $goodsNumberArray = $validator->validate('goodsNumberArray');
     $goodsSpecAddPriceArray = $validator->validate('goodsSpecAddPriceArray');
     $goodsSnArray = $validator->validate('goodsSnArray');
     $imgIdArray = $validator->validate('imgIdArray');
     if (empty($goodsSpecValue1Array)) {
         goto save_spec;
     }
     // 检查,商品属性名不能为空
     foreach ($goodsSpecNameArray as $goodsSpecName) {
         if (!empty($goodsSpecName)) {
             break;
         }
         $this->addFlashMessage('商品属性名不能为空');
         goto out_fail_edit_spec;
     }
     // 商品选项中不能有特殊符号
     $valueArray = array_merge($goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array);
     foreach ($valueArray as $valueItem) {
         if (empty($valueItem)) {
             continue;
         }
         // 商品规格不允许有特殊符号
         if (preg_match('#[,\\\\t\\s\\n\\+\\?\\^~!%/$]+#', $valueItem)) {
             $this->addFlashMessage('商品选项不能有特殊符号: 逗号、空格、回车、\\、? 等 ...');
             goto out_validate_fail;
         }
     }
     // 做数据格式转换,商品库存
     foreach ($goodsNumberArray as &$number) {
         $number = abs(intval($number));
     }
     unset($number);
     // 做数据格式转换,商品规格对应的加价
     foreach ($goodsSpecAddPriceArray as &$add_price) {
         $add_price = Money::toStorage(abs(floatval($add_price)));
     }
     unset($add_price);
     if (!$this->validate($validator)) {
         goto out_reroute;
     }
     save_spec:
     $goodsSpecService = new GoodsSpecService();
     $goodsSpecService->initWithData($goodsSpecNameArray, $goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array, $goodsNumberArray, $goodsSpecAddPriceArray, $goodsSnArray, $imgIdArray);
     // 保存数据
     $goodsSpecService->saveGoodsSpec($goods_id);
     $this->addFlashMessage('更新商品规格成功');
     out:
     // 正常退出
     $goodsSpecNameArray = is_array($goodsSpecNameArray) ? $goodsSpecNameArray : array();
     $goodsLogContent .= '属性名:' . implode(',', $goodsSpecNameArray) . "\n";
     $valueCount = count($goodsSpecValue1Array);
     for ($valueIndex = 0; $valueIndex < $valueCount; $valueIndex++) {
         $goodsLogContent .= '选择:' . @$goodsSpecValue1Array[$valueIndex] . ',' . @$goodsSpecValue2Array[$valueIndex] . ',' . @$goodsSpecValue3Array[$valueIndex] . ',' . '库存:' . @$goodsNumberArray[$valueIndex] . ',' . '加价:' . Money::toSmartyDisplay(@$goodsSpecAddPriceArray[$valueIndex]) . ',' . 'SN:' . @$goodsSnArray[$valueIndex] . ',' . 'image:' . @$imgIdArray[$valueIndex] . ',' . "\n";
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '商品规格', $goodsLogContent);
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     out_reroute:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods_id), true));
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
     return;
     out_validate_fail:
     global $smarty;
     $smarty->display('goods_edit_spec.tpl');
     return;
     out_fail_edit_spec:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods->goods_id), true));
 }
コード例 #9
0
ファイル: Search.php プロジェクト: jackycgq/bzfshop
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 查询条件
     $searchFormQuery = array();
     $searchFormQuery['g.is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale');
     $searchFormQuery['g.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     $searchFormQuery['g.goods_name'] = $validator->validate('goods_name');
     $searchFormQuery['g.goods_sn'] = $validator->validate('goods_sn');
     $searchFormQuery['g.warehouse'] = $validator->validate('warehouse');
     $searchFormQuery['g.shelf'] = $validator->validate('shelf');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 构造查询条件
     $authSupplierUser = AuthHelper::getAuthUser();
     $searchFormQuery['g.suppliers_id'] = intval($authSupplierUser['suppliers_id']);
     // 建立查询条件
     $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery);
     // 查询商品列表
     $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray);
     if ($totalCount <= 0) {
         // 没商品,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Goods/Search');
     }
     // 商品列表
     $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, array(array('g.goods_id', 'desc')), $pageNo * $pageSize, $pageSize);
     $system_url_base_array = json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true);
     foreach ($goodsArray as &$goodsItem) {
         // 解析 system_tag_list,放入 system_array 的信息
         $systeArray = Utils::parseTagString($goodsItem['system_tag_list']);
         $goodsItem['system_array'] = array();
         foreach ($systeArray as $systemItem) {
             $goodsItem['system_array'][] = @$system_url_base_array[$systemItem]['name'];
         }
         // 商品规格
         if (!empty($goodsItem['goods_spec'])) {
             $goodsSpecService = new GoodsSpecService();
             $goodsSpecService->initWithJson($goodsItem['goods_spec']);
             $goodsItem['goods_spec'] = $goodsSpecService->getGoodsSpecDataArray();
         }
     }
     unset($goodsItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsArray', $goodsArray);
     out_display:
     $smarty->display('goods_search.tpl');
 }
コード例 #10
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, '/');
     // 返回首页
 }