手把手教大家做一个积分下载功能

alirpo
alirpo 这家伙很懒,还没有设置简介

21 人点赞了该文章 · 4409 浏览

先看一下图 如果是你想要的可以继续向下看
QQ截图20151018153330.jpg
QQ截图20151018153150.jpg
QQ截图20151018130915.jpg
QQ截图20151018130103.jpg
QQ截图20151018153538.jpg
  第一步 打开views\default\question\index.tpl.htm 找到<div class="mod-body clearfix"> 把<!-- 评论内容 --> <!-- end 评论内容 -->之间代码换成
<?php if (!$this->user_id) { ?>
                                        <div class="markitup-box">
                                        
                                        <div class="locked">游客,如果您要查看本回复请<a href="account/login/" ><font color="#FF0000">【登陆本平台】</a></font></div>
                                        </div>
                                       <?php }else{?>
                                       <div class="markitup-box">
                                            <?php  echo $val['answer_content']; ?>
                                        </div>

                                        <?php if ($val['attachs']) {  ?>
                                        <div class="aw-upload-img-list">
                                        <?php foreach ($val['attachs'] AS $attach) { ?>
                                        <?php if ($attach['is_image'] AND (!$val['insert_attach_ids'] OR !in_array($attach['id'], $val['insert_attach_ids']))) { ?>
                                            <a href="<?php echo $attach['attachment']; ?>" target="_blank" data-fancybox-group="thumb" rel="lightbox"><img src="<?php echo $attach['attachment']; ?>" class="img-thumbnail" alt="<?php echo $attach['attach_name']; ?>" /></a>
                                        <?php } ?>
                                        <?php } ?>
                                        </div>
                                        <?php } ?>
                                    
                                        
                                        <?php if ($val['attachs']) {  ?>
                                        <?php foreach ($val['attachs'] AS $attach) { ?>                                        
                                            <?php if (!$attach['is_image'] AND (!$val['insert_attach_ids'] OR !in_array($attach['id'], $val['insert_attach_ids']))) { ?>
                                        <div class="file_down line mt-10 f-12"><div class="file-inner"><a href="<?php echo download_url($attach['file_name'], $attach['attachment'],$this->question_info['question_id'],$val['answer_id']); ?>" target="_blank" class="grid mr-10 fileIcon-big icon_file_zip"></a><div class="info grid file-dw-info"><p><a href="<?php echo download_url($attach['file_name'], $attach['attachment'],$this->question_info['question_id'],$val['answer_id']); ?>" target="_blank" class="f-yahei" title="<?php echo $attach['file_name']; ?>"><?php echo $attach['file_name']; ?></a><span class="f-gray ml-10">【大小: <?php echo get_filesize($attach['attachment']);?>】</span> <font color="#990033">当前问题提问者免积分下载</font></p><p class="f-gray p-last f-green"><i class="i-solid-ok"></i> 已经过IWGM安全检测,放心下载  <font color="#990033">其他会员扣除下载积分  下载积分:<?php echo get_setting('integral_system_config_answer_file');?>元宝</font></p></div><a class="grid-r btn-42-file-down-new" target="_blank" href="<?php echo download_url($attach['file_name'], $attach['attachment'],$this->question_info['question_id'],$val['answer_id']); ?>"><i class="i-file-down"></i><div><b>点击下载</b><span>下载量:<?php echo $attach['down_amount'];?></span></div></a></div></div>
                                        
                                        <?php } ?>
                                            <?php } ?>                                        
                                        <?php } ?>                                
                                      <?php }?>

相关CSS自己写一下或者去仿个 继续打开system\functions.app.php寻找function download_url替换成
function download_url($file_name, $url, $qid, $aws_uid)
{
	return get_js_url('/file/download/' . base64_encode($file_name) . '' . base64_encode($url).''.base64_encode($qid).''.base64_encode($aws_uid));
}
还是这个文件system\functions.app.php增加
/**
 * 处理附件大小
 * @param  string $url
 * 
 */
 function get_filesize($url)
{
	
	$path = get_setting('upload_dir') . '/' . str_replace(get_setting('upload_url'), '', $url);
	$size = filesize($path);	
	$units = array(' B', ' KB', ' MB', ' GB', ' TB');		
		for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; 		
	return '<font color="#009900">'.round ($size, 2).$units[$i].'</font>'; 
	
}
打开app\file\main.php 全文替换 如果不想替换的 自己对照哪些更改了 自己改一下
<?php
/*
+--------------------------------------------------------------------------
|   WeCenter [#RELEASE_VERSION#]
|   ========================================
|   by WeCenter Software
|   © 2011 - 2014 WeCenter. All Rights Reserved
|   http://www.wecenter.com
|   ========================================
|   Support: WeCenter@qq.com
|
+---------------------------------------------------------------------------
*/


if (!defined('IN_ANWSION'))
{
	die;
}

class main extends AWS_CONTROLLER
{
	public function download_action()
	{
		$url = @base64_decode($_GET['url']);
		$q_id = @base64_decode($_GET['qid']);	
		$aws_uid = 	@base64_decode($_GET['aws_uid']);
		
		if (! $url)
		{
			H::redirect_msg(AWS_APP::lang()->_t('文件未找到'));
		}

		$path = get_setting('upload_dir') . '/' . str_replace(get_setting('upload_url'), '', $url);

		if (strstr($path, '..') OR !file_exists($path))
		{
			H::redirect_msg(AWS_APP::lang()->_t('文件未找到'));
		}		
		$question_info = $this->model('question')->get_question_info_by_id($q_id);
		$answer_info = $this->model('answer')->get_answer_by_id($aws_uid);
		
		$question_integral =  str_replace('-', '', get_setting('integral_system_config_answer_file'));
		if($this->user_id != $question_info['published_uid']){
			if ($this->user_info['integral'] < $question_integral and get_setting('integral_system_enabled') == 'Y'){				
				H::redirect_msg(AWS_APP::lang()->_t('你的剩余积分已经不足以进行此操作'));
			}else{
				$this->model('integral')->process($this->user_id, 'DOWNLOADE_FILE', get_setting('integral_system_config_answer_file'), '下载附件'.base64_decode($_GET['file_name']), $answer_info['answer_id']);				
				
			}			
		}
		
			$attachs = $this->model('publish')->get_attach('answer', $answer_info['answer_id']);
			
			$this->model('publish')->update_downant($attachs[$answer_info['answer_id']]['id'],$attachs[$answer_info['answer_id']]['down_amount']);
			
		HTTP::force_download_header(base64_decode($_GET['file_name']), filesize($path));

		readfile($path);
	}
}
打开models\integral.php寻找switch ($item['action']) 增加
case 'DOWNLOADE_FILE':
  打开models\publish.php 增加
public function update_downant($id, $down_amount){
		$num = $down_amount+1;
		$this->update('attach', array('down_amount' => $num), 'id =' . $id );
		return true;
	}
打开views\default\admin\settings.tpl.htm查找
<tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('回复被折叠'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <input name="integral_system_config_answer_fold" type="text" class="form-control" value="<?php echo $this->setting['integral_system_config_answer_fold']; ?>"/>
                            </div>
                        </div>
                    </td>
                </tr>
在下面增加
 <tr>
                    <td>
                        <div class="form-group">
                            <span class="col-sm-4 col-xs-3 control-label"><?php _e('下载附件'); ?>:</span>
                            <div class="col-sm-5 col-xs-8">
                                <input name="integral_system_config_answer_file" type="text" class="form-control" value="<?php echo $this->setting['integral_system_config_answer_file']; ?>"/>
                            </div>
                        </div>
                    </td>
                </tr>
数据库部份修改 aws_system_setting 增加值【varname】-> integral_system_config_answer_file 【value】->s:3:"-20"; aws_attach 增加字段 down_amount int 长度5 默认0 如有没有成功的 在下面回复问题             

发布于 2015-10-18 15:43

免责声明:

本文由 alirpo 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

sywb0596
2017-04-11 12:10
添加后,问题页面打开空白,求解
roger
2017-03-25 19:38
可以分享如何加积分字段给上传者增加积分?
roger
2016-05-24 02:02
按照你说的,已经成功,pc版下载无问题,手机版下载总是扣除双倍积分,积分记录里也是两次下载记录,有什么办法让附件重复下载只扣一次积分?
战国乱
2016-02-04 22:41
鼓励一下楼主,很有用的教程
柚游戏
2015-11-23 10:29
支持!支持!支持!支持!支持!支持!
roger
2015-10-31 09:43
刚看到,建议大神开发的更细化一点完善一点,我们付费团购都可以!扣分和奖励积分可以参考百度文库,他那个做的比较人性化!
lidanghong
2015-10-22 00:30
作个记号,回头使用并验证,感谢!
alirpo
2015-10-21 14:22
加上上传者设积分很简单 在附件表加个积分字段
八刀丁二
2015-10-20 21:43
不错,之前也想过开发,可能需求不大,加上官方没整合,用的人可能就少一点.
a279257725
2015-10-20 15:18
感谢你的无私分享!