Consult.php
3.65 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
<?php
namespace Home;
use LibModels\Web\Home\ConsultData;
use LibModels\Web\Product\SearchData;
use WebPlugin\Helpers;
use WebPlugin\HelperSearch;
use WebPlugin\Images;
/**
* 个人中心-我的咨询相关业务逻辑处理
*/
class ConsultModel
{
public static function ConsultList($uid , $page, $limit = 10)
{
$result = array('consults' => array(), 'pager' => array());
$skn = array();
$consult = ConsultData::getConsult($uid, $page, $limit);
if (isset($consult['code']) && $consult['code'] ==200 && isset($consult['data']['consult_list']) && !empty($consult['data']['consult_list'])) {
foreach ($consult['data']['consult_list'] as $key => $val) {
$skn[] = $val['skn'];
}
$goodsInfo = self::getProductGoodsInfo($skn);
foreach ($consult['data']['consult_list'] as $key => $val) {
if (!isset($goodsInfo[$val['skn']])) {
continue;
}
if ($val['answer']) {
$result['consults'][$key]['reply'] = $val['answer'];
}
$result['consults'][$key]['href'] = Helpers::getUrlBySkc($val['productId'], $goodsInfo[$val['skn']]['goods_id'], $goodsInfo[$val['skn']]['cn_alphabet']);;
$result['consults'][$key]['thumb'] = Images::getImageUrl($goodsInfo[$val['skn']]['images_url'], 60, 60, 1);
$result['consults'][$key]['name'] = $val['productName'];
$result['consults'][$key]['question'] = $val['ask'] ? $val['ask'] : '';
$result['consults'][$key]['consultTime'] = date('Y-m-d H:i:s', $val['askTime']);
}
//分页
$result['pager']['hasCheckAll'] = false;
$result['pager']['count'] = $consult['data']['total'];
$result['pager']['curPage'] = $consult['data']['page'];
$result['pager']['totalPages'] = $consult['data']['page_total'];
$result['pager']['pagerHtml'] = HelperSearch::pager($consult['data']['total'], $limit);
}
if (empty($result['consults'])) {
$result['consults']['empty'] = '您尚未咨询任何内容';
}
return $result;
}
/**
* 查询多个skn的默认商品
* @param $skn array
* @return array
*/
public static function getProductGoodsInfo($skn)
{
$result = array();
$param['query'] = implode(',', $skn);
$data = SearchData::searchAll($param);
if (isset($data['data']['product_list']) && !empty($data['data']['product_list'])) {
foreach ($data['data']['product_list'] as $key => $val) {
$defaultGoods = array();
$backGoods = array();
foreach ($val['goods_list'] as $k => $v) {
do {
$backGoods['goods_id'] = $v['goods_id'];
$backGoods['images_url'] = $v['images_url'];
$backGoods['cn_alphabet'] = $val['cn_alphabet'];
} while(false);
if ($v['is_default'] == 'Y') {
$defaultGoods['goods_id'] = $v['goods_id'];
$defaultGoods['images_url'] = $v['images_url'];
$defaultGoods['cn_alphabet'] = $val['cn_alphabet'];
}
if (!empty($defaultGoods)) {
break;
}
}
$result[$val['product_skn']] = $defaultGoods ? $defaultGoods : $backGoods;
}
}
return $result;
}
}