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')); } }