Memberfavoritesstore.php 7.1 KB

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