VIP.php
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Created by PhpStorm.
* User: yl3016
* Date: 16/3/21
* Time: 下午1:35
*/
namespace Home;
use LibModels\Web\Home\UserData;
use \WebPlugin\Helpers;
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'] = Helpers::getUrlSafe($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;
}
}