$where = ['comment_id'=>$id,'pid'=>['neq',0],'status'=>1];
$return = $this->where($where)->select();
/**
* 获取产品信息
* @param $id
* @param array $fieldArray
* @return mixed
*/
public function getOne($id,$fieldArray=array()){
$key = $this->cacheHashKey[0].$id;
if($this->redis && $this->redis->exists($key)){
if(empty($fieldArray)){
$rst = $this->redis->hGetAll($key);
}else{
$rst = $this->redis->hMGet($key,$fieldArray);
}
}else{
$rst = $this->model->where(['id'=>$id])->find();
if($rst){
$this->redis->hMset($key,$rst);
}
}
if(empty($rst)) return nil;
return $rst;
}
/**
* 得到产品下交易个数
* @param $uid
* @param $type 产品类型 1兑换
* @return mixed
* *抽奖和兑换记录合并
*/
public function getCount($type,$uid){
$key = $this->cacheZsetUidKey[0].'1'.'_'.$uid;
if( $this->redis && ($this->redis->exists($key)) ){
$count = $this->redis->zCount($key,"-inf","+inf");
}else{
$sqlWhere ='uid='.$uid.' and status=1';
$count = $this->model->where($sqlWhere)->count();
}
return $count;
}
/**
* 获取产品 下某个用户的交易成功的id
* 抽奖和兑换记录合并
* @param $type
* @param $uid
* @param int $start
* @param $end
* @return mixed
*/
public function getList($type,$uid,$start=0,$end=-1){
$key = $this->cacheZsetUidKey[0].'1'.'_'.$uid;
if( $this->redis && ($this->redis->exists($key)) ){
$return = $this->redis->zRevRange($key,$start,$end);
}else{
$sqlWhere ='uid='.$uid.' AND ((TYPE=1 AND STATUS=1) OR (TYPE=2 AND STATUS=2))';
$result = $this->model->where($sqlWhere)->order('id desc')->select();
if($result && $this->redis){
foreach($result as $k=>$v){
$this->redis->zAdd($key,$v['id'],$v['id']);
}
}else{
$result=array();
}
if($end == -1) $end=count($result);
$returnArray = array_slice($result,$start,$end-$start+1);
foreach($returnArray as $k=>$v){
$return[$k]=$v['id'];
}
}
return $return;
}
/*
* 更新
*/
public function update($id,$data){
$where = ['id'=>$id];
$result = $this->where($where)->save($data);
if($result === false){
return false;
}else{
$key = $this->cacheKey[0].$id;
if($this->redis && $this->redis->exists($key)){
$this->redis->hMset($key,$data);
}
return true;
}
}
//修改产品状态(状态0未上线 1上线 2下线)20150828
public function offline($idArray){
if( !is_array($idArray))return false;
$conditon['id']=array('in',$idArray);
$conditon['status']=1;
$rst= $this->model->where($conditon)->save(array('status'=>2));
if($rst!==false && $rst>0){
foreach($idArray as $id){
$hkey = $this->cacheHashKey[0].$id;
$zkey = $this->cacheZsetKey[0];
if($this->redis){
$this->redis->zDelete($zkey,$id);
$this->redis->DEL($hkey);
}
}
return true;
}
return false;
}
redis getone getcount getlist update
最新推荐文章于 2024-03-17 12:05:37 发布