Coupons.php
3.47 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Created by PhpStorm.
* User: yl3016
* Date: 16/3/21
* Time: 下午5:10
*/
namespace Home;
use LibModels\Web\Home\UserData;
use WebPlugin\Helpers;
class CouponsModel
{
const UNUSED = 'notuse';
const USED = 'use';
const INVALID = 'overtime';
public static function getCouponsList($uid, $type, $page, $limit)
{
$couponsInfo = UserData::getCouponsList($uid, $type, $page, $limit);
$result = array();
if (empty($couponsInfo['data']['couponList'])) {
return $result;
}
$coupons = $couponsInfo['data']['couponList'];
if ($coupons) {
foreach ($coupons as $k => $v) {
$result[$k]['id'] = $v['couponId'];
$result[$k]['code'] = $v['couponCode'];
// 格式化有效日期 "couponValidity": "2016.03.15-2016.03.31"
$dates = explode('-', $v['couponValidity']);
$result[$k]['beginTime'] = date('Y-m-d', date_timestamp_get(date_create_from_format('Y.m.d', $dates[0])));
$result[$k]['endTime'] = date('Y-m-d', date_timestamp_get(date_create_from_format('Y.m.d', $dates[1])));
if (empty($v['couponImageUrl'])) {
$result[$k]['img'] = '//static.yohobuy.com/images/v2/activity/default_coupon.jpg';
} else {
$result[$k]['img'] = $v['couponImageUrl'];
}
// 3天之内即将要过期
if (($v['overTime'] - time()) < 259200) {
$result[$k]['endSoon'] = true;
} else {
$result[$k]['endSoon'] = false;
}
$result[$k]['value'] = sprintf("¥%.2f", $v['couponValue']);
$result[$k]['validity'] = $v['couponValidity'];
$result[$k]['useRemark'] = $v['couponDetailInfomation'];
if ($type == self::USED) {
$result[$k]['orderNum'] = isset($v['orderCode']) ? $v['orderCode'] : '';
$result[$k]['orderDetailUrl'] = Helpers::url('/home/orders/detail', array('orderCode' => isset($v['orderCode']) ? $v['orderCode'] : ''));
$result[$k]['orderSum'] = sprintf("¥%.2f", isset($v['orderPrice']) ? $v['orderPrice'] : 0);
$result[$k]['payment'] = sprintf("¥%.2f", isset($v['actuallyPaid']) ? $v['actuallyPaid'] : 0);
$date = date_create_from_format('Y-m-d H:i:s', isset($v['usedTime']) ? $v['usedTime'] : 0);
if ($date) {
$result[$k]['useTime'] = date('Y-m-d H:i', date_timestamp_get($date));
} else {
$result[$k]['useTime'] = '';
}
} else {
$result[$k]['status'] = $v['isValidity'] ? '可使用' : '已过期';
}
if (isset($v['couponType'])) {
$result[$k]['type'] = $v['couponType'];
// 免邮券面值显示‘免邮’
if ($v['couponType'] == 5) {
$result[$k]['value'] = '免邮';
}
}
}
$result['pager']['total'] = $couponsInfo['data']['total'];
$result['pager']['pageTotal'] = $couponsInfo['data']['totalPageNum'];
$result['pager']['page'] = $page;
}
return $result;
}
}