Commit ca374dea by 朱继来

调整cms,若缓存不存在,则读取数据库

parent 83112cc0
......@@ -18,11 +18,11 @@ return array(
'DB_OTHER' => array(
'CMS' => array(
'db_type' => 'mysql',
'db_user' => 'ichuntcms',
'db_pwd' => 'ichuntcms#zsyM',
'db_user' => 'liexin_icsales',
'db_pwd' => 'liexin_icsales#zsyM',
'db_host' => '192.168.2.232',
'db_port' => '3306',
'db_name' => 'ichuntcms',
'db_name' => 'liexin_icsales',
'db_charset'=>'utf8',
),
'FS' => array(
......
......@@ -8,7 +8,8 @@ class CmsController extends BaseController
// 获取热门商品
public function getHotGoods()
{
$res = $this->checkApi(); // 接口校验
$request = I('request.');
$res = $this->checkApi($request); // 接口校验
if ($res === false) return $this->jsonReturn(11001, '接口校验失败');
......
<?php
namespace Home\Model;
use Think\Model;
/**
* 配置系统模型
* @authors yc ()
* @date 2017-08-02 11:15:25
* @version $Id$
*/
class CmsModel extends Model {
protected $autoCheckFields = false;
public function _initialize()
{
parent::_initialize();
$this->ScmsModel = D('Home/Scms');
$this->connection = C('DB_OTHER.CMS');
}
public function getModel($key = '', $field = 'model_id')
{
static $model_key;
if (!isset($model_key[$key])) {
$this->ScmsModel = D('Home/Scms');
$model_key[$key] = $this->ScmsModel->getModel($key);
if (empty($model_key[$key])) {
$map = array(
'model_key' => $key,
);
$model_key[$key] = $this->table('lie_model')->where($map)->field('model_id, model_name')->find();
}
}
return $model_key[$key][$field];
}
private function formatwhere($map, $where)
{
if (is_string($where)) {
if (!empty($where)) {
$where = array('_string' => $where);
} else {
$where = array();
}
}
$map = array_merge($map, $where);
return $map;
}
/**
* 获取基本配置
* @return [type] [description]
*/
public function getSetting()
{
$data = $this->table('lie_setting')->getField('set_key,set_val');
return $data;
}
/**
* 获取底部链接分类
* @param [type] $fcat_key [description]
* @return [type] [description]
*/
public function getFooterLinkCat($fcat_key)
{
$this->ScmsModel = D('Home/Scms');
$datas = $this->ScmsModel->getFooterLinkCat($fcat_key, 'fcat_id');
if (!empty($datas)) {
return $datas;
}
$map = array(
'fcat_key' => $fcat_key,
);
$datas = $this->table('lie_footer_link_cat')->where($map)->limit($limit)->getField('fcat_id');
return $datas;
}
/**
* 获取底部链接分类列表
* @param string $where [description]
* @param string $limit [description]
* @return [type] [description]
*/
public function getFooterLinkCatList($where = '', $limit = '')
{
$this->ScmsModel = D('Home/Scms');
$parent_id = isset($where['parent_id']) ? $where['parent_id'] : 0;
$datas = $this->ScmsModel->getFooterLinkCat('', '', $parent_id);
if (!empty($datas)) {
$datas = array_slice($datas, 0, $limit);
return $datas;
}
$datas = $this->table('lie_footer_link_cat')->where($where)->limit($limit)
->order('sort DESC')->field('fcat_id,fcat_name,parent_id')
->select();
return $datas;
}
/**
* 获取底部链接
* @param [type] $fcat_key [description]
* @return [type] [description]
*/
public function getFooterLink($fcat_id, $where = '', $limit = '')
{
$this->ScmsModel = D('Home/Scms');
$datas = $this->ScmsModel->getFooterLink($fcat_id);
if (!empty($datas)) {
$dats = array_slice($datas, 0, $limit);
return $datas;
}
$map = array(
'fcat_id' => $fcat_id,
'status' => 1,
);
$map = $this->formatwhere($map, $where);
$datas = $this->table('lie_footer_link')->where($map)->limit($limit)->field('flink_name,url,class,tip')->select();
return $datas;
}
/**
* 获取基础分类ID
* @param [type] $tags [description]
* @param string $field [description]
* @return [type] [description]
*/
public function getBaseCat($tags, $field = 'bcat_id')
{
static $bcat;
if (!isset($bcat[$tags])) {
$map = array(
'tags' => $tags,
);
$bcat[$tags] = $this->table('lie_base_cat')->where($map)->field('bcat_id, bcat_name')->find();
}
return $bcat[$tags][$field];
}
/**
* 获取配置分类值
* @param [type] $tags [description]
* @param string $where [description]
* @param string $limit [description]
* @return [type] [description]
*/
public function getBaseList($tags, $where = '', $limit = '')
{
$bcat_id = $this->getBaseCat($tags);
$map = array(
'bcat_id' => $bcat_id,
'_string' => "(status = 1) OR (status = 2 AND open_time >= {$_SERVER['REQUEST_TIME']} AND close_time <= {$_SERVER['REQUEST_TIME']})",
);
$map = $this->formatwhere($map, $where);
$datas = $this->table('lie_base')->where($map)->limit($limit)->order('sort DESC')->field('*')->select();
return $datas;
}
}
......@@ -69,7 +69,22 @@ class ScmsModel
public function getBaseList($tags, $where='', $limit=1)
{
$bcat_id = $this->getBcatId($tags); // 分类ID
return $this->getBase($bcat_id, $limit, $where);
$datas = $this->getBase($bcat_id, $limit, $where);
// 若缓存不存在,则读取数据库
if (!$datas) {
$cms = D('Home/Cms');
if (strpos($where, '&') !== false) { // 缓存里的条件用&连接
$where = explode('&', $where);
} else {
$where = $where ? $where.' and status=1' : 'status=1';
}
return $cms->getBaseList($tags, $where, $limit);
}
return $datas;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment