/** * * 根据某些查询条件取得商品的列表 * * @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 run(array $params) { $pageSize = 500; $goodsBasicService = new Goods(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array()); for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) { // 查询商品 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize); foreach ($goodsArray as $goodsItem) { $goods_id = $goodsItem['goods_id']; printLog('begin process goods [' . $goods_id . ']'); $goodsObj = $goodsBasicService->loadGoodsById($goods_id); if ($goodsObj->isEmpty()) { printLog('goods [' . $goods_id . '] is empty'); } else { $goodsObj->goods_desc = str_replace('tuan.bangzhufu.com', 'www.bangzhufu.com', $goodsObj->goods_desc); $goodsObj->goods_desc = str_replace('cdn.bzfshop.net', 'img.bangzhufu.com', $goodsObj->goods_desc); $goodsObj->goods_desc = preg_replace('!/Goods/View/goods_id~([0-9]+).html!', '/Goods/View/goods_id-\\1.html', $goodsObj->goods_desc); $goodsObj->update_time = \Core\Helper\Utility\Time::gmTime(); $goodsObj->save(); } unset($goodsObj); printLog('end process goods [' . $goods_id . ']'); } } }
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 Search($f3) { // 权限检查 $this->requirePrivilege('manage_account_user_search'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits()->min(0)->validate('pageNo'); $pageSize = $validator->digits()->min(0)->validate('pageSize'); //查询条件 $searchFormQuery = array(); $searchFormQuery['user_id'] = $validator->digits()->filter('ValidatorIntValue')->validate('user_id'); $searchFormQuery['user_name'] = $validator->validate('user_name'); $searchFormQuery['email'] = $validator->validate('email'); $orderByUserMoney = $validator->validate('orderByUserMoney'); // 设置缺省值 $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10; if (!$this->validate($validator)) { goto out_display; } // 建立查询条件 $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery); // 查询管理员列表 $totalCount = SearchHelper::count(SearchHelper::Module_User, $searchParamArray); if ($totalCount <= 0) { // 没用户,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Account/User/Search'); } $orderByArray = array(); switch ($orderByUserMoney) { case 1: $orderByArray[] = array('user_money', 'desc'); break; case 2: $orderByArray[] = array('user_money', 'asc'); break; default: break; } // 加入缺省排序 $orderByArray[] = array('user_id', 'desc'); // 用户列表 $userInfoArray = SearchHelper::search(SearchHelper::Module_User, 'user_id, user_name, email, sns_login, user_money, last_login', $searchParamArray, $orderByArray, $pageNo * $pageSize, $pageSize); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('userInfoArray', $userInfoArray); out_display: $smarty->display('account_user_search.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 run(array $params) { global $f3; $outputFile = $f3->get('TEMP') . 'CheckGoodsInnerImageUrl.log'; $imageHostAllow = array('img.bangzhufu.com'); $pageSize = 500; $goodsBasicService = new Goods(); $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array()); for ($pageNo = 0; $pageNo * $pageSize < $totalGoodsCount; $pageNo++) { // 查询商品 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id', array(), array(array('g.goods_id', 'asc')), $pageNo * $pageSize, $pageSize); foreach ($goodsArray as $goodsItem) { $goods_id = $goodsItem['goods_id']; printLog('begin process goods [' . $goods_id . ']'); $goodsObj = $goodsBasicService->loadGoodsById($goods_id); if ($goodsObj->isEmpty()) { printLog('goods [' . $goods_id . '] is empty'); } else { $patternMatch = array(); preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsObj->goods_desc, $patternMatch, PREG_SET_ORDER); $isFirst = true; // 处理每一个图片 foreach ($patternMatch as $matchItem) { $imageUrl = $matchItem[2]; $urlInfo = parse_url($imageUrl); if (!in_array(@$urlInfo['host'], $imageHostAllow)) { if ($isFirst) { $isFirst = false; $f3->write($outputFile, "\n\ngoods_id:" . $goodsObj->goods_id . "\n", true); } $f3->write($outputFile, "\t" . $matchItem[2] . "\n", true); printLog('illegal image url [' . $matchItem[2] . ']'); } } unset($patternMatch); } unset($goodsObj); printLog('end process goods [' . $goods_id . ']'); } } }
public function get($f3) { global $smarty; // 生成 smarty 的缓存 id $smartyCacheId = 'Shop|Index'; // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_shop_index')); if ($smarty->isCached('shop_index.tpl', $smartyCacheId)) { goto out_display; } // 滑动图片广告 $shop_index_adv_slider = json_decode(bzf_get_option_value('shop_index_adv_slider'), true); if (!empty($shop_index_adv_slider)) { $smarty->assign('shop_index_adv_slider', $shop_index_adv_slider); } // 今日新品 $recommandGoodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $this->searchExtraCondArray, array(array('goods_id', 'desc')), 0, 40); if (!empty($recommandGoodsArray)) { $smarty->assign('recommandGoodsArray', $recommandGoodsArray); } // 广告 advBlock $shop_index_advblock_json_data = json_decode(bzf_get_option_value('shop_index_advblock_json_data'), true); if (!empty($shop_index_advblock_json_data)) { // 生成随机的 id 号给 html 使用 foreach ($shop_index_advblock_json_data as &$advBlockObject) { $advBlockObject['id'] = Utils::generateRandomHtmlId(); foreach ($advBlockObject['advBlockImageArray'] as &$advBlockImage) { $advBlockImage['id'] = Utils::generateRandomHtmlId(); } } $smarty->assign('shop_index_advblock_json_data', $shop_index_advblock_json_data); } // 移动端对应的 URL,用于百度页面适配 $smarty->assign('currentPageMobileUrl', RouteHelper::makeShopSystemUrl(PluginHelper::SYSTEM_MOBILE, '/')); out_display: $smarty->assign('seo_title', $smarty->getTemplateVars('seo_title') . ',' . $f3->get('HOST')); $smarty->display('shop_index.tpl', $smartyCacheId); }
/** * 输出商品的列表 * * @param $f3 * @param $pageNo */ public function outputGoodsViewListXml($f3, $pageNo) { global $smarty; // 缓存 1 小时 enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT); $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $pageNo); // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance(); // 查询商品 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'g.goods_id, g.add_time, g.update_time', array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray(), 'g'))), array(array('g.goods_id', 'desc')), $pageNo * $this->pageSize, $this->pageSize); $xmlItems = ''; if (empty($goodsArray)) { goto out; } $currentGmTime = Time::gmTime(); $goodsArrayCount = count($goodsArray); for ($index = 0; $index < $goodsArrayCount; $index++) { $xmlItems .= $this->getGoodsItemXml($goodsArray[$index], $currentGmTime); } out: $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" > \t{$xmlItems} </urlset> XML; unset($xmlItems); $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
/** * 下载 拣货单 * * @param $f3 * @param $validator */ public function downloadJianHuo($f3, $validator) { $outputColumnArray = array('warehouse' => '仓库', 'shelf' => '货架', 'goods_sn' => '货号', 'goods_name' => '商品名', 'goods_attr' => '属性规格', 'goods_number' => '数量', 'suppliers_price' => '供货单价', 'total_suppliers_price' => '供货总价', 'total_suppliers_shipping_fee' => '供货快递'); $outputColumnMoneyArray = array('suppliers_price', 'total_suppliers_price', 'total_suppliers_shipping_fee'); //表单查询 $searchFormQuery = array(); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); // 快递信息 $expressType = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('expressType'); switch ($expressType) { case 1: $searchFormQuery['og.shipping_id'] = 0; break; case 2: $searchFormQuery['og.shipping_id'] = array('>', 0); break; default: break; } if (!$this->validate($validator)) { goto out_fail; } if (Utils::isBlank($searchFormQuery['og.goods_id']) && Utils::isBlank($payTimeStart)) { $this->addFlashMessage('查询参数非法'); goto out_fail; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); $searchFormQuery['og.suppliers_id'] = $authSupplierUser['suppliers_id']; $searchParamArray = array(); $searchParamArray[] = array('oi.order_id = og.order_id'); //供货商,只查看有效订单,其它订单不显示 $searchParamArray[] = array('og.order_goods_status > 0'); // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr, sum(og.goods_number) as goods_number, sum(og.suppliers_price * og.goods_number) as total_suppliers_price, sum(og.suppliers_shipping_fee) as total_suppliers_shipping_fee', $searchParamArray, array(array('og.warehouse', 'asc'), array('og.shelf', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr'); // 没有数据,退出 if (empty($orderGoodsArray)) { goto out; } // 查询订单对应的商品 $goodsIdArray = array(); foreach ($orderGoodsArray as $orderGoodsItem) { $goodsIdArray[] = $orderGoodsItem['goods_id']; } $goodsIdArray = array_unique($goodsIdArray); $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'goods_id, goods_name_short, suppliers_price', array(array(QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT))), null, 0, $f3->get('sysConfig[max_query_record_count]')); $goodsIdToGoodsMap = array(); foreach ($goodsArray as $goodsItem) { $goodsIdToGoodsMap[$goodsItem['goods_id']] = $goodsItem; } require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php'; // 设置Excel缓存,防止数据太多拖死了程序 \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp); // 导出为 Excel 格式 $objPHPExcel = new \PHPExcel(); // 设置工作 sheet $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); // 格式化数据 $rowIndex = 1; $lastWarehouseShelf = null; $orderGoodsArraySize = count($orderGoodsArray); // 输出头部信息 $colIndex = 1; foreach ($outputColumnArray as $value) { $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $value); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFont()->setBold(true); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFB0B0B0'); $colIndex++; } $rowIndex++; // 换行 for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) { // 取得这行数据 $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex]; // 填入商品数据 $orderGoodsItem['goods_name'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['goods_name_short']; $orderGoodsItem['suppliers_price'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['suppliers_price']; if ($lastWarehouseShelf != $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']) { $lastWarehouseShelf = $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']; // 不同的取货地点,需要特殊处理 $rowIndex += 2; // 跳过 2 行 } // 输出一行数据 $colIndex = 1; foreach ($outputColumnArray as $key => $value) { $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : ''; if (!in_array($key, $outputColumnMoneyArray)) { $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING); } else { // 转换价格显示 $cellValue = Money::toSmartyDisplay($cellValue); } $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); $colIndex++; } $rowIndex++; // 换行 } $fileName = '拣货单_' . $searchFormQuery['og.goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s'); // 输出为 Excel5 格式 $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel); header('Content-Type: application/vnd.ms-excel'); if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"'); } else { header('Content-Disposition: attachment; filename="' . $fileName . '.xls"'); } header('Cache-Control: max-age=0'); $objWriter->save('php://output'); //输出到浏览器 die; out: echo "没有数据"; die; out_fail: // 失败,打印错误消息 $flashMessageArray = $this->flashMessageArray; foreach ($flashMessageArray as $flashMessage) { echo $flashMessage . '<br />'; } }
public function get($f3) { global $smarty; // 首先做参数合法性验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits('pageNo 参数非法')->min(0, true, 'pageNo 参数非法')->validate('pageNo'); // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['g.category_id'] = $validator->required('商品分类不能为空')->digits('分类id非法')->min(1, true, '分类id非法')->filter('ValidatorIntValue')->validate('category_id'); // 这里支持多品牌查询 $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id')); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax); $searchFormQuery['g.shop_price'] = array($shopPriceMin, $shopPriceMax); // 属性过滤 $filter = $validator->validate('filter'); // 排序 $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('g.sort_order', 'desc'); $orderByParam[] = array('g.goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 45; // 每页固定显示 45 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Category|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $filter . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_category.tpl', $smartyCacheId)) { goto out_display; } $goodsCategoryService = new GoodsCategoryService(); $category = $goodsCategoryService->loadCategoryById($searchFormQuery['g.category_id'], 1800); if ($category->isEmpty()) { $this->addFlashMessage('分类[' . $searchFormQuery['category_id'] . ']不存在'); goto out_fail; } $smarty->assign('category', $category); $metaData = json_decode($category['meta_data'], true); $metaFilterArray = @$metaData['filterArray']; // 1. 我们需要在左侧显示分类层级结构 $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray($category['parent_meta_id'], false, 1800); $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray); /** * 构造 Filter 数组,结构如下 * * array( * '商品品牌' => array( * filterKey => 'brand_id' * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ), * '颜色' => array( * filterKey => 'filter', * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ) * ) * */ $goodsFilterArray = array(); // filter 查询在这个条件下进行 $goodsFilterQueryCond = array_merge($this->searchExtraCondArray, array(array('g.category_id', '=', $searchFormQuery['g.category_id']))); // 2. 商品品牌查询 $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0); $brandIdArray = array_map(function ($elem) { return $elem['brand_id']; }, $goodsBrandIdArray); if (!empty($brandIdArray)) { $goodsBrandService = new GoodsBrandService(); $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray))); $filterBrandArray = array(); foreach ($goodsBrandArray as $brand) { $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']); } if (!empty($filterBrandArray)) { $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray); } } // 3. 查询属性过滤 if (!empty($metaFilterArray)) { $goodsTypeService = new GoodsTypeService(); foreach ($metaFilterArray as $filterItem) { $goodsTypeAttrItem = $goodsTypeService->loadGoodsTypeAttrItemById($filterItem['attrItemId']); if ($goodsTypeAttrItem->isEmpty()) { continue; } // 取得商品属性值列表 $goodsAttrItemValueArray = SearchHelper::search(SearchHelper::Module_GoodsAttrGoods, 'min(ga.goods_attr_id) as goods_attr_id, ga.attr_item_value', array_merge($goodsFilterQueryCond, array(array('ga.attr_item_id', '=', $filterItem['attrItemId']))), null, 0, 0, 'ga.attr_item_value'); if (!empty($goodsAttrItemValueArray)) { $filterValueArray = array(); foreach ($goodsAttrItemValueArray as $itemValue) { $filterValueArray[] = array('value' => $itemValue['goods_attr_id'], 'text' => $itemValue['attr_item_value']); } $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => $filterValueArray); } else { // 如果这个属性完全没有值(没有一个商品设过任何值),我们弄一个空的 $goodsFilterArray[$goodsTypeAttrItem['meta_name']] = array('filterKey' => 'filter', 'filterValueArray' => array()); } } } // 赋值给模板 if (!empty($goodsFilterArray)) { $smarty->assign('goodsFilterArray', $goodsFilterArray); } // 4. 商品查询 if (!empty($metaFilterArray)) { // 构造 attrItemId $metaFilterTypeIdArray = array(); foreach ($metaFilterArray as $metaFilterItem) { $metaFilterTypeIdArray[] = $metaFilterItem['attrItemId']; } // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析 // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray, array(array('ga.filter', implode('.', $metaFilterTypeIdArray), $filter))); } else { // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); } $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } $smarty->assign('goodsArray', $goodsArray); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); // SEO 考虑,网页标题加上分类的名称 $smarty->assign('seo_title', $category['meta_name'] . ',' . $smarty->getTemplateVars('seo_title')); out_display: // 滑动图片广告 $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true); if (!empty($goods_search_adv_slider)) { $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider); } $smarty->display('goods_category.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
/** * 输出文章的列表 * * @param $f3 * @param $pageNo */ public function outputArticleViewListXml($f3, $pageNo) { global $smarty; // 缓存 1 小时 enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT); $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__ . '\\' . $pageNo); // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } // 查询商品 $articleArray = SearchHelper::search(SearchHelper::Module_Article, 'a.article_id, a.update_time', QueryBuilder::buildSearchParamArray(array('a.is_open' => 1)), array(array('a.article_id', 'desc')), $pageNo * $this->pageSize, $this->pageSize); $xmlItems = ''; if (empty($articleArray)) { goto out; } foreach ($articleArray as $articleItem) { $articleViewUrl = RouteHelper::makeUrl('/Article/View', array('article_id' => $articleItem['article_id']), false, true); $articleLastModTime = date('Y-m-d\\TH:i:sP', Time::gmTimeToLocalTime($articleItem['update_time'])); $xmlItems .= <<<XMLITEM \t <url> \t <loc><![CDATA[{$articleViewUrl}]]></loc> \t <lastmod>{$articleLastModTime}</lastmod> \t <changefreq>always</changefreq> </url> XMLITEM; } out: $apiXml = <<<XML <?xml version="1.0" encoding="utf-8" ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" > \t{$xmlItems} </urlset> XML; unset($xmlItems); $smarty->assign('outputContent', $apiXml); out_display: header('Content-Type:text/xml;charset=utf-8'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 //查询信息 $smarty->display('empty.tpl', $smartyCacheId); }
public function get($f3) { global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits()->min(0)->validate('pageNo'); $pageSize = $validator->digits()->min(0)->validate('pageSize'); // 设置缺省值 $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10; // 查询条件 $searchFormQuery = array(); $searchFormQuery['g.is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale'); $searchFormQuery['g.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['g.goods_name'] = $validator->validate('goods_name'); $searchFormQuery['g.goods_sn'] = $validator->validate('goods_sn'); $searchFormQuery['g.warehouse'] = $validator->validate('warehouse'); $searchFormQuery['g.shelf'] = $validator->validate('shelf'); if (!$this->validate($validator)) { goto out_display; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); $searchFormQuery['g.suppliers_id'] = intval($authSupplierUser['suppliers_id']); // 建立查询条件 $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery); // 查询商品列表 $totalCount = SearchHelper::count(SearchHelper::Module_Goods, $searchParamArray); if ($totalCount <= 0) { // 没商品,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Goods/Search'); } // 商品列表 $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, $this->searchFieldSelector, $searchParamArray, array(array('g.goods_id', 'desc')), $pageNo * $pageSize, $pageSize); $system_url_base_array = json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true); foreach ($goodsArray as &$goodsItem) { // 解析 system_tag_list,放入 system_array 的信息 $systeArray = Utils::parseTagString($goodsItem['system_tag_list']); $goodsItem['system_array'] = array(); foreach ($systeArray as $systemItem) { $goodsItem['system_array'][] = @$system_url_base_array[$systemItem]['name']; } // 商品规格 if (!empty($goodsItem['goods_spec'])) { $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithJson($goodsItem['goods_spec']); $goodsItem['goods_spec'] = $goodsSpecService->getGoodsSpecDataArray(); } } unset($goodsItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('goodsArray', $goodsArray); out_display: $smarty->display('goods_search.tpl'); }
public function Search($f3) { /** * 我们使用搜索模块做搜索操作 */ $searchFieldSelector = 'og.*, oi.system_id, oi.consignee'; 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; // shippingStatus, 0 全部,1 已发货,2 未发货 $shippingStatus = $validator->digits()->min(1)->validate('shippingStatus'); //订单表单查询 $searchFormQuery = array(); $searchFormQuery['og.order_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('order_id'); $searchFormQuery['og.rec_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('rec_id'); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['og.goods_name'] = $validator->validate('goods_name'); $searchFormQuery['oi.order_sn'] = $validator->validate('order_sn'); $order_goods_status = $validator->min(0)->filter('ValidatorIntValue')->validate('order_goods_status'); if (null == $order_goods_status) { // 选择 请求退款、退款中、退款完成 状态的订单 $searchFormQuery['og.order_goods_status'] = array('>', OrderGoodsService::OGS_PAY); } else { $searchFormQuery['og.order_goods_status'] = $order_goods_status; } $searchFormQuery['oi.consignee'] = $validator->validate('consignee'); $searchFormQuery['oi.mobile'] = $validator->validate('mobile'); $searchFormQuery['oi.address'] = $validator->validate('address'); $searchFormQuery['oi.postscript'] = $validator->validate('postscript'); $searchFormQuery['og.memo'] = $validator->validate('memo'); //退款时间 $refundTimeStartStr = $validator->validate('refund_time_start'); $refundTimeStart = Time::gmStrToTime($refundTimeStartStr) ?: null; $refundTimeEndStr = $validator->validate('refund_time_end'); $refundTimeEnd = Time::gmStrToTime($refundTimeEndStr) ?: null; $searchFormQuery['og.refund_time'] = array($refundTimeStart, $refundTimeEnd); //完成时间 $refundFinishTimeStartStr = $validator->validate('refund_finish_time_start'); $refundFinishTimeStart = Time::gmStrToTime($refundFinishTimeStartStr) ?: null; $refundFinishTimeEndStr = $validator->validate('refund_finish_time_end'); $refundFinishTimeEnd = Time::gmStrToTime($refundFinishTimeEndStr) ?: null; $searchFormQuery['og.refund_finish_time'] = array($refundFinishTimeStart, $refundFinishTimeEnd); if (!$this->validate($validator)) { goto out_display; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); // 供货商只能查看自己商品对应的订单 $searchFormQuery['og.suppliers_id'] = intval($authSupplierUser['suppliers_id']); // 构造查询条件 $searchParamArray = array(); // 用户取消的订单商品我们就不再显示了 $searchParamArray[] = array(QueryBuilder::buildNotInCondition('oi.order_status', array(OrderBasicService::OS_CANCELED, OrderBasicService::OS_INVALID), \PDO::PARAM_INT)); if (1 == $shippingStatus) { // 1 未发货 $searchParamArray[] = array('og.shipping_id = 0'); } elseif (2 == $shippingStatus) { // 2 已发货 $searchParamArray[] = array('og.shipping_id <> 0'); } else { // do nothing } // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); // 使用哪个搜索模块 $searchModule = SearchHelper::Module_OrderGoodsOrderInfo; // 查询订单列表 $totalCount = SearchHelper::count($searchModule, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Order/Refund/Search'); } // 查询订单列表 $orderGoodsArray = SearchHelper::search($searchModule, $searchFieldSelector, $searchParamArray, array(array('og.order_id', 'desc')), $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('order_refund_search.tpl'); }
public function Search($f3) { global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits()->min(0)->validate('pageNo'); $pageSize = $validator->digits()->min(0)->validate('pageSize'); // 设置缺省值 $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10; // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['a.article_id'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('article_id'); $searchFormQuery['a.title'] = $validator->validate('title'); $searchFormQuery['a.description'] = $validator->validate('description'); $searchFormQuery['a.cat_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('cat_id'); $searchFormQuery['a.admin_user_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('admin_user_id'); $searchFormQuery['a.is_open'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_open'); if (!$this->validate($validator)) { goto out; } // 建立查询条件 $searchParamArray = QueryBuilder::buildSearchParamArray($searchFormQuery); // 查询商品列表 $totalCount = SearchHelper::count(SearchHelper::Module_Article, $searchParamArray); if ($totalCount <= 0) { // 没数据,可以直接退出了 goto out; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Article/Article/Search'); } // 文章列表 $articleArray = SearchHelper::search(SearchHelper::Module_Article, '*', $searchParamArray, array(array('a.article_id', 'desc')), $pageNo * $pageSize, $pageSize); // 取得 文章分类 id $categoryIdArray = array(); foreach ($articleArray as $articleItem) { $categoryIdArray[] = $articleItem['cat_id']; } $categoryIdArray = array_unique($categoryIdArray); // 取得分类信息 $articleCategoryService = new ArticleCategoryService(); $categoryArray = $articleCategoryService->fetchCategoryArrayByIdArray($categoryIdArray); // 建立 cat_id ---> cateogry 信息的反查表 $categoryIdToCategoryArray = array(); foreach ($categoryArray as $categoryItem) { $categoryIdToCategoryArray[$categoryItem['meta_id']] = $categoryItem; } // 放入分类信息 foreach ($articleArray as &$articleItem) { if (isset($categoryIdToCategoryArray[$articleItem['cat_id']])) { // 很老的商品,分类信息可能已经不存在了 $articleItem['cat_name'] = $categoryIdToCategoryArray[$articleItem['cat_id']]['meta_name']; } } unset($articleItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('articleArray', $articleArray); out: $smarty->display('article_article_search.tpl'); }
public function get($f3) { global $smarty; if (!$f3->get('GET')) { // 没有任何查询,直接显示空页面 goto out; } // 参数验证 $validator = new Validator($f3->get('GET')); //订单表单查询 $searchFormQuery = array(); //下单时间 $addTimeStartStr = $validator->validate('add_time_start'); $addTimeStart = Time::gmStrToTime($addTimeStartStr) ?: null; $addTimeEndStr = $validator->validate('add_time_end'); $addTimeEnd = Time::gmStrToTime($addTimeEndStr) ?: null; $searchFormQuery['oi.add_time'] = array($addTimeStart, $addTimeEnd); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); if (!($addTimeStart || $addTimeEnd || $payTimeStart || $payTimeEnd)) { $this->addFlashMessage('必须最少选择一个时间'); goto out; } $searchFormQuery['oi.kefu_user_id'] = $validator->required('必须选择一个客服')->digits()->filter('ValidatorIntValue')->validate('kefu_user_id'); if (!$this->validate($validator)) { goto out; } // 权限检查 $authAdminUser = AuthHelper::getAuthUser(); // 客服可以查看自己的页面 if ($searchFormQuery['oi.kefu_user_id'] !== $authAdminUser['user_id']) { // 用户查看的不是自己的业绩,需要特别的权限 if (!$this->hasPrivilege('manage_stat_kaohe_kefu')) { $this->addFlashMessage('你没有权限查看别人的业绩统计'); goto out; } } // 统计订单金额总和 $orderGoodsStat = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.order_goods_status' . ',count(1) as total_order_goods_count' . ',sum(og.goods_price) as total_goods_price' . ',sum(og.shipping_fee) as total_shipping_fee' . ',sum(og.discount) as total_discount' . ',sum(og.extra_discount) as total_extra_discount' . ',sum(og.refund) as total_refund' . ',sum(og.extra_refund) as total_extra_refund', QueryBuilder::buildSearchParamArray($searchFormQuery), array(array('og.order_goods_status', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.order_goods_status'); // 订单状态显示 foreach ($orderGoodsStat as &$orderGoodsStatItem) { $orderGoodsStatItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsStatItem['order_goods_status']]; } unset($orderGoodsStatItem); // 统计总结果 $orderGoodsStatTotal = array(); $orderGoodsStatTotal['total_order_goods_count'] = 0; $orderGoodsStatTotal['total_goods_price'] = 0; $orderGoodsStatTotal['total_shipping_fee'] = 0; $orderGoodsStatTotal['total_discount'] = 0; $orderGoodsStatTotal['total_extra_discount'] = 0; $orderGoodsStatTotal['total_refund'] = 0; $orderGoodsStatTotal['total_extra_refund'] = 0; foreach ($orderGoodsStat as $orderGoodsStatItem) { // 未付款的订单不计入统计 if ($orderGoodsStatItem['order_goods_status'] < OrderGoodsService::OGS_PAY) { continue; } // 统计计算 $orderGoodsStatTotal['total_order_goods_count'] += $orderGoodsStatItem['total_order_goods_count']; $orderGoodsStatTotal['total_goods_price'] += $orderGoodsStatItem['total_goods_price']; $orderGoodsStatTotal['total_shipping_fee'] += $orderGoodsStatItem['total_shipping_fee']; $orderGoodsStatTotal['total_discount'] += $orderGoodsStatItem['total_discount']; $orderGoodsStatTotal['total_extra_discount'] += $orderGoodsStatItem['total_extra_discount']; $orderGoodsStatTotal['total_refund'] += $orderGoodsStatItem['total_refund']; $orderGoodsStatTotal['total_extra_refund'] += $orderGoodsStatItem['total_extra_refund']; } // 给 smarty 赋值 $smarty->assign('orderGoodsStat', $orderGoodsStat); $smarty->assign('orderGoodsStatTotal', $orderGoodsStatTotal); out: $smarty->display('stat_kaohe_kefu.tpl'); }
/** * 查询下线的商品 * * @param $pageNo * * @return mixed */ private function queryDeleteGoods($pageNo) { $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance(); return SearchHelper::search(SearchHelper::Module_Goods, $this->fieldSelector, array(array('is_on_sale = 0'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))), array(array('g.goods_id', 'desc')), $pageNo * self::$pageSize, self::$pageSize); }
public function get($f3) { // 权限检查 $this->requirePrivilege('manage_goods_search'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $pageNo = $validator->digits()->min(0)->validate('pageNo'); $pageSize = $validator->digits()->min(0)->validate('pageSize'); // 设置缺省值 $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10; // 搜索参数数组 $searchFormQuery = array(); $searchFormQuery['g.is_on_sale'] = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('is_on_sale'); $searchFormQuery['g.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['g.suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id'); $searchFormQuery['g.goods_name'] = $validator->validate('goods_name'); $searchFormQuery['g.cat_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('cat_id'); $searchFormQuery['g.type_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('type_id'); $searchFormQuery['g.brand_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('brand_id'); $searchFormQuery['g.goods_sn'] = $validator->validate('goods_sn'); $searchFormQuery['g.warehouse'] = $validator->validate('warehouse'); $searchFormQuery['g.shelf'] = $validator->validate('shelf'); $searchFormQuery['g.admin_user_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('admin_user_id'); $systemTag = $validator->validate('system_tag'); if (!empty($systemTag)) { $searchFormQuery['g.system_tag_list'] = Utils::makeTagString(array($systemTag)); } if (!$this->validate($validator)) { goto out_display; } // 查询条件 $searchParamArray = array(); // 根据推广渠道做搜索 $goods_promote = $validator->validate('goods_promote'); if (!empty($goods_promote)) { switch ($goods_promote) { case '360tequan': $searchParamArray[] = array('gp.360tequan_price > 0'); break; case '360tegong': $searchParamArray[] = array('gp.360tegong_enable = 1'); break; default: // do nothing break; } } // 建立查询条件 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); // 查询商品列表 $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsPromote, $searchParamArray); if ($totalCount <= 0) { // 没商品,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Goods/Search'); } // 商品列表 $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsPromote, 'g.goods_id, g.system_tag_list, g.cat_id, g.admin_user_name, g.goods_name, g.goods_number' . ', g.goods_spec, g.is_on_sale, g.type_id' . ', g.market_price, g.shop_price, g.shipping_fee, g.shipping_free_number' . ', g.suppliers_id, g.suppliers_price, g.suppliers_shipping_fee, g.warehouse, g.shelf', $searchParamArray, array(array('g.goods_id', 'desc')), $pageNo * $pageSize, $pageSize); // 取得供货商 id 列表,商品分类 id $supplierIdArray = array(); $categoryIdArray = array(); $typeIdArray = array(); foreach ($goodsArray as $goodsItem) { $supplierIdArray[] = $goodsItem['suppliers_id']; $categoryIdArray[] = $goodsItem['cat_id']; $typeIdArray[] = $goodsItem['type_id']; } $supplierIdArray = array_unique($supplierIdArray); $categoryIdArray = array_unique($categoryIdArray); //取得供货商信息 $userSupplierService = new UserSupplierService(); $supplierArray = $userSupplierService->fetchSupplierArrayBySupplierIdArray($supplierIdArray); // 建立 suppliers_id --> supplier 的反查表,方便快速查询 $supplierIdToSupplierArray = array(); foreach ($supplierArray as $supplier) { $supplierIdToSupplierArray[$supplier['suppliers_id']] = $supplier; } $system_url_base_array = json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true); // 放入供货商信息 foreach ($goodsArray as &$goodsItem) { if (isset($supplierIdToSupplierArray[$goodsItem['suppliers_id']])) { // 很老的订单,用户可能被删除了 $goodsItem['suppliers_name'] = $supplierIdToSupplierArray[$goodsItem['suppliers_id']]['suppliers_name']; } // 解析 system_tag_list,放入 system_array 的信息 $systeArray = Utils::parseTagString($goodsItem['system_tag_list']); $goodsItem['system_array'] = array(); foreach ($systeArray as $systemItem) { $goodsItem['system_array'][] = @$system_url_base_array[$systemItem]['name']; } // 商品规格 if (!empty($goodsItem['goods_spec'])) { $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithJson($goodsItem['goods_spec']); $goodsItem['goods_spec'] = $goodsSpecService->getGoodsSpecDataArray(); } } unset($goodsItem); // 取得分类信息 $categoryBasicService = new CategoryBasicService(); $categoryArray = $categoryBasicService->fetchCategoryArrayByIdArray($categoryIdArray); // 建立 cat_id ---> cateogry 信息的反查表 $categoryIdToCategoryArray = array(); foreach ($categoryArray as $categoryItem) { $categoryIdToCategoryArray[$categoryItem['meta_id']] = $categoryItem; } // 放入分类信息 foreach ($goodsArray as &$goodsItem) { if (isset($categoryIdToCategoryArray[$goodsItem['cat_id']])) { // 很老的商品,分类信息可能已经不存在了 $goodsItem['cat_name'] = $categoryIdToCategoryArray[$goodsItem['cat_id']]['meta_name']; } } unset($goodsItem); // 取得商品类型信息 $goodsTypeService = new GoodsTypeService(); $goodsTypeArray = $goodsTypeService->fetchGoodsTypeArrayByTypeIdArray($typeIdArray); // 建立 type_id ---> type 信息的反查表 $typeIdToTypeArray = array(); foreach ($goodsTypeArray as $goodsType) { $typeIdToTypeArray[$goodsType['meta_id']] = $goodsType; } // 放入类型信息 foreach ($goodsArray as &$goodsItem) { if (isset($typeIdToTypeArray[$goodsItem['type_id']])) { $goodsItem['type_name'] = $typeIdToTypeArray[$goodsItem['type_id']]['meta_name']; } } unset($goodsItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('goodsArray', $goodsArray); $smarty->assign('system_url_base_array', json_decode(ManageThemePlugin::getOptionValue('system_url_base_array'), true)); out_display: $smarty->display('goods_search.tpl'); }
public function Search($f3) { // 权限检查 $this->requirePrivilege('manage_order_order_search'); /** * 我们使用搜索模块做搜索操作 */ $searchFieldSelector = 'oi.order_id, oi.order_sn, oi.add_time, oi.confirm_time, oi.user_id, oi.order_status, oi.pay_status' . ', oi.goods_amount, oi.shipping_fee, oi.discount, oi.system_id, oi.kefu_user_id, oi.kefu_user_name, oi.kefu_user_rate'; 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; // 构造查询条件 $searchParamArray = array(); //表单查询 $searchFormQuery = array(); $searchFormQuery['oi.order_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('order_id'); $searchFormQuery['oi.order_sn'] = $validator->validate('order_sn'); $searchFormQuery['oi.pay_no'] = $validator->validate('pay_no'); $searchFormQuery['oi.consignee'] = $validator->validate('consignee'); $searchFormQuery['oi.mobile'] = $validator->validate('mobile'); $searchFormQuery['oi.address'] = $validator->validate('address'); $searchFormQuery['oi.postscript'] = $validator->validate('postscript'); $searchFormQuery['oi.system_id'] = array('=', $validator->validate('system_id')); $searchFormQuery['oi.kefu_user_id'] = $validator->filter('ValidatorIntValue')->validate('kefu_user_id'); $utmSource = $validator->validate('utm_source'); if ('SELF' == $utmSource) { $searchParamArray[] = array('orf.utm_source is null'); } else { $searchFormQuery['orf.utm_source'] = array('=', $utmSource); } $utmMedium = $validator->validate('utm_medium'); if ('SELF' == $utmMedium) { $searchParamArray[] = array('orf.utm_medium is null'); } else { $searchFormQuery['orf.utm_medium'] = array('=', $utmMedium); } //下单时间 $addTimeStartStr = $validator->validate('add_time_start'); $addTimeStart = Time::gmStrToTime($addTimeStartStr) ?: null; $addTimeEndStr = $validator->validate('add_time_end'); $addTimeEnd = Time::gmStrToTime($addTimeEndStr) ?: null; $searchFormQuery['oi.add_time'] = array($addTimeStart, $addTimeEnd); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); if (!$this->validate($validator)) { goto out_display; } // 构造查询条件 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); // 使用哪个搜索模块 $searchModule = SearchHelper::Module_OrderInfo; if (!empty($utmSource) || !empty($utmMedium)) { $searchModule = SearchHelper::Module_OrderInfoOrderRefer; } $totalCount = SearchHelper::count($searchModule, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Order/Order/Search'); } // 订单列表 $orderInfoArray = SearchHelper::search($searchModule, $searchFieldSelector, $searchParamArray, array(array('oi.order_id', 'desc')), $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); // 取得用户 id 列表 $userIdArray = array(); foreach ($orderInfoArray as $orderInfoItem) { $userIdArray[] = $orderInfoItem['user_id']; } $userIdArray = array_unique($userIdArray); //取得用户信息 $userBasicService = new UserBasicService(); $userArray = $userBasicService->fetchUserArrayByUserIdArray($userIdArray); // 建立 user_id --> user 的反查表,方便快速查询 $userIdToUserArray = array(); foreach ($userArray as $user) { $userIdToUserArray[$user['user_id']] = $user; } // 放入用户信息 foreach ($orderInfoArray as &$orderInfoItem) { if (isset($userIdToUserArray[$orderInfoItem['user_id']])) { // 很老的订单,用户可能被删除了 $orderInfoItem['user_name'] = $userIdToUserArray[$orderInfoItem['user_id']]['user_name']; $orderInfoItem['email'] = $userIdToUserArray[$orderInfoItem['user_id']]['email']; } } // 前面用了引用,这里一定要清除,防止影响后面的数据 unset($orderInfoItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('orderInfoArray', $orderInfoArray); out_display: $smarty->display('order_order_search.tpl'); }
/** * 在这里做数据库查询 * * @param $f3 * * @return array */ private function doQuery($f3) { // 返回结果 $orderGoodsArray = array(); // 参数验证 $validator = new Validator($f3->get('GET')); //订单表单查询 $searchFormQuery = array(); //下单时间 $addTimeStartStr = $validator->validate('add_time_start'); $addTimeStart = Time::gmStrToTime($addTimeStartStr) ?: null; $addTimeEndStr = $validator->validate('add_time_end'); $addTimeEnd = Time::gmStrToTime($addTimeEndStr) ?: null; $searchFormQuery['oi.add_time'] = array($addTimeStart, $addTimeEnd); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); if (!($addTimeStart || $addTimeEnd || $payTimeStart || $payTimeEnd)) { $this->addFlashMessage('必须最少选择一个时间'); goto out; } $searchFormQuery['orf.login_type'] = array('=', $validator->validate('login_type')); $searchFormQuery['oi.system_id'] = array('=', $validator->validate('system_id')); // 构造查询条件 $searchParamArray = array(); $utmSource = $validator->validate('utm_source'); if ('SELF' == $utmSource) { $searchParamArray[] = array('orf.utm_source is null'); } else { $searchFormQuery['orf.utm_source'] = array('=', $utmSource); } $utmMedium = $validator->validate('utm_medium'); if ('SELF' == $utmMedium) { $searchParamArray[] = array('orf.utm_medium is null'); } else { $searchFormQuery['orf.utm_medium'] = array('=', $utmMedium); } if (!$this->validate($validator)) { goto out; } // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfoOrderRefer, 'og.rec_id, og.order_id, og.goods_id, og.order_goods_status, og.goods_number, og.goods_price, og.shipping_fee' . ', og.shipping_fee, og.suppliers_price, og.suppliers_shipping_fee, og.discount, og.extra_discount, og.refund' . ',og.extra_refund, og.refund_note, og.extra_refund_note, og.suppliers_refund, og.cps_rate, og.cps_fix_fee' . ',oi.pay_status, oi.surplus, oi.bonus, oi.pay_time, oi.add_time, orf.utm_source, orf.utm_medium, orf.login_type', $searchParamArray, array(array('og.order_id', 'asc'), array('og.rec_id', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]')); // 每个订单就只有一个 surplus, bonus ,我们清除掉多余的值 $lastOrderId = 0; foreach ($orderGoodsArray as &$orderGoodsItem) { if ($lastOrderId != $orderGoodsItem['order_id']) { $lastOrderId = $orderGoodsItem['order_id']; // 记住操作的订单 id continue; } // 同一个订单的 order_goods ,清除多余的 surplus, bonus $orderGoodsItem['surplus'] = 0; $orderGoodsItem['bonus'] = 0; } unset($orderGoodsItem); out: // 这里返回结果 return $orderGoodsArray; }
public function ListGoods($f3) { // 权限检查 $this->requirePrivilege('manage_order_statistics_listgoods'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); //订单表单查询 $searchFormQuery = array(); $systemId = $validator->validate('system_id'); $searchFormQuery['oi.system_id'] = array('=', $systemId); //下单时间 $createTimeStartStr = $validator->validate('create_time_start'); $createTimeStart = Time::gmStrToTime($createTimeStartStr) ?: null; $createTimeEndStr = $validator->validate('create_time_end'); $createTimeEnd = Time::gmStrToTime($createTimeEndStr) ?: null; $searchFormQuery['og.create_time'] = array($createTimeStart, $createTimeEnd); if (empty($createTimeStart) || empty($createTimeEnd)) { goto out_display; } // 查询订单列表,最多查询 10000 条记录,防止拖死数据库 $orderGoodsArray = SearchHelper::search(empty($systemId) ? SearchHelper::Module_OrderGoods : SearchHelper::Module_OrderGoodsOrderInfo, 'og.rec_id, og.order_goods_status, og.goods_id, og.goods_admin_user_id, og.goods_admin_user_name, og.goods_name, og.goods_number', QueryBuilder::buildSearchParamArray($searchFormQuery), array(array('og.rec_id', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]')); $goodsStatisticsArray = array(); // 做商品统计 foreach ($orderGoodsArray as $orderGoodsItem) { if (!isset($goodsStatisticsArray[$orderGoodsItem['goods_id']])) { $goodsStatisticsArray[$orderGoodsItem['goods_id']] = array(); //商品信息 $goodsStatisticsArray[$orderGoodsItem['goods_id']]['goods_id'] = $orderGoodsItem['goods_id']; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['goods_name'] = $orderGoodsItem['goods_name']; // 商品对应的编辑信息 $goodsStatisticsArray[$orderGoodsItem['goods_id']]['goods_admin_user_id'] = $orderGoodsItem['goods_admin_user_id']; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['goods_admin_user_name'] = $orderGoodsItem['goods_admin_user_name']; //订单信息 $goodsStatisticsArray[$orderGoodsItem['goods_id']]['total_order_number'] = 0; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['unpay_order_number'] = 0; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['pay_order_number'] = 0; //售出商品信息 $goodsStatisticsArray[$orderGoodsItem['goods_id']]['total_goods_number'] = 0; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['unpay_goods_number'] = 0; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['pay_goods_number'] = 0; } $goodsStatisticsArray[$orderGoodsItem['goods_id']]['total_order_number'] += 1; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['total_goods_number'] += $orderGoodsItem['goods_number']; switch ($orderGoodsItem['order_goods_status']) { case OrderGoodsService::OGS_UNPAY: $goodsStatisticsArray[$orderGoodsItem['goods_id']]['unpay_order_number'] += 1; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['unpay_goods_number'] += $orderGoodsItem['goods_number']; break; case OrderGoodsService::OGS_PAY: $goodsStatisticsArray[$orderGoodsItem['goods_id']]['pay_order_number'] += 1; $goodsStatisticsArray[$orderGoodsItem['goods_id']]['pay_goods_number'] += $orderGoodsItem['goods_number']; break; default: // 退款订单,不处理 break; } } // 按照订单数量排序 $goodsIdTotalOrderNumberArray = array(); foreach ($goodsStatisticsArray as $goodsStatisticsItem) { $goodsIdTotalOrderNumberArray[] = str_pad($goodsStatisticsItem['total_order_number'], 7, '0', STR_PAD_LEFT) . '-' . str_pad($goodsStatisticsItem['goods_id'], 7, '0', STR_PAD_LEFT); } // 排序 rsort($goodsIdTotalOrderNumberArray); $sortGoodsStatisticsArray = array(); foreach ($goodsIdTotalOrderNumberArray as $item) { $tmpArray = explode('-', $item); $sortGoodsStatisticsArray[] = $goodsStatisticsArray[intval($tmpArray[1])]; } // 给模板赋值 $smarty->assign('sortGoodsStatisticsArray', $sortGoodsStatisticsArray); out_display: $smarty->display('order_statistics_listgoods.tpl'); }
public function Search($f3) { // 权限检查 $this->requirePrivilege('manage_order_goods_search'); /** * 我们使用搜索模块做搜索操作 */ $searchFieldSelector = 'og.*, oi.user_id, oi.system_id, oi.kefu_user_id, oi.kefu_user_name, oi.kefu_user_rate'; 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; // shippingStatus, 0 全部,1 已发货,2 未发货 $shippingStatus = $validator->digits()->min(1)->validate('shippingStatus'); //订单表单查询 $searchFormQuery = array(); $searchFormQuery['og.order_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('order_id'); $searchFormQuery['og.rec_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('rec_id'); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['og.goods_name'] = $validator->validate('goods_name'); $searchFormQuery['oi.order_sn'] = $validator->validate('order_sn'); $searchFormQuery['oi.pay_no'] = $validator->validate('pay_no'); $order_goods_status = $validator->min(-1)->filter('ValidatorIntValue')->validate('order_goods_status'); if ($order_goods_status >= 0) { $searchFormQuery['og.order_goods_status'] = $order_goods_status; } $searchFormQuery['oi.consignee'] = $validator->validate('consignee'); $searchFormQuery['oi.mobile'] = $validator->validate('mobile'); $searchFormQuery['oi.address'] = $validator->validate('address'); $searchFormQuery['oi.postscript'] = $validator->validate('postscript'); $searchFormQuery['og.memo'] = $validator->validate('memo'); $searchFormQuery['oi.kefu_user_id'] = $validator->filter('ValidatorIntValue')->validate('kefu_user_id'); $searchFormQuery['og.goods_admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('goods_admin_user_id'); //下单时间 $createTimeStartStr = $validator->validate('create_time_start'); $createTimeStart = Time::gmStrToTime($createTimeStartStr) ?: null; $createTimeEndStr = $validator->validate('create_time_end'); $createTimeEnd = Time::gmStrToTime($createTimeEndStr) ?: null; $searchFormQuery['og.create_time'] = array($createTimeStart, $createTimeEnd); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); if (!$this->validate($validator)) { goto out_display; } // 构造查询条件 $searchParamArray = array(); // 用户取消的订单商品我们就不再显示了 $searchParamArray[] = array(QueryBuilder::buildNotInCondition('oi.order_status', array(OrderBasicService::OS_CANCELED, OrderBasicService::OS_INVALID), \PDO::PARAM_INT)); if (1 == $shippingStatus) { // 1 未发货 $searchParamArray[] = array('og.shipping_id = 0'); } elseif (2 == $shippingStatus) { // 2 已发货 $searchParamArray[] = array('og.shipping_id <> 0'); } else { // do nothing } // 用户查询,目前支持 用户名、邮箱 查询 $user_name = $validator->validate('user_name'); $email = $validator->validate('email'); if (!empty($user_name) || !empty($email)) { $userQuery = array(); $userQuery['user_name'] = $user_name; $userQuery['email'] = $email; $userBasicService = new UserBasicService(); $queryUserArray = $userBasicService->_fetchArray('users', 'user_id', QueryBuilder::buildQueryCondArray($userQuery), array('order' => 'user_id desc'), 0, 1000); unset($userBasicService); if (empty($queryUserArray)) { $this->addFlashMessage('搜索的用户不存在'); } else { $userIdArray = array(); foreach ($queryUserArray as $queryUser) { $userIdArray[] = $queryUser['user_id']; } if (!empty($userIdArray)) { $searchParamArray[] = array(QueryBuilder::buildInCondition('oi.user_id', $userIdArray, \PDO::PARAM_INT)); } unset($userIdArray); unset($queryUserArray); } } $utmSource = $validator->validate('utm_source'); if ('SELF' == $utmSource) { $searchParamArray[] = array('orf.utm_source is null'); } else { $searchFormQuery['orf.utm_source'] = array('=', $utmSource); } $utmMedium = $validator->validate('utm_medium'); if ('SELF' == $utmMedium) { $searchParamArray[] = array('orf.utm_medium is null'); } else { $searchFormQuery['orf.utm_medium'] = array('=', $utmMedium); } // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); // 使用哪个搜索模块 $searchModule = SearchHelper::Module_OrderGoodsOrderInfo; if (!empty($utmSource) || !empty($utmMedium)) { $searchModule = SearchHelper::Module_OrderGoodsOrderInfoOrderRefer; } // 查询订单列表 $totalCount = SearchHelper::count($searchModule, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Order/Goods/Search'); } // 查询订单列表 $orderGoodsArray = SearchHelper::search($searchModule, $searchFieldSelector, $searchParamArray, array(array('og.order_id', 'desc')), $pageNo * $pageSize, $pageSize); // 订单的支付状态显示 foreach ($orderGoodsArray as &$orderGoodsItem) { $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']]; } // 前面用了引用,这里一定要清除,防止影响后面的数据 unset($orderGoodsItem); // 取得用户 id 列表 $userIdArray = array(); foreach ($orderGoodsArray as $orderGoodsItem) { $userIdArray[] = $orderGoodsItem['user_id']; } $userIdArray = array_unique($userIdArray); //取得用户信息 $userBasicService = new UserBasicService(); $userArray = $userBasicService->fetchUserArrayByUserIdArray($userIdArray); // 建立 user_id --> user 的反查表,方便快速查询 $userIdToUserArray = array(); foreach ($userArray as $user) { $userIdToUserArray[$user['user_id']] = $user; } // 放入用户信息 foreach ($orderGoodsArray as &$orderGoodsItem) { if (isset($userIdToUserArray[$orderGoodsItem['user_id']])) { // 很老的订单,用户可能被删除了 $orderGoodsItem['user_name'] = $userIdToUserArray[$orderGoodsItem['user_id']]['user_name']; $orderGoodsItem['email'] = $userIdToUserArray[$orderGoodsItem['user_id']]['email']; } } // 前面用了引用,这里一定要清除,防止影响后面的数据 unset($orderGoodsItem); // 给模板赋值 $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('orderGoodsArray', $orderGoodsArray); out_display: $smarty->display('order_goods_search.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(); $searchKeywords = $validator->validate('keywords'); $searchFormQuery['g.goods_name'] = $searchKeywords; // 这里支持多品牌查询 $searchFormQuery['g.brand_id'] = array('=', $validator->validate('brand_id')); // 价格区间查询 $shopPriceMin = $validator->filter('ValidatorFloatValue')->validate('shop_price_min'); $shopPriceMin = null == $shopPriceMin ? null : Money::toStorage($shopPriceMin); $shopPriceMax = $validator->filter('ValidatorFloatValue')->validate('shop_price_max'); $shopPriceMax = null == $shopPriceMax ? null : Money::toStorage($shopPriceMax); $searchFormQuery['g.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('g.sort_order', 'desc'); $orderByParam[] = array('g.goods_id', 'desc'); // 参数验证 if (!$this->validate($validator) || empty($searchFormQuery)) { goto out_fail; } $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 45; // 每页固定显示 45 个商品 // 生成 smarty 的缓存 id $smartyCacheId = 'Goods|Search|' . md5(json_encode($searchFormQuery) . json_encode($orderByParam) . '_' . $pageNo . '_' . $pageSize); // 开启并设置 smarty 缓存时间 enableSmartyCache(true, bzf_get_option_value('smarty_cache_time_goods_search')); if ($smarty->isCached('goods_search.tpl', $smartyCacheId)) { goto out_display; } $goodsCategoryService = new GoodsCategoryService(); // 1. 我们需要在左侧显示分类层级结构 $goodsCategoryTreeArray = $goodsCategoryService->fetchCategoryTreeArray(0, false, 1800); $smarty->assign('goodsCategoryTreeArray', $goodsCategoryTreeArray); /** * 构造 Filter 数组,结构如下 * * array( * '商品品牌' => array( * filterKey => 'brand_id' * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ), * '颜色' => array( * filterKey => 'filter', * filterValueArray => array( array(value=>'13', text=>'品牌1'), ...) * ) * ) * */ $goodsFilterArray = array(); // filter 查询在这个条件下进行 $goodsFilterQueryCond = array_merge(QueryBuilder::buildSearchParamArray(array('g.goods_name' => $searchKeywords)), $this->searchExtraCondArray); // 2. 商品品牌查询 $goodsBrandIdArray = SearchHelper::search(SearchHelper::Module_Goods, 'distinct(g.brand_id)', array_merge($goodsFilterQueryCond, array(array('g.brand_id > 0'))), null, 0, 0); $brandIdArray = array_map(function ($elem) { return $elem['brand_id']; }, $goodsBrandIdArray); if (!empty($brandIdArray)) { $goodsBrandService = new GoodsBrandService(); $goodsBrandArray = $goodsBrandService->fetchBrandArrayByIdArray(array_unique(array_values($brandIdArray))); $filterBrandArray = array(); foreach ($goodsBrandArray as $brand) { $filterBrandArray[] = array('value' => $brand['brand_id'], 'text' => $brand['brand_name']); } if (!empty($filterBrandArray)) { $goodsFilterArray['品牌'] = array('filterKey' => 'brand_id', 'filterValueArray' => $filterBrandArray); } } if (!empty($goodsFilterArray)) { $smarty->assign('goodsFilterArray', $goodsFilterArray); } // 3. 商品属性过滤 TODO: 等以后扩展,看看 Search 怎么做属性过滤 // 4. 商品查询 // 构造 filter 参数,注意 filter 参数在 GoodsGoodsAttr 中具体解析 // 合并查询参数 $searchParamArray = array_merge(QueryBuilder::buildSearchParamArray($searchFormQuery), $this->searchExtraCondArray); $totalCount = SearchHelper::count(SearchHelper::Module_GoodsGoodsAttr, $searchParamArray); if ($totalCount <= 0) { goto out_display; // 没有商品,直接显示 } // 页号可能是用户乱输入的,我们需要检查 if ($pageNo * $pageSize >= $totalCount) { goto out_fail; // 返回首页 } $goodsArray = SearchHelper::search(SearchHelper::Module_GoodsGoodsAttr, 'g.goods_id, g.cat_id, g.goods_sn, g.goods_name, g.brand_id, g.goods_number, g.market_price' . ', g.shop_price, g.suppliers_id, g.virtual_buy_number, g.user_buy_number, g.user_pay_number' . ', (g.virtual_buy_number + g.user_pay_number) as total_buy_number', $searchParamArray, $orderByParam, $pageNo * $pageSize, $pageSize); if (empty($goodsArray)) { goto out_display; } $smarty->assign('goodsArray', $goodsArray); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); // SEO 考虑,网页标题加上分类的名称 $smarty->assign('seo_title', '商品搜索,' . $searchKeywords . ',' . $smarty->getTemplateVars('seo_title')); out_display: // 滑动图片广告 $goods_search_adv_slider = json_decode(bzf_get_option_value('goods_search_adv_slider'), true); if (!empty($goods_search_adv_slider)) { $smarty->assign('goods_search_adv_slider', $goods_search_adv_slider); } $smarty->display('goods_search.tpl', $smartyCacheId); return; out_fail: // 失败从这里返回 RouteHelper::reRoute($this, '/'); // 返回首页 }
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 Search($f3) { /** * 我们使用搜索模块做搜索操作 */ $searchFieldSelector = 'og.*, oi.pay_time, oi.system_id'; 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; // shippingStatus, 0 全部,1 已发货,2 未发货 $shippingStatus = $validator->digits()->min(1)->validate('shippingStatus'); //表单查询 $searchFormQuery = array(); $searchFormQuery['og.order_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('order_id'); $searchFormQuery['og.rec_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('rec_id'); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); $searchFormQuery['og.order_goods_status'] = $validator->min(1)->filter('ValidatorIntValue')->validate('order_goods_status'); $searchFormQuery['og.goods_sn'] = $validator->validate('goods_sn'); $searchFormQuery['oi.consignee'] = $validator->validate('consignee'); $searchFormQuery['oi.mobile'] = $validator->validate('mobile'); $searchFormQuery['oi.address'] = $validator->validate('address'); $searchFormQuery['oi.postscript'] = $validator->validate('postscript'); $searchFormQuery['og.memo'] = $validator->validate('memo'); //下单时间 $addTimeStartStr = $validator->validate('add_time_start'); $addTimeStart = Time::gmStrToTime($addTimeStartStr) ?: null; $addTimeEndStr = $validator->validate('add_time_end'); $addTimeEnd = Time::gmStrToTime($addTimeEndStr) ?: null; $searchFormQuery['oi.add_time'] = array($addTimeStart, $addTimeEnd); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); if (!$this->validate($validator)) { goto out_display; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); // 供货商只能查看自己商品对应的订单 $searchFormQuery['og.suppliers_id'] = intval($authSupplierUser['suppliers_id']); $searchParamArray = array(); // 供货商只能查看已经付款的订单 $searchParamArray[] = array('og.order_goods_status > 0'); if (1 == $shippingStatus) { // 1 未发货 $searchParamArray[] = array('og.shipping_id = 0'); } elseif (2 == $shippingStatus) { // 2 已发货 $searchParamArray[] = array('og.shipping_id <> 0'); } else { // do nothing } // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); // 查询订单列表 $totalCount = SearchHelper::count(SearchHelper::Module_OrderGoodsOrderInfo, $searchParamArray); if ($totalCount <= 0) { // 没订单,可以直接退出了 goto out_display; } // 页数超过最大值,返回第一页 if ($pageNo * $pageSize >= $totalCount) { RouteHelper::reRoute($this, '/Order/Goods/Search'); } // 订单列表 $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, $searchFieldSelector, $searchParamArray, array(array('oi.pay_time', 'desc')), $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('order_goods_search.tpl'); }