Authored by htoooth

fix

@@ -108,6 +108,7 @@ const cancel = (req, res, next) => { @@ -108,6 +108,7 @@ const cancel = (req, res, next) => {
108 let uid = req.user.uid; 108 let uid = req.user.uid;
109 let id = req.query.id; 109 let id = req.query.id;
110 let type = req.query.type || 'product'; 110 let type = req.query.type || 'product';
  111 + let group = req.query.group || {};
111 112
112 if (!uid || !id) { 113 if (!uid || !id) {
113 return res.json({ 114 return res.json({
@@ -116,7 +117,7 @@ const cancel = (req, res, next) => { @@ -116,7 +117,7 @@ const cancel = (req, res, next) => {
116 }); 117 });
117 } 118 }
118 119
119 - favoriteService.cancelAsync(uid, id, type).then((result) => { 120 + favoriteService.cancelAsync(uid, id, group, type).then((result) => {
120 return res.json(result); 121 return res.json(result);
121 }).catch(next); 122 }).catch(next);
122 }; 123 };
@@ -351,8 +351,29 @@ const disableNoticeAsync = (uid, id) => { @@ -351,8 +351,29 @@ const disableNoticeAsync = (uid, id) => {
351 })(); 351 })();
352 }; 352 };
353 353
354 -const cancelAsync = (uid, id, type) => {  
355 - return favoriteApi.cancel[type](uid, id); 354 +const cancelBrandAsync = co(function * (uid, ids ,group) {
  355 + if (group.bid) {
  356 + yield favoriteApi.cancel.brand(uid, group.bid);
  357 + }
  358 +
  359 + if (group.sid) {
  360 + yield favoriteApi.cancel.shop(uid, group.sid);
  361 + }
  362 +
  363 + let result = yield favoriteApi.cancel.brand(uid, ids);
  364 +
  365 + return result;
  366 +});
  367 +
  368 +/**
  369 + * ids 可能是 group
  370 + */
  371 +const cancelAsync = (uid, ids, group, type) => {
  372 + if (type === 'brand') {
  373 + return cancelBrandAsync(uid, ids, group);
  374 + }
  375 +
  376 + return favoriteApi.cancel[type](uid, ids);
356 }; 377 };
357 378
358 module.exports = { 379 module.exports = {
@@ -364,5 +385,6 @@ module.exports = { @@ -364,5 +385,6 @@ module.exports = {
364 reductionAsync, 385 reductionAsync,
365 enableNoticeAsync, 386 enableNoticeAsync,
366 disableNoticeAsync, 387 disableNoticeAsync,
367 - cancelAsync 388 + cancelAsync,
  389 + cancelBrandAsync
368 }; 390 };
@@ -395,7 +395,6 @@ $('#me-checkall').click(function() { @@ -395,7 +395,6 @@ $('#me-checkall').click(function() {
395 // 删除收藏 395 // 删除收藏
396 $('.del-favorite').click(function(e) { 396 $('.del-favorite').click(function(e) {
397 var id = $(this).closest('.fav-row').data('id'), 397 var id = $(this).closest('.fav-row').data('id'),
398 - shopid = $(this).closest('.fav-row').data('shopid'),  
399 brandorshoptype = $(this).closest('.fav-row').data('brandorshoptype'); 398 brandorshoptype = $(this).closest('.fav-row').data('brandorshoptype');
400 399
401 e.preventDefault(); 400 e.preventDefault();
@@ -405,9 +404,7 @@ $('.del-favorite').click(function(e) { @@ -405,9 +404,7 @@ $('.del-favorite').click(function(e) {
405 url: '/home/favorite/cancel', 404 url: '/home/favorite/cancel',
406 data: { 405 data: {
407 id: id, 406 id: id,
408 - shopid: shopid,  
409 - brandorshoptype: brandorshoptype,  
410 - type: favType 407 + type: brandorshoptype || favType
411 } 408 }
412 }).then(function(data) { 409 }).then(function(data) {
413 if (data.code === 200) { 410 if (data.code === 200) {
@@ -420,6 +417,7 @@ $('.del-favorite').click(function(e) { @@ -420,6 +417,7 @@ $('.del-favorite').click(function(e) {
420 $('#me-del-checked').click(function() { 417 $('#me-del-checked').click(function() {
421 var ids = [], 418 var ids = [],
422 name = '商品'; 419 name = '商品';
  420 + var group = {};
423 421
424 if (favType === 'brand') { 422 if (favType === 'brand') {
425 name = '品牌'; 423 name = '品牌';
@@ -429,7 +427,17 @@ $('#me-del-checked').click(function() { @@ -429,7 +427,17 @@ $('#me-del-checked').click(function() {
429 427
430 if (confirm('您确定要删除您收藏的' + name + '吗?')) { 428 if (confirm('您确定要删除您收藏的' + name + '吗?')) {
431 $('.checkbox input[type="checkbox"]:checked').each(function() { 429 $('.checkbox input[type="checkbox"]:checked').each(function() {
432 - ids.push($(this).closest('.fav-row').data('id')); 430 + var $favRow = $(this).closest('.fav-row'),
  431 + rdata = $favRow.data();
  432 +
  433 + ids.push(rdata.id);
  434 +
  435 + if (rdata.brandorshoptype) {
  436 + if (!group[rdata.brandorshoptype]) {
  437 + group[rdata.brandorshoptype] = [];
  438 + }
  439 + group[rdata.brandorshoptype].push(rdata.id);
  440 + }
433 }); 441 });
434 442
435 if (ids.length === 0) { 443 if (ids.length === 0) {
@@ -442,6 +450,10 @@ $('#me-del-checked').click(function() { @@ -442,6 +450,10 @@ $('#me-del-checked').click(function() {
442 url: '/home/favorite/cancel', 450 url: '/home/favorite/cancel',
443 data: { 451 data: {
444 id: ids.join(','), 452 id: ids.join(','),
  453 + group: {
  454 + bid: group.brand ? group.brand.join(',') : '',
  455 + sid: group.shop ? group.shop.join(',') : ''
  456 + },
445 type: favType 457 type: favType
446 } 458 }
447 }).then(function() { 459 }).then(function() {