phpcms2008积分操作函数的使用方法
2015-10-22 00:00
639 查看
摘要: phpcms2008积分操作函数的使用方法
Php代码
1.
2. $pay = load('pay_api.class.php', 'pay', 'api');
3. $pay->update_exchange('phpcms', 'point', -$readpoint, $data['title'].$contentid, '', $contentid.$C['repeatchargedays']);
第一句:加载pay类文件;
第二句:调用 pay类里的update_exchange函数来操作积分.
函数原型如下:
Php代码
1. /**
2. *
3. * @params string $module moudel name
4. * @params string $type ( point or amount(money) )
5. * @params float $number (point or money) amount (如果减少 point(or money) 用'-'(减号)连接)
6. * @params mixed $note note
7. * @params mixed $userid 为0表示为当前用户 int&array 使用array的时候建议对用户进行增加 point or amount
8. * @params string $authid 文章权限
9. * @return boolean
10. */
11.
12. function update_exchange($module, $type, $number, $note = '', $userid =0, $authid = '')
13. {
14. global $MODULE, $_userid, $_username, $_point, $_amount;
15. $inputid = $_userid;
16. $inputer = $_username;
17. if(!isset($MODULE[$module])) showmessage('模块不存在!');
18. $field = $type == 'point' ? 'point' : 'amount';
19. if(!is_numeric($number)) showmessage('金额不对!');
20. $number = floatval($number);
21. $time = date('Y-m-d H:i:s', TIME);
22. $ip = IP;
23. $authid = trim($authid);
24. if(!emptyempty($authid))
25. {
26. $authid = md5(AUTH_KEY.$authid);
27. }
28. if(!is_array($userid))
29. {
30. $userid = intval($userid);
31. if($userid < 1)
32. {
33. $userid = $_userid;
34. $username = $_username;
35. if ('amount' == $type)
36. {
37. $blance = $_amount + $number;
38. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
39. if($blance > 9999.99) {$this->error = 7;return false;} //showmessage('金额超过最大额');
40. }
41. else
42. {
43. $blance = $_point + $number;
44. if($blance < 0) {$this->error = 1; return false;} //showmessage('点数不足');
45. }
46. $this->member->set($userid, array($field=>$blance));
47. $value = "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$userid}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}')";
48. }
49. else
50. {
51. $userinfo = $this->member->get($userid, array($field,'username'));
52. $username = $userinfo['username'];
53. if ('amount' == $type)
54. {
55. $blance = $userinfo['amount'] + $number;
56. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
57. if($blance > 9999.99) {$this->error = 7;return false;} //showmessage('金额超过最大额');
58. }
59. else
60. {
61. $blance = $userinfo['point'] + $number;
62. if($blance < 0) {$this->error = 1;return false;} //showmessage('点数不足');
63. }
64. $this->member->set($userid, array($field=>$blance));
65. $value = "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$userid}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}')";
66. }
67. $this->setStat($type,$number);
68. }
69. else
70. {
71. $value = '';
72. foreach($userid AS $k => $v)
73. {
74. if($v && !emptyempty($v))
75. {
76. $userinfo = $this->member->get($v, array($field,'username'));
77. $username = $userinfo['username'];
78. if ('amount' == $type)
79. {
80. $blance = $userinfo['amount'] + $number;
81. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
82. }
83. else
84. {
85. $blance = $userinfo['point'] + $number;
86. if($blance < 0) {$this->error = 1;return false;} //showmessage('点数不足');
87. }
88. $this->member->set($userid, array($field=>$blance));
89. $value .= "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$v}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}'),";
90. $this->setStat($type,$number);
91. }
92. }
93. $value = substr($value, 0, -1);
94. }
95. $sql = "INSERT INTO `$this->exchange_table` (`module` ,`type`,`number`,`blance` ,`userid`,`username`,`inputid`,`inputer`, `time`, `ip`, `note`, `authid`) VALUES ".$value;
96. if ($this->db->query($sql)) return true;
97. }
函数 update_exchange($module, $type, $number, $note = '', $userid =0, $authid = '') 有6个参数;
* @params string $module moudel name
* @params string $type ( point or amount(money) )
* @params float $number (point or money) amount (如果减少 point(or money) 用'-'(减号)连接)
* @params mixed $note note
* @params mixed $userid 为0表示为当前用户 int&array 使用array的时候建议对用户进行增加 point or amount
* @params string $authid 文章权限
具体的就不多解释了.希望大家仔细看看这段解释.
用这个类和函数,可以实现你对积分的操作,比如登陆增加积分,评论增加积分等.
以登陆增加积分为例,在登陆处理文件 member/login.php 里,实际上它调用了member.class.php类文件的login函数;
那在member/include/member.class.php 的login函数里 $this->_userid = $r['userid']; 下面加如下代码:
Php代码
1. $pay = load('pay_api.class.php', 'pay', 'api');
2. $pay->update_exchange('member', 'point', 5, '登陆增加积分5分', $this->_userid, '');
即表示登陆增加5分.当然如果你还需要更加复杂的处理,比如一天登陆n次只增加一次积分等等,需要另外开发了.
本文内容同步发布在phpcms官方论坛:
http://bbs.phpcms.cn/thread-150913-1-1.html
phpcms2008积分操作函数的使用方法
如果安装了pay模块,也就是财务模块.直接使用以下代码:Php代码
1.
2. $pay = load('pay_api.class.php', 'pay', 'api');
3. $pay->update_exchange('phpcms', 'point', -$readpoint, $data['title'].$contentid, '', $contentid.$C['repeatchargedays']);
第一句:加载pay类文件;
第二句:调用 pay类里的update_exchange函数来操作积分.
函数原型如下:
Php代码
1. /**
2. *
3. * @params string $module moudel name
4. * @params string $type ( point or amount(money) )
5. * @params float $number (point or money) amount (如果减少 point(or money) 用'-'(减号)连接)
6. * @params mixed $note note
7. * @params mixed $userid 为0表示为当前用户 int&array 使用array的时候建议对用户进行增加 point or amount
8. * @params string $authid 文章权限
9. * @return boolean
10. */
11.
12. function update_exchange($module, $type, $number, $note = '', $userid =0, $authid = '')
13. {
14. global $MODULE, $_userid, $_username, $_point, $_amount;
15. $inputid = $_userid;
16. $inputer = $_username;
17. if(!isset($MODULE[$module])) showmessage('模块不存在!');
18. $field = $type == 'point' ? 'point' : 'amount';
19. if(!is_numeric($number)) showmessage('金额不对!');
20. $number = floatval($number);
21. $time = date('Y-m-d H:i:s', TIME);
22. $ip = IP;
23. $authid = trim($authid);
24. if(!emptyempty($authid))
25. {
26. $authid = md5(AUTH_KEY.$authid);
27. }
28. if(!is_array($userid))
29. {
30. $userid = intval($userid);
31. if($userid < 1)
32. {
33. $userid = $_userid;
34. $username = $_username;
35. if ('amount' == $type)
36. {
37. $blance = $_amount + $number;
38. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
39. if($blance > 9999.99) {$this->error = 7;return false;} //showmessage('金额超过最大额');
40. }
41. else
42. {
43. $blance = $_point + $number;
44. if($blance < 0) {$this->error = 1; return false;} //showmessage('点数不足');
45. }
46. $this->member->set($userid, array($field=>$blance));
47. $value = "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$userid}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}')";
48. }
49. else
50. {
51. $userinfo = $this->member->get($userid, array($field,'username'));
52. $username = $userinfo['username'];
53. if ('amount' == $type)
54. {
55. $blance = $userinfo['amount'] + $number;
56. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
57. if($blance > 9999.99) {$this->error = 7;return false;} //showmessage('金额超过最大额');
58. }
59. else
60. {
61. $blance = $userinfo['point'] + $number;
62. if($blance < 0) {$this->error = 1;return false;} //showmessage('点数不足');
63. }
64. $this->member->set($userid, array($field=>$blance));
65. $value = "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$userid}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}')";
66. }
67. $this->setStat($type,$number);
68. }
69. else
70. {
71. $value = '';
72. foreach($userid AS $k => $v)
73. {
74. if($v && !emptyempty($v))
75. {
76. $userinfo = $this->member->get($v, array($field,'username'));
77. $username = $userinfo['username'];
78. if ('amount' == $type)
79. {
80. $blance = $userinfo['amount'] + $number;
81. if($blance < 0) {$this->error = 0; return false;} //showmessage('金额不足');
82. }
83. else
84. {
85. $blance = $userinfo['point'] + $number;
86. if($blance < 0) {$this->error = 1;return false;} //showmessage('点数不足');
87. }
88. $this->member->set($userid, array($field=>$blance));
89. $value .= "('{$module}' ,'{$type}','{$number}','{$blance}' ,'{$v}','{$username}','{$inputid}','{$inputer}', '{$time}', '{$ip}', '{$note}', '{$authid}'),";
90. $this->setStat($type,$number);
91. }
92. }
93. $value = substr($value, 0, -1);
94. }
95. $sql = "INSERT INTO `$this->exchange_table` (`module` ,`type`,`number`,`blance` ,`userid`,`username`,`inputid`,`inputer`, `time`, `ip`, `note`, `authid`) VALUES ".$value;
96. if ($this->db->query($sql)) return true;
97. }
函数 update_exchange($module, $type, $number, $note = '', $userid =0, $authid = '') 有6个参数;
* @params string $module moudel name
* @params string $type ( point or amount(money) )
* @params float $number (point or money) amount (如果减少 point(or money) 用'-'(减号)连接)
* @params mixed $note note
* @params mixed $userid 为0表示为当前用户 int&array 使用array的时候建议对用户进行增加 point or amount
* @params string $authid 文章权限
具体的就不多解释了.希望大家仔细看看这段解释.
用这个类和函数,可以实现你对积分的操作,比如登陆增加积分,评论增加积分等.
以登陆增加积分为例,在登陆处理文件 member/login.php 里,实际上它调用了member.class.php类文件的login函数;
那在member/include/member.class.php 的login函数里 $this->_userid = $r['userid']; 下面加如下代码:
Php代码
1. $pay = load('pay_api.class.php', 'pay', 'api');
2. $pay->update_exchange('member', 'point', 5, '登陆增加积分5分', $this->_userid, '');
即表示登陆增加5分.当然如果你还需要更加复杂的处理,比如一天登陆n次只增加一次积分等等,需要另外开发了.
本文内容同步发布在phpcms官方论坛:
http://bbs.phpcms.cn/thread-150913-1-1.html
相关文章推荐
- phpcms常用标签(函数)
- phpcms2008常用函数
- 解决PHPCMS会员注册未对Ucenter中会员数据进行验证的问题
- phpcms黄页留言复制成在线报名系统
- phpcms整合Ucenter找回密码无效的解决方法
- PHPCMS2008广告模板SQL注入漏洞修复
- yii dao操作
- php手机号中间几位替换成星号
- PHP学习步骤
- PHP学习攻略 教你高效快速成为技术高手
- php学习进阶攻略
- php制作简单验证码
- php扩展
- PHP静态成员变量和非静态成员变量
- php5.5版本之后 对象复制就是直接引用
- 使PhpStorm支持CI框架语法提示的方法
- EKL PHP 调取_search接口查询 添加购物车统计
- EKL PHP 调取_search接口查询 注册统计
- php集成工具