member_favorites.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * 我的收藏
  4. *
  5. *
  6. *
  7. *
  8. */
  9. //use Shopnc\Tpl;
  10. defined('InShopNC') or exit('Access Invalid!');
  11. require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
  12. require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
  13. require_once (BASE_ROOT_PATH . '/helper/user_session/favorite.php');
  14. class member_favoritesControl extends mbMemberControl
  15. {
  16. static $stTypes = array('goods','brand');
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. }
  21. public function indexOp()
  22. {
  23. $mod_favorites = Model('favorites');
  24. $favorites = $mod_favorites->getGoodsFavoritesList(array('member_id' => $_SESSION['member_id']), '*', $this->page_size);
  25. $page_count = $mod_favorites->gettotalpage();
  26. $gids = [];
  27. foreach ($favorites as $item)
  28. {
  29. if($item['fav_type'] == 'goods') {
  30. $gids[] = intval($item['fav_id']);
  31. }
  32. elseif($item['fav_type'] == 'brand') {
  33. }
  34. else {
  35. continue;
  36. }
  37. }
  38. if(empty($gids))
  39. {
  40. return self::outsuccess(array('special_list' => null,
  41. 'summary' => null,
  42. 'groupbuy' => null,
  43. 'limitime' => null,
  44. 'bundling' => null,
  45. 'mobile_page' => mobile_page($page_count)));
  46. }
  47. $helper = new goods_helper();
  48. $ret = $helper->online_summary($gids,$related_goods);
  49. $block = special_formater::format_goods($gids,'我的商品',$ret['sort_summary']);
  50. $blocks[] = $block;
  51. return self::outsuccess(array('special_list' => $blocks,
  52. 'summary' => $ret['summary'],
  53. 'groupbuy' => $ret['groupbuy'],
  54. 'limitime' => $ret['limitime'],
  55. 'bundling' => $ret['bundling'],
  56. 'mobile_page' => mobile_page($page_count)));
  57. }
  58. private function format($goods_ids,$sort_summary)
  59. {
  60. $result = [];
  61. foreach ($goods_ids as $goods_id)
  62. {
  63. $block = [];
  64. $block['item_title'] = '';
  65. $block['item_type'] = 'home1';
  66. $summary = $sort_summary[$goods_id];
  67. $item['image'] = $summary['goods_image_url'];
  68. $item['show_type'] = "favorite";
  69. $item['show_data'] = strval($goods_id);
  70. $item['type'] = "goods";
  71. $item['data'] = strval($goods_id);
  72. $item['title'] = $summary['goods_mobile_name'];
  73. $block['items'][] = $item;
  74. $result[] = $block;
  75. $result[] = special_formater::def_divider();
  76. }
  77. return $result;
  78. }
  79. public function addOp()
  80. {
  81. $fav_type = $_POST['fav_type'];
  82. $fav_id = intval($_POST['fav_id']);
  83. if ($fav_id <= 0 || empty($fav_type) || !in_array($fav_type,self::$stTypes)) {
  84. return self::outerr(errcode::ErrParamter,"参数错误");
  85. }
  86. $mod_fav = Model('favorites');
  87. $favorites_info = $mod_fav->getOneFavorites(array('fav_id' => $fav_id, 'fav_type' => $fav_type, 'member_id' => $_SESSION['member_id']));
  88. if (!empty($favorites_info)) {
  89. return self::outsuccess(null);
  90. }
  91. else
  92. {
  93. $insert_arr = array();
  94. $insert_arr['member_id'] = $_SESSION['member_id'];
  95. $insert_arr['fav_id'] = $fav_id;
  96. $insert_arr['fav_type'] = $fav_type;
  97. $insert_arr['fav_time'] = time();
  98. $result = $mod_fav->addFavorites($insert_arr);
  99. if ($result)
  100. {
  101. if($fav_type == 'goods') {
  102. $mod_goods = Model('goods');
  103. $mod_goods->editGoodsById(array('goods_collect' => array('exp', 'goods_collect + 1')), array($fav_id));
  104. $favorate = new user_session\favorite();
  105. $favorate->add('goods',$fav_id);
  106. } else {
  107. $favorate = new user_session\favorite();
  108. $favorate->add('brand',$fav_id);
  109. }
  110. return self::outsuccess(null);
  111. } else {
  112. return self::outerr(errcode::ErrParamter,"参数错误");
  113. }
  114. }
  115. }
  116. public function delOp()
  117. {
  118. $fav_id = intval($_POST['fav_id']);
  119. $fav_type = $_POST['fav_type'];
  120. if ($fav_id <= 0 || empty($fav_type) || !in_array($fav_type,self::$stTypes)) {
  121. return self::outerr(errcode::ErrParamter,"参数错误");
  122. }
  123. $favorate = new user_session\favorite();
  124. $favorate->del($fav_type,$fav_id);
  125. $model_favorites = Model('favorites');
  126. $ret = $model_favorites->delFavorites(array('fav_id' => $fav_id,'fav_type' => $fav_type, 'member_id' => $_SESSION['member_id']));
  127. if($ret == false) {
  128. return self::outerr(errcode::ErrParamter,"该收藏不存在或者已经被删除.");
  129. }
  130. else {
  131. return self::outsuccess(array('fav_id' => $fav_id));
  132. }
  133. }
  134. }