PHP根據信譽點數或者分數來匹配對應商家或者賣家的等級,仿淘寶多商家信譽等級
核心函數
function getCreditScore($credit_score) {
$pic = "";
$rank = "";
$diamond_bei = intval($credit_score / 50); //鉆石倍數
$cron_bei = intval($credit_score / 250); //皇冠倍數
$rank_star = "";
if ($cron_bei > 0) { //皇冠顯示
if ($cron_bei == 1) {
$pic .= "<img title src='images/s_crown_1.gif'>";
$rank .= "一皇冠";
} elseif ($cron_bei == 2) {
$pic .= "<img title src='images/s_crown_2.gif'>";
$rank .= "二皇冠";
} elseif ($cron_bei == 3) {
$pic .= "<img title src='images/s_crown_3.gif'>";
$rank .= "三皇冠";
} elseif ($cron_bei == 4) {
$pic .= "<img title src='images/s_crown_4.gif'>";
$rank .= "四皇冠";
} else {
$pic .= "<img title src='images/s_crown_5.gif'>";
$rank .= "五皇冠";
}
$rank_star = $credit_score % 250;
$diamond_bei = intval(($credit_score - intval($credit_score / 250) * 250) / 50); //鉆石倍數
}
if ($diamond_bei > 0) { //鉆石顯示
$diamond_style = "";
if ($cron_bei > 0) {
$diamond_style = "style='margin:0 2px 0 5px'";
}
if ($diamond_bei == 1) {
$pic .= "<img title src='images/s_blue_1.gif' $diamond_style>";
$rank .= "一鉆";
} elseif ($diamond_bei == 2) {
$pic .= "<img title src='images/s_blue_2.gif' $diamond_style>";
$rank .= "二鉆";
} elseif ($diamond_bei == 3) {
$pic .= "<img title src='images/s_blue_3.gif' $diamond_style>";
$rank .= "三鉆";
} elseif ($diamond_bei == 4) {
$pic .= "<img title src='images/s_blue_4.gif' $diamond_style>";
$rank .= "四鉆";
} elseif ($diamond_bei == 5) {
$pic .= "<img title src='images/s_blue_5.gif' $diamond_style>";
$rank .= "五鉆";
}
$rank_star = $credit_score % 50;
}
if ($cron_bei == 0 && $diamond_bei == 0) {
$rank_star = $credit_score;
}
if (0 <= $rank_star && $rank_star <= 10) {
$pic .= "<img class='xy' title src='images/s-star-1.gif'>";
$rank .= "一星";
} elseif (11 < $rank_star && $rank_star <= 20) {
$pic .= "<img class='xy' title src='images/s-star-2.gif'>";
$rank .= "兩星";
} elseif (21 < $rank_star && $rank_star <= 30) {
$pic .= "<img class='xy' title src='images/s-star-3.gif'>";
$rank .= "三星";
} elseif (31 < $rank_star && $rank_star <= 40) {
$pic .= "<img class='xy' title src='images/s-star-4.gif'>";
$rank .= "四星";
} elseif (41 < $rank_star && $rank_star <= 50) {
$pic .= "<img class='xy' title src='images/s-star-5.gif'>";
$rank .= "五星";
}
$title = "title= '" . $rank . "(" . $credit_score . "個信譽點) '";
$a = $pic . "<span class='credit_stars'>" . $credit_score . "個信譽點</span>";
$b = str_replace("title", $title, $a);
return $b;
}