Favorite.php
4.46 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
<?php
/**
* Public 收藏
* User: elkan
* Date: 2014-8-19
* Time: PM1:08
*/
class YHMApi_App_V1_Favorite extends YHMApi_App_V1_Base {
/**
* 获取收藏的商品
* @param array $params
* @param string $fields
*/
public static function getGoodsByUid(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
$offset = !empty($params['offset']) ? (int) $params['offset'] : '0';
$num = !empty($params['num']) ? (int) $params['num'] : "10";
$data = YHMPassport_Models_Favorite_Goods_Client::getListByUid($params['uid'], $offset, $num);
$goodlist = array();
foreach ($data as $k => $v) {
$goodlist[] = self::_getGoodsForList($v["product_skc"]);
}
return self::result(200, '收藏的商品', $goodlist);
}
/**
* 获取收藏的卖家
* @param array $params
* @param string $fields
*/
public static function getStoreByUid(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
$offset = !empty($params['offset']) ? (int) $params['offset'] : '0';
$num = !empty($params['num']) ? (int) $params['num'] : "10";
$data = YHMPassport_Models_Favorite_Store_Client::getListByUid($params['uid'], $offset, $num);
$storeList = array();
foreach ($data as $k => $v) {
$storeList[] = self::_getStoreForList($v['store_id']);
}
return self::result(200, '获取收藏的店铺', $storeList);
}
/**
* 收藏商品
* @param array $params
* @param type $fields
* @return type
*/
public static function addGoods(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
if (empty($params['product_skc'])) {
return self::result(400, '商品skc不能为空');
}
$goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($params['product_skc']);
$id = YHMPassport_Models_Favorite_Goods_Client::add($params['uid'], $params['product_skc'], $goods_info['sale_price']);
if ($id < 0) {
return self::result(500,'收藏失败');
}
return self::result(200, "添加成功", $id);
}
/**
* 取消收藏商品
* @param array $params
* @param type $fields
* @return type
*/
public static function cancelFavoriteGoods(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
if (empty($params['product_skc'])) {
return self::result(400, '收藏id不能为空');
}
$status = YHMPassport_Models_Favorite_Goods_Client::del($params['uid'], $params['product_skc']);
return self::result(200, "已取消收藏");
}
/**
* 收藏店铺
* @param array $params
* @param type $fields
* @return type
*/
public static function addStore(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
if (empty($params['store_id'])) {
return self::result(400, '店铺id不能为空');
}
$arr=YHMPassport_Models_Favorite_Store_Client:: findIsFavoriteByStoreId($params['uid'], $params['store_id']);
if (isset($arr['id'])&&($arr['id']>0))
{
return self::result(200, "已收藏", $arr['id']);
}
$id = YHMPassport_Models_Favorite_Store_Client::add($params['uid'], $params['store_id']);
if ($id < 0) {
return 0;
}
return self::result(200, "添加成功", $id);
}
/**
* 取消收藏店铺
* @param array $params
* @param type $fields
* @return type
*/
public static function cancelFavoriteStore(array $params, $fields = '*') {
if (empty($params['uid'])) {
return self::result(400, '用户id不能为空');
}
if (empty($params['store_id'])) {
return self::result(400, '收藏店铺id不能为空');
}
$status = YHMPassport_Models_Favorite_Store_Client::del($params['uid'], $params['store_id']);
if (empty($status)) {
return self::reuslt(400, "删除失败");
}
return self::result(200, "已取消收藏");
}
}