public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $notifyUrl = $validator->required()->validate('notifyUrl'); $this->validate($validator); //设置订单 ID $this->orderId = $orderId; // 取得订单 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderId); if (empty($orderInfo) || $orderInfo->isEmpty()) { throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']'); } $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'] . '|WAP'; // 构造要请求的参数数组,无需改动 $parameterCreate = array("req_data" => '<direct_trade_create_req><subject>' . $desc . '</subject><out_trade_no>' . $orderInfo['order_sn'] . '_' . $orderInfo['order_id'] . '</out_trade_no><total_fee>' . Money::toDisplay($orderInfo['order_amount'], 2) . "</total_fee><seller_account_name>" . $this->account . "</seller_account_name><notify_url>" . $notifyUrl . "</notify_url><out_user>" . $orderInfo['user_id'] . "</out_user><merchant_url></merchant_url>" . "<call_back_url>" . $returnUrl . "</call_back_url></direct_trade_create_req>", "service" => $this->configServiceCreate, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "req_id" => date("Ymdhms"), "format" => $this->configFormat, "v" => $this->configVersion); // 首先申请 Token $result = $this->callAlipayWapGateway($this->buildRequestLinkData($parameterCreate)); // 调用GetToken方法,并返回token $token = $this->getToken($result); if (!$token) { printLog($this->getGatewayType() . ' 获取 token 失败'); return null; } // 构造要请求的参数数组,无需改动 $parameterExecute = array("req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>", "service" => $this->configServiceExecute, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "call_back_url" => $returnUrl, "format" => $this->configFormat, "v" => $this->configVersion); return $this->configGateway . $this->buildRequestLinkData($parameterExecute); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_plugin_configure'); global $smarty; // 参数验证 $validator = new Validator($f3->get('POST')); $yiqifacps_rate_web = $validator->required()->validate('yiqifacps_rate_web'); $yiqifacps_rate_mobile = $validator->required()->validate('yiqifacps_rate_mobile'); $qqcaibei_key1 = $validator->required()->validate('qqcaibei_key1'); $qqcaibei_key2 = $validator->required()->validate('qqcaibei_key2'); $yiqifacps_duration = $validator->required()->digits()->min(1)->validate('yiqifacps_duration'); if (!$this->validate($validator)) { goto out_display; } // 保存设置 YiqifaCpsPlugin::saveOptionValue('yiqifacps_rate_web', $yiqifacps_rate_web); YiqifaCpsPlugin::saveOptionValue('yiqifacps_rate_mobile', $yiqifacps_rate_mobile); YiqifaCpsPlugin::saveOptionValue('yiqifacps_duration', $yiqifacps_duration); YiqifaCpsPlugin::saveOptionValue('qqcaibei_key1', $qqcaibei_key1); YiqifaCpsPlugin::saveOptionValue('qqcaibei_key2', $qqcaibei_key2); $this->addFlashMessage('保存设置成功'); out_display: $smarty->display('yiqifacps_configure.tpl', 'post'); }
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'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); goto out_fail; } $adminService = new AdminUserService(); // 验证用户登陆 $admin = $adminService->doAuthAdmin($input['user_name'], $input['user_name'], $input['password']); if (!$admin) { $this->addFlashMessage("登陆失败,用户名、密码错误"); goto out_fail; } // 记录用户的登陆信息 $adminUserInfo = $admin->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); try { // 记录用户登录日志 AdminLog::logAdminOperate('user.login', '用户登录', 'IP:' . $f3->get('IP')); } catch (\Exception $e) { // do nothing } $this->addFlashMessage("登陆成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败从这里入口 $smarty->display('user_login.tpl', 'User|Login|post'); }
/** * 更新用户的第一个地址信息 * * @return object 返回新的地址对象 * * @param int $userId 用户数字 ID * @param array $addressInfo 包含地址信息的数组 */ public function updateUserFirstAddress($userId, array $addressInfo) { // 参数验证 $validator = new Validator(array('userId' => $userId, 'addressInfo' => $addressInfo)); $userId = $validator->required()->digits()->min(1)->validate('userId'); $addressInfo = $validator->required()->requireArray(false)->validate('addressInfo'); $this->validate($validator); $firstAddress = $this->loadUserFirstAddress($userId); // 补充、修正数据 $addressInfo['user_id'] = $userId; $firstAddress->copyFrom($addressInfo); $firstAddress->save(); return $firstAddress; }
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'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); 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'); // 设置用户名在网页显示 ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true); ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name); $this->addFlashMessage("注册成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败,从这里出口 $smarty->display('user_login.tpl', 'User|Register|post'); }
public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $this->validate($validator); $this->orderId = $orderId; //设置订单 ID // 自己调用 notify 完成订单支付 $this->doNotifyUrl(null); return $returnUrl . '?order_id=' . $orderId; //返回 returnUrl }
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 Edit($f3) { // 权限检查 $this->requirePrivilege('manage_goods_brand_listbrand'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $brand_id = $validator->digits()->min(1)->validate('brand_id'); if (!$brand_id) { $brand_id = 0; } $goodsBrandService = new GoodsBrandService(); $goodsBrand = $goodsBrandService->loadBrandById($brand_id); if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } unset($validator); $validator = new Validator($f3->get('POST')); $goodsBrand->brand_name = $validator->required()->validate('brand_name'); $goodsBrand->brand_desc = $validator->required()->validate('brand_desc'); $goodsBrand->brand_logo = $validator->validate('brand_logo'); $goodsBrand->is_custom = $validator->digits()->filter('ValidatorIntValue')->validate('is_custom'); $goodsBrand->custom_page = $f3->get('POST[custom_page]'); if (!$this->validate($validator)) { goto out_display; } $goodsBrand->save(); if (0 == $brand_id) { $this->addFlashMessage('新建商品品牌成功'); } else { $this->addFlashMessage('更新商品品牌成功'); } // 记录管理员日志 AdminLog::logAdminOperate('goods.brand.edit', '编辑品牌', $goodsBrand->brand_name); out_display: // 新建的品牌,reRoute 到编辑页面 if (!$brand_id) { RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Brand/Edit', array('brand_id' => $goodsBrand->brand_id), true)); } //给 smarty 模板赋值 $smarty->assign($goodsBrand->toArray()); $smarty->display('goods_brand_edit.tpl'); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Goods/Brand/ListBrand'); }
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 ListAttrItem($f3) { // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->required()->digits()->min(1)->validate('typeId'); $errorMessage = ''; if (!$this->validate($validator)) { $errorMessage = implode('|', $this->flashMessageArray); goto out_fail; } // 检查缓存 $cacheKey = md5(__FILE__ . '\\' . __METHOD__ . '\\' . $meta_id); $attrItemArray = $f3->get($cacheKey); if (!empty($attrItemArray)) { goto out; } $goodsTypeService = new GoodsTypeService(); $attrItemArray = $goodsTypeService->fetchGoodsTypeAttrItemArray($meta_id); $f3->set($cacheKey, $attrItemArray, 300); //缓存 5 分钟 out: $f3->expire(60); // 客户端缓存 1 分钟 Ajax::header(); echo Ajax::buildResult(null, null, $attrItemArray); return; out_fail: Ajax::header(); echo Ajax::buildResult(-1, $errorMessage, null); }
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'); $pageNo = $validator->digits()->min(0)->validate('pageNo'); if (!$this->validate($validator)) { goto out_fail; } // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|' . $goods_id . '|AjaxGoodsComment_' . $pageNo; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_view')); if ($smarty->isCached('ajax_goodscomment.tpl', $smartyCacheId)) { goto out_display; } $this->preparePage($goods_id, $pageNo); out_display: $f3->expire(600); // 让客户端缓存 10 分钟 $smarty->display('ajax_goodscomment.tpl', $smartyCacheId); return; out_fail: // output nothing return; }
/** * 根据 goods_id 得到一个商品的图片集 * * @param $f3 */ public function GalleryThumb($f3) { // 参数验证 $validator = new Validator($f3->get('GET')); $errorMessage = ''; $goods_id = $validator->required()->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); if (!$this->validate($validator)) { $errorMessage = implode('|', $this->flashMessageArray); goto out_fail; } $goodsGalleryService = new GoodsGalleryService(); $galleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsId($goods_id); $thumImageList = array(); foreach ($galleryArray as $galleryItem) { $thumImageList[] = array('img_id' => $galleryItem['img_id'], 'thumb_url' => RouteHelper::makeImageUrl($galleryItem['thumb_url'])); } out: Ajax::header(); echo Ajax::buildResult(null, null, $thumImageList); return; out_fail: // 失败,返回出错信息 Ajax::header(); echo Ajax::buildResult(-1, $errorMessage, null); }
/** * 根据组名取得商品属性组 * * @param string $groupName * * @return \Core\Modal\SqlMapper */ public function loadGoodsAttrGroupByName($groupName) { // 参数验证 $validator = new Validator(array('groupName' => $groupName)); $groupName = $validator->required()->validate('groupName'); $this->validate($validator); return $this->loadMetaByTypeAndName(GoodsAttrGroup::META_TYPE, $groupName); }
/** * 取得商品的图像集合 * * @return array 图像集合 array(array(图片1), array(图片2)) * * @param int $goodsId 商品的 ID 号 * @param int $ttl 缓存时间 */ public function fetchGoodsGalleryArrayByGoodsId($goodsId, $ttl = 0) { // 参数验证 $validator = new Validator(array('goodsId' => $goodsId)); $goodsId = $validator->required()->digits()->validate('goodsId'); $this->validate($validator); return $this->_fetchArray('goods_gallery', '*', array(array('goods_id =?', $goodsId)), array('order' => 'img_sort_order desc, img_id asc'), 0, 0, $ttl); }
public function countGoodsLogArray($goods_id, $ttl = 0) { // 参数验证 $validator = new Validator(array('goods_id' => $goods_id)); $goods_id = $validator->required()->digits()->min(1)->validate('goods_id'); $this->validate($validator); return $this->_countArray('goods_log', array(array('goods_id = ?', $goods_id)), null, $ttl); }
/** * 更新或者新建一个快递公司 * * @param $f3 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_misc_express_edit'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->digits()->validate('meta_id'); $meta_id = $meta_id ?: 0; // 加载 快递信息 $expressService = new ExpressService(); $expressInfo = $expressService->loadMetaById($meta_id); if (Request::isRequestGet()) { goto out_assign; } // 安全性检查 if ($meta_id > 0) { if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo->meta_type) { $this->addFlashMessage('非法ID[' . $meta_id . ']'); goto out; } } unset($validator); $validator = new Validator($f3->get('POST')); $inputArray = array(); $inputArray['meta_type'] = ExpressService::META_TYPE; $inputArray['meta_name'] = $validator->required()->validate('meta_name'); $inputArray['meta_ename'] = $validator->required()->validate('meta_ename'); $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order'); $inputArray['meta_status'] = $validator->digits()->validate('meta_status'); $inputArray['meta_desc'] = $validator->validate('meta_desc'); if (!$this->validate($validator)) { goto out; } // 保存 $expressInfo->copyFrom($inputArray); $expressInfo->save(); $this->addFlashMessage('快递信息保存成功'); // POST 成功从这里退出 RouteHelper::reRoute($this, RouteHelper::makeUrl('/Misc/Express/Edit', array('meta_id' => $expressInfo->meta_id), true)); return; out_assign: $smarty->assign($expressInfo->toArray()); out: $smarty->display('misc_express_edit.tpl'); }
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 ListChildTreeNodeAllStr($f3) { // 参数验证 $validator = new Validator($f3->get('GET')); $errorMessage = ''; $treeKey = $validator->required()->validate('treeKey'); $parentId = $validator->digits()->min(0)->validate('parentId'); $parentId = $parentId ?: 0; // 用户也可以通过 treeNodeName 来做查询 $treeNodeName = $validator->validate('treeNodeName'); if (!$this->validate($validator)) { $errorMessage = implode('|', $this->flashMessageArray); goto out_fail; } // 检查缓存 $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $treeKey . '\\' . $parentId . '\\' . $treeNodeName); $outputArray = $f3->get($cacheKey); if (!empty($outputArray)) { goto out; } $metaTreeService = new MetaTreeService(); if (!empty($treeNodeName)) { $treeNode = $metaTreeService->loadTreeNodeWithTreeKeyAndName($treeKey, $treeNodeName); if (!$treeNode->isEmpty()) { $parentId = $treeNode['meta_id']; } } // 取得树形的层级结构 $treeNodeArray = $metaTreeService->fetchChildTreeNodeArrayAll($treeKey, $parentId); // 构建显示输出 $outputArray = array(); function buildHierarchyArray(&$outputArray, $treeNodeArray, $separator = '') { $hierarchySeparator = '---------->'; foreach ($treeNodeArray as $treeNodeItem) { $outputItem = array(); $outputItem['meta_id'] = $treeNodeItem['meta_id']; $outputItem['meta_name'] = $treeNodeItem['meta_name']; $outputItem['display_text'] = $separator . $treeNodeItem['meta_name']; $outputArray[] = $outputItem; // 有子节点,递归建立子节点 if (isset($treeNodeItem['child_list'])) { buildHierarchyArray($outputArray, $treeNodeItem['child_list'], $separator . $hierarchySeparator); } } } buildHierarchyArray($outputArray, $treeNodeArray, ''); $f3->set($cacheKey, $outputArray, 600); //缓存 10 分钟 out: Ajax::header(); echo Ajax::buildResult(null, null, $outputArray); return; out_fail: // 失败,返回出错信息 Ajax::header(); echo Ajax::buildResult(-1, $errorMessage, null); }
/** * 取得供货商下面商品的总数,用于分页显示 * * @return int 商品总数 * * @param int $suppliers_id 供货商的ID * @param int $ttl 缓存时间 */ public function countSupplierGoodsArray($suppliers_id, $ttl = 0) { // 参数验证 $validator = new Validator(array('suppliers_id' => $suppliers_id, 'ttl' => $ttl)); $suppliers_id = $validator->required()->digits()->min(1)->validate('suppliers_id'); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); return $this->_countArray('goods', array(array('suppliers_id = ? AND is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1', $suppliers_id)), null, $ttl); }
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'); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_plugin_configure'); global $smarty; // 参数验证 $validator = new Validator($f3->get('POST')); $partner_id = $validator->required()->validate('partner_id'); $partner_key = $validator->required()->validate('partner_key'); if (!$this->validate($validator)) { goto out_display; } // 保存设置 TenpayPlugin::saveOptionValue('partner_id', $partner_id); TenpayPlugin::saveOptionValue('partner_key', $partner_key); $this->addFlashMessage('保存设置成功'); out_display: $smarty->display('tenpay_configure.tpl', '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'); if (!$this->validate($validator)) { goto out_fail; } // 检查验证码是否有效 $captchaController = new \Controller\Image\Captcha(); if (!$captchaController->validateCaptcha($p_captcha)) { $this->addFlashMessage("验证码错误"); 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'); // 设置用户名在网页显示 ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true); ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name); $this->addFlashMessage("登陆成功"); // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页 RouteHelper::jumpBack($this, '/', true); return; // 这里正常返回 out_fail: // 失败从这里入口 $smarty->display('user_login.tpl', 'User|Login|post'); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_get'); // 参数验证 $validator = new Validator($f3->get('POST')); $goods_id = $validator->required('商品ID不能为空')->validate('goods_id'); $action = $validator->required('操作不能为空')->validate('action'); //任务时间 $taskTimeStr = $validator->required('必须选择时间')->validate('task_time'); $taskTime = Time::gmStrToTime($taskTimeStr) ?: null; if (!$this->validate($validator)) { goto out; } $authAdminUser = AuthHelper::getAuthUser(); // 添加 Cron 任务 CronHelper::addCronTask($authAdminUser['user_name'] . '[' . $authAdminUser['user_id'] . ']', GoodsCronTask::$task_name, @GoodsCronTask::$actionDesc[$action] . '[' . $goods_id . ']', '\\Core\\Cron\\GoodsCronTask', $taskTime, $f3->get('POST'), $goods_id); $this->addFlashMessage('成功添加定时任务'); out: RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Cron', array('goods_id' => $goods_id), true)); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_plugin_configure'); global $smarty; // 参数验证 $validator = new Validator($f3->get('POST')); // shop $shop_dev360auth_app_id = $validator->required()->digits()->validate('shop_dev360auth_app_id'); $shop_dev360auth_app_key = $validator->required()->validate('shop_dev360auth_app_key'); $shop_dev360auth_app_secrect = $validator->required()->validate('shop_dev360auth_app_secrect'); // aimeidaren $aimeidaren_dev360auth_app_id = $validator->required()->digits()->validate('aimeidaren_dev360auth_app_id'); $aimeidaren_dev360auth_app_key = $validator->required()->validate('aimeidaren_dev360auth_app_key'); $aimeidaren_dev360auth_app_secrect = $validator->required()->validate('aimeidaren_dev360auth_app_secrect'); if (!$this->validate($validator)) { goto out_display; } // 保存设置 shop Dev360AuthPlugin::saveOptionValue('shop_dev360auth_app_id', $shop_dev360auth_app_id); Dev360AuthPlugin::saveOptionValue('shop_dev360auth_app_key', $shop_dev360auth_app_key); Dev360AuthPlugin::saveOptionValue('shop_dev360auth_app_secrect', $shop_dev360auth_app_secrect); // 保存设置 aimeidaren Dev360AuthPlugin::saveOptionValue('aimeidaren_dev360auth_app_id', $aimeidaren_dev360auth_app_id); Dev360AuthPlugin::saveOptionValue('aimeidaren_dev360auth_app_key', $aimeidaren_dev360auth_app_key); Dev360AuthPlugin::saveOptionValue('aimeidaren_dev360auth_app_secrect', $aimeidaren_dev360auth_app_secrect); $this->addFlashMessage('保存设置成功'); out_display: $smarty->display('dev360auth_configure.tpl', 'post'); }
/** * 检查 order_goods 对应的评论记录是否已经存在 * * @param int $rec_id * * @return bool */ public function isOrderGoodsCommentExist($rec_id) { if (!$rec_id) { return false; } // 参数验证 $validator = new Validator(array('rec_id' => $rec_id)); $rec_id = $validator->required()->digits()->min(1)->validate('rec_id'); $this->validate($validator); $dataMapper = new DataMapper('goods_comment'); $dataMapper->loadOne(array('rec_id = ?', $rec_id), null, 0); return !$dataMapper->isEmpty(); }
public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $notifyUrl = $validator->required()->validate('notifyUrl'); $this->validate($validator); //设置订单 ID $this->orderId = $orderId; // 取得订单 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderId); if (empty($orderInfo) || $orderInfo->isEmpty()) { throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']'); } $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id']; //构造要请求的参数数组,无需改动 $parameter = array("service" => "create_direct_pay_by_user", "partner" => $this->partnerId, "payment_type" => 1, "notify_url" => $notifyUrl, "return_url" => $returnUrl, "seller_email" => $this->account, "out_trade_no" => $orderInfo['order_sn'] . '_' . $orderInfo['order_id'], "subject" => $desc, "total_fee" => Money::toDisplay($orderInfo['order_amount'], 2), "body" => $desc, "show_url" => '', "anti_phishing_key" => '', "exter_invoke_ip" => '', "_input_charset" => 'utf-8'); //建立请求 $alipaySubmit = new AlipaySubmit($this->alipayConfig); return $alipaySubmit->buildRequestUrl($parameter); }
public function post($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('POST')); $addressInfo = array(); $addressInfo['consignee'] = $validator->required('姓名不能为空')->validate('consignee'); $addressInfo['address'] = $validator->required('地址不能为空')->validate('address'); $addressInfo['mobile'] = $validator->required('手机号码不能为空')->digits('手机号码格式不正确')->validate('mobile'); $addressInfo['tel'] = $validator->validate('tel'); $addressInfo['zipcode'] = $validator->digits('邮编格式不正确')->validate('zipcode'); if (!$this->validate($validator)) { goto out_fail; } $userInfo = AuthHelper::getAuthUser(); $userAddressService = new UserAddressService(); $userAddressService->updateUserFirstAddress($userInfo['user_id'], $addressInfo); $this->addFlashMessage('地址更新成功'); RouteHelper::reRoute($this, '/My/Address'); return; out_fail: // 失败返回 $smarty->display('my_address.tpl', 'post'); }
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); }