Store.php
3.42 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
<?php
/**
* 店铺相关接口
* @author tongdesheng
*
*/
class YHMApi_App_V1_Store extends YHMApi_App_V1_Base {
/**
*
* @param array $params
* @param string $fields
*/
public static function getListByType(array $params, $fields = '*') {
$store_type = $params['store_type'];
$offset = $params['offset'];
$num = $params['num'];
$hasgoods = 1;
$hasstock = 1;
$selectParams = array(
'storetype' => $store_type,
'viewNum' => $num,
'page' => intval($offset / $num) + 1,
'hasgoods' => $hasgoods,
'hasstock' => $hasstock,
'order_type' => 'star:desc'
);
if (!empty($params['uid'])) {
$selectParams['searchuid'] = $params['uid'];
}
$selectParams['hasstock'] = 1;
$selectParams['hasgoods'] = 1;
$storeList = array();
try {
$storeSearch = new YHMSearch_Store();
$storeIdList = $storeSearch->getList($selectParams);
foreach ($storeIdList as $storeId) {
$storeData = self::_getStoreForList($storeId);
if (empty($storeData['newest_goods_list'])) {
// continue;
}
$storeList[] = $storeData;
}
} catch (Exception $ex) {
return self::result(500, '搜索服务异常');
}
return self::result(200, "卖家列表", $storeList);
}
/**
* 通过uid获取店铺id
* @param array $params
* @param string $fields
*/
public static function getStoreIdByUid(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, 'uid不能为空');
}
$uid = $params['uid'];
$store_id = YHMStore_Models_Store_Client::getStoreIdByUid($uid);
return self::result(200, '获取成功', array('store_id' => $store_id));
}
/**
* 店铺信息
* @param array $params
* @param string $fields
*/
public static function info(array $params, $fields = '*') {
if (empty($params['store_id'])) {
return self::result(400, '店铺id不能为空');
}
$store_id = $params['store_id'];
$store = YHMStore_Models_Store_Client::getById($store_id);
//在售商品总数
$sell_num = YHMProduct_Models_Goods_Client::getCountGoodsByStoreId($store_id);
//已售商品总数
$sold_num = YHMOrders_Models_Orders_Client::getCountOrderByStatus($store_id);
//已购数量
$buyed = YHMOrders_Models_Orders_Client::getCountBuyedByBuyerId($store['uid']);
//是否收藏
if (!empty($params['uid'])) {
$favorite = YHMPassport_Models_Favorite_Store_Client::findIsFavoriteByStoreId($params['uid'], $store_id);
}
$is_favorite = 'N';
if (!empty($favorite)) {
$is_favorite = 'Y';
}
//需要将店铺id转化成uid
$uid = $store['uid'];
$storeInfo = self::_getUserInfo($uid);
$storeInfo['sell_num'] = (isset($sell_num[0]['sell_num']))?$sell_num[0]['sell_num']:0; //在售商品
$storeInfo['sold_num'] = ($sold_num)?$sold_num:0; //售出数量
$storeInfo['purchased_num'] = ($buyed)?$buyed:0; //已购数量
$storeInfo['is_favorite'] = $is_favorite;
return self::result(200, '店铺信息', $storeInfo);
}
}