public function get($f3) { // 设置 order_refer 记录,记录在客户端 $orderRefer = array(); // 检查彩贝的记录 $caibeiRefer = $f3->get('SESSION[yiqifa_caibei_order_refer]'); if (!empty($caibeiRefer)) { $orderRefer = $caibeiRefer; unset($orderRefer['refer_host']); // 去掉彩贝的 refer_host } // 清除彩贝记录 $f3->set('SESSION[yiqifa_caibei_order_refer]', null); $orderRefer['utm_source'] = 'YIQIFACPS'; // 保存额外的 亿起发 参数 $validator = new Validator($_REQUEST); $referParamArray = array(); $referParamArray['src'] = $validator->validate('src'); $referParamArray['cid'] = $validator->validate('cid'); $referParamArray['wi'] = $validator->validate('wi'); $referParamArray['channel'] = $validator->validate('channel'); $orderRefer['refer_param'] = json_encode($referParamArray); //设置 cookie ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration')); // 页面跳转到商品 $url = $validator->validate('url'); $redirectUrl = empty($url) ? '/' : $url; RouteHelper::reRoute($this, $redirectUrl); return; }
/** * 列出结算列表 * * @param $f3 */ public function ListSettle($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; // 表单查询 $formQuery = array(); //结算时间 $settleTimeStartStr = $validator->validate('settle_time_start'); $settleTimeStart = Time::gmStrToTime($settleTimeStartStr) ?: null; $settleTimeEndStr = $validator->validate('settle_time_end'); $settleTimeEnd = Time::gmStrToTime($settleTimeEndStr) ?: null; $formQuery['create_time'] = array($settleTimeStart, $settleTimeEnd); //是否已经付款 $is_pay = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('is_pay'); switch ($is_pay) { case 1: $formQuery['pay_time'] = 0; break; case 2: $formQuery['pay_time'] = array($is_pay, null); break; default: break; } // 供货商只能查看自己的结算历史 $authSupplierUser = AuthHelper::getAuthUser(); $formQuery['suppliers_id'] = $authSupplierUser['suppliers_id']; // 构建查询条件 $condArray = null; if (!empty($formQuery)) { $condArray = QueryBuilder::buildQueryCondArray($formQuery); } // 查询结算列表 $orderSettleService = new OrderSettleService(); $totalCount = $orderSettleService->countOrderSettleArray($condArray); if ($totalCount <= 0) { // 没商品,可以直接退出了 goto out; } // 页数超过最大值,返回 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Order/Settle/ListSettle'); } // 结算列表 $orderSettleArray = $orderSettleService->fetchOrderSettleArray($condArray, $pageNo * $pageSize, $pageSize); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('orderSettleArray', $orderSettleArray); out: $smarty->display('order_settle_listsettle.tpl'); }
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 get($f3) { global $smarty; // 权限检查 $this->requirePrivilege('manage_misc_cron'); // 参数验证 $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 : 20; //查询条件 $searchFormQuery = array(); $searchFormQuery['task_name'] = $validator->validate('task_name'); $searchFormQuery['task_desc'] = $validator->validate('task_desc'); $returnCode = $validator->digits()->filter('ValidatorIntValue')->validate('return_code'); if (0 === $returnCode) { $searchFormQuery['task_run_time'] = array('>', 0); $searchFormQuery['return_code'] = 0; } elseif ($returnCode > 0) { $searchFormQuery['task_run_time'] = array('>', 0); $searchFormQuery['return_code'] = array('<>', 0); } else { // do nothing } //任务时间 $taskTimeStartStr = $validator->validate('task_time_start'); $taskTimeStart = Time::gmStrToTime($taskTimeStartStr) ?: null; $taskTimeEndStr = $validator->validate('task_time_end'); $taskTimeEnd = Time::gmStrToTime($taskTimeEndStr) ?: null; $searchFormQuery['task_time'] = array($taskTimeStart, $taskTimeEnd); if (!$this->validate($validator)) { goto out_display; } // 建立查询条件 $searchParamArray = QueryBuilder::buildQueryCondArray($searchFormQuery); $cronTaskService = new CronTaskService(); $totalCount = $cronTaskService->countCronTaskArray($searchParamArray); if ($totalCount <= 0) { // 没任务,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Misc/Cron'); } $cronTaskArray = $cronTaskService->fetchCronTaskArray($searchParamArray, $pageNo * $pageSize, $pageSize); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('cronTaskArray', $cronTaskArray); out_display: $smarty->display('misc_cron.tpl'); }
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'); }
/** * * 根据某些查询条件取得商品的列表 * * @param $f3 */ public function Search($f3) { // 参数验证 $validator = new Validator($f3->get('GET')); $errorMessage = ''; $searchFormQuery = array(); $searchFormQuery['is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale'); $searchFormQuery['goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id'); $searchFormQuery['goods_name'] = $validator->validate('goods_name'); $searchFormQuery['cat_id'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('cat_id'); if (!$this->validate($validator)) { $errorMessage = implode('|', $this->flashMessageArray); goto out_fail; } // 建立查询条件 $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery); // 商品列表 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, array(array('goods_id', 'desc')), 0, 25); out: Ajax::header(); echo Ajax::buildResult(null, null, $goodsArray); return; out_fail: // 失败,返回出错信息 Ajax::header(); echo Ajax::buildResult(-1, $errorMessage, null); }
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); }
/** * 角色详情显示 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_account_role_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->digits()->min(1)->validate('meta_id'); $meta_id = $meta_id > 0 ? $meta_id : 0; if (!$this->validate($validator)) { goto out; } // 查询角色信息 $metaRoleService = new MetaRoleService(); $role = $metaRoleService->loadRoleById($meta_id); if (0 != $meta_id && $role->isEmpty()) { // 不存在的角色 $this->addFlashMessage('角色不存在'); goto out; } if ($role->isEmpty()) { // 新建角色 $this->requirePrivilege('manage_account_role_create'); } if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } // 权限检查 $this->requirePrivilege('manage_account_role_edit_post'); // 用户提交了更新请求,这里做角色信息更新 $validator = new Validator($f3->get('POST')); $metaRoleService->saveRole($meta_id, $validator->validate('meta_name'), $validator->validate('meta_desc'), $role['meta_data']); if (0 == $meta_id) { $this->addFlashMessage('成功新建角色'); } else { $this->addFlashMessage('角色信息更新成功'); } out_display: //给 smarty 模板赋值 $smarty->assign($role->toArray()); out: $smarty->display('account_role_edit.tpl'); }
/** * 更新或者新建一个分类 * * @param $f3 */ public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_goods_category_edit'); // 参数验证 $validator = new Validator($f3->get('POST')); $meta_id = $validator->digits()->validate('meta_id'); $meta_id = $meta_id ?: 0; $meta_name = $validator->validate('meta_name'); $parent_meta_id = $validator->digits()->validate('parent_meta_id'); $meta_sort_order = $validator->digits()->validate('meta_sort_order'); $meta_status = $validator->digits()->validate('meta_status'); // 筛选属性 $filterTypeIdArray = $validator->validate('filterTypeIdArray'); $filterAttrItemIdArray = $validator->validate('filterAttrItemIdArray'); if (!$this->validate($validator)) { goto out; } if ($parent_meta_id > 0 && $parent_meta_id == $meta_id) { $this->addFlashMessage('父分类不能指向自己'); goto out; } // 构造筛选属性结构 $filterArray = array(); $count = min(count($filterTypeIdArray), count($filterAttrItemIdArray)); for ($index = 0; $index < $count; $index++) { $typeId = abs(intval($filterTypeIdArray[$index])); $attrItemId = abs(intval($filterAttrItemIdArray[$index])); if ($typeId <= 0 || $attrItemId <= 0) { // 非法值跳过 continue; } $filterArray[] = array('typeId' => $typeId, 'attrItemId' => $attrItemId); } $meta_data = array('filterArray' => $filterArray); $goodsCategoryService = new GoodsCategoryService(); $goodsCategoryService->saveCategoryById($meta_id, $parent_meta_id, $meta_name, null, json_encode($meta_data), $meta_sort_order, $meta_status); // 清除商品分类的缓存 ClearHelper::clearGoodsCategory(); $this->addFlashMessage('商品分类保存成功'); out: RouteHelper::reRoute($this, '/Goods/Category'); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_theme_adv_configure'); // 参数验证 $validator = new Validator($f3->get('POST')); // slider 广告设置 $imageArray = $validator->validate('image'); $urlArray = $validator->validate('url'); $targetArray = $validator->validate('target'); $imageSize = is_array($imageArray) ? count($imageArray) : 0; $shop_index_adv_slider = array(); // 组织数据结构 for ($index = 0; $index < $imageSize; $index++) { $shop_index_adv_slider[] = array('image' => $imageArray[$index], 'url' => $urlArray[$index], 'target' => $targetArray[$index]); } ShopThemePlugin::saveOptionValue('shop_index_adv_slider', json_encode($shop_index_adv_slider)); // 清除 /Shop/Index 页面 $shopClear = new ShopClear(); $shopClear->clearHomePage(); $this->addFlashMessage('保存设置成功'); RouteHelper::reRoute($this, '/Theme/Shop/AdvShopSlider'); }
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 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'); }
/** * 更新或者新建一个快递公司 * * @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) { // 上传路径 $dataPathRoot = $f3->get('sysConfig[data_path_root]'); if (empty($dataPathRoot)) { $dataPathRoot = $f3->get('BASE') . '/data'; } // 上传路径对应的 URL 前缀 $dataUrlPrefix = $f3->get('sysConfig[data_url_prefix]'); if (empty($dataUrlPrefix)) { $dataUrlPrefix = $f3->get('BASE') . '/data'; } // 操作 $validator = new Validator($f3->get('GET')); $action = $validator->validate('action'); $kindEditor = new \KindEditor\KindEditor(); $kindEditor->doAction($dataPathRoot, $dataUrlPrefix, $action); }
public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_article_category_edit'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->digits()->validate('meta_id'); $meta_id = $meta_id ?: 0; // 加载 分类信息 $articleCategoryService = new ArticleCategoryService(); $articleCategory = $articleCategoryService->loadArticleCategoryById($meta_id); if (Request::isRequestGet()) { goto out_assign; } // 安全性检查 if ($meta_id > 0) { if ($articleCategory->isEmpty() || ArticleCategoryService::META_TYPE != $articleCategory->meta_type) { $this->addFlashMessage('非法ID[' . $meta_id . ']'); goto out; } } unset($validator); $validator = new Validator($f3->get('POST')); $inputArray = array(); $inputArray['meta_type'] = ArticleCategoryService::META_TYPE; $inputArray['meta_name'] = $validator->required()->validate('meta_name'); $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order'); $inputArray['meta_desc'] = $validator->validate('meta_desc'); if (!$this->validate($validator)) { goto out; } // 保存 $articleCategory->copyFrom($inputArray); $articleCategory->save(); $this->addFlashMessage('分类信息保存成功'); // POST 成功从这里退出 RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Category/Edit', array('meta_id' => $articleCategory->meta_id), true)); return; out_assign: $smarty->assign($articleCategory->toArray()); out: $smarty->display('article_category_edit.tpl'); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_plugin_configure'); global $smarty; // 参数验证 $validator = new Validator($f3->get('POST')); $etaofeed_seller_id = $validator->required()->validate('etaofeed_seller_id'); $etaofeed_goods_url_extra_param = $validator->validate('etaofeed_goods_url_extra_param'); if (!$this->validate($validator)) { goto out_display; } // 保存设置 EtaoFeedPlugin::saveOptionValue('etaofeed_seller_id', $etaofeed_seller_id); EtaoFeedPlugin::saveOptionValue('etaofeed_goods_url_extra_param', $etaofeed_goods_url_extra_param); $this->addFlashMessage('保存设置成功'); out_display: $smarty->display('etaofeed_configure.tpl', 'post'); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_theme_adv_configure'); // 参数验证 $validator = new Validator($f3->get('POST')); // 广告设置 json 数据,由 JavaScript 打包发送过来 $shop_index_advblock_json_data = $validator->validate('shop_index_advblock_json_data'); $jsonObject = json_decode($shop_index_advblock_json_data, true); if (empty($jsonObject)) { $shop_index_advblock_json_data = null; } ShopThemePlugin::saveOptionValue('shop_index_advblock_json_data', $shop_index_advblock_json_data); // 清除 /Shop/Index 页面 $shopClear = new ShopClear(); $shopClear->clearHomePage(); $this->addFlashMessage('保存设置成功'); RouteHelper::reRoute($this, '/Theme/Shop/AdvShopBlock'); }
/** * 取得 goods 和 goods_promote 的 join 结果,同时取得 goods 对应的所有商品 * 由于这个函数的代价非常大(几千个商品,上万个图片),所以我们一定要做缓存 * * @return array array('goods' => $goodsArray, 'goodsIdToGalleryArray' => $goodsIdToGalleryArray) * * @param array $queryCondArray 查询条件 * @param string $sort * @param int $offset * @param int $limit * @param int $ttl 缓存时间 * * @return array */ public function fetchGoodsGalleryPromote($queryCondArray, $sort, $offset, $limit, $ttl = 0) { // 首先做参数验证 $validator = new Validator(array('sort' => $sort, 'offset' => $offset, 'limit' => $limit, 'ttl' => $ttl)); $offset = $validator->digits()->min(0)->validate('offset'); $limit = $validator->digits()->min(0)->validate('limit'); $ttl = $validator->digits()->min(0)->validate('ttl'); $sort = $validator->validate('sort'); // 查询商品信息 $condArray = array(); $condArray[] = array('g.goods_id = gp.goods_id'); $formQuery = array(); $formQuery['is_delete'] = 0; $formQuery['is_on_sale'] = 1; $formQuery['is_alone_sale'] = 1; if (!empty($queryCondArray)) { $condArray = array_merge($condArray, $queryCondArray); } $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery)); $goodsArray = $this->_fetchArray(array('goods' => 'g', 'goods_promote' => 'gp'), 'g.system_tag_list, g.goods_name, g.goods_name_short, g.brand_id, g.goods_number, g.market_price, g.shop_price, g.cat_id' . ', g.sort_order, g.goods_brief, g.seo_keyword, g.goods_notice , g.virtual_buy_number, g.user_pay_number' . ', gp.* ', $condArray, array('order' => $sort), $offset, $limit, $ttl); // options // 如果没有数据就退出 if (empty($goodsArray)) { return array(); } // 查询商品图片 $goodsIdArray = array(); foreach ($goodsArray as $goodsItem) { $goodsIdArray[] = $goodsItem['goods_id']; } $goodsGalleryService = new GoodsGalleryService(); $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray, $ttl); // 建立 goods_id --> goods_gallery 的反查表 $goodsIdToGalleryArray = array(); foreach ($goodsGalleryArray as $goodsGalleryItem) { if (!isset($goodsIdToGalleryArray[$goodsGalleryItem['goods_id']])) { $goodsIdToGalleryArray[$goodsGalleryItem['goods_id']] = array(); } $goodsIdToGalleryArray[$goodsGalleryItem['goods_id']][] = $goodsGalleryItem; } return array('goods' => $goodsArray, 'goodsIdToGalleryArray' => $goodsIdToGalleryArray); }
/** * 更新商品的库存 * * @param int $goods_id * @param string $specStr 商品规格 * @param int $goods_number 库存 */ public function updateGoodsGoodsNumber($goods_id, $specStr, $goods_number) { // 参数验证 $validator = new Validator(array('goods_id' => $goods_id, 'specStr' => $specStr, 'goods_number' => $goods_number)); $goods_id = $validator->required()->digits()->min(1)->validate('goods_id'); $specStr = $validator->validate('specStr'); $goods_number = $validator->required()->digits()->min(1)->validate('goods_number'); $this->validate($validator); $goodsBasicService = new GoodsBasicService(); $goods = $goodsBasicService->loadGoodsById($goods_id); if ($goods->isEmpty()) { // 不存在的商品,退出 return; } // 商品有规格选择,我们需要计算规格的库存 if (!empty($goods->goods_spec)) { $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithJson($goods->goods_spec); $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($specStr); if (empty($goodsSpecDataArray)) { goto no_spec_goods_calc; // 不正常的商品规格选择,按照普通购买计算库存 } // 计算剩余库存 $specGoodsNumber = @$goodsSpecDataArray['goods_number']; $specGoodsNumber -= $goods_number; $specGoodsNumber = $specGoodsNumber >= 0 ? $specGoodsNumber : 0; // 确保库存不能为负数 // 更新商品规格对应的库存 $goodsSpecService->setGoodsSpecGoodsNumber($specStr, $specGoodsNumber); $goods->goods_spec = $goodsSpecService->getJsonStr(); $goods->save(); return; } no_spec_goods_calc: // 普通商品,没有商品规格选择 $goods->goods_number -= $goods_number; // 确保库存不能是负数 $goods->goods_number = $goods->goods_number >= 0 ? $goods->goods_number : 0; $goods->save(); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_plugin_theme_configure'); // 参数验证 $validator = new Validator($f3->get('POST')); foreach ($this->optionKeyArray as $optionKey) { if (in_array($optionKey, $this->optionKeyNoFilterArray)) { $optionValue = $f3->get('POST[' . $optionKey . ']'); } else { $optionValue = $validator->validate($optionKey); } MobileThemePlugin::saveOptionValue($optionKey, $optionValue); } // 清除所有缓存 $cacheClear = new MobileClear(); $cacheClear->clearAllCache(); $this->addFlashMessage('保存设置成功'); out_display: global $smarty; $smarty->display('theme_mobile_configure.tpl', 'post'); }
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'); }
/** * 取得用户的 account_log 列表 * * @return array 格式 array(array('key'=>'value', 'key'=>'value', ...)) * * @param int $userId 用户 ID * @param string $filter 查询条件 * @param int $offset 用于分页的开始 >= 0 * @param int $limit 每页多少条 * @param int $ttl 缓存多少时间 */ public function fetchUserAccountLogArray($userId, $filter, $offset = 0, $limit = 10, $ttl = 0) { // 参数验证 $validator = new Validator(array('userId' => $userId, 'filter' => $filter, 'offset' => $offset, 'limit' => $limit, 'ttl' => $ttl)); $userId = $validator->required()->digits()->min(1)->validate('userId'); $filter = $validator->validate('filter'); $offset = $validator->digits()->min(0)->validate('offset'); $limit = $validator->required()->digits()->min(1)->validate('limit'); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); // 需要联表查询 $accountLog = new DataMapper('account_log'); if (!empty($filter)) { $filter .= ' and user_id = ?'; } else { $filter = 'user_id = ?'; } return $accountLog->find(array($filter, $userId), array('order' => 'log_id desc', 'offset' => $offset, 'limit' => $limit), $ttl); }
public function post($f3) { // 参数验证 $validator = new Validator($f3->get('POST')); $dbHost = $validator->validate('dbHost'); $dbPort = $validator->validate('dbPort'); $dbName = $validator->validate('dbName'); // 系统通用的配置 $sysConfig = $validator->validate('sysConfig'); if (!$this->validate($validator)) { goto out_fail; } try { // 对云平台要做特殊处理 if (CloudHelper::CLOUD_ENGINE_SAE == CloudHelper::$currentEngineStr) { $dbPdo = 'mysql:host=' . SAE_MYSQL_HOST_M . ';port=' . SAE_MYSQL_PORT . ';dbname=' . SAE_MYSQL_DB; $sysConfig['db_username'] = SAE_MYSQL_USER; $sysConfig['db_password'] = SAE_MYSQL_PASS; goto import_data; } if (CloudHelper::CLOUD_ENGINE_BAE3 == CloudHelper::$currentEngineStr) { $sysConfig['db_username'] = $sysConfig['bae3_api_key']; $sysConfig['db_password'] = $sysConfig['bae3_secret_key']; } // 检查是否需要创建数据库 $dbPdo = 'mysql:host=' . $dbHost . ';port=' . $dbPort; $dbEngine = new \Core\Modal\DbEngine($dbPdo, $sysConfig['db_username'], $sysConfig['db_password']); // 检查数据库是否存在,从而确定我们是否应该新建一个数据库 $shouldCreateDatabase = true; $databaseArray = $dbEngine->exec('SHOW DATABASES'); foreach ($databaseArray as $databaseItem) { if ($databaseItem['Database'] == $dbName) { $shouldCreateDatabase = false; break; } } if ($shouldCreateDatabase) { // 在这里创建一个新的数据库 $dbEngine->exec('CREATE DATABASE ' . $dbName); } // 重新初始化数据库连接 unset($dbPdo); unset($dbEngine); $dbPdo = 'mysql:host=' . $dbHost . ';port=' . $dbPort . ';dbname=' . $dbName; // 更新配置文件 env.cfg $filePath = INSTALL_PATH . '/../protected/Config/env.cfg'; $fileContent = file_get_contents($filePath); $fileContent = preg_replace('/sysConfig\\[env\\]="[^"]*"/', 'sysConfig[env]="prod"', $fileContent); file_put_contents($filePath, $fileContent); // 更新配置文件 common-prod.cfg $filePath = INSTALL_PATH . '/../protected/Config/common-prod.cfg'; $fileContent = file_get_contents($filePath); $fileContent = preg_replace('/sysConfig\\[db_pdo\\]="[^"]*"/', 'sysConfig[db_pdo]="' . $dbPdo . '"', $fileContent); // 清除 demo 配置 $fileContent = preg_replace('/sysConfig\\[is_demo\\]=1/', 'sysConfig[is_demo]=0', $fileContent); // 清除 Cache 的设置 $sysConfig['cache'] = ''; foreach ($sysConfig as $key => $value) { $fileContent = preg_replace('/sysConfig\\[' . $key . '\\]="[^"]*"/', 'sysConfig[' . $key . ']="' . $value . '"', $fileContent); } file_put_contents($filePath, $fileContent); import_data: // 这里完成导入数据的工作 $pdoObject = new \PDO($dbPdo, $sysConfig['db_username'], $sysConfig['db_password']); // 解析 sql 文件,导入数据 $sqlFileContent = file_get_contents(INSTALL_PATH . '/Asset/data/bzfshop.sql'); $sqlFileContent = SqlHelper::removeComment($sqlFileContent); $sqlArray = SqlHelper::splitToSqlArray($sqlFileContent, ';'); foreach ($sqlArray as $sqlQuery) { $pdoObject->exec($sqlQuery); } unset($pdoObject); } catch (\PDOException $e) { $this->addFlashMessage($e->getMessage()); goto out_fail; } $this->addFlashMessage('数据导入成功'); // 成功,进入到下一步 RouteHelper::reRoute($this, '/Install/Step4'); return; out_fail: // 失败从这里退出 global $smarty; $smarty->assign('currentEngineStr', CloudHelper::$currentEngineStr); $smarty->display('install_step3.tpl'); }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo'); // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['category_id'] = $validator->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id'); $searchFormQuery['suppliers_id'] = $validator->digits('供货商id非法')->min(1, true, '供货商id非法')->filter('ValidatorIntValue')->validate('suppliers_id'); $searchFormQuery['goods_name'] = $validator->validate('goods_name'); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $searchFormQuery['shop_price'] = array($shopPriceMin, $shopPriceMax); // 排序 $orderBy = $validator->oneOf(array('', 'total_buy_number', 'shop_price', 'add_time'))->validate('orderBy'); $orderDir = $validator->oneOf(array('', 'asc', 'desc'))->validate('orderDir'); $orderByParam = array(); if (!empty($orderBy)) { $orderByParam = array(array($orderBy, $orderDir)); } //增加一些我们的缺省排序 $orderByParam[] = array('sort_order', 'desc'); $orderByParam[] = array('goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 10; // 每页固定显示 10 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, MobileThemePlugin::getOptionValue('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) { goto out_display; } // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } // 取得 商品ID 列表 $goodsIdArray = array(); foreach ($goodsArray as $goodsItem) { $goodsIdArray[] = $goodsItem['goods_id']; } // 取得商品的图片 $goodsGalleryService = new GoodsGalleryService(); $goodsGalleryArray = $goodsGalleryService->fetchGoodsGalleryArrayByGoodsIdArray($goodsIdArray); $currentGoodsId = -1; $goodsThumbImageArray = array(); $goodsImageArray = array(); foreach ($goodsGalleryArray as $goodsGalleryItem) { if ($currentGoodsId == $goodsGalleryItem['goods_id']) { continue; //每个商品我们只需要一张图片,跳过其它的图片 } $currentGoodsId = $goodsGalleryItem['goods_id']; // 新的商品 id $goodsThumbImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['thumb_url']); $goodsImageArray[$currentGoodsId] = RouteHelper::makeImageUrl($goodsGalleryItem['img_url']); } // 赋值给模板 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('goodsArray', $goodsArray); $smarty->assign('goodsThumbImageArray', $goodsThumbImageArray); $smarty->assign('goodsImageArray', $goodsImageArray); out_display: $smarty->display('goods_search.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
public function Edit($f3) { global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $article_id = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id'); if (!$this->validate($validator)) { goto out_fail; } // 取得文章 $articleService = new ArticleService(); $article = $articleService->loadArticleById($article_id); if ($article_id > 0 && $article->isEmpty()) { $this->addFlashMessage('文章ID[' . $article_id . ']非法'); goto out_fail; } // 只是显示文章内容而已 if (Request::isRequestGet()) { $smarty->assign('article', $article->toArray()); goto out_get; } // 权限检查 $this->requirePrivilege('manage_article_article_edit'); // 从这里开始是修改文章内容 unset($validator); $articleInfoArray = $f3->get('POST[article]'); $validator = new Validator($articleInfoArray); // 获得修改数据 $inputArray = array(); $inputArray['title'] = $validator->required()->validate('title'); $inputArray['seo_keyword'] = $validator->validate('seo_keyword'); $inputArray['cat_id'] = $validator->validate('cat_id'); $inputArray['is_open'] = $validator->validate('is_open'); $inputArray['description'] = $validator->validate('description'); $inputArray['content'] = $articleInfoArray['content']; // 不要过滤 html if (!$this->validate($validator)) { goto out_get; } $authAdminUser = AuthHelper::getAuthUser(); // 新建文章 if ($article_id <= 0) { $inputArray['admin_user_id'] = $authAdminUser['user_id']; $inputArray['admin_user_name'] = $authAdminUser['user_name']; $inputArray['add_time'] = Time::gmTime(); } // 文章更新 $inputArray['update_user_id'] = $authAdminUser['user_id']; $inputArray['update_user_name'] = $authAdminUser['user_name']; $inputArray['update_time'] = Time::gmTime(); // 保存修改 $article->copyFrom($inputArray); $article->save(); // 清除文章缓存 ClearHelper::clearArticleCacheById($article->article_id); $this->addFlashMessage('文章保存成功'); RouteHelper::reRoute($this, RouteHelper::makeUrl('/Article/Article/Edit', array('article_id' => $article->article_id), true)); return; // POST 从这里退出 out_get: // GET 从这里退出 $smarty->display('article_article_edit.tpl'); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Article/Article/Search'); }
public function AttrItemEdit($f3) { // 权限检查 $this->requirePrivilege('manage_goods_type_listtype'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $meta_id = $validator->digits()->min(1)->validate('meta_id'); if (!$meta_id) { $meta_id = 0; } $goodsTypeService = new GoodsTypeService(); $goodsAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($meta_id); if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } unset($validator); $validator = new Validator($f3->get('POST')); if (0 === $meta_id) { // 新建的组 $goodsAttrItem->parent_meta_id = $validator->required()->validate('typeId'); } // 属性组 $goodsAttrItem->meta_key = $validator->digits()->validate('meta_key'); $goodsAttrItem->meta_name = $validator->required()->validate('meta_name'); $goodsAttrItem->meta_desc = $validator->required()->validate('meta_desc'); $goodsAttrItem->meta_sort_order = $validator->digits()->validate('meta_sort_order'); // 属性类型,单选、单行输入、多行输入 $goodsAttrItem->meta_ename = $validator->required()->validate('meta_ename'); // 选项列表,逗号分隔 $goodsAttrItem->meta_data = $validator->validate('meta_data'); if (!$this->validate($validator)) { goto out_display; } $goodsAttrItem->save(); if (0 === $meta_id) { $this->addFlashMessage('新建商品属性成功'); } else { $this->addFlashMessage('更新商品属性成功'); } // 记录管理员日志 AdminLog::logAdminOperate('goods.type.attritem.edit', '商品属性', $goodsAttrItem->meta_name); out_display: // 新建的,reRoute 到编辑页面 if (!$meta_id) { RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Type/AttrItemEdit', array('meta_id' => $goodsAttrItem->meta_id), true)); } //给 smarty 模板赋值 $smarty->assign('typeId', $goodsAttrItem->parent_meta_id); $smarty->assign($goodsAttrItem->toArray()); $smarty->display('goods_type_attritemedit.tpl'); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Goods/Type/ListType'); }
/** * 设置订单的信息,注意:这个方法里面糅合了很多功能,通过 action="xxxx" 来区分 * * @param $f3 */ public function Update($f3) { // 验证 action $validator = new Validator($f3->get('GET')); $action = $validator->required()->oneOf(array('set_extra_discount', 'set_suppliers_price', 'set_shipping_no', 'set_memo', 'set_refund', 'set_extra_refund'), '非法操作')->validate('action'); if (!$this->validate($validator)) { goto out; } // 验证提交上来的参数 $validator = new Validator($f3->get('POST')); $updateValueArray = array(); $rec_id = $validator->required()->digits()->min(1)->validate('rec_id'); // 针对不同的 action 做不同的验证 switch ($action) { case 'set_extra_discount': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_extra_discount'); $updateValueArray['extra_discount'] = Money::toStorage($validator->validate('extra_discount')); $updateValueArray['extra_discount_note'] = $validator->required()->validate('extra_discount_note'); break; case 'set_suppliers_price': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_suppliers_price'); $updateValueArray['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price')); $updateValueArray['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee')); break; case 'set_shipping_no': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_shipping_no'); $updateValueArray['shipping_id'] = $validator->digits()->min(1)->validate('shipping_id'); $updateValueArray['shipping_no'] = $validator->validate('shipping_no'); break; case 'set_memo': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_memo'); $updateValueArray['memo'] = $validator->validate('memo'); break; case 'set_refund': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_refund'); $updateValueArray['refund'] = Money::toStorage($validator->validate('refund')); $updateValueArray['refund_note'] = $validator->required()->validate('refund_note'); $updateValueArray['refund_time'] = Time::gmTime(); $updateValueArray['suppliers_refund'] = Money::toStorage($validator->validate('suppliers_refund')); $updateValueArray['suppliers_refund_note'] = $validator->required()->validate('suppliers_refund_note'); break; case 'set_extra_refund': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_extra_refund'); $updateValueArray['extra_refund'] = Money::toStorage($validator->validate('extra_refund')); $updateValueArray['extra_refund_note'] = $validator->required()->validate('extra_refund_note'); $updateValueArray['extra_refund_time'] = Time::gmTime(); break; default: // 非法的 action goto out; } if (!$this->validate($validator)) { goto out; } // 取 order_goods $orderBasicService = new OrderBasicService(); $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id); if ($orderGoods->isEmpty()) { $this->addFlashMessage('非法订单'); goto out_fail; } // 取得 orderInfo $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']); // 针对不同的 action 做额外不同的工作 $action_note = ''; switch ($action) { case 'set_extra_discount': // 商品只有是未付款状态才可以设置额外优惠 if (OrderGoodsService::OGS_UNPAY != $orderGoods['order_goods_status']) { $this->addFlashMessage('只有未付款订单才可以给予额外优惠'); goto out; } // 额外优惠允许的最大金额 $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount']; $maxExtraDiscount = intval($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]')); $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]')); $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount); // 额外优惠不能超过商品本身的金额 if ($updateValueArray['extra_discount'] > $maxExtraDiscount) { $this->addFlashMessage('额外优惠不能超过商品总金额 ' . $maxExtraDiscount); goto out; } // 设置额外余额,需要重新计算 order_info 中的值 $diffDiscount = 0; if ($orderGoods->extra_discount != $updateValueArray['extra_discount']) { $diffDiscount = $updateValueArray['extra_discount'] - $orderGoods->extra_discount; } $orderInfo->extra_discount += $diffDiscount; $orderInfo->order_amount -= $diffDiscount; $action_note .= '额外优惠:' . Money::toSmartyDisplay($updateValueArray['extra_discount']) . ","; $action_note .= '优惠说明:' . $updateValueArray['extra_discount_note'] . "\n"; break; case 'set_suppliers_price': $action_note .= '供货价:' . Money::toSmartyDisplay($updateValueArray['suppliers_price']) . ","; $action_note .= '供货快递费:' . Money::toSmartyDisplay($updateValueArray['suppliers_shipping_fee']) . "\n"; break; case 'set_shipping_no': if ($updateValueArray['shipping_id'] > 0) { //取得快递信息 $expressService = new ExpressService(); $expressInfo = $expressService->loadMetaById($updateValueArray['shipping_id']); if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) { $this->addFlashMessage('快递ID非法'); goto out; } $updateValueArray['shipping_name'] = $expressInfo['meta_name']; } else { $updateValueArray['shipping_name'] = null; } $action_note .= '快递公司:' . $updateValueArray['shipping_name'] . "\n"; $action_note .= '快递单号:' . $updateValueArray['shipping_no'] . "\n"; break; case 'set_memo': $action_note .= '客服备注:' . $updateValueArray['memo'] . "\n"; break; case 'set_refund': // 检查订单状态 if (!in_array($orderGoods['order_goods_status'], array(OrderGoodsService::OGS_PAY, OrderGoodsService::OGS_ASKREFUND))) { $this->addFlashMessage('订单状态非法,不能退款'); goto out; } if ($orderGoods['settle_id'] > 0) { $this->addFlashMessage('已经结算的订单不能退款'); goto out; } // 订单设置为 申请退款 $updateValueArray['order_goods_status'] = OrderGoodsService::OGS_ASKREFUND; // 同步更新 order_info 中的 refund 字段 $diffRefund = 0; if ($orderGoods->refund != $updateValueArray['refund']) { $diffRefund = $updateValueArray['refund'] - $orderGoods->refund; } $orderInfo->refund += $diffRefund; // 检查金额,对一些常见错误提出警告 if (0 == $updateValueArray['refund']) { $this->addFlashMessage('警告:你确定给顾客退款金额设置为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?'); } if (0 == $updateValueArray['suppliers_refund']) { $this->addFlashMessage('警告:你确定供货商给我们退款金额为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?'); } if ($updateValueArray['refund'] <= $updateValueArray['suppliers_refund']) { $this->addFlashMessage('警告:给顾客退款金额 <= 供货商给我们的退款金额'); } // 日志信息记录 $action_note .= '申请退款' . "\n"; $action_note .= '顾客金额:' . Money::toSmartyDisplay($updateValueArray['refund']) . ","; $action_note .= '顾客说明:' . $updateValueArray['refund_note'] . "\n"; $action_note .= '供货商金额:' . Money::toSmartyDisplay($updateValueArray['suppliers_refund']) . ","; $action_note .= '供货商说明:' . $updateValueArray['suppliers_refund_note'] . "\n"; break; case 'set_extra_refund': // 检查订单状态 if (OrderGoodsService::OGS_UNPAY == $orderGoods['order_goods_status']) { $this->addFlashMessage('订单状态非法,不能退款'); goto out; } $action_note .= '额外退款:' . Money::toSmartyDisplay($updateValueArray['extra_refund']) . ","; $action_note .= '退款说明:' . $updateValueArray['extra_refund_note'] . "\n"; break; default: // 非法的 action goto out; } // 更新订单信息 $orderGoods->copyFrom($updateValueArray); $orderGoods->update_time = Time::gmTime(); $orderGoods->save(); // 更新 order_info 的 update_time 字段 $orderInfo->update_time = Time::gmTime(); $orderInfo->save(); // 添加订单操作日志 $authAdminUser = AuthHelper::getAuthUser(); $orderActionService = new OrderActionService(); $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authAdminUser['user_name'], 0, $orderInfo['shipping_status']); $this->addFlashMessage('订单信息保存成功'); out: RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Goods/Detail', array('rec_id' => $rec_id), true)); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Order/Goods/Search', false); }
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'); }