コード例 #1
0
 /**
  * 其它系统加载本主题
  *
  * @return bool
  */
 private function doOtherAction()
 {
     // 获取当前插件的根地址
     $currentThemeBasePath = dirname(__FILE__);
     require_once $currentThemeBasePath . '/manage/Code/Cache/MobileClear.php';
     // 注册 Smarty 缓存清除功能,用户在 Manage 后台编辑商品的时候就能智能清除缓存了
     ClearHelper::registerInstanceClass('\\Cache\\MobileClear');
     return true;
 }
コード例 #2
0
ファイル: SaeAssetManager.php プロジェクト: jackycgq/bzfshop
 public function __construct($system)
 {
     global $f3;
     $this->assetUrlPrefix = $f3->get('sysConfig[webroot_url_prefix]') . '/asset';
     $this->assetBasePath = '/' . $system . '/asset';
     // 注册 F3 的路由,所有 /asset 请求都由我们自己处理
     global $f3;
     $f3->route('GET /asset/*', __CLASS__ . '->fetchAsset');
     // 注册 Clear方法,用于清除 Asset 资源
     ClearHelper::registerInstanceClass(__NAMESPACE__ . '\\' . 'SaeAssetClear');
 }
コード例 #3
0
ファイル: Cache.php プロジェクト: swcug/bzfshop
 public function clearArticleCacheById($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_misc_cache');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $article_id = $validator->required('商品ID不能为空')->digits()->validate('article_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     ClearHelper::clearArticleCacheById($article_id);
     $this->addFlashMessage('商品[' . $article_id . ']页面清理成功');
     out:
     // 从这里退出
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
コード例 #4
0
ファイル: ClearCache.php プロジェクト: jackycgq/bzfshop
 public function get($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_get');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 清除商品缓存
     ClearHelper::clearGoodsCacheById($goods_id);
     $this->addFlashMessage('商品[' . $goods_id . '] 缓存清除成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
コード例 #5
0
ファイル: Promote.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goodsPromoteInfo = $f3->get('POST.goods_promote');
     if (empty($goodsPromoteInfo)) {
         goto out_fail_validate;
     }
     //安全性处理
     unset($goodsPromoteInfo['promote_id']);
     $goodsPromoteInfo['goods_id'] = $goods_id;
     // 写入到数据库
     $goodsBasicService = new GoodsBasicService();
     $goodsPromote = $goodsBasicService->loadGoodsPromoteByGoodsId($goods_id);
     $goodsPromote->copyFrom($goodsPromoteInfo);
     $goodsPromote->save();
     // 记录商品编辑日志
     $goodsLogContent = '360分类:' . $goodsPromote['360tuan_category'] . ',' . $goodsPromote['360tuan_category_end'] . "\n" . "360排序:" . $goodsPromote['360tuan_sort_order'];
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], static::$goodsLogDesc, $goodsLogContent);
     // 成功,显示商品详情
     $this->addFlashMessage('商品推广渠道保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Promote', array('goods_id' => $goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     $smarty->display('goods_edit_promote.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #6
0
ファイル: Payment.php プロジェクト: swcug/bzfshop
 /**
  * 标记订单已经支付
  *
  * @param int    $orderId 订单数字ID
  * @param int    $payId   支付类型,比如 4 代表财付通,5代表支付宝
  * @param string $payType 支付类型,比如 alipay, tenpay
  * @param string $payNo   支付方返回的交易编号,比如支付宝返回的交易号
  */
 public function markOrderInfoPay($orderId, $payId, $payType, $payNo, $note = '', $username = '******')
 {
     global $logger;
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'payId' => $payId));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $payId = $validator->required()->digits()->min(1)->validate('payId');
     $this->validate($validator);
     // 订单操作,需要保证事务
     $dbEngine = DataMapper::getDbEngine();
     try {
         $dbEngine->begin();
         // 更新 order_info
         $orderBasicService = new Order();
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         if ($orderInfo->isEmpty()) {
             $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' invalid order_id [' . $orderId . ']');
             throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
         }
         $currentGmTime = Time::gmTime();
         $orderInfo->order_status = Order::OS_CONFIRMED;
         $orderInfo->pay_status = Order::PS_PAYED;
         $orderInfo->update_time = $currentGmTime;
         $orderInfo->confirm_time = $currentGmTime;
         $orderInfo->pay_time = $currentGmTime;
         $orderInfo->pay_id = $payId;
         $orderInfo->pay_type = $payType;
         $orderInfo->pay_no = $payNo;
         $orderInfo->money_paid = $orderInfo->order_amount;
         $orderInfo->save();
         // 更新 order_goods
         $orderGoodsService = new Goods();
         $orderGoodsService->markOrderGoodsPay($orderInfo);
         if (empty($note)) {
             $note = '[' . $payType . ']付款确认';
         }
         //记录订单操作日志
         $orderActionService = new Action();
         $orderActionService->logOrderAction($orderId, 0, Order::OS_CONFIRMED, Order::PS_PAYED, Goods::OGS_PAY, $note, $username, 0, $orderInfo['shipping_status']);
         // 提交事务
         $dbEngine->commit();
         // 记录成功日志
         $logger->addLogInfo(\Core\Log\Base::INFO, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' success order_id [' . $orderId . ']');
     } catch (Exception $e) {
         // 记录异常日志
         $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', print_r($e->getTrace(), true));
         $dbEngine->rollback();
     }
     // 由于商品库存发生变化,我们需要清除商品缓存,显示新的库存
     // 注意: 这个操作绝对不能在前面的 Transaction 中操作,防止对数据库性能造成巨大影响
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     $goodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $goodsIdArray[] = $orderGoodsItem['goods_id'];
     }
     $goodsIdArray = array_unique($goodsIdArray);
     foreach ($goodsIdArray as $goodsId) {
         // 清除商品的缓存,确保库存数据显示是正确的
         ClearHelper::clearGoodsCacheById($goodsId);
     }
 }
コード例 #7
0
ファイル: Gallery.php プロジェクト: jackycgq/bzfshop
 /**
  * 从网络抓取图片进入相册
  *
  * @param $f3
  */
 public function Fetch($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     $imageUrl = $validator->required('图片地址不能为空')->validate('imageUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 抓取图片,伪装成浏览器防止被某些服务器阻止
     $webInstance = \Web::instance();
     $webInstance->engine('curl');
     $request = $webInstance->request($imageUrl, array('user_agent' => 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729)'));
     if (!$request || isset($request['http_code']) && 200 != $request['http_code']) {
         $this->addFlashMessage('抓取失败,请检查你的抓取地址');
         goto out;
     }
     // 把图片保存到 Storage 中
     $cloudStorage = CloudHelper::getCloudModule(CloudHelper::CLOUD_MODULE_STORAGE);
     // 图片文件先保存到临时文件中
     $tempSrcFilePath = $cloudStorage->getTempFilePath();
     file_put_contents($tempSrcFilePath, $request['body']);
     // 上传目录
     $dataPathRoot = $f3->get('sysConfig[data_path_root]');
     $saveFilePathRelative = 'upload/image/' . date("Y/m/d") . '/' . date("YmdHis") . '_' . rand(1, 10000) . strtolower(strrchr($imageUrl, '.'));
     // 文件上传到 Storage
     if (!$cloudStorage->moveFileToStorage($dataPathRoot, $saveFilePathRelative, $tempSrcFilePath)) {
         $this->addFlashMessage('保存文件到存储失败,失败');
         goto out;
     }
     @unlink($tempSrcFilePath);
     // 保存 goods_gallery 记录
     $imageOriginalFileRelativeName = $saveFilePathRelative;
     $pathInfoArray = pathinfo($imageOriginalFileRelativeName);
     //生成头图
     $imageFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $f3->get('sysConfig[image_width]') . 'x' . $f3->get('sysConfig[image_height]') . '.jpg';
     StorageImageHelper::resizeImage($dataPathRoot, $imageOriginalFileRelativeName, $imageFileRelativeName, $f3->get('sysConfig[image_width]'), $f3->get('sysConfig[image_height]'));
     //生成缩略图
     $imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $f3->get('sysConfig[image_thumb_width]') . 'x' . $f3->get('sysConfig[image_thumb_height]') . '.jpg';
     StorageImageHelper::resizeImage($dataPathRoot, $imageOriginalFileRelativeName, $imageThumbFileRelativeName, $f3->get('sysConfig[image_thumb_width]'), $f3->get('sysConfig[image_thumb_height]'));
     //保存 goods_gallery 记录
     $goodsGalleryService = new GoodsGalleryService();
     // ID 为0,返回一个新建的 dataMapper
     $goodsGallery = $goodsGalleryService->_loadById('goods_gallery', 'img_id=?', 0);
     $goodsGallery->goods_id = $goods_id;
     $goodsGallery->img_desc = '网络下载图片';
     $goodsGallery->img_original = $imageOriginalFileRelativeName;
     $goodsGallery->img_url = $imageFileRelativeName;
     $goodsGallery->thumb_url = $imageThumbFileRelativeName;
     $goodsGallery->save();
     $this->addFlashMessage('抓取图片成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goodsGallery->goods_id);
     out:
     // 释放资源
     unset($request);
     unset($webInstance);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Gallery', array('goods_id' => $goods_id), true));
     return;
     // 成功从这里返回
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #8
0
ファイル: MobileClear.php プロジェクト: jackycgq/bzfshop
 public function clearGoodsCacheById($goods_id)
 {
     ClearHelper::smartyClearCache($this->getThemeSmarty(), null, 'Goods|' . $goods_id);
 }
コード例 #9
0
ファイル: theme_load.php プロジェクト: jackycgq/bzfshop
 * @author QiangYu
 *
 * 主题加载文件,用于主题自身的初始化
 *
 * */
use Core\Plugin\SystemHelper;
$themeUniqueId = 'theme_manage';
$themeVersion = $f3->get('sysConfig[version]') ?: '1.0';
$themeBasePath = dirname(__FILE__);
// 增加当前主题的 autoload 路径
SystemHelper::addAutoloadPath($themeBasePath . '/Code', true);
// 加载路由定义
$f3->config($themeBasePath . '/route.cfg');
$f3->config($themeBasePath . '/route-rewrite.cfg');
// 注册一个通用的缓存清除程序
\Core\Cache\ClearHelper::registerInstanceClass('\\Core\\Cache\\ShareClear');
// 设置模板文件路径
$smarty->addTemplateDir($themeBasePath . '/Tpl/');
// 注册模块
\Core\Asset\ManagerHelper::registerModule($themeUniqueId, $themeVersion, $themeBasePath . '/Asset');
// 发布主题的资源文件
\Core\Asset\ManagerHelper::publishAsset($themeUniqueId, 'bootstrap-custom');
\Core\Asset\ManagerHelper::publishAsset($themeUniqueId, 'css');
\Core\Asset\ManagerHelper::publishAsset($themeUniqueId, 'img');
\Core\Asset\ManagerHelper::publishAsset($themeUniqueId, 'js');
// 加载 smarty 的扩展,里面有一些我们需要用到的函数
require_once dirname(__FILE__) . '/Code/smarty_helper.php';
// 注册 smarty 函数
smarty_helper_register($smarty);
// 注册资源应用函数
function smarty_helper_get_asset_url(array $paramArray, $smarty)
コード例 #10
0
ファイル: GoodsCronTask.php プロジェクト: jackycgq/bzfshop
 /**
  * 商品修改价格
  *
  * @param array $paramArray
  *
  * @return array
  */
 public function setPrice(array $paramArray)
 {
     $resultArray = array('code' => '-1', 'message' => '参数错误');
     $goods_id = abs(intval(@$paramArray['goods_id']));
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         goto out;
     }
     // 更新商品字段
     $goodsUpdateFieldArray = @$paramArray['goods'];
     foreach ($goodsUpdateFieldArray as $field => $value) {
         if (in_array($field, array('goods_id'))) {
             // 安全考虑,一些字段不允许修改
             continue;
         }
         // 价格特殊处理
         if ('shop_price' == $field) {
             $goods->shop_price = Money::toStorage($value);
             continue;
         }
         $goods->{$field} = $value;
     }
     $goods->save();
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods->goods_id);
     $resultArray = array('code' => '0', 'message' => '商品[' . $goods_id . ']属性修改成功');
     out:
     return $resultArray;
 }
コード例 #11
0
ファイル: LinkGoods.php プロジェクト: jackycgq/bzfshop
 /**
  * 增加商品关联
  *
  * @param $f3
  */
 public function ajaxAddLink($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post', true);
     // 首先做参数验证
     $validator = new Validator($f3->get('GET'));
     $errorMessage = '';
     $goods_id = $validator->required()->digits()->min(1)->validate('goods_id');
     $link_goods_id = $validator->required()->digits()->min(1)->validate('link_goods_id');
     if (!$this->validate($validator)) {
         $errorMessage = implode('|', $this->flashMessageArray);
         goto out_fail;
     }
     $dataMapper = new DataMapper('link_goods');
     $dataMapper->loadOne(array('goods_id = ? and link_goods_id = ?', $goods_id, $link_goods_id));
     // 已经关联了,不要重复关联
     if (!$dataMapper->isEmpty()) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 添加记录
     $dataMapper->goods_id = $goods_id;
     $dataMapper->link_goods_id = $link_goods_id;
     $dataMapper->admin_id = $authAdminUser['user_id'];
     $dataMapper->save();
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     // 记录商品编辑日志
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '添加商品关联', $link_goods_id);
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     out_fail:
     // 失败,返回出错信息
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
コード例 #12
0
ファイル: ShopClear.php プロジェクト: jackycgq/bzfshop
 /**
  * 清除搜索页缓存
  */
 public function clearGoodsSearch()
 {
     ClearHelper::smartyClearCache($this->getThemeSmarty(), null, 'Goods|Search');
     ClearHelper::smartyClearCache($this->getThemeSmarty(), null, 'Goods|Category');
 }
コード例 #13
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));
 }
コード例 #14
0
ファイル: Team.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goodsTeam = $f3->get('POST.goods_team');
     if (empty($goodsTeam)) {
         goto out_fail_validate;
     }
     $validator = new Validator($goodsTeam);
     $goodsTeamInfo = array();
     $goodsTeamInfo['goods_id'] = $goods_id;
     //表单数据验证、过滤
     $goodsTeamInfo['team_enable'] = $validator->digits()->validate('team_enable');
     $goodsTeamInfo['team_title'] = $validator->required('团购标题不能为空')->validate('team_title');
     $goodsTeamInfo['team_seo_keyword'] = $validator->validate('team_seo_keyword');
     $goodsTeamInfo['team_seo_description'] = $validator->validate('team_seo_description');
     $goodsTeamInfo['team_price'] = Money::toStorage($validator->validate('team_price'));
     $goodsTeamInfo['team_sort_order'] = $validator->filter('ValidatorIntValue')->validate('team_sort_order');
     $goodsTeamInfo['team_per_number'] = $validator->filter('ValidatorIntValue')->validate('team_per_number');
     $goodsTeamInfo['team_min_number'] = $validator->filter('ValidatorIntValue')->validate('team_min_number');
     $goodsTeamInfo['team_max_number'] = $validator->filter('ValidatorIntValue')->validate('team_max_number');
     $goodsTeamInfo['team_pre_number'] = $validator->filter('ValidatorIntValue')->validate('team_pre_number');
     //单独解析时间
     $team_begin_time_str = $validator->validate('team_begin_time_str');
     $teamBeginTime = Time::gmStrToTime($team_begin_time_str);
     if ($teamBeginTime <= 0) {
         $this->addFlashMessage('团购开始时间无效');
         goto out_fail_validate;
     }
     $goodsTeamInfo['team_begin_time'] = $teamBeginTime;
     $team_end_time_str = $validator->validate('team_end_time_str');
     $teamEndTime = Time::gmStrToTime($team_end_time_str);
     if ($teamEndTime <= 0) {
         $this->addFlashMessage('团购结束时间无效');
         goto out_fail_validate;
     }
     $goodsTeamInfo['team_end_time'] = $teamEndTime;
     //参数验证
     if (!$this->validate($validator)) {
         goto out_fail_validate;
     }
     // 写入到数据库
     unset($goodsTeam);
     $goodsBasicService = new GoodsBasicService();
     $goodsTeam = $goodsBasicService->loadGoodsTeamByGoodsId($goods_id);
     $goodsTeam->copyFrom($goodsTeamInfo);
     $goodsTeam->save();
     // 成功,显示商品详情
     $this->addFlashMessage('商品团购信息保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Team', array('goods_id' => $goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     $smarty->display('goods_edit_team.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #15
0
ファイル: Edit.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     $isCreateGoods = false;
     // 是否是创建新商品
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail_list_goods;
     }
     unset($validator);
     // 用户提交的商品信息做验证
     $goods = $f3->get('POST[goods]');
     if (empty($goods)) {
         goto out_fail_validate;
     }
     $validator = new Validator($goods);
     $goodsInfo = array();
     //表单数据验证、过滤
     $goodsInfo['goods_name'] = $validator->required('商品名不能为空')->validate('goods_name');
     $goodsInfo['goods_name_short'] = $validator->required('商品短标题不能为空')->validate('goods_name_short');
     $goodsInfo['keywords'] = $validator->validate('keywords');
     $goodsInfo['seo_title'] = $validator->validate('seo_title');
     $goodsInfo['seo_keyword'] = $validator->validate('seo_keyword');
     $goodsInfo['seo_description'] = $validator->validate('seo_description');
     $goodsInfo['goods_sn'] = $validator->validate('goods_sn');
     $goodsInfo['warehouse'] = $validator->validate('warehouse');
     $goodsInfo['shelf'] = $validator->validate('shelf');
     $goodsInfo['cat_id'] = $validator->required('商品分类不能为空')->filter('ValidatorIntValue')->validate('cat_id');
     // 记录管理员
     $authAdminUser = AuthHelper::getAuthUser();
     $goodsInfo['admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('admin_user_id');
     // 如果没有选择管理员,就用当前管理员
     if (empty($goodsInfo['admin_user_id'])) {
         $goodsInfo['admin_user_id'] = $authAdminUser['user_id'];
         $goodsInfo['admin_user_name'] = $authAdminUser['user_name'];
     } else {
         $adminUserService = new AdminUserService();
         $adminUser = $adminUserService->loadAdminById($goodsInfo['admin_user_id']);
         if ($adminUser->isEmpty()) {
             $this->addFlashMessage('管理员[' . $goodsInfo['admin_user_id'] . ']不存在');
             goto out_fail_validate;
         }
         $goodsInfo['admin_user_name'] = $adminUser['user_name'];
         unset($adminUser);
         unset($adminUserService);
     }
     $goodsInfo['brand_id'] = $validator->filter('ValidatorIntValue')->validate('brand_id');
     $goodsInfo['suppliers_id'] = $validator->required('供货商不能为空')->filter('ValidatorIntValue')->validate('suppliers_id');
     $goodsInfo['is_alone_sale'] = $validator->filter('ValidatorIntValue')->validate('is_alone_sale');
     $goodsInfo['is_best'] = $validator->filter('ValidatorIntValue')->validate('is_best');
     $goodsInfo['is_new'] = $validator->filter('ValidatorIntValue')->validate('is_new');
     $goodsInfo['is_hot'] = $validator->filter('ValidatorIntValue')->validate('is_hot');
     $goodsInfo['is_on_sale'] = $validator->filter('ValidatorIntValue')->validate('is_on_sale');
     $goodsInfo['market_price'] = Money::toStorage($validator->validate('market_price'));
     $goodsInfo['shop_price'] = Money::toStorage($validator->validate('shop_price'));
     $goodsInfo['shipping_fee'] = Money::toStorage($validator->validate('shipping_fee'));
     $goodsInfo['shipping_free_number'] = $validator->validate('shipping_free_number');
     $goodsInfo['goods_number'] = abs($validator->filter('ValidatorIntValue')->validate('goods_number'));
     $goodsInfo['virtual_buy_number'] = $validator->filter('ValidatorIntValue')->validate('virtual_buy_number');
     $goodsInfo['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price'));
     $goodsInfo['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee'));
     $goodsInfo['sort_order'] = $validator->validate('sort_order');
     $goodsInfo['warn_number'] = $validator->filter('ValidatorIntValue')->validate('warn_number');
     $goodsInfo['goods_brief'] = @$goods['goods_brief'];
     //不需要过滤 html
     $goodsInfo['goods_notice'] = @$goods['goods_notice'];
     //不需要过滤 html
     $goodsInfo['goods_after_service'] = @$goods['goods_after_service'];
     //不需要过滤 html
     $goodsInfo['seller_note'] = $validator->validate('seller_note');
     $goodsInfo['system_tag_list'] = Utils::makeTagString(@$goods['system_tag_list']);
     // 生成系统的 tag string
     $goodsInfo['update_time'] = Time::gmTime();
     // 商品的更新时间
     $goodsInfo['goods_desc'] = @$goods['goods_desc'];
     //不需要过滤 html
     if (!$this->validate($validator)) {
         goto out_fail_validate;
     }
     // 某些时候,我们不允许编辑直接粘贴别人网站的图片上来,所以我们需要过滤图片的域名
     $goodsDescAllowImageDomainArray = $f3->get('sysConfig[goods_desc_allow_image_domain_array]');
     if ($goodsDescAllowImageDomainArray && is_array($goodsDescAllowImageDomainArray) && !empty($goodsDescAllowImageDomainArray)) {
         $patternMatch = array();
         preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsInfo['goods_desc'], $patternMatch, PREG_SET_ORDER);
         // 检查每一个图片
         foreach ($patternMatch as $matchItem) {
             $imageUrl = $matchItem[2];
             $urlInfo = parse_url($imageUrl);
             if (!in_array(@$urlInfo['host'], $goodsDescAllowImageDomainArray)) {
                 $this->addFlashMessage('商品详情非法图片 ' . $imageUrl);
                 goto out_fail_validate;
             }
         }
     }
     // 写入到数据库
     unset($goods);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     // 判断是否是新建商品
     $isCreateGoods = $goods->isEmpty();
     if ($isCreateGoods) {
         // 权限检查
         $this->requirePrivilege('manage_goods_create');
         $goodsInfo['add_time'] = Time::gmTime();
     }
     $post_goods_sn = $validator->validate('goods_sn');
     if ($isCreateGoods && !Utils::isBlank($post_goods_sn)) {
         $goodsInfo['goods_sn'] = $post_goods_sn;
     }
     $goods->copyFrom($goodsInfo);
     $goods->save();
     // 新商品需要自动生成 goods_sn
     if ($isCreateGoods && Utils::isBlank($post_goods_sn)) {
         $goods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $goods['goods_id'];
         $goods->save();
     }
     // 取得供货商信息
     $supplierName = '';
     if (!empty($goods['suppliers_id'])) {
         $supplierUserService = new SupplierUserService();
         $supplierInfo = $supplierUserService->loadSupplierById($goods['suppliers_id']);
         if (!$supplierInfo->isEmpty()) {
             $supplierName = $supplierInfo['suppliers_name'];
         }
     }
     // 记录商品编辑日志
     $goodsLogContent = '商品编辑:[' . $goods['admin_user_id'] . ']' . $goods['admin_user_name'] . "\n" . '上架状态:' . ($goods['is_on_sale'] > 0 ? '已上架' : '未上架') . "\n" . '销售价:' . Money::toSmartyDisplay($goods['shop_price']) . '  供货价:' . Money::toSmartyDisplay($goods['suppliers_price']) . "\n" . '快递费:' . Money::toSmartyDisplay($goods['shipping_fee']) . '  供货快递费:' . Money::toSmartyDisplay($goods['suppliers_shipping_fee']) . "\n" . ($goods['shipping_free_number'] > 0 ? '' . $goods['shipping_free_number'] . "件免邮\n" : '') . '商品排序:' . $goods['sort_order'] . "\n" . '系统Tag:' . $goods['system_tag_list'] . "\n" . '供货商:[' . $goods['suppliers_id'] . ']' . $supplierName;
     $goodsLogService = new GoodsLogService();
     $goodsLogService->addGoodsLog($goods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], $isCreateGoods ? '新建商品' : static::$goodsLogDesc, $goodsLogContent);
     // 成功,显示商品详情
     $this->addFlashMessage('商品信息保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods->goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $goods->goods_id), true));
     return;
     // 参数验证失败
     out_fail_validate:
     if (!$goods_id) {
         // 新建商品验证失败
         RouteHelper::reRoute($this, '/Goods/Create');
         return;
     }
     $smarty->assign('goods', $goodsInfo);
     $smarty->display('goods_edit_edit.tpl');
     return;
     out_fail_list_goods:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #16
0
ファイル: Type.php プロジェクト: swcug/bzfshop
 public function post($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_edit_edit_post');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     unset($validator);
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($goods_id);
     if ($goods->isEmpty()) {
         $this->addFlashMessage('商品ID[' . $goods_id . ']非法');
         goto out_fail;
     }
     // 商品类型属性做验证
     $validator = new Validator($f3->get('POST'));
     //表单数据验证、过滤
     $type_id = $validator->digits()->min(1)->validate('type_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $goodsTypeService = new GoodsTypeService();
     // 商品类型发生了变化,清除所有旧的属性
     if ($goods['type_id'] != $type_id) {
         $goodsTypeService->removeAllGoodsAttrItemValue($goods_id);
         $goods->type_id = $type_id;
         $goods->save();
     }
     // 获得属性值列表
     $goodsAttrValueArray = $f3->get('POST[goodsAttrValueArray]');
     if (!empty($goodsAttrValueArray)) {
         foreach ($goodsAttrValueArray as $goodsAttrValueInfo) {
             $goodsAttrValueInfo = @json_decode($goodsAttrValueInfo, true);
             if (empty($goodsAttrValueInfo)) {
                 continue;
             }
             // 更新属性值
             $goodsAttrValue = $goodsTypeService->loadGoodsAttrById(intval($goodsAttrValueInfo['goods_attr_id']));
             $goodsAttrValue->goods_id = $goods_id;
             $goodsAttrValue->attr_item_id = $goodsAttrValueInfo['meta_id'];
             $goodsAttrValue->attr_item_value = $goodsAttrValueInfo['attr_item_value'];
             $goodsAttrValue->save();
         }
     }
     // 成功,显示商品详情
     $this->addFlashMessage('商品类型属性保存成功');
     //清除缓存,确保商品显示正确
     ClearHelper::clearGoodsCacheById($goods_id);
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Type', array('goods_id' => $goods_id), true));
     return;
     out_fail:
     RouteHelper::reRoute($this, '/Goods/Search');
 }
コード例 #17
0
ファイル: Article.php プロジェクト: jackycgq/bzfshop
 public function Edit($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $article_id = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得文章
     $articleService = new ArticleService();
     $article = $articleService->loadArticleById($article_id);
     if ($article_id > 0 && $article->isEmpty()) {
         $this->addFlashMessage('文章ID[' . $article_id . ']非法');
         goto out_fail;
     }
     // 只是显示文章内容而已
     if (Request::isRequestGet()) {
         $smarty->assign('article', $article->toArray());
         goto out_get;
     }
     // 权限检查
     $this->requirePrivilege('manage_article_article_edit');
     // 从这里开始是修改文章内容
     unset($validator);
     $articleInfoArray = $f3->get('POST[article]');
     $validator = new Validator($articleInfoArray);
     // 获得修改数据
     $inputArray = array();
     $inputArray['title'] = $validator->required()->validate('title');
     $inputArray['seo_keyword'] = $validator->validate('seo_keyword');
     $inputArray['cat_id'] = $validator->validate('cat_id');
     $inputArray['is_open'] = $validator->validate('is_open');
     $inputArray['description'] = $validator->validate('description');
     $inputArray['content'] = $articleInfoArray['content'];
     // 不要过滤 html
     if (!$this->validate($validator)) {
         goto out_get;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     // 新建文章
     if ($article_id <= 0) {
         $inputArray['admin_user_id'] = $authAdminUser['user_id'];
         $inputArray['admin_user_name'] = $authAdminUser['user_name'];
         $inputArray['add_time'] = Time::gmTime();
     }
     // 文章更新
     $inputArray['update_user_id'] = $authAdminUser['user_id'];
     $inputArray['update_user_name'] = $authAdminUser['user_name'];
     $inputArray['update_time'] = Time::gmTime();
     // 保存修改
     $article->copyFrom($inputArray);
     $article->save();
     // 清除文章缓存
     ClearHelper::clearArticleCacheById($article->article_id);
     $this->addFlashMessage('文章保存成功');
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Article/Edit', array('article_id' => $article->article_id), true));
     return;
     // POST 从这里退出
     out_get:
     // GET 从这里退出
     $smarty->display('article_article_edit.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Article/Article/Search');
 }
コード例 #18
0
ファイル: Category.php プロジェクト: jackycgq/bzfshop
 /**
  * 删除一个分类
  *
  * @param $f3
  */
 public function Remove($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_category_edit');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->required()->digits()->min(1)->validate('meta_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     $goodsCategoryService = new GoodsCategoryService();
     $category = $goodsCategoryService->loadCategoryById($meta_id);
     if ($category->isEmpty()) {
         $this->addFlashMessage('分类不存在');
         goto out;
     }
     // 检查当前分类是否存在子分类
     $childArray = $goodsCategoryService->fetchCategoryArray($category['meta_id'], true);
     if (!empty($childArray)) {
         $this->addFlashMessage('当前分类有子分类,不能删除');
         goto out;
     }
     // 检查当前分类是否有商品
     $categoryGoodsCountArray = $goodsCategoryService->calcCategoryGoodsCount();
     foreach ($categoryGoodsCountArray as $categoryItem) {
         if ($meta_id == $categoryItem['cat_id'] && $categoryItem['goods_count'] > 0) {
             $this->addFlashMessage('当前分类有商品,不能删除');
             goto out;
         }
     }
     // 删除分类
     $category->erase();
     // 清除商品分类的缓存
     ClearHelper::clearGoodsCategory();
     $this->addFlashMessage('分类删除成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }