Memberfavoritesstore.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 收藏店铺控制器
  15. */
  16. class Memberfavoritesstore extends MobileMember {
  17. public function initialize() {
  18. parent::initialize(); // TODO: Change the autogenerated stub
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberfavorites.lang.php');
  20. }
  21. /**
  22. * @api {POST} api/memberfavoritesstore/favorites_list 店铺收藏列表
  23. * @apiVersion 1.0.0
  24. * @apiGroup MemberFavorites
  25. *
  26. * @apiHeader {String} X-DS-KEY 用户授权token
  27. *
  28. * @apiParam {String} per_page 每页显示数量
  29. * @apiParam {String} page 当前页数
  30. *
  31. * @apiSuccess {String} code 返回码,10000为成功
  32. * @apiSuccess {String} message 返回消息
  33. * @apiSuccess {Object} result 返回数据
  34. * @apiSuccess {Object[]} result.favorites_list 收藏列表
  35. * @apiSuccess {Int} result.favorites_list.fav_id 收藏ID
  36. * @apiSuccess {Int} result.favorites_list.fav_time 收藏时间
  37. * @apiSuccess {String} result.favorites_list.fav_time_text 收藏时间描述
  38. * @apiSuccess {Int} result.favorites_list.goods_count 商品数量
  39. * @apiSuccess {String} result.favorites_list.store_avatar 店铺头像名称
  40. * @apiSuccess {String} result.favorites_list.store_avatar_url 店铺头像完整路径
  41. * @apiSuccess {Int} result.favorites_list.store_collect 收藏数量
  42. * @apiSuccess {Int} result.favorites_list.store_id 店铺ID
  43. * @apiSuccess {String} result.favorites_list.store_name 店铺名称
  44. * @apiSuccess {Int} result.page_total 总页数
  45. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  46. */
  47. public function favorites_list() {
  48. $favorites_model = model('favorites');
  49. $store_model = model('store');
  50. $favorites_list = $favorites_model->getStoreFavoritesList(array(array(
  51. 'member_id' ,'=', $this->member_info['member_id'],
  52. )), '*', $this->pagesize);
  53. $store_list = array();
  54. $favorites_list_indexed = array();
  55. foreach ($favorites_list as $v) {
  56. $item = array();
  57. $item['fav_id'] = $v['fav_id'];
  58. $item['store_id'] = $v['store_id'];
  59. $item['store_name'] = $v['store_name'];
  60. $item['fav_time'] = $v['fav_time'];
  61. $item['fav_time_text'] = date('Y-m-d H:i', $v['fav_time']);
  62. $store = $store_model->getStoreInfoByID($v['store_id']);
  63. $item['goods_count'] = $store['goods_count'];
  64. $item['store_collect'] = $store['store_collect'];
  65. $item['store_avatar'] = $store['store_avatar'];
  66. $item['store_avatar_url'] = get_store_logo($store['store_avatar']);
  67. $store_list[] = $item;
  68. }
  69. $result = array_merge(array('favorites_list' => $store_list), mobile_page($favorites_model->page_info));
  70. ds_json_encode(10000, '', $result);
  71. }
  72. /**
  73. * @api {POST} api/memberfavoritesstore/favorites_add 添加店铺收藏
  74. * @apiVersion 1.0.0
  75. * @apiGroup MemberFavorites
  76. *
  77. * @apiHeader {String} X-DS-KEY 用户授权token
  78. *
  79. * @apiParam {String} store_id 店铺ID
  80. *
  81. * @apiSuccess {String} code 返回码,10000为成功
  82. * @apiSuccess {String} message 返回消息
  83. */
  84. public function favorites_add() {
  85. $fav_id = intval(input('post.store_id'));
  86. if ($fav_id <= 0) {
  87. ds_json_encode(10001, lang('param_error'));
  88. }
  89. $favorites_model = model('favorites');
  90. //判断是否已经收藏
  91. $favorites_info = $favorites_model->getOneFavorites(array(
  92. 'fav_id' => $fav_id, 'fav_type' => 'store',
  93. 'member_id' => $this->member_info['member_id'],
  94. ));
  95. if (!empty($favorites_info)) {
  96. ds_json_encode(10001, lang('favorite_already_favorite_store'));
  97. }
  98. //判断店铺是否为当前会员所有
  99. $seller_info = model('seller')->getSellerInfo(array('member_id' => $this->member_info['member_id']));
  100. if ($fav_id == $seller_info['store_id']) {
  101. ds_json_encode(10001, lang('favorite_no_my_store'));
  102. }
  103. //添加收藏
  104. $insert_arr = array();
  105. $insert_arr['member_id'] = $this->member_info['member_id'];
  106. $insert_arr['member_name'] = $this->member_info['member_name'];
  107. $insert_arr['fav_id'] = $fav_id;
  108. $insert_arr['fav_type'] = 'store';
  109. $insert_arr['fav_time'] = TIMESTAMP;
  110. $result = $favorites_model->addFavorites($insert_arr);
  111. if ($result) {
  112. //增加收藏数量
  113. $store_model = model('store');
  114. $store_model->editStore(array('store_collect' => Db::raw('store_collect+1')), array('store_id' => $fav_id));
  115. ds_json_encode(10000, lang('favorite_collect_success'), array('success' => '1'));
  116. } else {
  117. ds_json_encode(10001, lang('favorite_collect_fail'));
  118. }
  119. }
  120. /**
  121. * @api {POST} api/memberfavoritesstore/favorites_del 删除店铺收藏
  122. * @apiVersion 1.0.0
  123. * @apiGroup MemberFavorites
  124. *
  125. * @apiHeader {String} X-DS-KEY 用户授权token
  126. *
  127. * @apiParam {String} fav_id 主键ID
  128. *
  129. * @apiSuccess {String} code 返回码,10000为成功
  130. * @apiSuccess {String} message 返回消息
  131. */
  132. public function favorites_del() {
  133. $fav_id = intval(input('post.fav_id'));
  134. if ($fav_id <= 0) {
  135. ds_json_encode(10001, lang('param_error'));
  136. }
  137. $favorites_model = model('favorites');
  138. $store_model = model('store');
  139. $condition = array();
  140. $condition[] = array('fav_type','=','store');
  141. $condition[] = array('fav_id','=',$fav_id);
  142. $condition[] = array('member_id','=',$this->member_info['member_id']);
  143. //判断是否已经收藏
  144. $favorites_info = $favorites_model->getOneFavorites($condition);
  145. if (empty($favorites_info)) {
  146. ds_json_encode(10001, lang('favorite_del_fail'));
  147. }
  148. $favorites_model->delFavorites($condition);
  149. $store_model->editStore(array('store_collect' => Db::raw('store_collect-1'),), array(array('store_id', '=', $fav_id), array('store_collect', '>', 0),));
  150. ds_json_encode(10000, lang('favorite_del_success'), array('success' => '1'));
  151. }
  152. }