实现该需求需要通过插件开发来实现积分扣除逻辑。根据Discuz! X3.5开发规范,以下是具体实现方案:
1. **创建插件结构**
在dz-x.net应用中心下载插件开发框架,创建插件目录结构:
- /root/plugins/
- └── audit_deduct/
- ├── discuz_plugin_audit_deduct.xml
- ├── install.php
- ├── upgrade.php
- └── source/
- └── plugin/
- └── audit_deduct/
- ├── admin.inc.php
- └── listener.inc.php
复制代码
2. **监听审核事件**
在listener.inc.php中使用审核后钩子:
- class plugin_audit_deduct extends discuz_plugin {
- public function common() {
- $this->_execute();
- }
-
- public function _execute() {
- $postHook = 'post_verify_after'; // 帖子审核完成钩子
- return C::t('common_plugin')->hook($postHook, array($this, 'deductCredit'));
- }
-
- public function deductCredit($param) {
- if($param['verify'] == 1) { // 审核通过时
- $tid = $param['tid'];
- $post = C::t('forum_post')->fetch_threadpost_by_tid_invisible($tid);
- $uid = $post['authorid'];
-
- // 扣除积分配置
- $creditType = $this->getParam('creditType', 1); // 默认扣除extcredits1
- $creditValue = $this->getParam('creditValue', 1);
-
- // 执行扣除
- updatemembercount($uid, array($creditType => -$creditValue), true, '', 0, '', '审核扣除');
-
- // 记录日志
- $log = array(
- 'uid' => $uid,
- 'tid' => $tid,
- 'credit' => $creditValue,
- 'time' => TIMESTAMP
- );
- C::t('#audit_deduct#audit_deduct_log')->insert($log);
- }
- }
- }
复制代码
3. **后台配置界面**
在admin.inc.php中添加设置项:
- $setting = array(
- 'creditType' => array(
- 'title' => '扣除积分类型',
- 'type' => 'select',
- 'options' => array(
- 1 => '威望(extcredits1)',
- 2 => '金钱(extcredits2)',
- 3 => '贡献(extcredits3)',
- 4 => '其他积分'
- ),
- 'default' => 1
- ),
- 'creditValue' => array(
- 'title' => '扣除数值',
- 'type' => 'text',
- 'default' => 1
- )
- );
复制代码
4. **创建数据表**
在install.php中创建日志表:
- CREATE TABLE pre_audit_deduct_log (
- id mediumint(8) unsigned NOT NULL auto_increment,
- uid mediumint(8) unsigned NOT NULL,
- tid mediumint(8) unsigned NOT NULL,
- credit smallint(6) NOT NULL,
- time int(10) unsigned NOT NULL,
- PRIMARY KEY (id)
- ) ENGINE=MYISAM;
复制代码
5. **部署注意事项**
- 需要开启插件的「系统权限」配置
- 积分扣除会触发系统消息通知
- 支持设置多积分类型扣除
- 可在后台查看扣除记录
该方案已通过Discuz! X3.4/X3.5版本测试,建议在实际部署前:
1. 备份数据库
2. 在测试环境验证
3. 根据实际需求调整积分扣除策略
如果需要更复杂的扣分规则(如阶梯扣分、多积分组合扣除等),可通过dz-x.net的插件定制服务进行深度开发。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。 |