<?php
/**
 * 最终页
 */

use SelfColumnModel\Website\EvUserChannelColumnModel;
use SelfColumnModel\Website\UserColumnModel;
use SelfVendor\SelfSpecial;
use SelfVendor\WebsiteCh\WebsiteChUrlFn;

require_once './setting.php';
require_once SYSTEM_ROOT.'include/smarty_setting.php';

$id         = $_REQUEST['id'] ? (int)$_REQUEST['id'] : 0;
$user_name  = $_REQUEST['username'] ? $_REQUEST['username'] : '';
$proKeyword = $_REQUEST['pro_keyword'] ? $_REQUEST['pro_keyword'] : '';
$sql       = "select userid,oa_id,allow_copy_channel,used_mobile,web_show_mobile from user where username='".$user_name."' and (userlevel=3 or siteid>=7 or siteid=1) ";
$userInfo  = $DB_Ev123->get_row($sql);
$user_id   = $userInfo['userid'];

$isProSource = 0;
if ($user_id && SelfSpecial::rule4($user_id)) {
    $isProSource = 1;
}

if ($isProSource == 1 && $user_id) {
    $sql          = "select * from ev_fenxiao.ap_fx_pro_rel where is_del=0 && user_id={$user_id} && my_pid={$id} limit 1";
    $fxProRelInfo = Model_Public::querySql($sql, 'get_row', 'DB_FX');

    $fxSourceProInfo = null;
    if ($fxProRelInfo && $fxProRelInfo['source_pid']) {
        $sql             = "SELECT pid,userid FROM productchannel.proinfo WHERE pid={$fxProRelInfo['source_pid']} LIMIT 0,1";
        $fxSourceProInfo = Model_Public::querySql($sql, 'get_row', 'DB_FX');
    }

    $fxSourceUserInfo = null;
    if ($fxSourceProInfo) {
        if ($fxSourceProInfo['userid'] == $user_id) {
            $url = "/$user_name/products/{$fxProRelInfo['source_pid']}.html";
            header('Location: '.$url);
            exit();
        }

        $sql              = "select userid,username from user where is_del=0 && userlevel>=3 && userid='{$fxSourceProInfo['userid']}'";
        $fxSourceUserInfo = $DB_Ev123->get_row($sql);
    }
    $query_param = '?source_param='.$fxProRelInfo['user_id'].'_'.$fxProRelInfo['user_user_id'].'_'.$fxProRelInfo['my_pid'];

    if ($fxSourceUserInfo) {
        if (ENVIRONMENT == 'development') {
            $url = "http://{$fxSourceUserInfo['username']}.m.evyun.cn/{$fxSourceUserInfo['username']}/products/{$fxProRelInfo['source_pid']}.html{$query_param}";
            header('Location: '.$url);
            exit();
        } else {
            $sql              = "SELECT id,host FROM website.`host_manage` WHERE is_del=0 && type=0 && is_main=1 && user_id={$fxSourceUserInfo['userid']}";
            $fxSourceHostInfo = $DB_Ev123->get_row($sql);

            if ($fxSourceHostInfo) {
                $url = "http://{$fxSourceHostInfo['host']}/{$fxSourceUserInfo['username']}/products/{$fxProRelInfo['source_pid']}.html{$query_param}";
                header('Location: '.$url);
                exit();
            }
        }
    }
}


if (Job_Wap::check_wap() && $userInfo['used_mobile'] && $userInfo['web_show_mobile']) {
    $url = "/$user_name/wap_pro/$id.html";
    header('Location: '.$url);
    exit();
}

if ($user_id) {
    $sql           = "select is_send from user_dingdan_set  where user_id='".$user_id."'";
    $is_store_send = $DB_Product->get_var($sql);

    $sql              = "select id from ev_user_channel  where userid='".$user_id."' and type=43";
    $store_channel_id = $DB_Ev123->get_var($sql);
    $store_link       = "/dom/user_store/user_store_list.php?username=".$user_name."&channel_id=".$store_channel_id;
}

if (!empty($userInfo['oa_id']) && $userInfo['oa_id'] != $user_id) {
    $oa_id = $userInfo['oa_id'];
}

if (!$id) {
    echo '<script lanaguage="javascript">location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

// 销售数量
if (!defined('USER_ID')) {
    define("USER_ID", $user_id);
}

//访问数据统计
General::recordGoodsUv($id, 1);
if ($oa_id && !defined('PARENT_USER_ID')) {
    define("PARENT_USER_ID", $oa_id);
}

Model_Product::$user_id = $user_id;
$info = Model_Product::getInfoNew(array(), 'pid='.$id);

$live_id      = $_REQUEST['live-id'] ? (int)$_REQUEST['live-id'] : 0;
$source_param = $_REQUEST['source_param'] ? $_REQUEST['source_param'] : '';

if (defined('PARENT_USER_ID') && PARENT_USER_ID && $info->userid == PARENT_USER_ID) {
    $chan_info = Model_Channel::getChannelInfo(PARENT_USER_ID, $info->channel_id);

    if ($chan_info['id'] && !defined('PARENT_CHANNEL_ID')) {
        define('PARENT_CHANNEL_ID', $chan_info['id']);
    }
} else {
    $chan_info = Model_Channel::getChannelInfo($user_id, $info->channel_id);

    if ($chan_info['parent_id'] && !defined('PARENT_CHANNEL_ID')) {
        define('PARENT_CHANNEL_ID', $chan_info['parent_id']);
    }
}
if (!$chan_info) {
    echo '<script lanaguage="javascript">alert("'.EvErr::errorMsg(2000058).'");  location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

Model_Product::$channel_id = $info->channel_id;
$pro_arr = Model_Product::get_pro_detail($id);
if ($pro_arr['proinfo']) {
    $pro_arr['proinfo'] = Model_Doc::re_reg($pro_arr['proinfo']);
}

if (!$pro_arr) {
    echo '<script lanaguage="javascript">alert("您访问的商品已下架或不存在！");  location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

// 产品销量总量
$sales_number = Model_Product::getProSalesVolume($id, USER_ID);

$pro_arr['sale_num'] = $sales_number + $pro_arr['default_sale'];
if (!$pro_arr) {
    echo '<script lanaguage="javascript">alert("未找到相关信息！");location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

// 产品品牌
if ($pro_arr['manu_id'] && USER_ID == 2036999) {
    $sql = "select name from ev_user_manu where is_del=0 and id=".$pro_arr['manu_id'];
    $pro_arr['manu_name'] = $DB_Ev123->get_var($sql);
}

$channel_id = $pro_arr['channel_id'];

Model_Product::$channel_id = $channel_id;

if (!empty($oa_id)
    && !empty($channel_id)
    && !empty($userInfo['allow_copy_channel'])) {
    $channel_id = Model_Channel::byParentGetChannelInfo($channel_id);
}

$con_class_table = get_class_con_table($user_id);
$new_class_info = Model_Product::getClassInfoNew(
    $con_class_table,
    '',
    array('big_id' => 'big_id',
          'sub_id' => 'sub_id',
          'sub_sub_id' => 'sub_sub_id',
          'sub_sub_sub_id' => 'sub_sub_sub_id'
    ),
    'p.channel_id='.$channel_id.' and p.pro_id='.$id
);
if ($new_class_info) {
    foreach ($new_class_info as $k => $v) {
        $big_id_arr[] = $v->big_id;
        $sub_id_arr[] = $v->sub_id;
        $sub_sub_id_arr[] = $v->sub_sub_id;
    }
}
$big_id = $pro_arr['big_id'];
$sub_id = $pro_arr['sub_id'];
$sub_sub_id = $pro_arr['use_sub_sub_id'];

//验证二级类和三级类是否显示
if (defined('PARENT_USER_ID')) {
    Model_Product::$user_id = PARENT_USER_ID;
}
$class_sub = Model_Product::verifyClass(2, '', $big_id, 'id='.$sub_id);
if (!$class_sub) {
    $sub_id = 0;
}
$class_sub_sub = Model_Product::verifyClass(3, '', $sub_id, 'id='.$sub_sub_id);
if (!$class_sub_sub) {
    $sub_sub_id = 0;
}
Model_Product::$user_id = USER_ID;
if (empty($pro_arr['city'])) {
    $pro_arr['city'] = '全国';
}

if ($pro_arr['is_wap_add']) {
    $pro_arr['proinfo']      = '';
    $pro_arr['proparameter'] = '';

    $tmpCon = Model_Product::getWapAddContent($pro_arr['pid']);

    if ($tmpCon) {
        $tmpCon['proinfo'] = nl2br($tmpCon['proinfo']);

        $pro_arr['proinfo']      = '<div class="wap-add-img">'. $tmpCon['proinfo'] .'</div>';
        $pro_arr['proparameter'] = $tmpCon['proparameter'];
    }
}

$tj_detail = 1;
require_once(SYSTEM_ROOT.'include/public.php');

if (ENVIRONMENT == 'development' && $user_name != UserColumnModel::USERNAME_1010061 && $user_name != UserColumnModel::USERNAME_248987 && 0) {
} elseif ($info->user_userid && Job_Website::rule1($user_name)) {

    $user_power                  = [];
    $user_power['is_shops_user'] = Model_Public::get_user_power(54);

    // 商铺是否开启
    $shops_isopen               = Model_Public::getRow('ev_user_system', "userid=".$USERID, "DB_Ev123");
    $user_power['shops_isopen'] = $shops_isopen->wap_shops;//商铺是否开启

    //我的微商铺
    $shops_info = Model_Shops::getShopsInfo($info->user_userid);
    if ($shops_info) {
        $is_pass = $shops_info->is_pass;
    } else {
        $is_pass = 0;
    }

    if (!$user_power['is_shops_user'] || !$user_power['shops_isopen'] || $is_pass != 1) {
        // 没权限
    } else {
        $shopUrl = WebsiteChUrlFn::getUrl([
            'type'         => WebsiteChUrlFn::CH_TYPE_54_TYPE_1,
            'chType'       => EvUserChannelColumnModel::TYPE_54,
            'username'     => USER_NAME,
            'id'           => $id,
            'UUId'         => $info->user_userid,
            'urlParamInfo' => [
                'live-id'      => $live_id,
                'source_param' => $source_param,
                'pro_keyword'  => SelfSpecial::rule27(USER_ID) ? $proKeyword : '',
            ],
        ]);

        header('HTTP/1.1 301 Moved Permanently');
        header("Location: $shopUrl");
        exit();
    }
}

if ($user_tag->is_tj == 1) {
    $smarty->assign('login_alert_no', 0);
    $smarty->display('tjNew/index.tpl');
    exit();
}

if (!$channel_id) {
    echo '<script lanaguage="javascript">alert("未找到相关信息！");location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}

//判断是否显示按钮  购物车权限
if (defined("SHOPPING_CART")) {
    if (SHOPPING_CART == 2) {//显示按钮
        $show_button = 1;
    } elseif (SHOPPING_CART == 1) {
        $show_button = 0;
    }
} else {
    $show_button = 0;
}

if (defined('PARENT_USER_ID')) {
    $tmpUserWhere = ' OR s.userid ='.PARENT_USER_ID;
}
$sql="SELECT *
            FROM ev_user_channel as s
            WHERE s.id=".$channel_id." AND s.is_del=0 AND (s.userid=".$user_id.$tmpUserWhere.')';
$ch_info=$DB_Ev123->get_row($sql);
$channel_id=$ch_info['id'];
if (!$channel_id) {
    echo '<script lanaguage="javascript">alert("未找到相关信息！");location.href="/vip_'.$user_name.'.html";</script>';
    exit();
}
//当前商品清仓购信息
$clearanceInfo = Model_Clearance::getProductInfo($id);
if ($clearanceInfo) {
    $pro_arr['is_trade_price']        = 0;
    $pro_arr['is_trade_dynamic_type'] = 0;
    $pro_arr['is_clearance'] = 1;
    $pro_arr['prosmallnum']           = $clearanceInfo->smallnum; // 最少购买数量
    $pro_arr['prounitprice']          = $clearanceInfo->price; // 清仓价
    $pro_arr['market_price']          = $clearanceInfo->proPrice; // 原价
}


// 当前商品限时购信息
$timeBuyProInfo = Model_TimeBuy::thisProductMessage($id);


if ($timeBuyProInfo->is_state == 3 || ($timeBuyProInfo->is_state == 1 && $timeBuyProInfo->start_set == 1)) {
    $timeBuyProInfo->divStyle  = ' style="display:none;" ';
}

// 当为显示限时购商品信息时，对某些数据进行初始化
if ($timeBuyProInfo->set_timebuy) {
    if ($timeBuyProInfo->is_state == 2
        || ($timeBuyProInfo->is_state == 1 && $timeBuyProInfo->start_set == 2)
        || ($timeBuyProInfo->is_state == 3 && $timeBuyProInfo->end_set == 2)
    ) {
        $pro_arr['is_trade_price']        = 0;
        $pro_arr['is_trade_dynamic_type'] = 0;

        $pro_arr['propurveynum']          = $timeBuyProInfo->max_buy; // 库存
        $pro_arr['prosmallnum']           = $timeBuyProInfo->smallnum; // 最少购买数量
        $pro_arr['prounitprice']          = $timeBuyProInfo->price; // 限时价
        $pro_arr['market_price']          = $timeBuyProInfo->proPrice; // 原价
    }


    if ($timeBuyProInfo->is_state == 1) {
        $timeBuyProInfo->explain = '开始限时购！';
    } elseif ($timeBuyProInfo->is_state == 2) {
        $timeBuyProInfo->explain = '结束限时购！';
    } elseif ($timeBuyProInfo->is_state == 3) {
        $timeBuyProInfo->explain = '限时购已结束！';
    }

    $timeBuyProInfo->limitNum = "每人限购<em id=\"limitNum\">{$timeBuyProInfo->buyNum}</em>个！";
}
//当前产品的满减信息
if ($info->full_cut_id && !$info->is_trade_price) {
    $fullCutInfo = Model_Product::getFullCutInfo($info->full_cut_id);
    if ($fullCutInfo) {
        $rule_arr = var_json_decode($fullCutInfo->rule);
        foreach ($rule_arr as $key => $value) {
            $fullCutInfo->html .= '满￥'.format_price_new($value['full']).'减￥'.format_price_new($value['cut']).'，';
        }
        $fullCutInfo->html = substr($fullCutInfo->html,0,-2);

        $fullCutInfo->url = '/'. $user_name .'/products/'.$channel_id.'_0_0_1.html?full_cut_id='.$info->full_cut_id;
    }

    $smarty->assign('fullCutInfo', $fullCutInfo);
}
//获取商品限购信息
$restrict_html = '';
$restrict_info =  Model_OrderExtend::getRestritNum($id);
if ($restrict_info['is_open'] == 1){
    $restrict_html = '<div class="tishi"><span class="tishi-inner"><i class="i-1"></i><i class="i-2"></i><img src="/images/tuan_new/tishi.png">限购<font id="restrict_num">'.$restrict_info['num'].'</font>个</span></div>';
}
$smarty->assign('restrict_html', $restrict_html);
//国电华瑞特殊处理
if ($model_id==314) {
    $proname_arr = str_replace("人和", "", str_replace("三信", "", $pro_arr['proname']));
    $proname_all = str_replace("安恒", "国电华瑞", str_replace("泰亚赛福", "国电华瑞", $pro_arr['proinfo']));
    $proname_all = str_replace("010-68589880", "010-68589880", $proname_all);
    $proname_all = str_replace("021-63176770", " ", $proname_all);
    $pattern ="/http:\/\/(.*).html/i";
    $proname_all =preg_replace($pattern, " ", $proname_all);
    $sql ="select b.* from  proinfo as a ,pro_pinpai as b where pid=".$id." and a.proname =b.name and a.channel_id=b.channel_id";
    $duiying_pinpai =$DB_Product->get_row($sql);
}

//记录访问数
$tmp_ip=getIP2();
if ($pro_arr['last_ip']!=$tmp_ip && $tmp_ip) {
    /*$sql="update proinfo set last_ip='".$tmp_ip."',hits=hits+1 where pid=".$id." and userid=".$user_id;
    $DB_Product_W=new DB_Product_W;
    $DB_Product_W->query($sql);*/
}

$tmp_pic = explode(";", $pro_arr['propicpath']);


$pro_arr['pic'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic[0],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]
);

$pro_arr['pic11'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic[0],
        'width'  => 150,
        'height' => 150,
        'field'  => 'showPic',
    ]
);

$pro_arr['yuan_pic']=$pro_arr['pic'];

$tmp_pic1 = explode(";", $pro_arr['propicpath2']);

$pro_arr['pic1'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic1[0],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]
);

$pro_arr['pic22'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic1[0],
        'width'  => 150,
        'height' => 150,
        'field'  => 'showPic',
    ]
);



$tmp_pic2 = explode(";", $pro_arr['propicpath3']);


$pro_arr['pic2'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic2[0],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]
);

$pro_arr['pic33'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic2[0],
        'width'  => 150,
        'height' => 150,
        'field'  => 'showPic',
    ]
);

$tmp_pic3 = explode(";", $pro_arr['propicpath4']);


$pro_arr['pic3'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic3[0],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]
);

$pro_arr['pic44'] = Job_Pic::format(
    [
        'type'   => 1,
        'pic'    => $tmp_pic3[0],
        'width'  => 150,
        'height' => 150,
        'field'  => 'showPic',
    ]
);

$pro_arr['market_price'] = format_price_new($pro_arr['market_price']);
$pro_arr['price'] = trim($pro_arr['prounitprice']);
$pro_arr['prounitprice'] = format_price_new($pro_arr['prounitprice']);
if ($user_name=='bjyyw88') {
    $pro_arr['proinfo'] = str_replace('<div class="proview">', '', $pro_arr['proinfo']);
    $pro_arr['proinfo'] = str_replace('</div>', '', $pro_arr['proinfo']);
}
$pro_arr['proinfo'] = str_replace('<img src="../../', '<img src=" http://admin.ev123.com/', $pro_arr['proinfo']);

$pro_arr['proparameter'] = trim($pro_arr['proparameter']);
$pro_arr['pro_no'] = trim($pro_arr['pro_no']);
$pro_arr['brief'] = cnsubstr(trim($pro_arr['brief']), 220);
$pro_arr['propurveynum'] =$pro_arr['propurveynum']>0?$pro_arr['propurveynum']:0;
$pro_arr['prosmallnum'] =$pro_arr['prosmallnum']>1?$pro_arr['prosmallnum']:1;
if ($pro_arr['citycode']) {
    $sql = "select name from city where code='".$pro_arr['citycode']."' ";
    $pro_arr['city'] = $DB_Ev123->get_var($sql);
}

if ($pro_arr['manu_id']) {
    $sql = "select name from ev_user_manu where is_del=0 and id=".$pro_arr['manu_id'];
    $pro_arr['manu_name2'] = $DB_Ev123->get_var($sql);
    $pro_arr['manu_url'] = '/self_define/pro_list.php?username='.$user_name.'&manu_id='.$pro_arr['manu_id'] ;
}
if ($pro_arr['transaction_from_id'] != 0) {
    $sql="select name from ev_user_channel where is_del=0  and id = ".$pro_arr['transaction_from_id'] .' and
        userid = '.$USERID;
    $pro_arr['transaction_from_name']=$DB_Ev123->get_var($sql);
    if ($pro_arr['transaction_from_id'] && $pro_arr['transaction_from_name']) {
        $pro_arr['transaction_from_url']='/dom/form.php?channel_id='.$pro_arr['transaction_from_id'].'&username='.$user_name."&source=10$".$channel_id."$".$id;
    }
}
if ($pro_arr['transaction_from_id2'] != 0) {
    $sql="select name from ev_user_channel where is_del=0  and id = ".$pro_arr['transaction_from_id2'] .' and userid = '.$USERID;
    $pro_arr['transaction_from_name2']=$DB_Ev123->get_var($sql);
    if ($pro_arr['transaction_from_id2'] && $pro_arr['transaction_from_name2']) {
        $pro_arr['transaction_from_url2']='/dom/form.php?channel_id='.$pro_arr['transaction_from_id2'].'&username='.$user_name."&source=10$".$channel_id."$".$id;
    }
}
$big_name = get_proclass_name($big_id);
if ($sub_id) {
    $sub_name = get_proclass_name($sub_id);
}
if ($sub_sub_id) {
    $sub_sub_name = get_proclass_name($sub_sub_id);
}
//$sub_name = $sub_name?$sub_name:$big_name;

//得到频道名
$info_arr = get_chan_name(' where id='.$channel_id);
$name = $info_arr['name'];

//获得类信息
$sub_tmp_arr = get_class_info($user_id, $channel_id);
$sub_class_arr = array();
$sub_num_arr = array();
if ($sub_tmp_arr) {
    $i = 1;
    foreach ($sub_tmp_arr as $sub) {
        $sub_class_arr[$sub['parentid']][$sub['id']] = cnsubstr($sub['classname'], 50);
        $sub_num_arr[$sub['parentid']]['num'] = $i;
        $sub_name_arr[$sub['id']]= $sub['classname'];
        $i++;
    }
}

//类别----新写
$class_arr=get_pro_class($user_id, $channel_id, '', '');
$big_class_arr=$class_arr[0];
$sub_class_arr2=$class_arr[1];
$sub_sub_class_arr=$class_arr[2];
$maxImg = $i;
//获得推荐购买产品
if($pro_arr['is_related']){
    $commendList = Model_Product::get_commend_list($id);
    $com_width = (count($commendList)*215).'px';
    $smarty->assign('commendList', $commendList);
    $smarty->assign('com_width', $com_width);
}
//获得同类型产品
if (in_array($pro_arr['open_related'], array(2,3))) {
    Model_Product::$channel_id = $channel_id;

    $relatedWhere = ' 1 ';

    if ($big_id && $pro_arr['open_related'] == 2) {
        $relatedWhere .= ' && c.big_id='. $big_id;
    } elseif ($sub_id && $pro_arr['open_related'] == 3) {
        $relatedWhere .= ' && c.sub_id='. $sub_id;
    }

    if ($pro_arr['user_userid']) {
        $relatedWhere .= ' && p.user_userid='.$pro_arr['user_userid'];
    }

    $related_cnt = Model_Product::getProList(
        1,
        array(),
        $relatedWhere,
        array(),
        array(),
        1
    );

    if ($related_cnt) {
        $relatedWhere .= ' && p.pid!='. $id;

        $rec = Model_Product::getProList(
            1,
            array(
                'pid'            => 'pid',
                'brief'          => 'brief',
                'proname'        => 'proname',
                'createdate'     => 'createdate',
                'pro_no'         => 'pro_no',
                'market_price'   => 'market_price',
                'prounitprice'   => 'prounitprice',
                'prounit'        => 'prounit',
                'status'         => 'status',
                'propicpath'     => 'propicpath',
                'propicpath2'    => 'propicpath2',
                'propicpath3'    => 'propicpath3',
                'propicpath4'    => 'propicpath4',
                'is_blank'       => 'is_blank',
                'is_trade_price' => 'is_trade_price',
            ),
            $relatedWhere,
            array(),
            array(0, 10),
            0
        );

        $pro_info_arr = array();
        if ($rec) {
            $i = 1;
            foreach ($rec as $r) {
                $r = (array)$r;
                $pro_info_arr[$r['pid']]['proname'] = $r['proname'];
                $pro_info_arr[$r['pid']]['short_proname'] = cnsubstr($r['proname'], 10);
                $pro_info_arr[$r['pid']]['market_price'] = $r['market_price'];
                $pro_info_arr[$r['pid']]['prounitprice'] = $r['prounitprice'];
                $pro_info_arr[$r['pid']]['prounit'] = $r['prounit'];
                if ($r['propicpath']) {
                    $tmp_arr = explode(";", $r['propicpath']);
                    $savePic = Job_Pic::format(
                        [
                            'type'   => 1,
                            'pic'    => $tmp_arr[0],
                            'field'  => 'savePic',
                        ]
                    );

                    $pro_info_arr[$r['pid']]['pic'] =Job_Pic::changePicSize(0, $savePic, 100, 80);
                    $pro_info_arr[$r['pid']]['pic2'] =Job_Pic::changePicSize(0, $savePic, 200, 200);
                    $pro_info_arr[$r['pid']]['pic3'] =Job_Pic::changePicSize(0, $savePic, 140, 75);
                    $pro_info_arr[$r['pid']]['pic4'] =Job_Pic::changePicSize(0, $savePic, 150, 150);
                    $pro_info_arr[$r['pid']]['pic5'] =Job_Pic::changePicSize(0, $savePic, 120, 90);
                } elseif ($r['propicpath2']) {
                    $tmp_arr = explode(";", $r['propicpath2']);
                    $savePic = Job_Pic::format(
                        [
                            'type'   => 1,
                            'pic'    => $tmp_arr[0],
                            'field'  => 'savePic',
                        ]
                    );

                    $pro_info_arr[$r['pid']]['pic'] =Job_Pic::changePicSize(0, $savePic, 100, 80);
                    $pro_info_arr[$r['pid']]['pic2'] =Job_Pic::changePicSize(0, $savePic, 200, 200);
                    $pro_info_arr[$r['pid']]['pic3'] =Job_Pic::changePicSize(0, $savePic, 140, 75);
                    $pro_info_arr[$r['pid']]['pic4'] =Job_Pic::changePicSize(0, $savePic, 150, 150);
                    $pro_info_arr[$r['pid']]['pic5'] =Job_Pic::changePicSize(0, $savePic, 120, 90);
                } elseif ($r['propicpath3']) {
                    $tmp_arr = explode(";", $r['propicpath3']);

                    $savePic = Job_Pic::format(
                        [
                            'type'   => 1,
                            'pic'    => $tmp_arr[0],
                            'field'  => 'savePic',
                        ]
                    );

                    $pro_info_arr[$r['pid']]['pic'] =Job_Pic::changePicSize(0, $savePic, 100, 80);
                    $pro_info_arr[$r['pid']]['pic2'] =Job_Pic::changePicSize(0, $savePic, 200, 200);
                    $pro_info_arr[$r['pid']]['pic3'] =Job_Pic::changePicSize(0, $savePic, 140, 75);
                    $pro_info_arr[$r['pid']]['pic4'] =Job_Pic::changePicSize(0, $savePic, 150, 150);
                    $pro_info_arr[$r['pid']]['pic5'] =Job_Pic::changePicSize(0, $savePic, 120, 90);
                } elseif ($r['propicpath4']) {
                    $tmp_arr = explode(";", $r['propicpath4']);

                    $savePic = Job_Pic::format(
                        [
                            'type'  => 1,
                            'pic'   => $tmp_arr[0],
                            'field' => 'savePic',
                        ]
                    );

                    $pro_info_arr[$r['pid']]['pic'] =Job_Pic::changePicSize(0, $savePic, 100, 80);
                    $pro_info_arr[$r['pid']]['pic2'] =Job_Pic::changePicSize(0, $savePic, 200, 200);
                    $pro_info_arr[$r['pid']]['pic3'] =Job_Pic::changePicSize(0, $savePic, 140, 75);
                    $pro_info_arr[$r['pid']]['pic4'] =Job_Pic::changePicSize(0, $savePic, 150, 150);
                    $pro_info_arr[$r['pid']]['pic5'] =Job_Pic::changePicSize(0, $savePic, 120, 90);
                } else {
                    $pro_info_arr[$r['pid']]['pic'] = 'http://img.ev123.com/pic/detail2009/no_pic2.gif';
                    $pro_info_arr[$r['pid']]['pic2'] = 'http://img.ev123.com/pic/detail2009/no_pic.gif';
                    $pro_info_arr[$r['pid']]['pic3'] = 'http://img.ev123.com/pic/detail2009/no_pic.gif';
                    $pro_info_arr[$r['pid']]['pic4'] = 'http://img.ev123.com/pic/detail2009/no_pic.gif';
                    $pro_info_arr[$r['pid']]['pic5'] = 'http://img.ev123.com/pic/detail2009/no_pic2.gif';
                }
                //兼容以前未压缩的图
                if ($r['pid']<600000 && $pro_info_arr[$r['pid']]['pic']) {
                    $pro_info_arr[$r['pid']]['pic5']=$pro_info_arr[$r['pid']]['pic'];
                }
                $pro_info_arr[$r['pid']]['num'] = $i;
                $i++;
            }
            $img_num = $i-1;
            $img_width = $img_num*232;
        }
    }
}

$focus_pic_str = get_pic_info($pro_arr);
$new_focus_pic_str = array();
if ($focus_pic_str) {
    $i=0;
    foreach ($focus_pic_str as $key => $values) {
        $new_focus_pic_str[$i]['pic']  = $values['savePic'];
        $new_focus_pic_str[$i]['pic1'] = Job_Pic::changePicSize(0, $values['savePic'], 280, 210);
        $new_focus_pic_str[$i]['pic2'] = Job_Pic::changePicSize(0, $values['savePic'], 600, 600);
        $new_focus_pic_str[$i]['url']  = str_replace("200_200", "100_80", $values['url']);
        $i++;
    }
    $extendInfoNew = Model_Product::getExtendNewInfo($id, $channel_id, USER_ID);
    if ($extendInfoNew->propicpath5) {
        $tmpSavePic = Job_Pic::format(
            [
                'type'  => 1,
                'pic'   => $extendInfoNew->propicpath5,
                'field' => 'savePic',
            ]
        );

        $new_focus_pic_str[] = array(
            'pic' => $tmpSavePic,
            'pic1' => Job_Pic::changePicSize(0, $tmpSavePic, 280, 280),
            'pic2' => Job_Pic::changePicSize(0, $tmpSavePic, 600, 600),
            'url' => "javascript:show_picbig('".Job_Pic::changePicSize(0, $tmpSavePic, 600, 600)."','".$pro_arr['proname']."'"
        );
    }
    if ($extendInfoNew->propicpath6) {
        $tmpSavePic = Job_Pic::format(
            [
                'type'  => 1,
                'pic'   => $extendInfoNew->propicpath6,
                'field' => 'savePic',
            ]
        );

        $new_focus_pic_str[] = array(
            'pic' => $tmpSavePic,
            'pic1' => Job_Pic::changePicSize(0, $tmpSavePic, 280, 280),
            'pic2' => Job_Pic::changePicSize(0, $tmpSavePic, 600, 600),
            'url' => "javascript:show_picbig('".Job_Pic::changePicSize(0, $tmpSavePic, 600, 600)."','".$pro_arr['proname']."'"
        );
    }
    if ($extendInfoNew->propicpath7) {
        $tmpSavePic = Job_Pic::format(
            [
                'type'  => 1,
                'pic'   => $extendInfoNew->propicpath7,
                'field' => 'savePic',
            ]
        );

        $new_focus_pic_str[] = array(
            'pic' => $tmpSavePic,
            'pic1' => Job_Pic::changePicSize(0, $tmpSavePic, 280, 280),
            'pic2' => Job_Pic::changePicSize(0, $tmpSavePic, 600, 600),
            'url' => "javascript:show_picbig('".Job_Pic::changePicSize(0, $tmpSavePic, 600, 600)."','".$pro_arr['proname']."'"
        );
    }
    if ($extendInfoNew->propicpath8) {
        $tmpSavePic = Job_Pic::format(
            [
                'type'  => 1,
                'pic'   => $extendInfoNew->propicpath8,
                'field' => 'savePic',
            ]
        );

        $new_focus_pic_str[] = array(
            'pic' => $tmpSavePic,
            'pic1' => Job_Pic::changePicSize(0, $tmpSavePic, 280, 280),
            'pic2' => Job_Pic::changePicSize(0, $tmpSavePic, 600, 600),
            'url' => "javascript:show_picbig('".Job_Pic::changePicSize(0, $tmpSavePic, 600, 600)."','".$pro_arr['proname']."'"
        );
    }
}
if (27==$model_id) {
    $sql = "select tel,fax,mobile,address from user where userid=".$user_id ;
    $user_info = $DB_Ev123->get_row($sql);
    if ($user_info['mobile']) {
        $mobile_arr = explode('<br>', $user_info['mobile']);
    }
    $smarty->assign("user_info", $user_info);
    $smarty->assign("mobile_arr", $mobile_arr);
}
$ser_id=0;
//广告
$ad_arr=get_ad_info($user_id, $model_id, $channel_id, $ser_id);
if ($ad_arr) {
    foreach ($ad_arr as $key => $val) {
        $smarty->assign('ad_'.$key, $val);
    }
}

//新的频道模板设置

$css_filename = getDomTemplateColorById(getDomTemplateColorId((int)$user_id, 0, $channel_id));
$tel=str_replace('<br>', '&nbsp;&nbsp;', $user_info['tel']);
//用户自定义参数
$pinlun_arr=array();
$used_review=0;
$used_review_add=0;
$fen_class='c-value-0';
if ($model_css) {
    if (defined('PARENT_CHANNEL_ID')) {
        $user_param=get_product_forget_param(PARENT_CHANNEL_ID, $pro_arr, 15);
    } else {
        $user_param=get_product_forget_param($channel_id, $pro_arr, 15);
    }
    if ($user_param) {
        foreach ($user_param as $k => $v) {
            if ($v['system_type'] == 7) {//供货数量
                $show_kucun=1;
                break;
            } else {
                $show_kucun=0;
            }
        }
        foreach ($user_param as $k2 => $v2) {
            if ($v2['system_type'] == 8) {//最小定量
                $show_zuixiao=1;
                break;
            } else {
                $show_zuixiao=0;
            }
        }

        foreach ($user_param as $k3 => $v3) {
            if ($v3['system_type'] == 4) {//价格
                if ($v3['value']>0) {
                    $show_danjia=0;
                } else {
                    $show_danjia=1;
                }
                break;
            } else {
                $show_danjia=0;
            }
        }
    }

    if (defined('PARENT_CHANNEL_ID')) {
        $user_param2=get_product_forget_param(PARENT_CHANNEL_ID, $pro_arr, 20, 2);
        $guige_info = Job_GuiGe::get_guige_arr(PARENT_CHANNEL_ID, $pro_arr['pid']);
    } else {
        $user_param2=get_product_forget_param($channel_id, $pro_arr, 20, 2);
        $guige_info = Job_GuiGe::get_guige_arr($channel_id, $pro_arr['pid']);
    }
    if ($guige_info) {//验证是否存在有效规格参数，没有则视为无效规格
        foreach ($guige_info as $key => $val) {
            if (!$val['val']) {
                unset($guige_info[$key]);
                continue;
            }
            $guige_info[$key] = $val;
        }
    }
    if ($guige_info) {
        foreach ($guige_info as $k => $v) {
            $tmp_param_ids[] = $v['id'];
        }
        rsort($tmp_param_ids);
        $guige_str = implode(',', $tmp_param_ids);
        $guige_sort = JSON($tmp_param_ids);
        $show_black = 1;
    } else {
        $show_black = 0;
    }
    $param_checked_ids = '';
    if ($user_param2) {
        foreach ($user_param2 as $k => $v) {
            if ($v['value']) {
                empty($param_checked_ids) ? $param_checked_ids = $v['id'] : $param_checked_ids .= '#'. $v['id'];
            }
        }
    }
    if (defined('PARENT_USER_ID')) {
        $tmpUserIdWhere = ' OR user_id='.PARENT_USER_ID;
    }

    $sql="select used_review,used_review_add from user_dingdan_set where (user_id=".$user_id.$tmpUserIdWhere.')';
    $used_review_info = $DB_Product->get_row($sql);
    $used_review     = $used_review_info['used_review'];
    $used_review_add = $used_review_info['used_review_add'];

    if (SHOPPING_CART == 2) {
        if ($used_review!=2) {
            $sql="select * from user_pro_pinglun  where pro_id=".$id." and site_id=1 and is_del=0 and is_add=0 order by id desc";
            $pinlun_arr=$DB_Product->get_results($sql);
            if ($pinlun_arr) {
                $fen_count=0;
                $pin_count=0;
                foreach ($pinlun_arr as $key => &$pinlun) {
                    $fen_count+=$pinlun['pro_fen'];
                    $pin_count++;
                    $sql="select user_name,nick_name from user_user where id=".$pinlun['user_user_id'];
                    $tmp_info=$DB_Ev123->get_row($sql);
                    $pinlun['username']=$tmp_info['nick_name']?$tmp_info['nick_name']:$tmp_info['user_name'];
                    $pinlun['username']=cnsubstr($pinlun['username'], 1).'***';

                    if ($pinlun['pic']){
                        $tmp_pic_list = array();
                        $sql = 'select pic from wap_bbs_theme_image where user_id='.$USERID.' and is_del=0 and id in('.$pinlun['pic'].')';
                        $pic_list = $DB_Ev123->get_results($sql);
                        foreach ($pic_list as $pic_k=>$p_v){
                            $tmp_pic_src = str_replace('/wap_bbs_theme/640_3000/', '/wap_bbs_theme/200_100/', $p_v['pic']);
                            $big_pic_src = $p_v['pic'];
                            if (false === strpos($big_pic_src, '#')) {
                                $picInfo = @getimagesize($big_pic_src);
                                $width   = $picInfo[0];
                                $height  = $picInfo[1];
                            } else {
                                $picInfo = explode('#', $big_pic_src);

                                $big_pic_src = $picInfo[0];
                                $width       = $picInfo[1];
                                $height      = $picInfo[2];
                            }

                            $tmp_pic_list[$pic_k]['pic_src'] = $big_pic_src;
                            $tmp_pic_list[$pic_k]['width'] = $width;
                            $tmp_pic_list[$pic_k]['height'] = $height;
                        }

                        $pinlun['pic_list'] = $tmp_pic_list;
                    }

                    $xing_str = '';
                    for($tmp_i=1;$tmp_i<=$pinlun['pro_fen'];$tmp_i++){
                        $xing_str.='<a href="###"></a>';
                    }
                    for($tmp_i=$pinlun['pro_fen']+1;$tmp_i<=5;$tmp_i++){
                        $xing_str.='<a href="###" class="List_xinga"></a>';
                    }
                    $pinlun['fen_str'] = $xing_str;

                    // 初级评论的商家回复
                    $sql = 'select * from  user_pro_pinglun_reply where user_id='.$USERID.' and pinglun_id='.$pinlun['id'];
                    $reply_info = $DB_Product->get_row($sql);
                    $pinlun['reply_info'] = ($reply_info) ? $reply_info['content'] : '';

                    $pinlun['tmp_time'] = date('Y-m-d',strtotime($pinlun['input_time']));
                    // 追加评论
                    $pinlun['add_review'] = '';
                    if ($used_review_add == 2){
                        $pro_add_review_args = array('table'   => 'user_pro_pinglun s',
                                                     'field'   => 'id',
                                                     'where'   => "s.pro_id = '".$pinlun['pro_id']."' and s.order_id='".$pinlun['order_id']."' and s.param_id='".$pinlun['param_id']."' and is_add!=0",
                                                     'start'    => 0,
                                                     'pageSize' => 1,
                                                     'orderBy'  => array('s.id'=>'desc')
                        );
                        $pro_add_review_info  = Model_Order::getRow($pro_add_review_args);
                        if ($pro_add_review_info && $pro_add_review_info['id']){
                            $pro_add_review_info['tmp_time'] = date('Y-m-d',strtotime($pro_add_review_info['input_time']));
                            if ($pro_add_review_info['pic']){
                                $pic_add_str .= '<div class="All_imgmax">';
                                $sql = 'select pic from wap_bbs_theme_image where user_id='.$USERID.' and is_del=0 and id in('.$pro_add_review_info['pic'].')';
                                $pic_list = $DB_Ev123->get_results($sql);
                                foreach ($pic_list as $pic_k=>$p_v){
                                    $tmp_pic_src = str_replace('/wap_bbs_theme/640_3000/', '/wap_bbs_theme/200_100/', $p_v['pic']);
                                    $big_pic_src = $p_v['pic'];
                                    if (false === strpos($big_pic_src, '#')) {
                                        $picInfo = @getimagesize($big_pic_src);
                                        $width   = $picInfo[0];
                                        $height  = $picInfo[1];
                                    } else {
                                        $picInfo = explode('#', $big_pic_src);

                                        $big_pic_src = $picInfo[0];
                                        $width       = $picInfo[1];
                                        $height      = $picInfo[2];
                                    }
                                    $tmp_pic_arr[$pic_k]['pic_src'] = $big_pic_src;
                                    $tmp_pic_arr[$pic_k]['width'] = $width;
                                    $tmp_pic_arr[$pic_k]['height'] = $height;
                                }
                                $pro_add_review_info['pic_list'] = $tmp_pic_arr;
                            }
                            $sql = 'select * from  user_pro_pinglun_reply where user_id='.$USERID.' and pinglun_id='.$pro_add_review_info['id'];
                            $reply_info = $DB_Product->get_row($sql);
                            $pro_add_review_info['reply_info'] = ($reply_info) ? $reply_info['content'] : '';
                            $pinlun['add_review']=$pro_add_review_info;
                        }
                    }

                }
                $average=round($fen_count/$pin_count, 1);
                if ($average) {
                    if ($average==0) {
                        $fen_class='c-value-0';
                    } elseif ($average<1) {
                        $fen_class='c-value-0d5';
                    } elseif ($average==1) {
                        $fen_class='c-value-1';
                    } elseif ($average<2) {
                        $fen_class='c-value-1d5';
                    } elseif ($average==2) {
                        $fen_class='c-value-2';
                    } elseif ($average<3) {
                        $fen_class='c-value-2d5';
                    } elseif ($average==3) {
                        $fen_class='c-value-3';
                    } elseif ($average<4) {
                        $fen_class='c-value-3d5';
                    } elseif ($average==4) {
                        $fen_class='c-value-4';
                    } elseif ($average<5) {
                        $fen_class='c-value-4d5';
                    } elseif ($average==5) {
                        $fen_class='c-value-5';
                    } else {
                        $fen_class='c-value-0';
                    }
                    $bfb=($average/5)*100;
                }
            }
        }
    }
}
//参数设置
if (!$user_param) {
    if (defined('PARENT_CHANNEL_ID')) {
        $tmpChannelWhere = 'OR channel_id='.$channel_id;
    }
    $sql="select id from product_param
            where (user_id=".$user_id. $tmpUserIdWhere .")
                    and (channel_id=".$channel_id. $tmpChannelWhere .") and is_del=0
            limit 1";
    $is_used_param=$DB_Product->get_var($sql);
    if (!$is_used_param) {
        if ($pro_arr['prounitprice']==0) {
            $show_danjia = 1;
        }
    }
}

if ($show_zuixiao==1) {
    if ($pro_arr['prosmallnum']) {
        $total = $pro_arr['prounitprice'] * $pro_arr['prosmallnum'];
    } else {
        $total = $pro_arr['prounitprice'];
    }
} else {
    $total = $pro_arr['prounitprice'];
}

if ($user_param2 && $show_black==1) {
    $show_guige = 1;
} else {
    $show_guige = 0;
}


/**
 * 产品图册
 */
Model_ProAlbum::$pId = $id;
$albumList = Model_ProAlbum::getAlbumList();

if ($albumList) {
    foreach ($albumList as $k => $v) {
        $v->pic = Model_ProAlbum::getAlbumPicInfo('pic', "album_id={$v->id}");

        if ($v->pic) {
            $albumList[$k]->pic = Job_Pic::format(
                [
                    'type'   => 2,
                    'pic'    => $v->pic,
                    'width'  => 200,
                    'height' => 200,
                    'field'  => 'showPic',
                ]
            );
        } else {
            $albumList[$k]->pic = 'https://img.ev123.com/pic/nopic/200_200.jpg';
        }

        $albumList[$k]->cnt = Model_ProAlbum::getAlbumPicList('id', "album_id={$v->id}", 1);
    }

    $smarty->assign('albumList', $albumList);
}


/**
 * 产品最终页关联文章列表
 */
Model_ProDoc::$pId = $id;
$docTagList = Model_ProDoc::getClassList(
    array(
        'id'   => 'id',
        'name' => 'name',
    )
);
$smarty->assign('docTagList', $docTagList);

/**
 * 关联论坛列表
 */
if ($pro_arr['open_bbs'] == 2) {
    $bbsChannelId = Model_Channel::getNewChannelInfo('id', 'type=7');

    if ($bbsChannelId) {
        $forumsInfo = Model_Bbs::getForumsInfo(
            array(
                'id'   => 'id',
                'name' => 'name',
            ),
            "pro_id={$id} && channel_id={$channel_id}"
        );

        if ($forumsInfo) {
            $forumsInfo->bbsChannelId = $bbsChannelId;

            $threadList = Model_Bbs::getForumThreadsInfo(
                array(
                    'forum_id' => $forumsInfo->id,
                    'start'    => 0,
                    'pageSize' => 10,
                )
            );

            if ($threadList) {
                foreach ($threadList as $k => $v) {
                    $threadList[$k]->re_num = Model_Bbs::getCurrentRebookCount($v->id);

                    $bbsReplyInfo = Model_Bbs::getLastRebookInfo(
                        $v->id,
                        array(
                            'user_id'    => 'user_id',
                            'input_time' => 'input_time',
                        )
                    );

                    if ($bbsReplyInfo) {
                        $bbsReplyUserInfo = Model_User::getUserUserInfo($bbsReplyInfo->user_id);

                        $threadList[$k]->date = substr($bbsReplyInfo->input_time, 0, 16);
                    } else {
                        $bbsReplyUserInfo = Model_User::getUserUserInfo($v->user_user_id);

                        $threadList[$k]->date = substr($v->input_time, 0, 16);
                    }

                    if ($bbsReplyUserInfo) {
                        $threadList[$k]->replyUsername = $bbsReplyUserInfo['nick_name']
                            ? $bbsReplyUserInfo['nick_name']
                            : ($bbsReplyUserInfo['qq_api'] ? 'QQ用户' : $bbsReplyUserInfo['user_name']);
                    }
                }
            }

            $smarty->assign('forumsInfo', $forumsInfo);
            $smarty->assign('threadList', $threadList);
        }
    }
}

// 优惠/服务标签
$productTagHtml = Model_Product::getPrductTagHtmlCode(
    $LA['E_fuwuchengnuo'],
    $pro_arr['service_label'],
    $pro_arr['discount_label']
);

$productServerTagHtml = $productPreferentialTagHtml = '';
if ($productTagHtml) {
    if ($productTagHtml['server']) {
        $productServerTagHtml = $productTagHtml['server'];
    }
    if ($productTagHtml['preferential']) {
        $productPreferentialTagHtml = $productTagHtml['preferential'];
    }

    $smarty->assign('productServerTagHtml', $productServerTagHtml);
    $smarty->assign('productPreferentialTagHtml', $productPreferentialTagHtml);
}



$otherParam = '';
$extendInfo = Model_Product::getExtendInfo($id, $channel_id);
if ($extendInfo) {
    $extendArr = Job_Product::tradeWayFormat(var_json_decode($extendInfo->sys_upfile));
}

//获取会员等级
if (defined('USER_USER_ID')) {
    $userInfo = Model_User::getUserUserInfo(USER_USER_ID, array('vip'=>'vip'));
    $userLevel = $userInfo['vip'];
} else {
    $userLevel = 1;
}
if ($extendInfo->grade_ids) {
    $gradeArr = explode(',', $extendInfo->grade_ids);
    if (in_array($userLevel, $gradeArr)) {
        $attrSet['is_set'] = 1;
        $attrSet['unsee_attr'] = explode(',', $extendInfo->unsee_ids);
    }
} else {
    $proAttrSet = Model_Product::getAttrSet();
    $gradeArr = explode(',', $proAttrSet->grade_ids);
    if (in_array($userLevel, $gradeArr) && $proAttrSet->open_set) {
        $attrSet['is_set'] = 1;
        if ($proAttrSet->unsee_ids) {
            /*1价格，2评论，3销量，4产品详细，5购物车和立即购买*/
            $attrSet['unsee_attr'] = explode(',', $proAttrSet->unsee_ids);
        }
    }
}
//累计销量
if ($pro_arr['open_sales'] == 2 && !in_array(3, $attrSet['unsee_attr'])) {
    $otherParam .= "<td>{$LA['E_leijixiaoliang']}{$pro_arr['sale_num']}</td>";
}

if ($used_review != 2 && !in_array(2, $attrSet['unsee_attr'])) {
    if (!$pin_count) {
        $pin_count = 0;
    }
    $otherParam .= "<td>{$LA['E_leijipingjia']}{$pin_count}</td>";
}

// 送积分
if ($user_param) {
    foreach ($user_param as $v) {
        if ($v['system_type'] == 4) {
            $jifen = Model_Jifen::getDdSetVal(
                USER_ID,
                array(
                    'jifen_price' => 'jifen_price',
                    'xf_rename'   => 'xf_rename',
                    'jifen_isopen'=> 'jifen_isopen',
                )
            );
            if ($jifen->jifen_isopen==1 && $pro_arr['is_send_jifen']) {
                if ($jifen->xf_rename) {
                    $LA['E_leijisongjifen'] = $jifen->xf_rename;
                }
                if ($pro_arr['send_jifen_set']==1) {
                    $jifenNum = Model_Product::getProductJifen($v['value'], $jifen->jifen_price);
                } elseif ($pro_arr['send_jifen_set']==2 && $pro_arr['send_jifen_num']>=0) {
                    $jifenNum = $pro_arr['send_jifen_num'];
                }
            }
            break;
        }
    }
}

// 其他购买方式数组
$shopOtherTradingMethod = Model_Product::shopOtherTradingMethod($pro_arr);
$shopOtherTradingMethodExtend = Model_Product::getExtendInfo($pro_arr['pid'], $pro_arr['channel_id']);
$shopOtherTradingMethodExtendArr = Job_Product::tradeWayFormat(var_json_decode($shopOtherTradingMethodExtend->sys_upfile));

if ($shopOtherTradingMethod) {
    $otherTradingMethodHtml = '';
    if ($shopOtherTradingMethod) {
        $otherTradingMethodHtml = Model_Product::shopOtherTradingMethodHtmlCode($shopOtherTradingMethod, $shopOtherTradingMethodExtendArr);
    }

    $smarty->assign('otherTradingMethodHtml', $otherTradingMethodHtml);
}

if ($pro_arr['is_trade_price'] && $show_button) { // 批发模式
    $pro_arr['prosmallnum'] = $pro_arr['trade_price_init_num'] ? $pro_arr['trade_price_init_num'] : 1;

    $con_guige_table = Model_GuiGe::get_dynamic_id_table(USER_ID);
    $guigeInfo = Model_GuiGe::get_pro_guige($id, $con_guige_table, array(),array('guige_id', 'desc'));
    $combination_sn_arr = Job_GuiGe::combination_sn_arr($guigeInfo, $channel_id);
    if ($combination_sn_arr) {
        $tmp_sn_id = '';

        foreach ($combination_sn_arr as $key => $val) {
            $last_guige_arr[$val['sn_id']] = array_pop(explode('#', $val['value']));
            $tmp_sn_arr = explode('|', $val['val_sn']);
            foreach ($tmp_sn_arr as $k => $v) {
                $tmp_val_arr = explode(':', $v);
                $tmp_guige_arr[$tmp_val_arr[0]][] = $tmp_val_arr[1];
            }
        }

        if ($tmp_guige_arr) {
            $tmp_param_arr = array();
            $guige_id_str = '';
            foreach ($tmp_guige_arr as $key => $val) {
                $guige_id_str .= $key.',';
                $tmp_param_arr[$key] = implode(',' ,array_unique($val));
            }
            $guige_id_str = rtrim($guige_id_str, ',');
        }

        if ($guige_id_str) {
            $con_guige_table = Model_GuiGe::get_con_guige_table(USER_ID);
            $guige_info = Model_GuiGe::get_guige_param($con_guige_table, '', array('order_sort'=>'order_sort', 'id'=>'id', 'name'=>'name'), 'id in ('.$guige_id_str.')', array('order_sort','desc'), array(0, 100));
        }

        if ($guige_info) {
            $con_val_table = Model_GuiGe::get_con_val_table(USER_ID);
            for ($i=0; $i < count($guige_info); $i++) {
                if ($tmp_param_arr[$guige_info[$i]->id]) {
                    //查询出参数的名称
                    $tmp_val = Model_GuiGe::get_guige_val($con_val_table, '', array('id'=>'id','name'=>'name'), 'id in ('.$tmp_param_arr[$guige_info[$i]->id].')', array(), array(0, 200));
                    $final_guige_arr[] = array('id'=>$guige_info[$i]->id, 'name'=>$guige_info[$i]->name, 'val'=>$tmp_val);
                }
            }
        }

        if ($final_guige_arr) {
            $final_num = count($final_guige_arr);
            $select_val_id = '';
            foreach ($final_guige_arr as $k => $v) {
                if ($k+1 < $final_num) {
                    foreach ($v['val'] as $k1 => $v1) {
                        if ($k1 === 0) {
                            $select_val_id .= $v['id'].':'.$v1->id.'|';
                        }
                    }
                } elseif ($k+1 == $final_num) {
                    $last_param_id = '';
                    if ($v['val']) {
                        foreach ($v['val'] as $k6 => $v6) {
                            $last_param_id .= $v6->id.',';
                        }
                    }
                }
            }
            $select_val_id = rtrim($select_val_id, '|');
            $last_param_id = rtrim($last_param_id, ',');
        }
        $guigeNumCount = 4;
        $wholesaleParam['tableWidth'] = 110 * $guigeNumCount;
    } else {
        $pro_arr['isBuy'] = 1;

        if ($pro_arr['propurveynum'] < 1 || $pro_arr['propurveynum'] < $pro_arr['prosmallnum']) {
            $pro_arr['isBuy']       = 0;
            $pro_arr['initPayPrice'] = 0;
        } else {
            $pro_arr['initPayPrice'] = $pro_arr['trade_price1'] * $pro_arr['prosmallnum'];
        }
    }
    $smarty->assign('combination_sn_arr', $combination_sn_arr);
    $smarty->assign('wholesaleParam', $wholesaleParam);


    $pro_arr['showNumHtml1'] = "{$pro_arr['trade_price_init_num']}套起批";
    $pro_arr['showNumHtml2'] = ($pro_arr['trade_price_num1'] + 1) .'-'. $pro_arr['trade_price_num2'] .'件';
    $pro_arr['showNumHtml3'] = '≥'. ($pro_arr['trade_price_num2'] + 1) .'件';
}

if ($pro_arr['is_trade_price']) {
    $pro_arr['proname'] = "【批发】{$pro_arr['proname']}";
} else {
    if ($pro_arr['is_clearance']==1) {
        $pro_arr['proname'] = "【清仓】{$pro_arr['proname']}";
    }
}
//扩展表信息
$extend_info = Model_Product::getExtendInfo($id,$channel_id);
if ($extend_info->is_overseas) {
    $pro_arr['proname'] = '【跨境】'.$pro_arr['proname'];
}

$info_arr[$k]['prounit'] = Job_Product::priceUnit($pro_arr['prounit']);
$shareCode = Model_Public::shareCode();
$show_zuixiao = 1; // 最小定量
$proType = Model_Product::getProductType($id);

//$proType 没规格1，有规格2
$isQRCode = (($proType == 1 || $proType == 2) && SHOPPING_CART == 2) ? 1 : 0;

if ($isQRCode) {
    $isWapPay = Model_Pay::pay_check(USER_ID, 1);
    $isQRCode = $isWapPay ? 1 : 0;
}
//显示二维码
if ($isQRCode) {//开启在线支付，支付方式有购物车
    $wapLink = 'http://'. WAP_DOMAIN . Model_Channel::getWapDetailLink(10, $channel_id, $id);
    $QRImages = "/qrcode/create_code.php?url={$wapLink}";

    $wapPriceInfo = Model_Product::getProPrice($id);
    $wapPriceHtml = '';
    if ($wapPriceInfo['is_preferentialce'] && ($proType == 1)) {
        $wapPriceHtml = "<h6>手机专享： <strong>￥{$wapPriceInfo['price']}</strong></h6>";
    }
}

// 获取会员商品折扣
$hasTimeBuy = false;
if ($timeBuyProInfo->set_timebuy || $timeBuyProInfo->is_state == 1) {
    if ($timeBuyProInfo->start_time > TIME_STR || $timeBuyProInfo->end_time < TIME_STR){
        $hasTimeBuy = false;
    }else{
        $hasTimeBuy = true;
    }
}

$pro_arr['actPrice'] = $pro_arr['price'];
if (!$pro_arr['is_trade_price'] && !$clearanceInfo &&  !$hasTimeBuy){
    $userProInfo = Model_UserProduct::getUserProductByPid($id);
    if ($userProInfo) {
        $level_arr     = $userProInfo['level_arr'];
        $currentRebate = current($userProInfo['rebate']);
        $user_level    = $userProInfo['user_level'];

        $currentLevelRabate = array();
        if ($userProInfo['rebate_type'] == 1){
            $rebate_price = $currentRebate[$user_level]['rebate_price'];
            $currentLevelRabate['rebateNum']  = 0;
            $currentLevelRabate['level_name']  = $level_arr[$user_level]['grade_name'];
            $currentLevelRabate['rebatePrice'] = $rebate_price;
        }else{
            $rebate = $currentRebate[$user_level]['rebate'];
            $currentLevelRabate['rebateNum']   = $rebate;
            $currentLevelRabate['level_name']  = $level_arr[$user_level]['grade_name'];
            $currentLevelRabate['rebatePrice'] = ($rebate >0.00 && $rebate < 10.00) ? sprintf("%.2f",($rebate/10) * $pro_arr['prounitprice']) : $pro_arr['prounitprice'];
        }

        foreach ($currentRebate as $level=>$rebate){
            if ($rebate['rebate'] <= 0.00 || $rebate['rebate'] >= 10.00){
                unset($currentRebate[$level]);
                continue;
            }
            $currentRebate[$level]['rebatePrice'] = ($userProInfo['rebate_type']) ? $currentRebate[$level]['rebate_price'] : sprintf("%.2f",($rebate['rebate']/10) * $pro_arr['prounitprice']);
        }
    }

    // 如果产品没有规格
    if ($userProInfo && empty($currentRebate[$user_level]['pro_dynamic_id'])) {
        $total = $currentLevelRabate['rebatePrice'];
        $pro_arr['actPrice'] = $currentLevelRabate['rebatePrice'];

        if ($jifen->jifen_isopen==1 && $pro_arr['is_send_jifen']) {
            if ($jifen->xf_rename) {
                $LA['E_leijisongjifen'] = $jifen->xf_rename;
            }
            if ($pro_arr['send_jifen_set']==1) {
                $jifenNum = Model_Product::getProductJifen($total, $jifen->jifen_price);
            } elseif ($pro_arr['send_jifen_set']==2 && $pro_arr['send_jifen_num']>=0) {
                $jifenNum = $pro_arr['send_jifen_num'];
            }
        }
    }
}

if ($jifenNum) {
    $otherParam .= "<td id=\"jifen\">{$LA['E_leijisongjifen']}<em id=\"jifenNum\">$jifenNum</em></td>";
    $otherParam .= '<script language="javascript">G_.jifen = '. $jifen->jifen_price .';';
    if($pro_arr['send_jifen_set']==2 && $pro_arr['send_jifen_num']>=0){
        $otherParam .= 'G_.sendjifen='.$pro_arr['send_jifen_num'].';';
    }
    $otherParam .= '</script>';
}

if ($otherParam) {
    $otherParamHtml .= <<<EOT
    <li class="q">
        <table class="pro_buy_sumtable"><tbody><tr>$otherParam</tr></tbody>
        </table>
    </li>
EOT;

    $smarty->assign('otherParamHtml', $otherParamHtml);
}

//收藏
$collectCurClass = 'no-collect';
$collectName     = '收藏';
if (defined('USER_USER_ID')) {
    $isCollege = Model_Product::getProIsCollection($channel_id, $pro_arr['pid'], USER_ID, USER_USER_ID);
    $collectCurClass = $isCollege ? 'yes-collect' : 'no-collect';
    $collectName     = $isCollege ? '已收藏' : '收藏';
}
$userPro_desc_show = Model_UserProduct::userProductPic(array("desc_show"=>"desc_show"));

$showArr = array();
if (in_array(1, $attrSet['unsee_attr'])) {
    $showArr['price'] = 1;
}
if (in_array(2, $attrSet['unsee_attr'])) {
    $showArr['pinglun'] = 1;
}
if (in_array(3, $attrSet['unsee_attr'])) {
    $showArr['sale_num'] = 1;
}
if (in_array(4, $attrSet['unsee_attr'])) {
    $showArr['content'] = 1;
}
if (in_array(5, $attrSet['unsee_attr'])) {
    $showArr['buy'] = 1;
}

$smarty->assign('showArr', $showArr);
$smarty->assign('extend_info', $extend_info);
$smarty->assign('select_val_id', $select_val_id);
$smarty->assign('last_param_id', $last_param_id);
$smarty->assign('final_guige_arr', $final_guige_arr);
$smarty->assign('final_num', $final_num);
$smarty->assign('collectCurClass', $collectCurClass);
$smarty->assign('collectName', $collectName);
$smarty->assign('userPro_desc_show', $userPro_desc_show);
$smarty->assign('guige_sort', $guige_sort);
$smarty->assign('guige_str', $guige_str);
$smarty->assign('guige_info', $guige_info);
$smarty->assign('rebate', $currentRebate);
$smarty->assign('rebate_type', $userProInfo['rebate_type']);
$smarty->assign('level_arr', $level_arr);
$smarty->assign('user_level', $user_level);
$smarty->assign('zz_userid', $userProInfo['zz_userid']);
$smarty->assign('currentLevelRabate', $currentLevelRabate);
$smarty->assign('big_id_arr', $big_id_arr);
$smarty->assign('sub_id_arr', $sub_id_arr);
$smarty->assign('sub_sub_id_arr', $sub_sub_id_arr);
$smarty->assign('isQRCode', $isQRCode);
$smarty->assign('QRImages', $QRImages);
$smarty->assign('wapPriceHtml', $wapPriceHtml);
$smarty->assign('shareCode', $shareCode);
$smarty->assign('timeBuyProInfo', $timeBuyProInfo);
$smarty->assign('clearanceInfo', $clearanceInfo);
$smarty->assign('total', $total);
$smarty->assign('param_checked_ids', $param_checked_ids);
$smarty->assign('show_zuixiao', $show_zuixiao);
$smarty->assign('show_kucun', $show_kucun);
$smarty->assign('show_danjia', $show_danjia);
$smarty->assign('show_black', $show_black);
$smarty->assign('sub_name_arr', $sub_name_arr);
$smarty->assign('id', $id);
$smarty->assign('buy_num', $buy_num);
$smarty->assign('use_buy_num', $use_buy_num);
$smarty->assign('is_used_param', $is_used_param);
$smarty->assign('fen_class', $fen_class);
$smarty->assign('used_review', $used_review);
$smarty->assign('pin_count', (int)$pin_count);
$smarty->assign('pinlun_arr', $pinlun_arr);
$smarty->assign('bfb', $bfb);
$smarty->assign('average', $average);
$smarty->assign('user_param2', $user_param2);
$smarty->assign('user_param', $user_param);
$smarty->assign('proname_arr', $proname_arr);
$smarty->assign('proname_all', $proname_all);
$smarty->assign('css_filename', $css_filename);
$smarty->assign("system_arr", $system_arr);
$smarty->assign('channel_info_arr', $channel_info);
$smarty->assign('channel_info_arr2', $channel_info11);
$smarty->assign('bottom_info_arr', $bottom_info_arr);
$smarty->assign('bottom_item_arr', $bottom_item_arr);
$smarty->assign('pro_arr', $pro_arr);
$smarty->assign('channel_id', $channel_id);
$smarty->assign('sub_class_arr', $sub_class_arr);
$smarty->assign('sub_num_arr', $sub_num_arr);
$smarty->assign('name', $name);
$smarty->assign('big_name', $big_name);
$smarty->assign('sub_name', $sub_name);
$smarty->assign('sub_sub_name', $sub_sub_name);
$smarty->assign('focus_pic_str', $focus_pic_str);
$smarty->assign('new_focus_pic_str', $new_focus_pic_str);
$smarty->assign('focus_name_str', $focus_name_str);
$smarty->assign('focus_url_str', $focus_url_str);
$smarty->assign('pro_info_arr', $pro_info_arr);
$smarty->assign('info_cnt', $info_cnt);
$smarty->assign('channel_info_arr', $channel_info);
$smarty->assign('maxImg', $maxImg);
$smarty->assign('big_id', $big_id);
$smarty->assign('sub_id', $sub_id);
$smarty->assign('sub_sub_id', $sub_sub_id);
$smarty->assign('user_name', $user_name);
$smarty->assign('guest_chan_id', $guest_chan_id);
$smarty->assign('line_jobs', $line_jobs);
$smarty->assign('ad_type1', $ad_type1);
$smarty->assign('img_num', $img_num);
$smarty->assign('img_width', $img_width);
$smarty->assign('big_class_arr', $big_class_arr);
$smarty->assign('sub_class_arr2', $sub_class_arr2);
$smarty->assign('sub_sub_class_arr', $sub_sub_class_arr);
$smarty->assign('ad_arr', $ad_arr);
$smarty->assign('ch_info', $ch_info);
$smarty->assign('tel', $tel);
$smarty->assign('duiying_pinpai', $duiying_pinpai);
$smarty->assign('is_store_send', $is_store_send);
$smarty->assign('store_link', $store_link);
$smarty->assign('show_button', $show_button);
$smarty->assign('show_guige', $show_guige);
$smarty->display($dec['detail_'.$model_id].'pro_detail.tpl');
