redis php 分页 ,总数,修改数量 倒计时
来源:互联网 发布:淘宝网注册 编辑:程序博客网 时间:2024/05/24 07:36
C: public function index(){ if($this->getLoginStatus()==false){ $backUrl=U('Market/index'); header("Location:https://passport.jiemian.com/user/login?backurl=". urlencode($backUrl)); exit; } $this->getUserinfo($this->uid); $page = (int)I('get.page', 1); $pageSize=10; $count=$this->jifenShopProductModel->getCount(); if($count>0){ $idArray=$this->jifenShopProductModel->getList($pageSize*($page-1),$pageSize*$page-1); foreach($idArray as $k=>$id){ $list[$k] = $this->jifenShopProductModel->getOne($id); if(is_array($list[$k])){ $list[$k]['p_date']=$this->_index_product_time($list[$k]['startime'],$list[$k]['endtime'],$list[$k]['show']);//倒计时 :-1表示已结束 } } $pagination = pagination($count, U('Market/index'), $page, $pageSize); $this->assign('pagination', $pagination); } $this->assign('list',$list); $this->display(); } /** * 返回产品 列表页时间格式 * @param $startime 开始时间 * @param $endtime 结束时间 * @param $show 是否有货 * @return string 仅剩3天18小时33分有货 倒计时 :-1表示已结束 */ private function _index_product_time($startime,$endtime,$show){ $time_distance=0; $time_now=time(); // $time_tishi='对不起,活动结束,倒计时完毕!!'; $time_tishi='';//表示已经结束 $time_distance_status='仅剩'; if($time_now>=$startime && $time_now<=$endtime){ $time_distance =$endtime - $time_now; // 时间差:活动结束时间减去当前时间 }else if($time_now<$startime){ //未到开始时间 $time_distance = $startime- $time_now; // 时间差:活动结束时间减去当前时间 $time_distance_status='据开始还有'; } $kucun='无货'; if($show==1){ $kucun='有货'; } if($time_distance >= 0 && $time_now<=$endtime){ // 相减的差数换算成天数 $int_day = floor($time_distance/86400); $time_distance -= $int_day * 86400; // 相减的差数换算成小时 $int_hour = floor($time_distance/3600); $time_distance -= $int_hour * 3600; // 相减的差数换算成分钟 $int_minute = floor($time_distance/60); $time_distance -= $int_minute * 60; // 相减的差数换算成秒数 $int_second = floor($time_distance); // 判断小时小于10时,前面加0进行占位 if($int_hour < 10) $int_hour = "0" . $int_hour; // 判断分钟小于10时,前面加0进行占位 if($int_minute < 10) $int_minute = "0" . $int_minute; // 判断秒数小于10时,前面加0进行占位 if($int_second < 10) $int_second = "0" . $int_second; $time_show="<p>".$time_distance_status."<i>".$int_day."</i>天<i>".$int_hour."</i>小时<i>".$int_minute."</i>分<i>".$int_second."</i>秒<span>".$kucun."</span></p>"; }else{ $time_show=$time_tishi; } return $time_show; }#=========================================================================================模型:class JifenShopProductModel extends Model { private $cacheHashKey = array('jifen:hash:jifenshopproduct:', 0); private $cacheZsetKey = array('jifen:zset:jifenshopproduct:', 0); private $model; //重写构造函数 public function __construct() { parent::__construct(); $this->model= M('shop_product',"jifen_",'DB_JIFEN_DSN'); } /** * @param int $start * @param $end * @return mixed */ public function getList($start=0,$end=-1){ $keyOpen = $this->cacheZsetKey[0]; if( $this->redis && ($this->redis->exists($keyOpen)) ){ $return = $this->redis->zRevRange($keyOpen,$start,$end); }else{ $openSqlWhere =' status=1 and type=1'; $result = $this->model->where($openSqlWhere)->order('startime desc')->select(); if($result && $this->redis){ foreach($result as $k=>$v){ $this->redis->zAdd($keyOpen,$v['startime'],$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; } /** * 得到个数 * @return mixed */ public function getCount(){ $key = $this->cacheZsetKey[0]; if( $this->redis && ($this->redis->exists($key)) ){ $count = $this->redis->zCount($key,"-inf","+inf"); }else{ // $openSqlWhere ='startime<='.time().' and status=1'; $openSqlWhere =' status=1 and type=1'; $count = $this->model->where($openSqlWhere)->count(); } return $count; } /** * 获取 * @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 $product * @return bool */ public function productStatus($product){ if(!empty($product)){ /* if($product['status']==1 && time()<=$product['endtime'] && $product['stock_status']==0 && $product['stock_record']<=$product['stock']){ return true; }*/ $kucu=$product['stock']-$product['stock_record']; if($kucu>0 && $product['stock_status']==0){ return true; } } return false; } //修改产品交易人次 public function update_record_count($id){ $status= $this->model->where(['id'=>$id])->setInc('record_count',1); $key = $this->cacheHashKey[0].$id; if($status>0){ if($this->redis && $this->redis->exists($key)){ $this->redis->HINCRBYFLOAT($key,'record_count',1); } return true; } return false; } //修改产品交易量 public function add_stock_record($id,$ct){ if($id>0&& $ct>0){ $status= $this->model->where(['id'=>$id])->setInc('stock_record',$ct); $key = $this->cacheHashKey[0].$id; if($this->redis && $this->redis->exists($key)){ $this->redis->HINCRBYFLOAT($key,'stock_record',$ct); } return $status>0?true:false; }else{ return false; } }
0 0
- redis php 分页 ,总数,修改数量 倒计时
- PHP分页样式修改
- php mysql 获得表记录的总数及获取指定数量的数据
- 倒计时控制数量传递
- JPA实现分页 返回总数
- 计算页码总数(分页)
- hibernate_数据分页, 查询总数
- php倒计时
- php倒计时
- redis配置数据库数量
- 分页功能改善,以form方式提交查询条件,可手动修改每页显示数量
- mybatis3.1分页自动添加总数
- RN的购物车实现( 数量,单价,总价,总数 )
- redis 分页
- redis分页
- 修改oracle 链接数量
- 修改oacore的数量
- 笔记:修改数量
- UIWebView --- 内置的浏览器控件 加载网页
- yii2实现邮件发送
- Android项目结构
- SGI STL 第二级空间配置器 内存池
- Spring3.0注解
- redis php 分页 ,总数,修改数量 倒计时
- Python JSON模块
- 使用PHP QR Code生成二维码
- ubuntu下MySQL的安装及远程连接配置
- SQlite入门理解
- Extjs4 动态加载(Ext.Loader)
- leetcode-18 4Sum
- Xcode提示“expression is not assignable”
- 查找算法总结之二(动态查找表)