opensns点赞功能实现

因为点赞没有文本框,只有点赞按钮,所以实现就直接从后台添加需要的字段(数组形式),字段见数据库中的opensns_support数据表。具体实现方法:

1.index.html指向support://support/dosupport1

2.点赞功能集成在系统插件中,在根目录下Addons中controller控制的dosupport方法。

3.实现在SupportControll.class.php中,代码如下:

public function doSupport1()
    {
    	if (!is_login()) {
    		exit(json_encode(array('status' => 0, 'info' => '请登陆后再点赞。')));
    	}
    	$appname = I('POST.appname');
    	$table = I('POST.table');
    	$row = I('POST.row');
    	$aJump = I('POST.jump');
    
    	$message_uid = intval(I('POST.uid'));
    	$support['appname'] = $appname;
    	$support['table'] = $table;
    	//         $support['row'] = $row;
    	//         $support['uid'] = is_login();
    	
    	$support['row'] = array(262);
    	$support['uid'] = array(100);
    	$supportRow = array(268,269,270,269,270,271);
    	$supportUid = array(1,1,1,103,104,105);
    	
    	for($i = 0 ; $i < 3 ; $i++ ){
    		$support['row'] = $supportRow[$i];
    		$support['uid'] = $supportUid[$i];
    		D('Support')->where($support)->add($support);
//     	if (D('Support')->where($support)->count()) {
    
//     		exit(json_encode(array('status' => 0, 'info' => '您已经赞过,不能再赞了。')));
//     	} else {
//     		$support['create_time'] = time();
//     		if (D('Support')->where($support)->add($support)) {
    
//     			$this->clearCache($support);
    
//     			$user = query_user(array('nickname'),get_uid());
    
//     			D('Message')->sendMessage($message_uid,$title = $user['nickname'] . '赞了您。', $user['nickname'] . '给您点了个赞。',  $aJump , array('id' => $row));
//     			exit(json_encode(array('status' => 1, 'info' => '感谢您的支持。')));
//     		} else {
//     			exit(json_encode(array('status' => 0, 'info' => '写入数据库失败。')));
//     		}
    
//     	}
    	}
    	$this->clearCache($support);
    	
    	$user = query_user(array('nickname'),get_uid());
    	
    	D('Message')->sendMessage($message_uid,$title = $user['nickname'] . '赞了您。', $user['nickname'] . '给您点了个赞。',  $aJump , array('id' => $row));
    	exit(json_encode(array('status' => 1, 'info' => '感谢您的支持。')));
    }


你可能感兴趣的:(opensns点赞功能实现)