123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 收藏店铺控制器
- */
- class Memberfavoritesstore extends MobileMember
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberfavorites.lang.php');
- }
- /**
- * @api {POST} api/memberfavoritesstore/favorites_list 店铺收藏列表
- * @apiVersion 1.0.0
- * @apiGroup MemberFavorites
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiParam {String} per_page 每页显示数量
- * @apiParam {String} page 当前页数
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- * @apiSuccess {Object} result 返回数据
- * @apiSuccess {Object[]} result.favorites_list 收藏列表
- * @apiSuccess {Int} result.favorites_list.fav_id 收藏ID
- * @apiSuccess {Int} result.favorites_list.fav_time 收藏时间
- * @apiSuccess {String} result.favorites_list.fav_time_text 收藏时间描述
- * @apiSuccess {Int} result.favorites_list.goods_count 商品数量
- * @apiSuccess {String} result.favorites_list.store_avatar 店铺头像名称
- * @apiSuccess {String} result.favorites_list.store_avatar_url 店铺头像完整路径
- * @apiSuccess {Int} result.favorites_list.store_collect 收藏数量
- * @apiSuccess {Int} result.favorites_list.store_id 店铺ID
- * @apiSuccess {String} result.favorites_list.store_name 店铺名称
- * @apiSuccess {Int} result.page_total 总页数
- * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
- */
- public function favorites_list()
- {
- $favorites_model = model('favorites');
- $store_model = model('store');
- $favorites_list = $favorites_model->getStoreFavoritesList(array(array(
- 'member_id', '=', $this->member_info['member_id'],
- )), '*', $this->pagesize);
- $store_list = array();
- $favorites_list_indexed = array();
- foreach ($favorites_list as $v) {
- $item = array();
- $item['fav_id'] = $v['fav_id'];
- $item['store_id'] = $v['store_id'];
- $item['store_name'] = $v['store_name'];
- $item['fav_time'] = $v['fav_time'];
- $item['fav_time_text'] = date('Y-m-d H:i', $v['fav_time']);
- $store = $store_model->getStoreInfoByID($v['store_id']);
- $item['goods_count'] = $store['goods_count'];
- $item['store_collect'] = $store['store_collect'];
- $item['store_avatar'] = $store['store_avatar'];
- $item['store_avatar_url'] = get_store_logo($store['store_avatar']);
- $store_list[] = $item;
- }
- $result = array_merge(array('favorites_list' => $store_list), mobile_page($favorites_model->page_info));
- ds_json_encode(10000, '', $result);
- }
- /**
- * @api {POST} api/memberfavoritesstore/favorites_add 添加店铺收藏
- * @apiVersion 1.0.0
- * @apiGroup MemberFavorites
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiParam {String} store_id 店铺ID
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- */
- public function favorites_add()
- {
- $fav_id = intval(input('post.store_id'));
- if ($fav_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $favorites_model = model('favorites');
- //判断是否已经收藏
- $favorites_info = $favorites_model->getOneFavorites(array(
- 'fav_id' => $fav_id, 'fav_type' => 'store',
- 'member_id' => $this->member_info['member_id'],
- ));
- if (!empty($favorites_info)) {
- ds_json_encode(10001, lang('favorite_already_favorite_store'));
- }
- //判断店铺是否为当前会员所有
- $seller_info = model('seller')->getSellerInfo(array('member_id' => $this->member_info['member_id']));
- if ($fav_id == $seller_info['store_id']) {
- ds_json_encode(10001, lang('favorite_no_my_store'));
- }
- //添加收藏
- $insert_arr = array();
- $insert_arr['member_id'] = $this->member_info['member_id'];
- $insert_arr['member_name'] = $this->member_info['member_name'];
- $insert_arr['fav_id'] = $fav_id;
- $insert_arr['fav_type'] = 'store';
- $insert_arr['fav_time'] = TIMESTAMP;
- $result = $favorites_model->addFavorites($insert_arr);
- if ($result) {
- //增加收藏数量
- $store_model = model('store');
- $store_model->editStore(array('store_collect' => Db::raw('store_collect+1')), array('store_id' => $fav_id));
- ds_json_encode(10000, lang('favorite_collect_success'), array('success' => '1'));
- } else {
- ds_json_encode(10001, lang('favorite_collect_fail'));
- }
- }
- /**
- * @api {POST} api/memberfavoritesstore/favorites_del 删除店铺收藏
- * @apiVersion 1.0.0
- * @apiGroup MemberFavorites
- *
- * @apiHeader {String} X-DS-KEY 用户授权token
- *
- * @apiParam {String} fav_id 主键ID
- *
- * @apiSuccess {String} code 返回码,10000为成功
- * @apiSuccess {String} message 返回消息
- */
- public function favorites_del()
- {
- $fav_id = intval(input('post.fav_id'));
- if ($fav_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $favorites_model = model('favorites');
- $store_model = model('store');
- $condition = array();
- $condition[] = array('fav_type', '=', 'store');
- $condition[] = array('fav_id', '=', $fav_id);
- $condition[] = array('member_id', '=', $this->member_info['member_id']);
- //判断是否已经收藏
- $favorites_info = $favorites_model->getOneFavorites($condition);
- if (empty($favorites_info)) {
- ds_json_encode(10001, lang('favorite_del_fail'));
- }
- $favorites_model->delFavorites($condition);
- $store_model->editStore(array('store_collect' => Db::raw('store_collect-1'),), array(array('store_id', '=', $fav_id), array('store_collect', '>', 0),));
- ds_json_encode(10000, lang('favorite_del_success'), array('success' => '1'));
- }
- }
|