Example #1
0
 /**
  *
  * 根据某些查询条件取得商品的列表
  *
  * @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);
 }
Example #2
0
 /**
  * 列出结算列表
  *
  * @param $f3
  */
 public function ListSettle($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 表单查询
     $formQuery = array();
     //结算时间
     $settleTimeStartStr = $validator->validate('settle_time_start');
     $settleTimeStart = Time::gmStrToTime($settleTimeStartStr) ?: null;
     $settleTimeEndStr = $validator->validate('settle_time_end');
     $settleTimeEnd = Time::gmStrToTime($settleTimeEndStr) ?: null;
     $formQuery['create_time'] = array($settleTimeStart, $settleTimeEnd);
     //是否已经付款
     $is_pay = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('is_pay');
     switch ($is_pay) {
         case 1:
             $formQuery['pay_time'] = 0;
             break;
         case 2:
             $formQuery['pay_time'] = array($is_pay, null);
             break;
         default:
             break;
     }
     // 供货商只能查看自己的结算历史
     $authSupplierUser = AuthHelper::getAuthUser();
     $formQuery['suppliers_id'] = $authSupplierUser['suppliers_id'];
     // 构建查询条件
     $condArray = null;
     if (!empty($formQuery)) {
         $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     }
     // 查询结算列表
     $orderSettleService = new OrderSettleService();
     $totalCount = $orderSettleService->countOrderSettleArray($condArray);
     if ($totalCount <= 0) {
         // 没商品,可以直接退出了
         goto out;
     }
     // 页数超过最大值,返回
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Order/Settle/ListSettle');
     }
     // 结算列表
     $orderSettleArray = $orderSettleService->fetchOrderSettleArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderSettleArray', $orderSettleArray);
     out:
     $smarty->display('order_settle_listsettle.tpl');
 }
Example #3
0
 public function __construct()
 {
     $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
     // 我们只搜索有效商品
     $this->searchExtraCondArray = array(array('is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1'), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray())));
     // 选择我们需要的字段
     $this->searchFieldSelector = 'goods_id, goods_name, market_price, shop_price';
 }
Example #4
0
 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');
 }
Example #5
0
    public function get($f3)
    {
        global $smarty;
        $smartyCacheId = 'EtaoFeed|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '_\\' . __METHOD__);
        // 判断是否有缓存
        enableSmartyCache(true, 1200);
        // 缓存 20 分钟
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        $currentStamp = Time::localTimeStr();
        $sellerId = EtaoFeedPlugin::getOptionValue('etaofeed_seller_id');
        $categoryUrl = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Category', null, false, true);
        $itemDir = RouteHelper::makeUrl('/Thirdpart/EtaoFeed/Item', null, false, true);
        $itemIdXmlList = '';
        // 处理 delete 的商品
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 0'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))));
        if ($totalGoodsCount <= 0) {
            goto query_update_goods;
        }
        $totalPageCount = ceil($totalGoodsCount / Item::$pageSize);
        for ($index = 0; $index < $totalPageCount; $index++) {
            $itemIdXmlList .= '<outer_id action="delete">1' . $index . '</outer_id>';
        }
        query_update_goods:
        // 处理修改过的商品
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array('is_on_sale = 1'), array('update_time', '>=', EtaoFeedPlugin::getOptionValue('etaofeed_query_timestamp')), array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray()))));
        if ($totalGoodsCount <= 0) {
            goto out_output;
        }
        $totalPageCount = ceil($totalGoodsCount / Item::$pageSize);
        for ($index = 0; $index < $totalPageCount; $index++) {
            $itemIdXmlList .= '<outer_id action="upload">2' . $index . '</outer_id>';
        }
        out_output:
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <version>1.0</version>
  <modified>{$currentStamp}</modified>
  <seller_id>{$sellerId}</seller_id>
  <cat_url>{$categoryUrl}</cat_url>
  <dir>{$itemDir}/</dir>
  <item_ids>{$itemIdXmlList}</item_ids>
</root>
XML;
        $smarty->assign('outputContent', $apiXml);
        // 更新查询时间
        //EtaoFeedPlugin::saveOptionValue('etaofeed_query_timestamp', Time::gmTime());
        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);
    }
Example #6
0
 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');
 }
Example #7
0
 /**
  * 给出一组商品 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);
 }
Example #8
0
 /**
  * 对查询参数做一些处理,使得它能适合我们的 sql 搜索
  *
  * @param $searchParamArray
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 protected function prepareSearchParam($searchParamArray)
 {
     if (!is_array($searchParamArray)) {
         throw new \InvalidArgumentException('searchParam illegal : ' . var_export($searchParamArray, true));
     }
     $resultParamArray = array();
     foreach ($searchParamArray as $searchParam) {
         if (is_array($searchParam) && count($searchParam) == 3) {
             switch ($searchParam[0]) {
                 // 取分类下面的商品,包括子分类的商品,我们需要取得所有子分类的 ID 然后重新构造查询条件
                 case 'category_id':
                 case 'g.category_id':
                 case 'cat_id':
                 case 'g.cat_id':
                     $goodsCategoryService = new GoodsCategoryService();
                     // 最多取 5 层分类,缓存 10 分钟
                     $childrenIdArray = $goodsCategoryService->fetchCategoryChildrenIdArray($searchParam[2], 5, 600);
                     $childrenIdArray[] = $searchParam[2];
                     // 加入父节点
                     // 构造新的查询条件
                     $searchParam = array(QueryBuilder::buildInCondition('g.cat_id', $childrenIdArray, \PDO::PARAM_INT));
                     break;
                     // 允许多品牌查询,需要生成 OR 查询条件,多品牌查询的情况 brand_id = 123_45_65_35 ,采用 _ 作为分隔
                 // 允许多品牌查询,需要生成 OR 查询条件,多品牌查询的情况 brand_id = 123_45_65_35 ,采用 _ 作为分隔
                 case 'brand_id':
                 case 'g.brand_id':
                     // 只处理 = 的情况
                     if ('=' != $searchParam[1] || false === strpos($searchParam[2], '_')) {
                         break;
                     }
                     $brandValueArray = explode('_', $searchParam[2]);
                     $brandQueryCondArray = array();
                     foreach ($brandValueArray as $brandValue) {
                         if (!empty($brandValue)) {
                             $brandQueryCondArray[] = array('g.brand_id = ?', intval($brandValue));
                         }
                     }
                     // 生成一串的 OR 查询
                     $searchParam = QueryBuilder::buildOrFilter($brandQueryCondArray);
                     break;
                 default:
                     break;
             }
         }
         $resultParamArray[] = $searchParam;
     }
     return $resultParamArray;
 }
Example #9
0
 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');
 }
Example #10
0
 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');
 }
Example #11
0
 public function ListBrand($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_brand_listbrand');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 查询条件
     $formQuery = array();
     $formQuery['brand_name'] = $validator->validate('brand_name');
     $formQuery['brand_desc'] = $validator->validate('brand_desc');
     $formQuery['is_custom'] = $validator->filter('ValidatorIntValue')->validate('is_custom');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     $goodsBrandService = new GoodsBrandService();
     $totalCount = $goodsBrandService->countBrandArray($condArray);
     if ($totalCount <= 0) {
         // 没用户,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Goods/Brand/ListBrand');
     }
     // 查询数据
     $goodsBrandArray = $goodsBrandService->fetchBrandArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsBrandArray', $goodsBrandArray);
     out_display:
     $smarty->display('goods_brand_listbrand.tpl');
 }
Example #12
0
 public function ListComment($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_comment_listcomment');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 查询条件
     $formQuery = array();
     $formQuery['goods_id'] = $validator->filter('ValidatorIntValue')->validate('goods_id');
     $formQuery['is_show'] = $validator->filter('ValidatorIntValue')->validate('is_show');
     $formQuery['admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('admin_user_id');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     // 查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     $baseService = new BaseService();
     $totalCount = $baseService->_countArray('goods_comment', $condArray);
     if ($totalCount <= 0) {
         // 没用户,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Goods/AttrGroup/ListAttrGroup');
     }
     // 查询数据
     $goodsCommentArray = $baseService->_fetchArray('goods_comment', '*', $condArray, array('order' => 'comment_id desc'), $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsCommentArray', $goodsCommentArray);
     out_display:
     $smarty->display('goods_comment_listcomment.tpl');
 }
Example #13
0
 /**
  * 供货商列表显示
  */
 public function ListUser($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_supplier_listuser');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     //查询条件
     $formQuery = array();
     $formQuery['suppliers_name'] = $validator->validate('suppliers_name');
     $formQuery['suppliers_desc'] = $validator->validate('suppliers_desc');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     // 查询供货商列表
     $supplierUserService = new SupplierUserService();
     $totalCount = $supplierUserService->countSupplierArray($condArray);
     if ($totalCount <= 0) {
         // 没用户,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Account/Supplier/ListUser');
     }
     // 供货商列表
     $supplierUserArray = $supplierUserService->fetchSupplierArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('supplierUserArray', $supplierUserArray);
     out_display:
     $smarty->display('account_supplier_listuser.tpl');
 }
Example #14
0
 /**
  * 取得 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);
 }
Example #15
0
 public function ListType($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_goods_type_listtype');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 查询条件
     $formQuery = array();
     $formQuery['meta_name'] = $validator->validate('meta_name');
     $formQuery['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     // 查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     $goodsTypeService = new GoodsTypeService();
     $totalCount = $goodsTypeService->countGoodsTypeArray($condArray);
     if ($totalCount <= 0) {
         // 没数据,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Goods/Type/ListType');
     }
     // 查询数据
     $goodsTypeArray = $goodsTypeService->fetchGoodsTypeArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('goodsTypeArray', $goodsTypeArray);
     out_display:
     $smarty->display('goods_type_listtype.tpl');
 }
Example #16
0
 /**
  * 根据一组词返回一组词条
  *
  * @param  array   $wordArray   例如: array('360cps','yiqifacps',...)
  * @param int      $ttl
  *
  * @return array
  *
  * 格式为 array(
  *          array('word' => $word, 'name' => '用于显示的名字', 'desc' => '解释描述', 'data' => '额外数据'),
  *          array('word' => $word, 'name' => '用于显示的名字', 'desc' => '解释描述', 'data' => '额外数据'),
  *      )
  */
 public function getWordArray($wordArray, $ttl = 0)
 {
     $inCond = QueryBuilder::buildInCondition('meta_key', $wordArray, \PDO::PARAM_STR);
     $queryResult = $this->_fetchArray('meta', '*', array(array('meta_type = ? ', Dictionary::META_TYPE), array($inCond)), array('order' => 'meta_sort_order desc, meta_id desc'), 0, 0, $ttl);
     // 建立 word --> 记录 的倒查表
     $wordToMetaArray = array();
     foreach ($queryResult as $resultItem) {
         $wordToMetaArray[$resultItem['meta_key']] = $resultItem;
     }
     // 构造最后的查询结果
     $wordDict = array();
     foreach ($wordArray as $word) {
         if (array_key_exists($word, $wordToMetaArray)) {
             $meta = $wordToMetaArray[$word];
             $wordDict[] = array('word' => $word, 'name' => $meta['meta_name'], 'desc' => $meta['meta_desc'], 'data' => $meta['meta_data']);
         } else {
             $wordDict[] = array('word' => $word, 'name' => $word, 'desc' => $word, 'data' => '');
         }
     }
     return $wordDict;
 }
Example #17
0
    public function get($f3)
    {
        global $smarty;
        $cacheTime = 300;
        // 缓存5分钟
        enableSmartyCache(true, $cacheTime);
        $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__);
        // 判断是否有缓存
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        // 查询商品
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $condArray = array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray())));
        $apiGoodsService = new ApiGoodsService();
        $goodsGalleryPromoteArray = $apiGoodsService->fetchGoodsGalleryPromote($condArray, 'aimeidaren_sort_order desc, sort_order desc, goods_id desc', 0, 0, $cacheTime);
        // 商品和图片
        $goodsArray = $goodsGalleryPromoteArray['goods'];
        $goodsIdToGalleryArray = $goodsGalleryPromoteArray['goodsIdToGalleryArray'];
        $xmlItems = '';
        $goodsArrayCount = count($goodsArray);
        for ($index = 0; $index < $goodsArrayCount; $index++) {
            $xmlItems .= $this->getGoodsItemXml($index + 1, $goodsArray[$index], $goodsIdToGalleryArray);
        }
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<urlset>
\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);
    }
Example #18
0
 /**
  * 把一个表的数据转换到另外一个表中
  *
  * @param string   $srcTableName                     源表名
  * @param array    $condArray
  *                                                   array(
  *                                                   array('supplier_id = ?', $supplier_id)
  *                                                   array('is_on_sale = ?', 1)
  *                                                   array('supplier_price > ? or supplier_price < ?', $priceMin, $priceMax)
  * )
  * @param array    $optionArray                      排序分页等条件 ,格式例如  array('order' => 'goods_id asc', 'offset' => 100, 'limit' => '10')
  * @param string   $dstTableName                     目的表名
  * @param array    $columnMap                        列对应,格式如 array('id' => 'goods_id' , 'name' => 'goods_name')
  * @param array    $srcValueConvertFuncArray
  *              对源数据做装换,例如: array('id' => function($srcValue, $srcRecord){ return $srcValue + 1;} , ...),用闭包函数做转化
  * @param callable $recordPreFunc                    在查询到 src 的记录之后调用 ,函数原型 function(&$srcRecord){ ... }
  * @param callable $recordPostFunc                   在 src 已经往 dst 赋值完成之后,dst 还没有写入数据库之前调用,函数原型  function(&$srcRecord, &dstRecord){...}
  *
  */
 public function convertTable($srcTableName, $condArray, $optionArray, $dstTableName, $columnMap, $srcValueConvertFuncArray, $recordPreFunc = null, $recordPostFunc = null)
 {
     $srcFieldArray = array();
     $dstFieldArray = array();
     foreach ($columnMap as $srcField => $dstField) {
         $srcFieldArray[] = $srcField;
         $dstFieldArray[] = $dstField;
     }
     $srcTable = new SrcDataMapper($srcTableName);
     // 构造查询条件
     $filter = null;
     if (!empty($condArray)) {
         $filter = QueryBuilder::buildAndFilter($condArray);
     }
     // 获得总数
     $totalRecordCount = $srcTable->count($filter);
     printLog('begin convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource);
     $recordLeft = $totalRecordCount;
     // 剩余多少记录需要处理
     $queryOffset = 0;
     // 查询的起始位置
     while ($recordLeft > 0) {
         // 这次需要处理多少记录
         $processCount = $recordLeft > $this->batchProcessCount ? $this->batchProcessCount : $recordLeft;
         // 记录处理进度
         printLog('totalRecordCount:' . $totalRecordCount . ' recordLeft:' . $recordLeft . ' processCount:' . $processCount, self::$loggerSource);
         $recordLeft -= $processCount;
         // 从源表查询数据
         $srcField = '*';
         if (!empty($srcFieldArray)) {
             $srcField = implode(',', $srcFieldArray);
         }
         // 处理查询的起始位置
         $optionArray = array_merge($optionArray, array('offset' => $queryOffset, 'limit' => $processCount));
         $queryOffset += $processCount;
         // 查询数据
         $srcRecordList = $srcTable->select($srcField, $filter, $optionArray);
         // 转换数据到目标表中
         foreach ($srcRecordList as $srcRecordItem) {
             // PreFunc 处理
             if ($recordPreFunc) {
                 $recordPreFunc($srcRecordItem);
             }
             $dstTable = new DstDataMapper($dstTableName);
             //字段复制
             foreach ($columnMap as $srcField => $dstField) {
                 // 无意义的字段,不复制
                 if (null == $dstField) {
                     continue;
                 }
                 if (isset($srcValueConvertFuncArray) && isset($srcValueConvertFuncArray[$srcField])) {
                     if (!is_callable($srcValueConvertFuncArray[$srcField])) {
                         printLog($srcField . ' value convert is not function ', self::$loggerSource, \Core\Log\Base::ERROR);
                         continue;
                     }
                     // 做数据转化
                     $dstTable->{$dstField} = $srcValueConvertFuncArray[$srcField]($srcRecordItem[$srcField], $srcRecordItem);
                 } else {
                     $dstTable->{$dstField} = $srcRecordItem[$srcField];
                 }
             }
             // postFunc 处理
             if ($recordPostFunc) {
                 $recordPostFunc($srcRecordItem, $dstTable);
             }
             $dstTable->save();
             unset($dstTable);
             // 及时释放数据,优化内存使用
         }
         unset($srcRecordList);
         // 及时释放数据,优化内存使用
         gc_collect_cycles();
         // 主动做一次垃圾回收
     }
     printLog('finish convertTable ' . $srcTableName . '-->' . $dstTableName . ' totalRecordCount:' . $totalRecordCount, self::$loggerSource);
 }
Example #19
0
 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');
 }
Example #20
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($_GET);
     $cid = $validator->required()->validate('cid');
     $queryCreateDate = $validator->digits()->validate('d');
     $queryUpdateDate = $validator->digits()->validate('ud');
     // 参数有错误
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 不能同时为空
     if (empty($queryCreateDate) && empty($queryUpdateDate)) {
         goto out_fail;
     }
     if (!empty($queryCreateDate)) {
         // 参数检查,格式只能为 20120304 或者 2012030410
         $dateStrLen = strlen($queryCreateDate);
         if (8 != $dateStrLen && 10 != $dateStrLen) {
             goto out_fail;
         }
     }
     if (!empty($queryUpdateDate)) {
         // 参数检查,格式只能为 20120304 或者 2012030410
         $dateStrLen = strlen($queryUpdateDate);
         if (8 != $dateStrLen && 10 != $dateStrLen) {
             goto out_fail;
         }
     }
     enableSmartyCache(true, 60);
     //缓存1分钟,防止访问很频繁从而变成对网站的攻击
     $smartyCacheId = 'YiqifaCps|' . md5(json_encode(QueryOrder::$extraQueryCond) . '_' . $cid . '_' . $queryCreateDate . '_' . $queryUpdateDate);
     // 判断是否有缓存
     if ($smarty->isCached('yiqifacps_empty.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $txtOutput = '';
     // 构造查询条件
     $condArray = array();
     $condArray[] = array('orf.utm_source = ? or (orf.login_type = ? and orf.utm_source is null)', 'YIQIFACPS', 'qqlogin');
     // add_time 查询
     if (!empty($queryCreateDate)) {
         $startTime = 0;
         $endTime = 0;
         if (strlen($queryCreateDate) == 8) {
             $startTime = strtotime($queryCreateDate);
             $endTime = $startTime + 24 * 60 * 60;
         }
         if (strlen($queryCreateDate) == 10) {
             $datePart = substr($queryCreateDate, 0, 8);
             $hourPart = substr($queryCreateDate, 8, 2);
             $startTime = strtotime($datePart . " " . $hourPart . ":00:00");
             $endTime = $startTime + 60 * 60;
         }
         $condArray[] = array('oi.add_time >= ? and oi.add_time < ?', $startTime, $endTime);
     }
     // update_time 查询
     if (!empty($queryUpdateDate)) {
         $startTime = 0;
         $endTime = 0;
         if (strlen($queryUpdateDate) == 8) {
             $startTime = strtotime($queryUpdateDate);
             $endTime = $startTime + 24 * 60 * 60;
         }
         if (strlen($queryUpdateDate) == 10) {
             $datePart = substr($queryUpdateDate, 0, 8);
             $hourPart = substr($queryUpdateDate, 8, 2);
             $startTime = strtotime($datePart . " " . $hourPart . ":00:00");
             $endTime = $startTime + 60 * 60;
         }
         $condArray[] = array('oi.update_time >= ? and oi.update_time < ?', $startTime, $endTime);
     }
     /**
      * 加入额外的查询条件
      */
     if (!empty(QueryOrder::$extraQueryCond)) {
         $condArray[] = QueryOrder::$extraQueryCond;
     }
     // 查询订单,每次最多 2000 条数据,防止拖死系统
     $orderReferService = new OrderReferService();
     $orderReferInfoArray = $orderReferService->fetchOrderReferInfo($condArray, array('order' => 'oi.order_id asc'), 0, 2000);
     // 过滤 cid,只留下需要查询的 cid 数据,同时收集 order_id 用于查询 order_goods 信息
     $cidOrderReferInfoArray = array();
     $orderIdArray = array();
     foreach ($orderReferInfoArray as $orderReferInfoItem) {
         $referParamArray = json_decode($orderReferInfoItem['refer_param'], true);
         if (!empty($referParamArray['cid']) && $referParamArray['cid'] != $cid) {
             //不是要查询的订单,跳过
             continue;
             // ==== 为了测试临时注释的代码
         }
         $cidOrderReferInfoArray[] = $orderReferInfoItem;
         $orderIdArray[] = $orderReferInfoItem['order_id'];
     }
     unset($orderReferInfoArray);
     //清除旧数据
     $orderReferInfoArray = $cidOrderReferInfoArray;
     unset($cidOrderReferInfoArray);
     //清除临时数据
     if (empty($orderReferInfoArray)) {
         // 没有数据,跳出
         goto out;
     }
     $orderGoodsArray = $orderReferService->_fetchArray('order_goods', '*', array(array(QueryBuilder::buildInCondition('order_id', $orderIdArray))), array('order' => 'order_id asc, rec_id asc'), 0, 10000);
     //最多查询 10000 条记录,防止拖死系统
     // 建立 order_id --> array( order_goods ) 的反查表
     $orderIdToOrderGoodsArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         if (!isset($orderIdToOrderGoodsArray[$orderGoodsItem['order_id']])) {
             $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']] = array();
         }
         $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']][] = $orderGoodsItem;
     }
     // 根据订单构建 CPS 返回记录
     foreach ($orderReferInfoArray as $orderReferItem) {
         if (isset($orderIdToOrderGoodsArray[$orderReferItem['order_id']])) {
             $txtOutput .= $this->getOrderTxt($orderReferItem, $orderIdToOrderGoodsArray[$orderReferItem['order_id']]);
         }
     }
     out:
     $smarty->assign('outputContent', $txtOutput);
     out_display:
     //成功从这里返回
     header('Content-Type:text/plain;charset=utf-8');
     header("Cache-Control: no-cache, must-revalidate");
     // HTTP/1.1 //查询信息
     $smarty->display('yiqifacps_empty.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     echo "paramters error";
 }
Example #21
0
 /**
  * 取得对应分类下面商品的总数,用于分页显示
  *
  * @return int 商品总数
  *
  * @param int $categoryId 分类的ID
  * @param int $level 取得多少层,子分类有可能很深,我们只取有限层次
  * @param string $systemTag 系统标记
  * @param int $ttl 缓存时间
  */
 public function countGoodsArray($categoryId, $level, $systemTag, $ttl = 0)
 {
     // 参数验证
     $validator = new Validator(array('categoryId' => $categoryId, 'level' => $level, 'systemTag' => $systemTag, 'ttl' => $ttl));
     $categoryId = $validator->digits()->min(0)->validate('categoryId');
     $level = $validator->required()->digits()->min(1)->validate('level');
     $systemTag = $validator->validate('systemTag');
     $ttl = $validator->digits()->min(0)->validate('ttl');
     $this->validate($validator);
     $childrenIdArray = $this->fetchCategoryChildrenIdArray($categoryId, $level, $ttl);
     $childrenIdArray[] = $categoryId;
     // 加入父节点
     $queryCondArray = array();
     $queryCondArray[] = array('is_delete = 0 AND is_on_sale = 1 AND is_alone_sale = 1');
     // 构建 SQL 的 in 语句, cat_id in (100,20,30)
     $queryCondArray[] = array(QueryBuilder::buildInCondition('cat_id', $childrenIdArray, \PDO::PARAM_INT));
     if (!empty($systemTag)) {
         $queryCondArray[] = array('system_tag_list like ? ', '%' . Utils::makeTagString(array($systemTag)) . '%');
     }
     $dataMapper = new DataMapper('goods');
     return $dataMapper->count(QueryBuilder::buildAndFilter($queryCondArray), null, $ttl);
 }
Example #22
0
 /**
  * 管理员操作日志
  *
  * @param $f3
  */
 public function ListLog($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_admin_listlog');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     //查询条件
     $formQuery = array();
     $formQuery['user_id'] = $validator->filter('ValidatorIntValue')->validate('user_id');
     $formQuery['operate'] = $validator->validate('operate');
     $formQuery['operate_desc'] = $validator->validate('operate_desc');
     //操作时间
     $operateTimeStartStr = $validator->validate('operate_time_start');
     $operateTimeStart = Time::gmStrToTime($operateTimeStartStr) ?: null;
     $operateTimeEndStr = $validator->validate('operate_time_end');
     $operateTimeEnd = Time::gmStrToTime($operateTimeEndStr) ?: null;
     $formQuery['operate_time'] = array($operateTimeStart, $operateTimeEnd);
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 20;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 建立查询条件
     $condArray = QueryBuilder::buildQueryCondArray($formQuery);
     // 查询管理员列表
     $adminLogService = new AdminLogService();
     $totalCount = $adminLogService->countAdminLogArray($condArray);
     if ($totalCount <= 0) {
         // 没数据,可以直接退出了
         goto out_display;
     }
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/Account/Admin/ListLog');
     }
     // 管理员列表
     $adminLogArray = $adminLogService->fetchAdminLogArray($condArray, $pageNo * $pageSize, $pageSize);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('adminLogArray', $adminLogArray);
     out_display:
     $smarty->display('account_admin_listlog.tpl');
 }
Example #23
0
 /**
  * 根据 id array 取得一组 brand 的名字
  *
  * @param array $idArray
  * @param int $ttl
  * @return array
  */
 public function fetchBrandArrayByIdArray($idArray, $ttl = 0)
 {
     return $this->_fetchArray('brand', '*', array(array(QueryBuilder::buildInCondition('brand_id', $idArray, \PDO::PARAM_INT))), array('order' => 'sort_order desc, brand_id desc'), 0, 0, $ttl);
 }
Example #24
0
 /**
  * 在这里做数据库查询
  *
  * @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;
 }
Example #25
0
 /**
  * 下载 拣货单
  *
  * @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 />';
     }
 }
Example #26
0
 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, '/');
     // 返回首页
 }
Example #27
0
 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');
 }
Example #28
0
 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');
 }
Example #29
0
 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, '/');
     // 返回首页
 }
Example #30
0
    /**
     * 输出 sitemapIndex 文件
     */
    public function outputSiteMapXml($f3, $fileName)
    {
        global $smarty;
        //缓存 60 分钟
        enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT);
        $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__);
        // 判断是否有缓存
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        // sitemap 列表
        $siteMapFileList = '';
        // 当前时间
        $currentTime = time();
        /***************** 生成 /Goods/View 列表 *******************/
        // 查询商品数量,决定分页有多少页
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray(), 'g'))));
        $pageCount = ceil($totalGoodsCount / $this->pageSize);
        // 取得当前的目录路径
        $currentUrl = RouteHelper::getFullURL();
        $currentUrl = substr($currentUrl, 0, strrpos($currentUrl, $fileName));
        // 生成 goods 页面索引
        for ($index = 0; $index < $pageCount; $index++) {
            $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>';
        }
        /***************** 生成 /Goods/Search 列表 *******************/
        // 生成 search 页面索引
        $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsSearch_' . $currentTime . '_0.xml</loc></sitemap>';
        /***************** 生成 /Article/View 列表 *******************/
        // 查询商品数量,决定分页有多少页
        $totalArticleCount = SearchHelper::count(SearchHelper::Module_Article, QueryBuilder::buildSearchParamArray(array('a.is_open' => 1)));
        $pageCount = ceil($totalArticleCount / $this->pageSize);
        // 生成 Article 页面索引
        for ($index = 0; $index < $pageCount; $index++) {
            $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'ArticleView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>';
        }
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{$siteMapFileList}
</sitemapindex>
XML;
        $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);
    }