VIP.php 2.46 KB
<?php
/**
 * Created by PhpStorm.
 * User: yl3016
 * Date: 16/3/21
 * Time: 下午1:35
 */

namespace Home;

use LibModels\Web\Home\UserData;

class VIPModel
{
    /**
     * 个人中心-我的VIP
     * @param int $uid
     * @return array
     */
    public static function getVIPInfo($uid)
    {
        $vipInfo = UserData::getVIPInfoByUid($uid);
        $data = $vipInfo['data'];

        // VIP升级进度
        if ($data['next_need_cost'] == 0) {
            $proportion = '0%';
        } else {
            $proportion = floor($data['current_year_cost'] * 100 / $data['next_need_cost']);
            $proportion = $proportion > 100 ? 100 : $proportion;
            $proportion = $proportion . '%';
        }

        // VIP剩余天数
        $datetime1 = date_create(date("Y-m-d"));
        $datetime2 = date_create(date('Y-m-d', $data['vip_end_time']));
        $interval = date_diff($datetime1, $datetime2);
        $remainDays = $interval->format('%a');

        // VIP享受的优惠
        $preferences = array();
        $enjoyPreferences = $data['enjoy_preferential'];
        if ($enjoyPreferences) {
            foreach ($enjoyPreferences as $k => $v) {
                $preferences[$k]['id'] = $v['id'];
                $preferences[$k]['favTxt'] = $v['title'];
                $preferences[$k]['imgType'] = $v['pic'];
                $preferences[$k]['description'] = $v['description'];
            }
        }

        $vip = array(
            'title' => $data['current_vip_title'],
            'level' => $data['current_vip_level'],
            'totalCost' => sprintf("%.2f", $data['current_total_cost']),
            'nextTitle' => $data['next_vip_title'],
            'nextLevel' => $data['next_vip_level'],
            'nextCost' => sprintf("%.2f", $data['next_need_cost']),
            'enjoyPreferences' => $preferences,
            'yearCost' => sprintf("%.2f", $data['current_year_cost']),
            'upgradeCost' => sprintf("%.2f", $data['upgrade_need_cost']),
            'proportion' => $proportion,
            'reach' => date('Y.m.d', $data['vip_reach_time']),
            'start' => date('Y.m.d', $data['vip_start_time']),
            'end' => date('Y.m.d', $data['vip_end_time']),
            'remainDays' => $remainDays,
            'platinum' => $data['upgrade_need_cost'] > 0 ? false : true,
            'isVip' => $data['current_vip_level'] > 0 ? true : false,
        );
        return $vip;
    }

}