当前位置:

按天分组显示足迹或学习记录逻辑(可控是否分页)

本文最后更新于2019-09-30,已超过 1年没有更新,如果文章内容、图片或者下载资源失效,请留言反馈,我会及时处理,谢谢!

温馨提示:本文共3525个字,读完预计9分钟。

/*     
     * 获取学习记录  SP YP
     * $data 为數組
     * 必填參數
     * type 类型 'SP', 'YP'
     * openid 用戶openID
     * page 页码
     * psize 页数量
     * limit  限制条数  大于 0则不分页
     * */
    
    public function zkGetStudyRecord($data)
    {
        global $_W;
        global $_GPC;
        $type = array('SP', 'YP');
        if(!is_array($data) || $data[‘type’] == ” || $data[‘openid’] == ''){
            return '参数缺失';
        }
        if(!in_array($data[‘type’],$type)){
            return '类型有误';
        }
            
        $condition = ' and sr.uniacid=:uniacid and sr.type = :type and sr.openid = :openid ';
        $conditiontotal = ' and uniacid=:uniacid and type = :type and openid = :openid ';
        $params=array(':uniacid' => $_W[‘uniacid’],’:type’ => $data[‘type’],’:openid’ => $data[‘openid’]);
        if(intval($data[‘limit’])>0){//不分页
            $limit = (intval($data[‘limit’]) – 20) < 0 ? 20 : intval($data['limit']);
            $list = pdo_fetchall('SELECT sr.*,ip.title,ip.desc,ip.thumb,ip.id ipid FROM ' . tablename('ewei_shop_sns_study_record') . ' sr ' . ' left join ' . tablename('ewei_shop_ip_story') . ' ip on sr.fromid = ip.id ' .  (' WHERE 1 ' . $condition . '  ORDER BY sr.updatetime DESC limit ') . $limit , $params);
            $total = pdo_fetchcolumn('SELECT count(1) FROM ' . tablename('ewei_shop_sns_study_record') . (' WHERE 1 ' . $conditiontotal), $params);
            $total = (intval($total) – $limit) > 0 ? $limit : intval($total);
        }else{//分页
            $pindex = max(1, intval($data[‘page’]));
            $psize = (intval($data[‘psize’]) – 5) < 0 ? 5 : intval($data['psize']);
            if($pindex>1){
                $begin = ($pindex – 1) * $psize – 1;
                $psize2 = $psize + 1;
            }else{
                $begin = 0;
                $psize2 = $psize;
            }
            $list = pdo_fetchall('SELECT sr.*,ip.title,ip.desc,ip.thumb,ip.id ipid  FROM ' . tablename('ewei_shop_sns_study_record') . ' sr ' . ' left join ' . tablename('ewei_shop_ip_story') . ' ip on sr.fromid = ip.id ' .  (' WHERE 1 ' . $condition . '  ORDER BY sr.updatetime DESC limit ') . $begin . ',' . $psize2, $params);
            $total = pdo_fetchcolumn('SELECT count(1) FROM ' . tablename('ewei_shop_sns_study_record') . (' WHERE 1 ' . $conditiontotal), $params);
        }
        $isoneday = 0;
        $ishavedata = 1;
        if((intval($data[‘limit’]) <= 0) && ($pindex > 1)){
            if(!empty($list[1])){
                $day = $this->diffBetweenTwoDays(date('Y-m-d',$list[1][‘updatetime’]),date(‘Y-m-d’,$list[0][‘updatetime’]));
                if($day == 0){
                    $isoneday = 1;
                }
            }else{
                $ishavedata = 0;
            }
        }
        if(count($list)>1){
            $pageData = array();
            foreach($list as $k => $v){
                if($k == 0 && $pindex>1){
                    continue;
                }
                $kk = date('Y年m月d日',$v[‘updatetime’]);
                $pageDate[$kk][‘day’] = $kk;
                if(!is_array($pageDate[$kk][‘son’])){
                    $pageDate[$kk][‘son’] = array();
                }
                $sonData = array();
                $sonData[‘id’] = $v[‘id’];
                $sonData[‘title’] = $v[‘title’];
                $sonData[‘desc’] = $v[‘desc’];
                $sonData[‘thumb’] = tomedia($v[‘thumb’]);
                $sonData[‘ipid’] = $v[‘ipid’];
                //将子数组加入分组数组
                array_push($pageDate[$kk][‘son’],$sonData);
            }
        }
        
        $res = array();
        $res[‘pindex’] = $pindex;
        $res[‘psize’] = $psize;
        $res[‘isoneday’] = $isoneday;
        $res[‘ishavedata’] = $ishavedata;
        $res[‘total’] = $total;
        $res[‘limit’] = $limit;
        $res[‘pageDate’] = $pageDate;
        
        return $res;
    }

本文链接:,转发请注明来源!
评论已关闭。