Message.php
6.92 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
namespace Home;
use WebPlugin\Helpers;
use LibModels\Web\Home\MessageData;
use WebPlugin\Paging;
/**
* 个人中心——我的消息逻辑处理
*/
class MessageModel
{
/**
* 我的消息列表
* @param type $uid
* @param type $page
* @param type $size
* @return array
*/
public static function getInboxList($uid, $page, $size)
{
$result = array('messages' => array(), 'pager' => array());
$inboxlist = MessageData::getInboxList($uid, $page, $size);
if (!empty($inboxlist['data']['list']) && !empty($inboxlist['data'])) {
foreach ($inboxlist['data']['list'] as $inboxkey => $inboxval) {
//信息过滤
if ($inboxval['type'] == '$inboxval' || $inboxval['type'] == 'notice') {
continue;
}
$messages[$inboxkey]['href'] = Helpers::url('/home/message/content', array('page' => $page, 'id' => $inboxval['id'])); //消息内容链接
$messages[$inboxkey]['sender'] = isset($inboxval['from']) ? $inboxval['from'] : 0; //消息发言人
$messages[$inboxkey]['isNew'] = $inboxval['is_read'] == 'Y' ? false : true; //消息是否已读
$messages[$inboxkey]['title'] = isset($inboxval['title']) ? $inboxval['title'] : 0;
; //消息标题
$messages[$inboxkey]['time'] = date('Y-m-d H:i:s', $inboxval['create_time']); //消息创建时间
$messages[$inboxkey]['id'] = isset($inboxval['id']) ? $inboxval['id'] : 0;
; //消息唯一标识id
$result['messages'] = $messages;
}
$total = isset($inboxlist['data']['total']) ? $inboxlist['data']['total'] : 0; //消息总条数
$pageTotal = isset($inboxlist['data']['page_total']) ? $inboxlist['data']['page_total'] : 0; //总页数
$page = isset($inboxlist['data']['page']) ? $inboxlist['data']['page'] : 0; //当前页
$result['pager'] = self::getPager($page, $total, $pageTotal, $size);
}
else {
$result['messages']['empty'] = '您尚未收到任何短消息';
}
return $result;
}
/**
* 我的信息内容详情
* @param type $uid
* @param type $page
* @param type $size
* @param type $id
* @return type array
*/
public static function getContentData($uid, $page, $size, $id)
{
$result = array();
$inboxlist = MessageData::getInboxList($uid, $page, $size);
if (!empty($inboxlist['data']['list'])) {
foreach ($inboxlist['data']['list'] as $contentkey => $contentval) {
if ($contentval['id'] != $id) {
continue;
}
//信息过滤
if ($contentval['type'] == 'showGetCoin' || $contentval['type'] == 'notice') {
continue;
}
$result['sender'] = $contentval['from']; //消息发言人
$result['title'] = $contentval['title']; //消息标题
$result['time'] = date('Y-m-d H:i:s', $contentval['create_time']); //消息创建时间
//判断消息类型
switch ($contentval['type']) {
case 'pullCoupon':
//领取生日券消息
$result['coupons'] = array();
$coupondata = MessageData::getCouponId($uid); //获取优惠券信息
if (empty($coupondata['data']) || !isset($coupondata['data'])) {
continue;
}
foreach ($coupondata['data'] as $couponval) {
$result['coupons'][] = array(
'id' => isset($couponval['id']) ? $couponval['id'] : '',
'remark' => isset($couponval['couponName']) ? $couponval['couponName'] : '',
'useTime' => isset($contentval['body']['use_time']) ? $contentval['body']['use_time'] : '',
'pickTime' => isset($contentval['body']['collar_time']) ? $contentval['body']['collar_time'] : '',
'canPick' => true);
}
break;
case 'button':
//促销活动
$result['sale'] = array(
'image' => isset($contentval['body']['image']) ? $contentval['body']['image'] : '',
'content' => isset($contentval['body']['text']) ? $contentval['body']['text'] : '',
'btnLink' => isset($contentval['body']['pc_link']) ? $contentval['body']['pc_link'] : '',
'btnName' => isset($contentval['body']['button_text']) ? $contentval['body']['button_text'] : '',
);
break;
case 'pushCoupon':
//查看优惠券
$result['coupons'] = array();
$result['coupons'][] = array(
'remark' => isset($contentval['body']['coupon_name']) ? $contentval['body']['coupon_name'] : '',
'useTime' => isset($contentval['body']['time']) ? $contentval['body']['time'] : '',
'id' => isset($contentval['body']['inboxId']) ? $contentval['body']['inboxId'] : '',
'price' => isset($contentval['body']['price']) ? $contentval['body']['price'] : '',
'url' => Helpers::url('/home/coupons', array('t' => microtime(true)))
);
break;
default:
//普通文本
$result['text'] = array(
'content' => isset($contentval['body']['content']) ? $contentval['body']['content'] : ''
);
break;
}
}
}
return $result;
}
/**
* 设置分页数据
* @param type $page
* @param type $total
* @param type $totalPage
* @param type $size
* @return type
*/
public static function getPager($page, $total, $totalPage, $size)
{
$result = array();
if (isset($page) && isset($total) && isset($totalPage)) {
$result['count'] = $total;
$result['curPage'] = $page;
$result['totalPages'] = $totalPage;
$result['hasCheckAll'] = false;
$paging = new Paging('yoho');
$paging->setTotal($total)->setSize($size)->setQuery(array('page' => $page));
$result['pagerHtml'] = $paging->view(false);
}
return $result;
}
}