方维系统的二次开发,添加一个订阅品牌的功能,品牌就是方维里面的店铺,也就是加个喜欢店铺,收藏店铺的功能;
效仿单个分享的喜欢的功能进行,所以先分析分享的喜欢的功能,然后修改的地方如下:
①建立数据表
CREATE TABLE `fanwe_user_collect_shop` ( `id` INT NULL , `c_uid` INT( 11 ) NULL DEFAULT NULL , `shop_id` INT( 11 ) NULL DEFAULT NULL , `create_time` INT( 11 ) NULL DEFAULT '0', PRIMARY KEY ( `id` ) ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci
②对数据表的增删改查操作函数;
/core/service/shop.service.php 添加三个函数
/*=========== 喜欢收藏店铺,增删改查 BEGIN ==============*/ /* * //wt添加喜欢这个店铺的会员 * @author wangtongphp * */ function setShopCollectUser($shop_id){ $shop_id = (int)$shop_id; if(!$shop_id) return false; global $_FANWE; $c_uid = $_FANWE['uid']; $data = array(); $data['c_uid'] = $c_uid; $data['shop_id'] = $shop_id; $data['create_time'] = TIME_UTC; FDB::insert('user_collect_shop',$data); } /** * 获取会员是否已喜欢这个店铺 * @param int $share_id 店铺ID * @return array */ public function getIsShopCollectByUid($shop_id,$uid) { $shop_id = (int)$shop_id; $uid = (int)$uid; if(!$shop_id || !$uid) return false; $count = FDB::resultFirst('SELECT COUNT(*) FROM '.FDB::table('user_collect_shop').' WHERE shop_id = '.$shop_id.' AND c_uid = '.$uid); if((int)$count == 0) return false; else return true; } /** * 删除收藏的该店铺 * @param unknown_type $shop_id 店铺ID * @param unknown_type $uid 用户ID * @return string */ public function deleteShopCollectUser($shop_id,$uid) { $shop_id = (int)$shop_id; $uid = (int)$uid; if(!$shop_id || !$uid) return false; FDB::query('DELETE FROM '.FDB::table('user_collect_shop').' WHERE c_uid = '.$uid.' AND shop_id = '.$shop_id); return true; }
③前端ajax操作,收藏店铺功能
新建 /services/module/shop/fav.php 和 /services/module/shop/removefav.php 内容按照/services/module/share/下面两个文件写就可以;
④在个人中心调用我收藏的店铺(我关注的品牌),搜索即可,修改/core/module/u.module.php 中代码,添加这一功能即可。