首先列出当前用户的所有结算记录。
结算部分是先写的,用户登录部分就先简化处理,留待后面解决。
编辑index方法:
~~~
public function index($ap=0){
}
~~~
获取当前用户:
~~~
$activeuser = UserModel::where('status',1)->find();
~~~
获取结算列表:
~~~
$listcount = 0;
if($ap>0){
$list = AcctModel::where('ap',$srchap)
->where('uid',$activeuser['uid'])
->order('aid', 'desc')
->paginate(20);
$listcount = AcctModel::where('ap',$srchap)
->where('uid',$activeuser['uid'])
->count();
}else{
$list = AcctModel::where('uid',$activeuser['uid'])->order('aid', 'desc')->paginate(20);
$listcount = AcctModel::where('uid',$activeuser['uid'])->count();
}
~~~
然后输出变量到模板:
~~~
$this->assign('activeuser', $activeuser['username']);
$this->assign('listcount', $listcount);
$this->assign('list', $list);
~~~
最后调用模板:
~~~
return $this->fetch();
~~~
模板文件:
/apps/index/view/account/index.html
~~~
{layout name="layout" /}
<div class="container">
<div id="accountlist" class="grid">
{load href="__PUBLIC__/js/account_moderate.js" /}
<div class="actions">
<ul>
<li class="action">
<button type="button" onclick="location.href='http://127.0.0.1/tp5/public/index.php/index/account/account/';return false;" name="topicsubmit" id="fastpostsubmit" value="topicsubmit" tabindex="21" class="pn pnc btn btn-green"><strong>立即结算</strong></button>
</li>
</ul>
</div>
<div class="sorting">
<div class="ui8-select">
<span class="active-option">{$aptag}</span>
<i aria-hidden="true" class="fa fa-chevron-down icon_g"></i>
<ol class="options">
<li class="option" value="0"><a href="http://127.0.0.1/tp5/public/index.php/index/account/index/">全部账期</a></li>
<li class="option" value="1"><a href="http://127.0.0.1/tp5/public/index.php/index/account/index/ap/1">上月<span></span></a></li>
<li class="option" value="2"><a href="http://127.0.0.1/tp5/public/index.php/index/account/index/ap/2">前三月</a></li>
<li class="option" value="3"><a href="http://127.0.0.1/tp5/public/index.php/index/account/index/ap/3">前四月</a></li>
<li class="option" value="4"><a href="http://127.0.0.1/tp5/public/index.php/index/account/index/ap/4">前五月</a></li>
</ol>
</div>
<div class="ui8-select">
<span class="active-option">当前账户:<em>{$activeuser}</em> 共<em>{$listcount}</em>条记录</span>
</div>
</div>
<form method="post" autocomplete="off" name="moderate" id="moderate" action="http://127.0.0.1/tp5/public/index.php/index/account/">
<table class="listbox" cellpadding="1" cellspacing="0">
<tbody>
<tr class="ttr">
<td class="chk">选择</td>
<td class="ap">账期</td>
<td class="nick">合作者</td>
<td class="sum">分成金额</td>
<td class="pay">结算状态</td>
</tr>
</tbody>
{volist name="list" id="account" }
<tbody id="">
<tr class="{if condition="$mod neq 1"}tr1{else /}tr2{/if}">
<td><input onclick="tmodclick(this)" type="checkbox" name="moderate[]" value="{$account.aid}"></td>
<td><cite>{$account.ap}</cite></td>
<td><cite>{$account.anick}</cite></td>
<td><cite>{$account.amount}</cite></td>
<td><cite>{$account.pstatus}</cite></td>
</tr>
</tbody>
{/volist}
</table>
{load href="__PUBLIC__/css/moderator.css" /}
<div id="mdly" style="display: none;">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="t_l"></td>
<td class="t_c"></td>
<td class="t_r"></td>
</tr>
<tr>
<td class="m_l"></td>
<td class="m_c">
<div class="popcon">
<input type="hidden" name="optgroup">
<input type="hidden" name="operation">
<a class="cp" href="javascript:;" title="最小化" onclick="$('mdly').className='cpd'">最小化</a>
<label><input type="checkbox" name="chkall" class="pc" onclick="if(!($('mdct').innerHTML = modclickcount = checkall(this.form, 'moderate'))) {$('mdly').style.display = 'none';}">全选</label>
<h6><span>选中</span><strong onclick="$('mdly').className='';" onmouseover="this.title='最大化'" id="mdct" title="最大化">2</strong><span>条记录: </span></h6>
<p>
<button type="button" onclick="tmodaccounts(3, 'pay');return false;" name="paysubmit" id="paysubmit" value="paysubmit" tabindex="100" class="pn pnc btn btn-small btn-green"><strong>结算状态</strong></button>
<button type="button" onclick="tmodaccounts(3, 'delete');return false;" name="delsubmit" id="delsubmit" value="delsubmit" tabindex="101" class="pn pnc btn btn-small btn-red"><strong>删除</strong></button>
</p>
</div>
</td>
<td class="m_r"></td>
</tr>
<tr>
<td class="b_l"></td>
<td class="b_c"></td>
<td class="b_r"></td>
</tr>
</tbody>
</table>
</div>
</form>
<div class="pgbox">
{$list->render()}
</div>
</div>
</div>
~~~
打开浏览器
http://127.0.0.1/tp5/public/index.php/index/account/
页面输出类似
![](https://box.kancloud.cn/2016-07-10_5781a372f1056.png)
补充代码:
~~~
$time = time();
switch ($ap) {
case '1':
$srchap = date('Ym',strtotime("-1 month", $time));
$aptag = '上月';
break;
case '2':
$srchap = date('Ym',strtotime("-2 month", $time));
$aptag = '前三月';
break;
case '3':
$srchap = date('Ym',strtotime("-3 month", $time));
$aptag = '前四月';
break;
case '4':
$srchap = date('Ym',strtotime("-4 month", $time));
$aptag = '前五月';
break;
default:
$srchap = '';
$aptag = '全部账期';
break;
}
$this->assign('aptag', $aptag);
~~~
输出账期记录。