Comment.php
6.2 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2016-3-23
* Time: 14:48
*/
namespace Home;
use LibModels\Web\Home\CommentData;
use Plugin\Helpers;
use WebPlugin\HelperSearch;
/**
* 个人中心-我的评论
*/
class CommentModel
{
/**
* 我的评论列表页
* @param $uid
* @param $isComment
* @param $page
* @param $limit
* @return array
*/
public static function getCommentList($uid, $isComment, $page, $limit)
{
//转string值为bool值
if ($isComment == 'Y') {
$isComment = true;
}elseif($isComment == 'N') {
$isComment = false;
}
//调用接口获得评论列表数据
$result = CommentData::getCommentListData($uid);
$commentList = array();
$pager = array();
$commentList['isComment'] = $isComment;//标记当前列表展示状态(已评论、未评论)
$goodsNum = '0';//初始化商品数量
$commentList['goodsNum'] = '0';
//接口返回成功,则处理数据,否则返回空
if (isset($result['code']) && $result['code'] == 200 && !empty($result['data'])) {
foreach ($result['data'] as $key=>$value) {
foreach ($value['orderGoods'] as $k=>$v) {
//处理已评论的数据
if ($isComment && array_key_exists('comment', $v)) {
$commentList['orders'][$key]['orderNum'] = $value['orderCode'];
$commentList['orders'][$key]['orderTime'] = $value['createTime'];
$commentList['orders'][$key]['orderId'] = $value['orderId'];
$cnAlphabet = '';
if (!empty($v['cnAlphabet'])) {
$cnAlphabet = $v['cnAlphabet'];
}
$commentList['orders'][$key]['goods'][$k]['href'] = Helpers::getUrlBySkc($v['productId'], $v['goodsId'], $cnAlphabet);
$commentList['orders'][$key]['goods'][$k]['thumb'] = Helpers::getImageUrl($v['imageUrl'],100,100);
$commentList['orders'][$key]['goods'][$k]['name'] = isset($v['productName']) ? $v['productName'] : '';
$commentList['orders'][$key]['goods'][$k]['remark'] = $v['comment'];
$commentList['orders'][$key]['goods'][$k]['productSkn'] = $v['productSkn'];
$commentList['orders'][$key]['goods'][$k]['productId'] = $v['productId'];
$commentList['orders'][$key]['goods'][$k]['goodsId'] = $v['goodsId'];
$commentList['orders'][$key]['goods'][$k]['erpSkuId'] = $v['erpSkuId'];
$commentList['orders'][$key]['goods'] = array_values($commentList['orders'][$key]['goods']);
$goodsNum ++;
}
//处理未评论的数据
elseif (!$isComment && !array_key_exists('comment', $v)) {
$commentList['orders'][$key]['orderNum'] = $value['orderCode'];
$commentList['orders'][$key]['orderTime'] = $value['createTime'];
$commentList['orders'][$key]['orderId'] = $value['orderId'];
$cnAlphabet = '';
if (!empty($v['cnAlphabet'])) {
$cnAlphabet = $v['cnAlphabet'];
}
$commentList['orders'][$key]['goods'][$k]['href'] = Helpers::getUrlBySkc($v['productId'], $v['goodsId'], $cnAlphabet);
$commentList['orders'][$key]['goods'][$k]['thumb'] = Helpers::getImageUrl($v['imageUrl'],100,100);
$commentList['orders'][$key]['goods'][$k]['name'] = isset($v['productName']) ? $v['productName'] : '';
$commentList['orders'][$key]['goods'][$k]['productSkn'] = $v['productSkn'];
$commentList['orders'][$key]['goods'][$k]['productId'] = $v['productId'];
$commentList['orders'][$key]['goods'][$k]['goodsId'] = $v['goodsId'];
$commentList['orders'][$key]['goods'][$k]['erpSkuId'] = $v['erpSkuId'];
$commentList['orders'][$key]['goods'] = array_values($commentList['orders'][$key]['goods']);
$goodsNum ++;
}
}
}
//转关联数组为索引数组
$commentList['orders'] = isset($commentList['orders']) ? array_values($commentList['orders']) : array();
$commentList['goodsNum'] = $goodsNum;
$total = count($commentList['orders']);
$totalPage = ceil($total/$limit);
$begin = ($page - 1) * $limit; //每页第一个商品键名
$commentList['orders'] = array_slice($commentList['orders'], $begin, $limit); //截取该页显示的商品列表
$pager = self::setPager($page, $total, $totalPage, $limit);
}else{
$commentList['orders']['empty'] = $isComment ? '您还没有已评论的商品' : '您还没有未评论的商品';//没有数据返回空
}
//面包屑-左侧导航
$path = UserModel::getCenterCrumb('我的评论');
$leftNav = UserModel::getCenterLeftNav('我的评论', $uid);
$data = array(
'path'=>$path,
'homeNav'=>$leftNav,
'comment' => $commentList,
'userThumb' => UserModel::getUserHeadImg($uid),
'pager' => $pager
);
return $data;
}
/**
* 设置分页数据
* @param $page
* @param $total
* @param $totalPage
* @param $limit
* @return array
*/
public static function setPager($page, $total, $totalPage, $limit)
{
$result = array();
if (isset($page) && isset($total) && isset($totalPage)) {
$result['count'] = $total;
$result['curPage'] = $page;
$result['totalPages'] = $totalPage;
$result['pagerHtml'] = HelperSearch::pager($total, $limit);;
}
return $result;
}
}