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, '/'); // 返回首页 }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password'); $input['email'] = $validator->validate('email'); $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错 $p_captcha = Utils::filterAlnumStr($p_captcha); // 需要跳转回去的地址 $returnUrl = $validator->validate('returnUrl'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']'); goto out_fail; } $userService = new UserService(); // 检查用户是否已经注册 $isUserExist = $userService->isUserExist($input['user_name'], $input['email']); if ($isUserExist) { $this->addFlashMessage($isUserExist . '已经存在'); goto out_fail; } // 注册用户 $user = $userService->registerUser($input); if (!$user) { $this->addFlashMessage('用户注册失败,请稍后刷新页面重试'); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); $this->addFlashMessage("注册成功"); if ($returnUrl) { header('Location:' . $returnUrl); return; } else { // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); } return; // 这里正常返回 out_fail: // 失败,从这里出口 $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time()))); $smarty->display('user_register.tpl', 'User|Register|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name'); $input['password'] = $validator->required('密码不能为空')->validate('password'); $p_captcha = $validator->required('验证码不能为空')->validate('captcha'); // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错 $p_captcha = Utils::filterAlnumStr($p_captcha); // 需要跳转回去的地址 $returnUrl = $validator->validate('returnUrl'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']'); goto out_fail; } $userService = new UserService(); // 验证用户登陆 $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']); if (!$user) { $this->addFlashMessage("登陆失败,用户名、密码错误"); goto out_fail; } // 记录用户的登陆信息 $userInfo = $user->toArray(); unset($userInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($userInfo, 'normal'); $this->addFlashMessage("登陆成功"); if ($returnUrl) { header('Location:' . $returnUrl); return; } else { // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); } return; // 这里正常返回 out_fail: // 失败从这里出口 $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time()))); $smarty->display('user_login.tpl', 'User|Login|post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['oldpassword'] = $validator->validate('oldpassword'); $input['password'] = $validator->validate('password'); $input['email'] = $validator->validate('email'); $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone'); // 用户打算修改密码 if (!Utils::isBlank($input['password'])) { $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword'); } // 提供的旧密码,但是新密码为空 if (!Utils::isBlank($input['oldpassword'])) { $validator->required('新密码不能为空')->validate('password'); } if (!$this->validate($validator)) { goto out_fail; } $userInfo = AuthHelper::getAuthUser(); $userService = new UserService(); $user = $userService->loadUserById($userInfo['user_id']); if (!$user) { // 非法用户,应该让它自动登陆出去 $this->addFlashMessage('非法登陆用户'); RouteHelper::reRoute($this, '/User/Logout', false); } // 用户打算修改密码,但是旧密码不对 if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) { $this->addFlashMessage('旧密码不对'); goto out_fail; } // 更新数据 unset($input['oldpassword']); $userService->updateUser($user, $input); // 更新认证记录 AuthHelper::removeAuthUser(); AuthHelper::saveAuthUser($user->toArray()); $this->addFlashMessage('资料更新成功'); RouteHelper::reRoute($this, '/My/Profile'); return; // 这里正常返回 out_fail: // 失败返回 $smarty->display('my_profile.tpl', 'post'); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['phone'] = $validator->validate('phone'); $input['address'] = $validator->validate('address'); $input['oldpassword'] = $validator->validate('oldpassword'); $input['password'] = $validator->validate('password'); // 用户打算修改密码 if (!Utils::isBlank($input['password'])) { $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword'); } // 提供的旧密码,但是新密码为空 if (!Utils::isBlank($input['oldpassword'])) { $validator->required('新密码不能为空')->validate('password'); } if (!$this->validate($validator)) { goto out; } $authSupplierUser = AuthHelper::getAuthUser(); $supplierUserService = new SupplierUserService(); // 验证用户登陆 $supplierUser = $supplierUserService->loadSupplierById($authSupplierUser['suppliers_id']); if ($supplierUser->isEmpty()) { $this->addFlashMessage("非法登陆用户"); RouteHelper::reRoute($this, '/User/Logout', false); } // 用户打算修改密码,但是旧密码不对 if (!empty($input['password']) && !$supplierUserService->verifyPassword($authSupplierUser['suppliers_id'], $input['oldpassword'])) { $this->addFlashMessage('旧密码不对'); goto out; } // 更新数据 unset($input['oldpassword']); $supplierUserService->updateSupplier($supplierUser, $input); // 记录用户的登陆信息 $supplierUserInfo = $supplierUser->toArray(); unset($supplierUserInfo['password']); // 不要记录密码 AuthHelper::saveAuthUser($supplierUserInfo); $this->addFlashMessage("修改资料成功"); $smarty->assign($supplierUserInfo); out: // 从这里出去 $smarty->display('my_profile.tpl'); }
public function get($f3) { // 清除客户端所有数据 ClientData::clearClientData(); // 清除服务器端数据 AuthHelper::removeAuthUser(); $f3->clear('SESSION'); $this->addFlashMessage('成功退出登陆'); $backUrl = RouteHelper::getRefer(); if (Utils::isBlank($backUrl)) { // 没有来路域名则返回首页 $backUrl = '/'; } // 刷新当前页面 RouteHelper::reRoute($this, $backUrl, false); }
public function get($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_theme_adv_configure'); global $smarty; $shop_index_advblock_json_data = json_decode(ShopThemePlugin::getOptionValue('shop_index_advblock_json_data'), true); if (!empty($shop_index_advblock_json_data)) { // 生成随机的 id 号给 html 使用 foreach ($shop_index_advblock_json_data as &$advBlockObject) { $advBlockObject['id'] = Utils::generateRandomHtmlId(); foreach ($advBlockObject['advBlockImageArray'] as &$advBlockImage) { $advBlockImage['id'] = Utils::generateRandomHtmlId(); } } $smarty->assign('shop_index_advblock_json_data', $shop_index_advblock_json_data); } $smarty->display('theme_shop_advshop_block.tpl', 'get'); }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Shop|Index'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_shop_index')); if ($smarty->isCached('shop_index.tpl', $smartyCacheId)) { goto out_display; } // 滑动图片广告 $shop_index_adv_slider = json_decode(bzf_get_option_value('shop_index_adv_slider'), true); if (!empty($shop_index_adv_slider)) { $smarty->assign('shop_index_adv_slider', $shop_index_adv_slider); } // 今日新品 $recommandGoodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $this->searchExtraCondArray, array(array('goods_id', 'desc')), 0, 40); if (!empty($recommandGoodsArray)) { $smarty->assign('recommandGoodsArray', $recommandGoodsArray); } // 广告 advBlock $shop_index_advblock_json_data = json_decode(bzf_get_option_value('shop_index_advblock_json_data'), true); if (!empty($shop_index_advblock_json_data)) { // 生成随机的 id 号给 html 使用 foreach ($shop_index_advblock_json_data as &$advBlockObject) { $advBlockObject['id'] = Utils::generateRandomHtmlId(); foreach ($advBlockObject['advBlockImageArray'] as &$advBlockImage) { $advBlockImage['id'] = Utils::generateRandomHtmlId(); } } $smarty->assign('shop_index_advblock_json_data', $shop_index_advblock_json_data); } // 移动端对应的 URL,用于百度页面适配 $smarty->assign('currentPageMobileUrl', RouteHelper::makeShopSystemUrl(PluginHelper::SYSTEM_MOBILE, '/')); out_display: $smarty->assign('seo_title', $smarty->getTemplateVars('seo_title') . ',' . $f3->get('HOST')); $smarty->display('shop_index.tpl', $smartyCacheId); }
/** * 生成商品查看的 toolbar,用户可以查看 团购、商城、移动 * * @param array $paramArray * @param $smarty * * @return string */ function smarty_helper_function_goods_view_toolbar(array $paramArray, $smarty) { $goods_id = isset($paramArray['goods_id']) ? intval($paramArray['goods_id']) : 0; $system_tag_list = isset($paramArray['system_tag_list']) ? $paramArray['system_tag_list'] : ''; // 参数不对,没有东西可以输出 if ($goods_id <= 0) { return 'goods_id [' . $goods_id . '] 非法'; } // 如果不提供 system_tag_list 参数,我们从数据库查询 if (!array_key_exists('system_tag_list', $paramArray)) { static $goodsBasicService = null; if (!$goodsBasicService) { $goodsBasicService = new GoodsBasicService(); } // 缓存 5 秒钟 $goods = $goodsBasicService->loadGoodsById($goods_id, 5); if (!$goods->isEmpty()) { $system_tag_list = $goods['system_tag_list']; } else { return 'goods_id [' . $goods_id . '] 非法'; } } // 解析成 System Array $systemArray = \Core\Helper\Utility\Utils::parseTagString($system_tag_list); $htmlContent = '<div class="btn-group">'; $system_url_base_array = json_decode(\Theme\Manage\ManageThemePlugin::getOptionValue('system_url_base_array'), true); if (!empty($system_url_base_array)) { foreach ($systemArray as $system) { if (!array_key_exists($system, $system_url_base_array)) { // 不存在的系统,跳过 continue; } $themeSystem = $system_url_base_array[$system]; $htmlContent .= '<a title="查看' . $themeSystem['name'] . '商品详情" target="_blank" href="' . RouteHelper::makeShopSystemUrl($system, '/Goods/View', array('goods_id' => $goods_id)) . '" class="btn btn-mini btn-info">' . $themeSystem['name'] . '</a>'; } } $htmlContent .= '</div>'; return htmlspecialchars($htmlContent); }
/** * 对字符串做 mask 防止泄露关键信息,比如显示用户名 * * @param $string * * @return string */ function smarty_helper_modifier_mask_string($string) { return \Core\Helper\Utility\Utils::maskString($string); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $input = array(); $input['user_real_name'] = $validator->required('管理员名称不能为空')->validate('user_real_name'); $input['oldpassword'] = $validator->validate('oldpassword'); $input['password'] = $validator->validate('password'); $input['user_desc'] = $validator->validate('user_desc'); // 用户打算修改密码 if (!Utils::isBlank($input['password'])) { $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword'); if ($f3->get('sysConfig[is_demo]')) { $this->addFlashMessage('演示系统不允许修改密码'); goto out; } } // 提供的旧密码,但是新密码为空 if (!Utils::isBlank($input['oldpassword'])) { $validator->required('新密码不能为空')->validate('password'); } if (!$this->validate($validator)) { goto out; } $authAdminUser = AuthHelper::getAuthUser(); $adminUserService = new AdminUserService(); // 验证用户登陆 $adminUser = $adminUserService->loadAdminById($authAdminUser['user_id']); if ($adminUser->isEmpty()) { $this->addFlashMessage("非法登陆用户"); RouteHelper::reRoute($this, '/User/Logout', false); } // 用户打算修改密码,但是旧密码不对 if (!empty($input['password']) && !$adminUserService->verifyPassword($authAdminUser['user_id'], $input['oldpassword'])) { $this->addFlashMessage('旧密码不对'); goto out; } // 更新数据 unset($input['oldpassword']); $adminUserService->updateAdmin($adminUser, $input); // 记录用户的登陆信息 $adminUserInfo = $adminUser->toArray(); unset($adminUserInfo['password']); // 不要记录密码 // 取得用户的角色权限 $adminUserInfo['role_action_list'] = ''; if ($adminUserInfo['role_id'] > 0) { $metaRoleService = new MetaRoleService(); $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']); if (!$role->isEmpty()) { // 赋值角色权限 $adminUserInfo['role_action_list'] = $role['meta_data']; } } AuthHelper::saveAuthUser($adminUserInfo); $this->addFlashMessage("修改资料成功"); $smarty->assign($adminUserInfo); out: // 从这里出去 $smarty->display('my_profile.tpl'); }
/** * 取得对应分类下面商品的总数,用于分页显示 * * @return int 商品总数 * * @param int $categoryId 分类的ID * @param int $level 取得多少层,子分类有可能很深,我们只取有限层次 * @param string $systemTag 系统标记 * @param int $ttl 缓存时间 */ public function countGoodsArray($categoryId, $level, $systemTag, $ttl = 0) { // 参数验证 $validator = new Validator(array('categoryId' => $categoryId, 'level' => $level, 'systemTag' => $systemTag, 'ttl' => $ttl)); $categoryId = $validator->digits()->min(0)->validate('categoryId'); $level = $validator->required()->digits()->min(1)->validate('level'); $systemTag = $validator->validate('systemTag'); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); $childrenIdArray = $this->fetchCategoryChildrenIdArray($categoryId, $level, $ttl); $childrenIdArray[] = $categoryId; // 加入父节点 $queryCondArray = array(); $queryCondArray[] = array('is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1'); // 构建 SQL 的 in 语句, cat_id in (100,20,30) $queryCondArray[] = array(QueryBuilder::buildInCondition('cat_id', $childrenIdArray, \PDO::PARAM_INT)); if (!empty($systemTag)) { $queryCondArray[] = array('system_tag_list like ? ', '%' . Utils::makeTagString(array($systemTag)) . '%'); } $dataMapper = new DataMapper('goods'); return $dataMapper->count(QueryBuilder::buildAndFilter($queryCondArray), null, $ttl); }
public function getAssetUrl($moduleUniqueId, $relativeAssetPath) { $targetPath = $this->assetBasePath . DIRECTORY_SEPARATOR . $this->getModulePublishRelativeDir($moduleUniqueId) . DIRECTORY_SEPARATOR . $relativeAssetPath; // 简单的取根目录的地址 if (empty($relativeAssetPath)) { goto out; } // 智能发布资源 $this->publishAsset($moduleUniqueId, $relativeAssetPath); $targetModifyTime = filemtime($targetPath); out: $hashParam = ''; if ($this->fileHashUrl && is_file($targetPath)) { if (!$this->fileHashName) { // 只有文件才启用 hash 参数,其它不启用 $hashParam = $relativeAssetPath . '?hash=' . $targetModifyTime; } else { // hash 文件名,而不是在后面添加参数 $pathInfo = pathinfo($relativeAssetPath); $hashFile = $this->assetBasePath . DIRECTORY_SEPARATOR . $this->getModulePublishRelativeDir($moduleUniqueId) . DIRECTORY_SEPARATOR . $pathInfo['dirname'] . DIRECTORY_SEPARATOR . $targetModifyTime . '.' . $pathInfo['basename']; // hash 文件不存在,复制一个 if (!is_file($hashFile)) { Utils::copyFile($targetPath, $hashFile); } // 指向 hash 文件名 $hashParam = $pathInfo['dirname'] . '/' . $targetModifyTime . '.' . $pathInfo['basename']; } } else { $hashParam = $relativeAssetPath; } return $this->assetUrlPrefix . '/' . $this->getModulePublishRelativeDir($moduleUniqueId) . '/' . $hashParam; }
/** * * @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); } }
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, '/'); // 返回首页 }
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'); }
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'); }
/** * 复制一个文件,返回复制后文件的相对路径 * * @param string $dataPathRoot * @param string $fileRelativePath * * @return string */ public static function duplicateFile($dataPathRoot, $fileRelativePath) { $sourceFilePath = $dataPathRoot . '/' . $fileRelativePath; if (!is_file($sourceFilePath) || !file_exists($sourceFilePath)) { return ''; } $pathInfoArray = pathinfo($sourceFilePath); $baseFileName = $pathInfoArray['basename']; // 截断文件名,防止文件名太长了 if (strlen($baseFileName) > 12) { $baseFileName = substr($baseFileName, strlen($baseFileName) - 12); } $targetFilePath = $pathInfoArray['dirname'] . '/' . date("YmdHis") . '_' . rand(1, 10000) . '_' . $baseFileName; // 复制文件 Utils::copyFile($sourceFilePath, $targetFilePath); // 去掉 dataRootPath,返回相对路径 return str_replace($dataPathRoot . '/', '', $targetFilePath); }
/** * * 批量下载订单 * */ public function Download($f3) { // 权限检查 $this->requirePrivilege('manage_order_excel_download'); // 参数验证 $validator = new Validator($f3->get('GET')); //表单查询 $formQuery = array(); $formQuery['suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id'); $formQuery['goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); if (empty($formQuery['suppliers_id']) && empty($formQuery['goods_id'])) { $this->addFlashMessage('供货商ID 和 商品ID 不能同时为空'); goto out_fail; } //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $formQuery['pay_time'] = array($payTimeStart, $payTimeEnd); //额外退款,时间 $extraRefundTimeStartStr = $validator->validate('extra_refund_time_start'); $extraRefundTimeStart = Time::gmStrToTime($extraRefundTimeStartStr) ?: null; $extraRefundTimeEndStr = $validator->validate('extra_refund_time_end'); $extraRefundTimeEnd = Time::gmStrToTime($extraRefundTimeEndStr) ?: null; $formQuery['extra_refund_time'] = array($extraRefundTimeStart, $extraRefundTimeEnd); if (!$this->validate($validator)) { goto out_fail; } if (Utils::isBlank($formQuery['suppliers_id']) || (Utils::isBlank($payTimeStart) || Utils::isBlank($payTimeEnd)) && (Utils::isBlank($extraRefundTimeStart) || Utils::isBlank($extraRefundTimeEnd))) { $this->addFlashMessage('按照供货商下载订单必须提供时间段参数'); goto out_fail; } $condArray = array(); $condArray[] = array('oi.order_id = og.order_id'); $condArray[] = array('order_goods_status > 0'); // 表单查询 $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery)); $orderGoodsService = new OrderGoodsService(); $orderGoodsArray = $orderGoodsService->_fetchArray(array('order_info' => 'oi', 'order_goods' => 'og'), 'og.*, oi.add_time, oi.pay_time, oi.consignee, oi.mobile, oi.tel, oi.zipcode, oi.postscript, oi.address', $condArray, array('order' => 'oi.order_id asc, og.rec_id asc, og.goods_id asc'), 0, $f3->get('sysConfig[max_query_record_count]'), 0); //最多限制 max_query_record_count 条记录 // 转换显示格式 foreach ($orderGoodsArray as &$orderGoodsItem) { $orderGoodsItem['add_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['add_time'], 'Y-m-d H:i:s'); $orderGoodsItem['pay_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['pay_time'], 'Y-m-d H:i:s'); $orderGoodsItem['extra_refund_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['extra_refund_time'], 'Y-m-d H:i:s'); $orderGoodsItem['suppliers_total_price'] = $orderGoodsItem['suppliers_price'] * $orderGoodsItem['goods_number']; $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']]; } unset($orderGoodsItem); require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php'; // 设置Excel缓存,防止数据太多拖死了程序 \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp); // 导出为 Excel 格式 $objPHPExcel = new \PHPExcel(); // 设置工作 sheet $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); // 取得快递公司列表 $expressService = new ExpressService(); $expressArray = $expressService->fetchExpressArray(); //输出快递公司参考表 $this->outputExpressArray($activeSheet, $expressArray); //释放内存 unset($expressArray); unset($expressService); // 格式化数据 $rowIndex = 1; $lastOrderId = 0; $orderGoodsArraySize = count($orderGoodsArray); // 输出头部信息 $this->outputHeaderRow($activeSheet, $rowIndex); $rowIndex++; // 换行 for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) { // 取得这行数据 $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex]; if ($lastOrderId != $orderGoodsItem['order_id']) { $lastOrderId = $orderGoodsItem['order_id']; // 不同的订单,需要特殊处理 $rowIndex += 2; // 跳过 2 行 } // 输出数据 //$this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem, array('goods_name', 'goods_id')); $this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem); $rowIndex++; // 换行 } $fileName = '订单下载_' . $formQuery['goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s'); // 输出为 Excel5 格式 $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel); header('Content-Type: application/vnd.ms-excel'); if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"'); } else { header('Content-Disposition: attachment; filename="' . $fileName . '.xls"'); } header('Cache-Control: max-age=0'); $objWriter->save('php://output'); //输出到浏览器 die; out_fail: // 失败,打印错误消息 $flashMessageArray = $this->flashMessageArray; foreach ($flashMessageArray as $flashMessage) { echo $flashMessage . '<br />'; } }
/** * 是否是已经有记住的回跳 URL * * @return boolean * */ public static function hasRememberUrl() { global $f3; $uniqueKey = $f3->get('SESSION.' . Route::getUniqueKey()); return !Utils::isBlank($uniqueKey); }
/** * 下载 拣货单 * * @param $f3 * @param $validator */ public function downloadJianHuo($f3, $validator) { $outputColumnArray = array('warehouse' => '仓库', 'shelf' => '货架', 'goods_sn' => '货号', 'goods_name' => '商品名', 'goods_attr' => '属性规格', 'goods_number' => '数量', 'suppliers_price' => '供货单价', 'total_suppliers_price' => '供货总价', 'total_suppliers_shipping_fee' => '供货快递'); $outputColumnMoneyArray = array('suppliers_price', 'total_suppliers_price', 'total_suppliers_shipping_fee'); //表单查询 $searchFormQuery = array(); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); // 快递信息 $expressType = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('expressType'); switch ($expressType) { case 1: $searchFormQuery['og.shipping_id'] = 0; break; case 2: $searchFormQuery['og.shipping_id'] = array('>', 0); break; default: break; } if (!$this->validate($validator)) { goto out_fail; } if (Utils::isBlank($searchFormQuery['og.goods_id']) && Utils::isBlank($payTimeStart)) { $this->addFlashMessage('查询参数非法'); goto out_fail; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); $searchFormQuery['og.suppliers_id'] = $authSupplierUser['suppliers_id']; $searchParamArray = array(); $searchParamArray[] = array('oi.order_id = og.order_id'); //供货商,只查看有效订单,其它订单不显示 $searchParamArray[] = array('og.order_goods_status > 0'); // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr, sum(og.goods_number) as goods_number, sum(og.suppliers_price * og.goods_number) as total_suppliers_price, sum(og.suppliers_shipping_fee) as total_suppliers_shipping_fee', $searchParamArray, array(array('og.warehouse', 'asc'), array('og.shelf', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr'); // 没有数据,退出 if (empty($orderGoodsArray)) { goto out; } // 查询订单对应的商品 $goodsIdArray = array(); foreach ($orderGoodsArray as $orderGoodsItem) { $goodsIdArray[] = $orderGoodsItem['goods_id']; } $goodsIdArray = array_unique($goodsIdArray); $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'goods_id, goods_name_short, suppliers_price', array(array(QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT))), null, 0, $f3->get('sysConfig[max_query_record_count]')); $goodsIdToGoodsMap = array(); foreach ($goodsArray as $goodsItem) { $goodsIdToGoodsMap[$goodsItem['goods_id']] = $goodsItem; } require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php'; // 设置Excel缓存,防止数据太多拖死了程序 \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp); // 导出为 Excel 格式 $objPHPExcel = new \PHPExcel(); // 设置工作 sheet $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); // 格式化数据 $rowIndex = 1; $lastWarehouseShelf = null; $orderGoodsArraySize = count($orderGoodsArray); // 输出头部信息 $colIndex = 1; foreach ($outputColumnArray as $value) { $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $value); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFont()->setBold(true); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFB0B0B0'); $colIndex++; } $rowIndex++; // 换行 for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) { // 取得这行数据 $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex]; // 填入商品数据 $orderGoodsItem['goods_name'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['goods_name_short']; $orderGoodsItem['suppliers_price'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['suppliers_price']; if ($lastWarehouseShelf != $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']) { $lastWarehouseShelf = $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']; // 不同的取货地点,需要特殊处理 $rowIndex += 2; // 跳过 2 行 } // 输出一行数据 $colIndex = 1; foreach ($outputColumnArray as $key => $value) { $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : ''; if (!in_array($key, $outputColumnMoneyArray)) { $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING); } else { // 转换价格显示 $cellValue = Money::toSmartyDisplay($cellValue); } $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); $colIndex++; } $rowIndex++; // 换行 } $fileName = '拣货单_' . $searchFormQuery['og.goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s'); // 输出为 Excel5 格式 $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel); header('Content-Type: application/vnd.ms-excel'); if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"'); } else { header('Content-Disposition: attachment; filename="' . $fileName . '.xls"'); } header('Cache-Control: max-age=0'); $objWriter->save('php://output'); //输出到浏览器 die; out: echo "没有数据"; die; out_fail: // 失败,打印错误消息 $flashMessageArray = $this->flashMessageArray; foreach ($flashMessageArray as $flashMessage) { echo $flashMessage . '<br />'; } }
/** * 管理员详情显示 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_account_admin_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $user_id = $validator->digits()->min(1)->validate('user_id'); $user_id = $user_id > 0 ? $user_id : 0; if (!$this->validate($validator)) { goto out; } // 查询管理员信息 $adminUserService = new AdminUserService(); $adminUser = $adminUserService->loadAdminById($user_id); if (0 != $user_id && $adminUser->isEmpty()) { // 不存在的管理员 $this->addFlashMessage('管理员不存在'); goto out; } if ($adminUser->isEmpty()) { // 新建管理员 $this->requirePrivilege('manage_account_admin_create'); } else { if (AdminUserService::verifyPrivilege(AdminUserService::privilegeAll, $adminUser['action_list'])) { // 拥有最高权限的管理员只有他自己能编辑自己 $authAdminUser = AuthHelper::getAuthUser(); if ($authAdminUser['user_id'] != $adminUser['user_id']) { $this->addFlashMessage('超级管理员只有他自己能操作自己的信息'); RouteHelper::reRoute($this, '/Account/Admin/ListUser'); } } } if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } // 权限检查 $this->requirePrivilege('manage_account_admin_edit_post'); // 用户提交了更新请求,这里做管理员信息更新 // 参数验证 $inputArray = array(); $validator = new Validator($f3->get('POST')); $inputArray['user_name'] = $validator->required()->minlength(3)->validate('user_name'); $inputArray['disable'] = $validator->filter('ValidatorIntValue')->validate('disable'); $inputArray['user_real_name'] = $validator->required()->minlength(2)->validate('user_real_name'); $inputArray['is_kefu'] = $validator->filter('ValidatorIntValue')->validate('is_kefu'); $inputArray['user_desc'] = $validator->validate('user_desc'); $password = $validator->validate('password'); if (!Utils::isBlank($password)) { // 权限检查 $this->requirePrivilege('manage_account_admin_edit_change_account_password'); $inputArray['password'] = $password; if ($f3->get('sysConfig[is_demo]')) { $this->addFlashMessage('演示系统不允许修改密码'); goto out; } } if (!$this->validate($validator)) { goto out; } // 确认管理员账号没有重复 if (!empty($inputArray['user_name'])) { $tmpAdminUser = $adminUserService->loadAdminByUserName($inputArray['user_name']); if (0 == $user_id && !$tmpAdminUser->isEmpty() || !$tmpAdminUser->isEmpty() && $tmpAdminUser['user_id'] != $user_id) { $this->addFlashMessage('管理员账号 ' . $inputArray['user_name'] . ' 已经存在'); goto out; } } if ($adminUser['user_name'] != $inputArray['user_name']) { // 管理员账号发生修改,检查权限 $this->requirePrivilege('manage_account_admin_edit_change_account_password'); } // 更新管理员信息 $adminUserService->updateAdmin($adminUser, $inputArray); $this->addFlashMessage('管理员信息更新成功'); out_display: //给 smarty 模板赋值 $smarty->assign($adminUser->toArray()); out: $smarty->display('account_admin_edit.tpl'); }
/** * 更新用户信息到数据库 * * @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; }
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); }
/** * 供货商详情显示 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_account_supplier_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $suppliers_id = $validator->digits()->min(1)->validate('suppliers_id'); $suppliers_id = $suppliers_id > 0 ? $suppliers_id : 0; if (!$this->validate($validator)) { goto out; } // 查询供货商信息 $supplierUserService = new SupplierUserService(); $supplier = $supplierUserService->loadSupplierById($suppliers_id); if (0 != $suppliers_id && $supplier->isEmpty()) { // 不存在的供货商 $this->addFlashMessage('供货商不存在'); goto out; } if ($supplier->isEmpty()) { // 新建供货商账号,权限检查 $this->requirePrivilege('manage_account_supplier_create'); } if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } // 用户提交了更新请求,这里做供货商信息更新 // 权限检查 $this->requirePrivilege('manage_account_supplier_edit_post'); // 参数验证 $inputArray = array(); $validator = new Validator($f3->get('POST')); $inputArray['suppliers_account'] = $validator->required()->minlength(4)->validate('suppliers_account'); $inputArray['suppliers_name'] = $validator->required()->minlength(4)->validate('suppliers_name'); $inputArray['phone'] = $validator->validate('phone'); $inputArray['address'] = $validator->validate('address'); $inputArray['suppliers_desc'] = $validator->validate('suppliers_desc'); $password = $validator->validate('password'); if (!Utils::isBlank($password)) { // 权限检查 $this->requirePrivilege('manage_account_supplier_edit_change_account_password'); $inputArray['password'] = $password; } if (!$this->validate($validator)) { goto out; } // 确认供货商账号没有重复 if (!empty($inputArray['suppliers_account'])) { $tmpSupplierUser = $supplierUserService->loadSupplierBySupplierAccount($inputArray['suppliers_account']); if (0 == $suppliers_id && !$tmpSupplierUser->isEmpty() || !$tmpSupplierUser->isEmpty() && $tmpSupplierUser['suppliers_id'] != $suppliers_id) { $this->addFlashMessage('供货商账号 ' . $inputArray['suppliers_account'] . ' 已经存在'); goto out; } } // 如果供货商账号发生了变化 if ($supplier['suppliers_account'] != $inputArray['suppliers_account']) { // 权限检查 $this->requirePrivilege('manage_account_supplier_edit_change_account_password'); } // 更新供货商信息 $supplierUserService->updateSupplier($supplier, $inputArray); $this->addFlashMessage('供货商信息更新成功'); out_display: //给 smarty 模板赋值 $smarty->assign($supplier->toArray()); out: $smarty->display('account_supplier_edit.tpl'); }
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'); }
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 就不会被执行了 }