/** * * 根据某些查询条件取得商品的列表 * * @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 get($f3) { global $smarty; $myOrderTitleDesc = array(0 => '未付款订单', 1 => '已付款订单'); // 构造查询条件 $searchFormQuery = array(); // 参数验证 $validator = new Validator($f3->get('GET')); $orderStatus = $f3->get('GET[orderStatus]'); if (isset($orderStatus)) { $orderStatus = $searchFormQuery['order_status'] = $validator->digits('订单状态非法')->min(0)->filter('ValidatorIntValue')->validate('orderStatus'); } $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; if (!$this->validate($validator)) { goto out_display; } $myOrderTitle = '全部订单'; if (isset($orderStatus)) { $myOrderTitle = $myOrderTitleDesc[$orderStatus]; } $smarty->assign('myOrderTitle', $myOrderTitle); $userInfo = AuthHelper::getAuthUser(); // 查询订单 $searchFormQuery['user_id'] = $userInfo['user_id']; // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); $totalCount = SearchHelper::count(SearchHelper::Module_OrderInfo, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/My/Order'); } // 订单排序 $orderByParam = array(); $orderByParam[] = array('order_id', 'desc'); // 订单列表 $orderInfoArray = SearchHelper::search(SearchHelper::Module_OrderInfo, '*', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); foreach ($orderInfoArray as &$orderInfoItem) { $orderInfoItem['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfoItem['order_status']]; $orderInfoItem['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfoItem['pay_status']]; } unset($orderInfoItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('orderInfoArray', $orderInfoArray); out_display: $smarty->display('my_order.tpl', 'get'); }
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 get($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id'); // 商品信息 $goodsBasicService = new GoodsBasicService(); $goods = $goodsBasicService->loadGoodsById($goods_id); if ($goods->isEmpty()) { $this->addFlashMessage('商品ID[' . $goods . ']非法'); goto out_fail; } $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; if (!$this->validate($validator)) { goto out_fail; } //查询条件 $searchFormQuery = array(); $searchFormQuery['task_name'] = array('=', GoodsCronTask::$task_name); $searchFormQuery['search_param'] = array('=', $goods_id); // 建立查询条件 $searchParamArray = QueryBuilder::buildQueryCondArray($searchFormQuery); $cronTaskService = new CronTaskService(); $totalCount = $cronTaskService->countCronTaskArray($searchParamArray); if ($totalCount <= 0) { // 没任务,可以直接退出了 goto out_display; } $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->assign('goods', $goods->toArray()); $smarty->display('goods_edit_cron.tpl'); return; out_fail: RouteHelper::reRoute($this, '/Goods/Search'); }
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; }
/** * 更新或者新建一个快递公司 * * @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')); $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; if (!$this->validate($validator)) { goto out_display; } $userInfo = AuthHelper::getAuthUser(); // 构造查询条件 $searchFormQuery = array(); $searchFormQuery['oi.user_id'] = $userInfo['user_id']; // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); // 查询订单 $totalCount = SearchHelper::count(SearchHelper::Module_OrderGoodsOrderInfo, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/My/Order'); } // 订单排序 $orderByParam = array(); $orderByParam[] = array('og.rec_id', 'desc'); // 订单列表 $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.order_id, og.goods_id, og.goods_attr, og.goods_number, og.goods_price, og.shipping_fee' . ', og.create_time, og.order_goods_status, oi.order_sn, oi.pay_time', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); foreach ($orderGoodsArray as &$orderGoodsItem) { $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']]; } unset($orderGoodsItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('orderGoodsArray', $orderGoodsArray); out_display: $smarty->display('my_order.tpl', 'get'); }
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 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; if (!$this->validate($validator)) { goto out_display; } $userInfo = AuthHelper::getAuthUser(); $userBasicService = new UserBasicService(); $userInfo = $userBasicService->loadUserById($userInfo['user_id']); // 用户总共有资金余额 $smarty->assign('userMoney', $userInfo['user_money']); $accountLog = new AccountLogService(); // 用户总共有多少account_log $totalCount = $accountLog->countUserMoneyArray($userInfo['user_id'], 10); //缓存 10 秒钟 if ($totalCount <= 0) { // 没资金变动记录,可以直接退出了 goto out_display; } $smarty->assign('totalCount', $totalCount); // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/My/Money'); } // 传递分页的变量 $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); // account_log 列表 $accountLogArray = $accountLog->fetchUserMoneyArray($userInfo['user_id'], $pageNo * $pageSize, $pageSize, 10); //缓存 10 秒钟 foreach ($accountLogArray as &$accountLogItem) { $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']]; } unset($accountLogItem); $smarty->assign('accountLogArray', $accountLogArray); out_display: $smarty->display('my_money.tpl', 'get'); }
/** * 取得供货商下面商品的总数,用于分页显示 * * @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) { // 用户没有登陆,让用户去登陆 if (!AuthHelper::isAuthUser()) { // 如果已经记录了一个回跳 URL ,则不要再覆盖这个记录了 RouteHelper::reRoute($this, '/User/Login', !RouteHelper::hasRememberUrl()); } // 首先做参数合法性验证 $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'); $postScript = $validator->validate('postscript'); // 订单附言 if (!$this->validate($validator)) { goto out_fail; } $cartBasicService = new CartBasicService(); $cartBasicService->loadFromStorage(); // 加载购物车的数据 $cartContext =& $cartBasicService->getCartContextRef(); if ($cartContext->isEmpty()) { $this->addFlashMessage('购物车为空'); goto out_fail; } // 做一次购物车计算 $cartBasicService->calcOrderPrice(); // 如果购物车里面有错误消息,我们需要显示它 if ($cartContext->hasError()) { $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray()); } // 更新用户的地址信息 $userInfo = AuthHelper::getAuthUser(); $userAddressService = new UserAddressService(); $userAddressService->updateUserFirstAddress($userInfo['user_id'], $addressInfo); // 地址信息放入购物车结构 $cartContext->setAddressInfo($addressInfo); // 订单附言放入购物车 $cartContext->setValue('postscript', $postScript); // 创建或者更新订单 $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']); if (!$orderInfo || $orderInfo->isEmpty()) { //订单创建失败,报错 $this->addFlashMessage('订单创建失败,请联系客服'); goto out_fail; } //订单创建成功,清空购物车 $cartBasicService->clearStorage(); // 跳转到支付页面 RouteHelper::reRoute($this, RouteHelper::makeUrl('/Cart/Pay', array('order_id' => $orderInfo['order_id']), true)); return; out_fail: RouteHelper::reRoute($this, '/Cart/Show'); }
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'); }
/** * 更新或者新建一个分类 * * @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'); }
/** * 取得 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); }
/** * 根据用户 id 取得用户的第一个地址 * * @return object 用户信息记录 * @param int $userId 用户数字 ID * @param int $ttl 缓存时间 * * */ public function loadUserFirstAddress($userId, $ttl = 0) { // 参数验证 $validator = new Validator(array('userId' => $userId, 'ttl' => $ttl)); $userId = $validator->required()->digits()->min(1)->validate('userId'); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); $user = new DataMapper('user_address'); $user->loadOne(array('user_id=?', $userId), array('order' => 'address_id asc', 'offset' => 0, 'limit' => 1), $ttl); return $user; }
/** * 给出一组商品 ID,取得所有商品的图片, * 这是一个大查询,可能会很多数据,之所以加这个大查询的目的是, * 我们宁可要一个几百条记录的大查询,也不要几百个一条记录的小查询 * * @return array 图像集合 array(array(图片1), array(图片2)) * * @param array $goodsIdArray 商品的 ID 数组 * @param int $ttl 缓存时间 */ public function fetchGoodsGalleryArrayByGoodsIdArray(array $goodsIdArray, $ttl = 0) { if (!is_array($goodsIdArray) || empty($goodsIdArray)) { throw new \InvalidArgumentException('goodsIdArray must be an array not empty'); } // 参数验证 $validator = new Validator(array('ttl' => $ttl)); $ttl = $validator->digits()->min(0)->validate('ttl'); $this->validate($validator); $dataMapper = new DataMapper('goods_gallery'); $sqlInClause = QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT); return $dataMapper->find(array($sqlInClause), array('order' => 'goods_id asc , img_sort_order desc, img_id asc'), $ttl); }
/** * 设置商品规格对应的库存 * * @param string $specStr * @param int $goodsNumber */ public function setGoodsSpecGoodsNumber($specStr, $goodsNumber) { // 参数验证 $validator = new Validator(array('specStr' => $specStr, 'goodsNumber' => $goodsNumber)); $specStr = $validator->required()->validate('specStr'); $goodsNumber = $validator->digits()->min(0)->validate('goodsNumber'); $this->validate($validator); $goodsSpecDataArray = $this->getGoodsSpecDataArray($specStr); if (empty($goodsSpecDataArray)) { return; } $this->goodsNumberArray[$goodsSpecDataArray['index']] = $goodsNumber; }
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 get($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_get'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required('商品ID不能为空')->digits()->min(1)->validate('goods_id'); $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; if (!$this->validate($validator)) { goto out_fail; } $goodsLogService = new GoodsLogService(); $totalCount = $goodsLogService->countGoodsLogArray($goods_id); $goodsLogArray = $goodsLogService->fetchGoodsLogArray($goods_id, $pageNo * $pageSize, $pageSize); // 格式化内容的输出 foreach ($goodsLogArray as &$goodsLog) { if (!empty($goodsLog['content'])) { $goodsLog['content'] = nl2br($goodsLog['content']); } } unset($goodsLog); // 给模板赋值 $smarty->assign('goodsLogArray', $goodsLogArray); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->display('goods_edit_log.tpl'); return; out_fail: RouteHelper::reRoute($this, '/Goods/Search'); }
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 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 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 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'); }
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 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'); }