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); }
/** * 列出在线客服 * * @param $f3 */ public function ListKefuIdName($f3) { // 检查缓存 $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); $adminArray = $f3->get($cacheKey); if (!empty($adminArray)) { goto out; } $baseService = new BaseService(); $adminArray = $baseService->_fetchArray('admin_user', 'user_id,user_name', array(array('disable = 0'), array('is_kefu = 1')), array('order' => 'user_id desc'), 0, 0, 0); $f3->set($cacheKey, $adminArray, 300); //缓存 5 分钟 out: $f3->expire(60); // 客户端缓存 1 分钟 Ajax::header(); echo Ajax::buildResult(null, null, $adminArray); }
public function ListSupplierIdName($f3) { // 检查缓存 $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); $supplierArray = $f3->get($cacheKey); if (!empty($supplierArray)) { goto out; } $baseService = new BaseService(); $supplierArray = $baseService->_fetchArray('suppliers', 'suppliers_id,suppliers_account,suppliers_name', null, array('order' => 'suppliers_id desc'), 0, 0, 0); $f3->set($cacheKey, $supplierArray, 300); //缓存 5 分钟 out: $f3->expire(60); // 客户端缓存 1 分钟 Ajax::header(); echo Ajax::buildResult(null, null, $supplierArray); }
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 search($searchType, $fieldSelector, $searchParam, $orderByParam, $offset, $limit, $groupByStr = null) { // 构造查询条件 $searchParam = $this->prepareSearchParam($searchParam); $condArray = SqlSearch::buildSqlCondArray($searchParam); $optionArray = array(); if (!empty($orderByParam)) { $optionArray['order'] = SqlSearch::buildSqlOrderByStr($orderByParam); } if (!empty($groupByStr)) { $optionArray['group'] = $groupByStr; } if (empty($optionArray)) { $optionArray = null; } // 查询 $baseService = new BaseService(); return $baseService->_fetchArray($this->searchTable, $fieldSelector, $condArray, $optionArray, $offset, $limit, 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'); }
/** * 列出在线客服 * * @param $f3 */ public function ListKefuIdName($f3) { global $smarty; // 检查缓存 $smartyCacheId = 'Ajax|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); enableSmartyCache(true, 600); // 缓存 10 分钟 // 判断是否有缓存 if ($smarty->isCached('empty.tpl', $smartyCacheId)) { goto out_display; } $baseService = new BaseService(); $adminArray = $baseService->_fetchArray('admin_user', 'user_id,user_name', array(array('disable = 0'), array('is_kefu = 1')), array('order' => 'user_id desc'), 0, 0, 0); $smarty->assign('outputContent', Ajax::buildResult(null, null, $adminArray)); out_display: $f3->expire(600); // 客户端缓存 10 分钟 Ajax::header(); $smarty->display('empty.tpl', $smartyCacheId); }
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); }
/** * 列出订单的来源系统 * * @param $f3 */ public function ListOrderSystemId($f3) { // 检查缓存 $cacheKey = md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__); $resultArray = $f3->get($cacheKey); if (!empty($resultArray)) { goto out; } $baseService = new BaseService(); $queryResult = $baseService->_fetchArray('order_info', 'distinct(system_id)', array(array('system_id is not null')), null, 0, 0); if (empty($queryResult)) { $resultArray = array(); goto out; } // 构造词库 foreach ($queryResult as $queryItem) { $wordArray[] = $queryItem['system_id']; } // 字典服务转换显示 $metaDictionaryService = new MetaDictionaryService(); $resultArray = $metaDictionaryService->getWordArray($wordArray); $f3->set($cacheKey, $resultArray, 600); //缓存 10 分钟 out: Ajax::header(); echo Ajax::buildResult(null, null, $resultArray); }