Authored by Rock Zhang

添加收藏有关的接口,并处理有关数据;为个人中心首页添加一些链接地址

@@ -130,6 +130,24 @@ class UserData @@ -130,6 +130,24 @@ class UserData
130 } 130 }
131 131
132 /** 132 /**
  133 + * 取消收藏的商品数据
  134 + *
  135 + * @param int $uid 用户ID
  136 + * @param int $fav_id 要取消的收藏id
  137 + * @return array 接口返回的数据
  138 + */
  139 + public static function favoriteDelete($uid, $fav_id)
  140 + {
  141 + $param = Yohobuy::param();
  142 + $param['method'] = 'app.favorite.cancel';
  143 + $param['type'] = 'product';
  144 + $param['fav_id'] = $fav_id;
  145 + $param['client_secret'] = Sign::getSign($param);
  146 +
  147 + return Yohobuy::get(Yohobuy::API_URL, $param);
  148 + }
  149 +
  150 + /**
133 * YOHO币数据 151 * YOHO币数据
134 * 152 *
135 * @param int $uid 用户ID 153 * @param int $uid 用户ID
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="my-page yoho-page"> 2 <div class="my-page yoho-page">
3 <div class="my-header"> 3 <div class="my-header">
4 - <div class="user-info"> 4 + <div class="user-info"><!--/home/personaldetails-->
5 <img class="user-avatar" src="{{head_ico}}"> 5 <img class="user-avatar" src="{{head_ico}}">
6 <span class="username">{{profile_name}}</span> 6 <span class="username">{{profile_name}}</span>
7 {{#vip_info}} 7 {{#vip_info}}
@@ -11,11 +11,11 @@ @@ -11,11 +11,11 @@
11 </div> 11 </div>
12 </div> 12 </div>
13 <div class="my-link clearfix"> 13 <div class="my-link clearfix">
14 - <a class="link-item" href="/home/"> 14 + <a class="link-item" href="/home/favorite">
15 {{product_favorite_total}} 15 {{product_favorite_total}}
16 <p>收藏的商品</p> 16 <p>收藏的商品</p>
17 </a> 17 </a>
18 - <a class="link-item" href="/home/"> 18 + <a class="link-item" href="/home/favoritebrand">
19 {{brand_favorite_total}} 19 {{brand_favorite_total}}
20 <p>收藏的品牌</p> 20 <p>收藏的品牌</p>
21 </a> 21 </a>
@@ -54,26 +54,26 @@ @@ -54,26 +54,26 @@
54 </a> 54 </a>
55 </div> 55 </div>
56 <div class="group-list"> 56 <div class="group-list">
57 - <a class="list-item" href="/home/"> 57 + <a class="list-item" href="/home/coupons">
58 <span class="iconfont icon">&#xe63a;</span> 58 <span class="iconfont icon">&#xe63a;</span>
59 优惠券 59 优惠券
60 <span class="iconfont num">{{coupon_num}} &#xe604;</span> 60 <span class="iconfont num">{{coupon_num}} &#xe604;</span>
61 </a> 61 </a>
62 - <a class="list-item" href="/home/"> 62 + <a class="list-item" href="/home/currency">
63 <span class="iconfont icon">&#xe635;</span> 63 <span class="iconfont icon">&#xe635;</span>
64 YOHO 64 YOHO
65 <span class="iconfont num">{{yoho_coin_num}} &#xe604;</span> 65 <span class="iconfont num">{{yoho_coin_num}} &#xe604;</span>
66 </a> 66 </a>
67 </div> 67 </div>
68 <div class="group-list"> 68 <div class="group-list">
69 - <a class="list-item" href="/home/"> 69 + <a class="list-item" href="/home/message">
70 <span class="iconfont icon">&#xe636;</span> 70 <span class="iconfont icon">&#xe636;</span>
71 消息 71 消息
72 <span class="iconfont num">{{inbox_total}} &#xe604;</span> 72 <span class="iconfont num">{{inbox_total}} &#xe604;</span>
73 </a> 73 </a>
74 </div> 74 </div>
75 <div class="group-list"> 75 <div class="group-list">
76 - <a class="list-item" href="/home/"> 76 + <a class="list-item" href="/home/onlineService">
77 <span class="iconfont icon">&#xe63c;</span> 77 <span class="iconfont icon">&#xe63c;</span>
78 在线客服 78 在线客服
79 <span class="iconfont num">&#xe604;</span> 79 <span class="iconfont num">&#xe604;</span>
@@ -46,114 +46,23 @@ class HomeController extends AbstractAction @@ -46,114 +46,23 @@ class HomeController extends AbstractAction
46 * 用户收藏的商品 46 * 用户收藏的商品
47 */ 47 */
48 public function favoriteAction() { 48 public function favoriteAction() {
  49 + // 设置网站标题
  50 + $this->setTitle('我的收藏');
  51 + $this->setNavHeader('我的收藏', true, SITE_MAIN);
  52 +
49 $uid = $this->getUid(); 53 $uid = $this->getUid();
  54 + $uid = 8826435;
  55 + $gender = Helpers::getGenderByCookie();
50 56
51 $favProducts = \Index\UserModel::getFavProductData($uid); 57 $favProducts = \Index\UserModel::getFavProductData($uid);
52 -  
53 - //print_r($favProducts); 58 + $favBrands = \Index\UserModel::getFavBrandData($uid, $gender);
54 59
55 $this->_view->display('favorite', array( 60 $this->_view->display('favorite', array(
56 'favPage' => true, //加载js 61 'favPage' => true, //加载js
57 - 'pageHeader' => array(  
58 - 'navBack' => true,  
59 - 'navTitle' => '我的收藏',  
60 - 'navHome' => true  
61 - ),  
62 'pageFooter' => true, 62 'pageFooter' => true,
63 'favorite' => true, 63 'favorite' => true,
64 - 'hasFavProduct' => array(  
65 - '0' => array(  
66 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
67 - 'title' => 'adidas Originals ZX FLUXM22508 ',  
68 - 'price' => '¥800',  
69 - 'discountPrice' => false,  
70 - 'savePrice' => false,  
71 - 'sellOut' => true  
72 - ),  
73 - '1' => array(  
74 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
75 - 'title' => 'adidas Originals ZX FLUXM22508 ',  
76 - 'price' => '¥800',  
77 - 'discountPrice' => '¥500',  
78 - 'savePrice' => '¥300',  
79 - 'sellOut' => false  
80 - )  
81 - ),  
82 - 'hasFavBrand' => array(  
83 - '0' => array(  
84 - 'id' => '1',  
85 - 'brandImg' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
86 - 'brandName' => 'VANS',  
87 - 'update' => 12,  
88 - 'discount' => 10,  
89 - 'link' => '#',  
90 - 'productList' => array(  
91 - '0' => array(  
92 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
93 - 'price' => '¥240',  
94 - 'discount' => '¥240'  
95 - ),  
96 - '1' => array(  
97 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
98 - 'price' => '¥240',  
99 - 'discount' => '¥240'  
100 - ),  
101 - '2' => array(  
102 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
103 - 'price' => '¥240',  
104 - 'discount' => '¥240'  
105 - ),  
106 - '3' => array(  
107 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
108 - 'price' => '¥240',  
109 - 'discount' => '¥240'  
110 - )  
111 - )  
112 - ),  
113 - '1' => array(  
114 - 'id' => '2',  
115 - 'brandImg' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
116 - 'brandName' => 'VANS',  
117 - 'update' => 12,  
118 - 'discount' => 10,  
119 - 'link' => '#',  
120 - 'productList' => array(  
121 - '0' => array(  
122 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
123 - 'price' => '¥240',  
124 - 'discount' => '¥240'  
125 - ),  
126 - '1' => array(  
127 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
128 - 'price' => '¥240',  
129 - 'discount' => '¥240'  
130 - ),  
131 - '2' => array(  
132 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
133 - 'price' => '¥240',  
134 - 'discount' => '¥240'  
135 - ),  
136 - '3' => array(  
137 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
138 - 'price' => '¥240',  
139 - 'discount' => '¥240'  
140 - )  
141 - )  
142 - ),  
143 - '2' => array(  
144 - 'id' => '3',  
145 - 'brandImg' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
146 - 'brandName' => 'VANS',  
147 - 'update' => 12,  
148 - 'discount' => 10,  
149 - 'link' => '#',  
150 - 'productList' => array(  
151 - 'imgUrl' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',  
152 - 'price' => '¥240',  
153 - 'discount' => false  
154 - )  
155 - )  
156 - ) 64 + 'hasFavProduct' => $favProducts,
  65 + 'hasFavBrand' => $favBrands
157 )); 66 ));
158 } 67 }
159 68
@@ -161,9 +70,22 @@ class HomeController extends AbstractAction @@ -161,9 +70,22 @@ class HomeController extends AbstractAction
161 /** 70 /**
162 * 用户收藏的商品-删除 71 * 用户收藏的商品-删除
163 */ 72 */
164 - public function favoriteDelAction() { 73 + public function favoriteDelAction()
  74 + {
  75 + $result = array();
165 76
166 - //$this->echoJson(); 77 + if ($this->isAjax()) {
  78 + $uid = $this->getUid();
  79 + $fav_id = $this->post('fav_id', 0);
  80 +
  81 + $result = \Index\UserModel::favoriteDelete($uid, $fav_id);
  82 + }
  83 +
  84 + if (empty($result)) {
  85 + echo ' ';
  86 + } else {
  87 + $this->echoJson($result);
  88 + }
167 } 89 }
168 90
169 /** 91 /**
@@ -150,7 +150,19 @@ class UserModel @@ -150,7 +150,19 @@ class UserModel
150 150
151 // 处理用户收藏的商品数据 151 // 处理用户收藏的商品数据
152 if (isset($favProduct['data']) && !empty($favProduct['data'])) { 152 if (isset($favProduct['data']) && !empty($favProduct['data'])) {
153 - $result = $favProduct['data']; 153 + $product = array();
  154 + foreach ($favProduct['data']['product_list'] as $val) {
  155 + $product = array();
  156 + $product['imgUrl'] = $val['image'];
  157 + $product['title'] = $val['product_name'];
  158 + $product['price'] = '¥'.$val['market_price'];
  159 + $product['discountPrice'] = '¥'.$val['sales_price'];
  160 + $product['savePrice'] = ($val['market_price'] - $val['sales_price'] > 0) ? '¥'.($val['market_price'] - $val['sales_price']) : false;
  161 + $product['sellOut'] = boolval($val['price_down']);
  162 +
  163 + $result[] = $product;
  164 + }
  165 +
154 } 166 }
155 167
156 return $result; 168 return $result;
@@ -172,7 +184,43 @@ class UserModel @@ -172,7 +184,43 @@ class UserModel
172 184
173 // 处理用户收藏的品牌数据 185 // 处理用户收藏的品牌数据
174 if (isset($favBrand['data']) && !empty($favBrand['data'])) { 186 if (isset($favBrand['data']) && !empty($favBrand['data'])) {
175 - $result = $favBrand['data']; 187 + $brand = array();
  188 + foreach ($favBrand['data']['brand_list'] as $val) {
  189 + $brand = array();
  190 + $brand['id'] = $val['brand_id'];
  191 + $brand['brandImg'] = Images::getImageUrl($val['brand_ico'], 235, 314);
  192 + $brand['brandName'] = $val['brand_name'];
  193 + $brand['update'] = $val['new_product_num'];
  194 + $brand['discount'] = $val['product_discount_num'];
  195 + $brand['link'] = '#';
  196 +
  197 + // 处理品牌产品
  198 + $product = array();
  199 + foreach ($val['new_product'] as $one) {
  200 + $product = array();
  201 + $product['imgUrl'] = Images::getImageUrl($one['default_images'], 235, 314);
  202 + $product['price'] = '¥'.$one['market_price'];
  203 + $product['discount'] = '¥'.$one['sales_price'];
  204 +
  205 + $brand['productList'][] = $product;
  206 + }
  207 +
  208 + $result[] = $brand;
  209 + }
  210 + }
  211 +
  212 + return $result;
  213 + }
  214 +
  215 + public static function favoriteDelete($uid, $fav_id)
  216 + {
  217 + $result = array();
  218 +
  219 + if (empty($fav_id)) {
  220 + $result['code'] = 400;
  221 + $result['message'] = '取消的商品不可用';
  222 + } else {
  223 + $result = UserData::favoriteDelete($uid, $fav_id);
176 } 224 }
177 225
178 return $result; 226 return $result;