ThinkSNS用户积分操作函数

来自站长百科
跳转至: 导航、​ 搜索

导航: 上一页

为了方便操作,我们在核心公共方法库里增加用户积分操作的函数:

setUserScore($uid, $credit){
$api = new TS_API();
$array = array();
foreach ($credit['credit'] as $key=>$score){
$temp = $api->UserScore_checkScore($uid,$key,$score);
$array[] = $temp === 0 ? true:$temp ;
$credit_rule[$key] = $score;
}
if(count(array_filter($array)) != count($array)) return false;
$credit_rule['action'] = $credit['action'];
$credit_rule['actioncn'] = $credit['actioncn'];
$credit_rule['info'] = isset($credit['info']) &&
!empty($credit['info'])?$credit['info']:'{action}{sign}了{score}分{typecn}';
//操作积分
$score_result = $api->UserScore_setScore($uid,$credit_rule);
return $score_result;

参数说明:

参数 属性 空? 说明
uids int 需要积分操作的用户ID
credit array 积分数组,如: $test['credit'] ['score'] = 10; //增加10 个积分 $test['credit']['experience'] = 10; //增加10 个经验 $test['action'] = 'send_gift'; //积分类型 $test['actioncn'] = '发送礼物'; //积分说明

调用DEMO:

$test['credit']['score'] = 10;
$test['credit']['experience'] = 10;
$test['action'] = 'send_gift';
$test['actioncn'] = '发送礼物';
$res = setUserScore($uid, $test);
(返回:200 成功404 失败)

参考资料[ ]