Goods.php
3.68 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
<?php
/**
* 商品相关
*/
header("Content-type: text/html; charset=utf-8");
class YHMApi_App_V2_Goods extends YHMApi_App_V1_Goods
{
/**
* 获取品类列表数据
*
* @return json
*/
public static function getCategoryList(array $params, $fields = '*')
{
$categoryList = YHMProduct_Models_Category_Client::getCategoryList(3, 0, 1000);
$key = 'getCategoryList_key';
$list = Q_Cache::factory('Memcached')->get($key);
if(empty($list))
{
foreach ( $categoryList as $category)
{
// 商品父类
if (empty ( $category ['parent_id'] ))
{
$category ['sub_class'] = array ();
if (empty ( $list [$category ['id']] ))
{
$list [$category ['id']] = array ();
}
$list [$category ['id']] += $category;
}
else
{
$list [$category ['parent_id']] ['sub_class'] [] = $category;
}
}
$list = array_values($list);
$list = Q_Cache::factory('Memcached')->set($key, $list, 86400);
}
return self::result(200, '品类列表.', $list);
}
/**
* 获取首页最新商品
*
* @param array $params
* @param string $fields
*/
public static function getNewestIndexList(array $params, $fields = '*')
{
if(!isset($params ['num']))
{
$params ['num'] = 8;
}
if(!isset($params ['offset']))
{
$params ['offset'] = 0;
}
$params ['viewNum'] = $params ['num'];
$params ['page'] = intval($params ['offset'] / $params ['num']) + 1;
if (!empty($params['uid']))
{
$params['searchuid'] = $params['uid'];
}
$params ['stocknumber'] = 1; //库存数大于1的商品
$params ['status'] = 1;
$resultList = array();
try {
$searchObj = new YHMSearch_Goods ();
$skcList = $searchObj->getList($params);
if (!empty($skcList))
{
foreach ($skcList as $skc => $goodsName)
{
$productInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($skc);
if(!empty($productInfo))
{
$goodsImages = YHMProduct_Models_Goodsimages_Client::getByProductSkc($skc);
// 是否收藏商品
if (!empty($params ['uid']))
{
$favorite = YHMPassport_Models_Favorite_Goods_Client::findIsFavoriteBySkc($params ['uid'], $params ['product_skc']);
}
$favorite_num = YHMPassport_Models_Favorite_Goods_Client::getFavoriteTotal($skc);
$is_favorite = 'N';
if (!empty($favorite)) {
$is_favorite = 'Y';
}
//商品描述 goods_describe
$goods_describe = YHMProduct_Models_Goods_Client::getGoodsDescribeBySkc($skc);
$imageList = array();
foreach($goodsImages as $goodsImage)
{
$imageList[] = array(
'is_default' => $goodsImage['is_default'],
'image_url'=> YHMUpload_Images::template($goodsImage ['image_path'], 'yhfair-product'),
'id' => $goodsImage ['id'],
);
}
$is_deleted = 'N';
if ($productInfo['status'] == 0)
{
$is_deleted = 'Y';
}
$storeInfo = self::_getStoreForList($productInfo['store_id'] , false);
unset($storeInfo['newest_goods_list']);
$resultList[] = array(
'image_list' => $imageList,
'product_skc' => $skc,
'is_favorite' => $is_favorite, // 是否已收藏,
'favorite_num'=> $favorite_num,//收藏数
'area_code'=> $productInfo['area_code'],
'goods_name'=> $productInfo['goods_name'],
'goods_describe' => $goods_describe['goods_describe'],
'create_time' => $productInfo['create_time'],
'sale_price' => $productInfo['sale_price'],
'is_deleted' => $is_deleted)
+ $storeInfo;
}
}
}
} catch (Exception $e)
{
return self::result(500, '搜索服务异常');
}
return self::result(200, '首页最新商品', $resultList);
}
}