手把手教大家做一个积分下载功能
先看一下图 如果是你想要的可以继续向下看
第一步 打开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-20 15:17
2015-10-19 23:22
2015-10-19 09:34
2015-10-18 20:43
2015-10-18 19:58