private static function row() { if (SALE::pyramid(self::$id)) { /* if(count(SALE::$group) > 1){ # 多個群組 } */ $group_array = SALE::$group; foreach ($group_array as $group => $data) { VIEW::newBlock("TAG_SALE_BLOCK"); $level_count = count($data) - 1; # 共有幾層 $max_unit = pow(2, $level_count); VIEW::assign("PYRAMID_WIDTH", $max_unit * 150); foreach ($data as $level => $level_data) { VIEW::newBlock("TAG_SALE_LEVEL"); if (empty($level)) { VIEW::newBlock("TAG_SALE_UNIT"); VIEW::assign(array("PYRAMID_SPLIT" => pow(2, $level), "TAG_USED" => "used")); list($top_parent) = array_keys($level_data); $top_level = SALE::member_level($level_data[$top_parent]); self::output($level, $level_data[$top_parent], $data); # 顯示會員資訊 $zone[0] = $level_data[$top_parent]["id"]; # 紀錄父層區域 id } else { $unit_count = pow(2, $level); for ($i = 0; $i < $unit_count; $i++) { VIEW::newBlock("TAG_SALE_UNIT"); VIEW::assign("PYRAMID_SPLIT", pow(2, $level)); $zone_key = ceil(($i + 1) / 2) - 1; # 取得父層區域 key $unit_key = empty($i) || $i % 2 == 0 ? 0 : 1; $row = $level_data[$zone[$zone_key]][$unit_key]; # 取得資料 if (isset($row) && is_array($row)) { # 如果有資料 VIEW::assign("TAG_USED", "used"); self::output($level, $row, $data); # 顯示會員資訊 $new_zone[$i] = $row["id"]; # 紀錄父層區域 id } else { VIEW::assign("CONTENT_EMPTY", "empty"); } } unset($zone); $zone = $new_zone; } VIEW::gotoBlock("TAG_SALE_LEVEL"); VIEW::assign("VALUE_LEVEL", $top_level++); } } } }
public static function bonus($m_id = false) { SALE::pyramid($m_id); list($data) = self::$group; unset($data[0]); foreach ($data as $level => $cate) { $level_total = pow(2, $level); unset($member_count, $createdate); foreach ($cate as $sub_member) { $member_count[] = count($sub_member); # 取得會員創建時間 foreach ($sub_member as $memberRow) { $createdate[] = $memberRow["createdate"]; } } $member_total = array_sum($member_count); # 取得同階層總會員數 if ($level_total == $member_total) { $level_done[$level] = true; # 取得會員最晚創建時間 rsort($createdate); list($level_time[$level]) = $createdate; } } # 所有累計獎金 $bonus = self::bonus_count($level_done, $level_time); # 扣除已經發送獎金 $rsnum = CRUD::dataFetch('grant', array('m_id' => $m_id)); if (!empty($rsnum)) { foreach (CRUD::$data as $key => $row) { $granted_array[] = $row["granted"]; } $granted = array_sum($granted_array); return $bonus - $granted; } else { return $bonus; } }