ThinkSNS-应用开发范例-增加积分消费功能:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: <span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> 上一页</span> <div style="clear:both;"></div>)
 
无编辑摘要
 
第1行: 第1行:
<span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> [[ThinkSNS|上一页]]</span>
<span style="text-align:center; border:1px solid #000; float:right; padding:6px;"><strong>导航:</strong> [[ThinkSNS|上一页]]</span>
<div style="clear:both;"></div>
<div style="clear:both;"></div>
上面的程序基本完成了礼品的全部操作,接下来我们要增加积分消费功能。至于礼品消费的积分类型,是积分或者还是经验,可以在后台设置,详细请看后台程序说明。
'''首先'''在发送礼品页面增加显示当前用户所拥有多少积分的功能,我们只要在IndexAction.class.php 文件的Index 方法里增加以下程序即可:
<pre>
//获取当前用户的积分
$money = getCredit($this->mid,$this->api);
$moneyType = getC('creditName');
$this->assign('money',$money[$moneyType]);
</pre>
在发送礼品的[[模板]]里增加以下一行代码:我目前拥有的{$config.creditName}是: {$money}然后在发送礼品的函数里(UserGiftModel.class.php 的sendGift 方法)增加扣除所选礼品的相应积分程序:
<pre>
//扣除相应积分
$giftPrice = intval($giftInfo['price']);
$prices = $userNum*$giftPrice;
$type = getC('creditType');
$credit[$type] = '-'.$prices;
if(!$this->__setScore($fromUid,$credit)){
return '您的'.getC('creditName').'不足,发送礼品失败!';
}
</pre>
我们还在增加上面用到扣除积分封装函数:
<pre>
/**
* __setScore
* 扣除(或增加)用户相应积分
* @param $uid 用户ID,
$credit 积分数,为正时表示增加积分,为负时表示扣除积分
* @return void;
*/
private function __setScore($uid,$credit){
$test['credit'] = $credit;
$test['action'] = 'send_gift';
$test['actioncn'] = '发送礼物';
$res = setUserScore($uid, $test);
return $res;
}
</pre>
到这里积分消费功能增加完毕.
==参考资料==
*[http://www.thinksns.com 参考来源]
[[category:ThinkSNS]]

2010年5月24日 (一) 16:56的最新版本

导航: 上一页

上面的程序基本完成了礼品的全部操作,接下来我们要增加积分消费功能。至于礼品消费的积分类型,是积分或者还是经验,可以在后台设置,详细请看后台程序说明。

首先在发送礼品页面增加显示当前用户所拥有多少积分的功能,我们只要在IndexAction.class.php 文件的Index 方法里增加以下程序即可:

//获取当前用户的积分
$money = getCredit($this->mid,$this->api);
$moneyType = getC('creditName');
$this->assign('money',$money[$moneyType]);

在发送礼品的模板里增加以下一行代码:我目前拥有的{$config.creditName}是: {$money}然后在发送礼品的函数里(UserGiftModel.class.php 的sendGift 方法)增加扣除所选礼品的相应积分程序:

//扣除相应积分
$giftPrice = intval($giftInfo['price']);
$prices = $userNum*$giftPrice;
$type = getC('creditType');
$credit[$type] = '-'.$prices;
if(!$this->__setScore($fromUid,$credit)){
return '您的'.getC('creditName').'不足,发送礼品失败!';
}

我们还在增加上面用到扣除积分封装函数:

/**
* __setScore
* 扣除(或增加)用户相应积分
* @param $uid 用户ID,
$credit 积分数,为正时表示增加积分,为负时表示扣除积分
* @return void;
*/
private function __setScore($uid,$credit){
$test['credit'] = $credit;
$test['action'] = 'send_gift';
$test['actioncn'] = '发送礼物';
$res = setUserScore($uid, $test);
return $res;
}

到这里积分消费功能增加完毕.


参考资料[ ]