private function preparePage($goods_id, $pageNo) { global $smarty; // 设置缺省值 $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0; $pageSize = 10; // 每页显示 10 个 // 查询条件 $condArray = array(); $condArray[] = array('goods_id = ?', $goods_id); $condArray[] = array('is_show = 1'); $baseService = new BaseService(); $totalCount = $baseService->_countArray('goods_comment', $condArray); if ($totalCount <= 0) { // 没数据,可以直接退出了 return; } // 页数超过最大值 if ($pageNo * $pageSize >= $totalCount) { return; } // 查询数据 $goodsCommentArray = $baseService->_fetchArray('goods_comment', '*', $condArray, array('order' => 'comment_id desc'), $pageNo * $pageSize, $pageSize); // 给 smarty 赋值 $smarty->assign('currentUrl', RouteHelper::makeUrl('/Ajax/GoodsComment', array('goods_id' => $goods_id))); $smarty->assign('totalCount', $totalCount); $smarty->assign('pageNo', $pageNo); $smarty->assign('pageSize', $pageSize); $smarty->assign('goodsCommentArray', $goodsCommentArray); }
public function count($searchType, $searchParam, $groupByStr = null) { // 构造查询条件 $searchParam = $this->prepareSearchParam($searchParam); $condArray = SqlSearch::buildSqlCondArray($searchParam); $optionArray = array(); if (!empty($groupByStr)) { $optionArray['group'] = $groupByStr; } if (empty($optionArray)) { $optionArray = null; } // 查询结果 $baseService = new BaseService(); return $baseService->_countArray($this->searchTable, $condArray, $optionArray, 0); }
public function run(array $params) { global $f3; // 每次处理多少条记录 $batchProcessCount = 100; // 图片所在的根目录 $dataPathRoot = $f3->get('sysConfig[data_path_root]'); $image_thumb_width = $f3->get('sysConfig[image_thumb_width]'); $image_thumb_height = $f3->get('sysConfig[image_thumb_height]'); $goodsGalleryService = new GoodsGalleryService(); $baseService = new BaseService(); $totalGoodsGalleryCount = $baseService->_countArray('goods_gallery', null); // 记录处理开始 for ($offset = 0; $offset < $totalGoodsGalleryCount; $offset += $batchProcessCount) { $goodsGalleryArray = $baseService->_fetchArray('goods_gallery', '*', null, array('order' => 'img_id asc'), $offset, $batchProcessCount); foreach ($goodsGalleryArray as $goodsGalleryItem) { if (!is_file($dataPathRoot . '/' . $goodsGalleryItem['img_original'])) { continue; // 文件不存在,不处理 } $pathInfoArray = pathinfo($goodsGalleryItem['img_original']); //生成缩略图 $imageThumbFileRelativeName = $pathInfoArray['dirname'] . '/' . $pathInfoArray['filename'] . '_' . $image_thumb_width . 'x' . $image_thumb_height . '.jpg'; //重新生存缩略图 printLog('Re-generate File :' . $imageThumbFileRelativeName); StorageImageHelper::resizeImage($dataPathRoot, $goodsGalleryItem['img_original'], $imageThumbFileRelativeName, $image_thumb_width, $image_thumb_height); // 更新 goods_gallery 设置 printLog('update goods_gallery img_id [' . $goodsGalleryItem['img_id'] . ']'); $goodsGallery = $goodsGalleryService->loadGoodsGalleryById($goodsGalleryItem['img_id']); if (!$goodsGallery->isEmpty()) { $goodsGallery->thumb_url = $imageThumbFileRelativeName; $goodsGallery->save(); } // 主动释放资源 unset($goodsGallery); unset($pathInfoArray); unset($imageThumbFileRelativeName); } unset($goodsGalleryArray); printLog('re-generate thumb image offset : ' . $offset); } printLog('re-generate thumb image finished , offset : ' . $offset); }
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'); }
public function run(array $params) { global $f3; // 每次处理多少条记录 $batchProcessCount = 100; $baseService = new BaseService(); $totalGoodsCount = $baseService->_countArray('goods', null); // 记录处理开始 for ($offset = 0; $offset < $totalGoodsCount; $offset += $batchProcessCount) { $goodsArray = $baseService->_fetchArray('goods', 'goods_id', null, array('order' => 'goods_id asc'), $offset, $batchProcessCount); foreach ($goodsArray as $goodsItem) { $sql = "update " . DataMapper::tableName('goods') . ' set ' . ' user_buy_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? )' . ' ,user_pay_number = (select sum(goods_number) from ' . DataMapper::tableName('order_goods') . ' where goods_id = ? and order_goods_status > 0)' . ' where goods_id = ? order by goods_id asc limit 1 '; $dbEngine = DataMapper::getDbEngine(); $dbEngine->exec($sql, array(1 => $goodsItem['goods_id'], $goodsItem['goods_id'], $goodsItem['goods_id'])); } unset($goodsArray); printLog('calculate goods buy number offset : ' . $offset); } printLog('calculate goods buy number finished , offset : ' . $offset); }