接口 PHPOK_arclist

查看次数:1473,最后更新时间:2019-12-13 14:13

代码:

public function PHPOK_arclist()
{
    //这里编写相应的PHP信息
}

功能解释:用于改写获取的主题进行改写,如增加优惠码功能

获取列表使用

$rslist = $this->data('rslist');
$pid = $this->data('pid');

保存数据用

$this->data('rslist',$rslist);

示例(优惠券):

public function PHPOK_arclist()
{
    $rslist = $this->data('rslist');
    $pid = $this->data('pid');
    if(!$rslist || !is_array($rslist) || !$pid || !is_numeric($pid)){
        return false;
    }
    $ids = array_keys($rslist);
    $time = strtotime(date("Y-m-d",$this->time));
    $condition = "types='list' AND stopdate>=".$time." AND time_start<=".date("G",$this->time)." AND time_stop>=".date("G",$this->time);
    $clist = $this->model('coupon')->get_list($condition,0,999);
    if(!$clist){
        return false;
    }
    $couponlist = array();
    $_user = array();
    if($this->session->val('user_id')){
        $_user = $this->model('user')->get_one($this->session->val('user_id'));
    }
    foreach($clist as $key=>$value){
        //如果主题优惠码有针对会员及会员组,将会在这里筛选
        if($value['user_groupid'] || $value['users']){
            if(!$this->session->val('user_id')){
                continue;
            }
            $tmp_users = $value['users'] ? explode(",",$value['users']) : array();
            if($value['user_groupid'] != $_user['group_id'] && !in_array($_user['id'],$tmp_users)){
                continue;
            }
        }
        if($value['pid'] && $value['cateid']){
            $cids = array($value['cateid']);
            $this->model('cate')->get_sonlist_id($cids,$value['cateid'],true);
            $value['cateid_list'] = $cids;
        }
        if($value['tids']){
            $value['tids_list'] = explode(",",$value['tids']);
            if(array_intersect($ids,$value['tids_list'])){
                $couponlist[$value['id']] = $value;
                continue;
            }
        }
        if($value['cateid_list']){
            $couponlist[$value['id']] = $value;
            continue;
        }
        if($value['pid'] && $value['pid'] == $pid){
            $couponlist[$value['id']] = $value;
        }
    }
    if(!$couponlist || count($couponlist) < 1){
        return false;
    }
    foreach($rslist as $key=>$value){
        if(!$value['price']){
            continue;
        }
        $cateids = array();
        if($value['cate_id']){
            $cateids[] = $value['cate_id'];
        }
        if($value['catelist']){
            $cateids = array_merge($cateids,array_keys($value['catelist']));
        }
        if($value['_catelist']){
            foreach($value['_catelist'] as $kk=>$vv){
                $cateids[] = $vv['id'];
            }
        }
        if($cateids){
            $cateids = array_unique($cateids);
        }
        $tmplist = array();
        foreach($couponlist as $k=>$v){
            if($v['min_price'] && $v['min_price'] > $value['price']){
                continue;
            }
            if($v['tids'] && $v['tids_list'] && in_array($value['id'],$v['tids_list'])){
                $tmplist[] = $v;
                continue;
            }
            if($v['pid']){
                if($v['cateid_list'] && $cateids && array_intersect($v['cateid_list'],$cateids)){
                    $tmplist[] = $v;
                    continue;
                }
                if(!$v['cateid_list'] && $v['pid'] == $value['project_id']){
                    $tmplist[] = $v;
                    continue;
                }
            }else{
                $tmplist[] = $v;
                continue;
            }
        }
        if($tmplist && count($tmplist)>0){
            $value['price_old'] = $value['price'];
            $value['price'] = $this->_format($value['price'],$tmplist[0]);
            $value['apps']['coupon'] = array('rs'=>$tmplist[0],'list'=>$tmplist);
            $rslist[$key] = $value;
        }
    }
    $this->data('rslist',$rslist);
    return true;
}

private function _format($price,$rule)
{
    if(!$price){
        return false;
    }
    if(!is_array($rule)){
        return $price;
    }
    $price = floatval($price);
    if($rule['min_price'] && $price < $rule['min_price']){
        return $price;
    }
    if($rule['discount_type']){
        return $price - floatval($rule['discount_val']);
    }
    return $price - ($price * $rule['discount_val'] / 100);
}


没有找到答案?

您可以通过留言获取更多帮助。也可以通过社区提交相关问题。

留言 开发者社区
论坛咨询