首先列出当前用户的所有订单记录 编辑index方法: ~~~ public function index($ap=0){ } ~~~ 获取当前时间及当前用户: ~~~ $time = time(); $activeuser = UserModel::where('status',1)->find(); $this->assign('activeuser', $activeuser['username']); ~~~ 账期: ~~~ 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); $this->assign('ap', $ap); ~~~ 订单: ~~~ $listcount = 0; if($ap>0){ $list = OrderModel::where('ap',$srchap) ->where('uid',$activeuser['uid']) ->order('tid asc,onum desc') ->paginate(50); $listcount = OrderModel::where('ap',$srchap) ->where('uid',$activeuser['uid']) ->count(); }else{ $list = OrderModel::where('uid',$activeuser['uid'])->order('tid asc,onum desc')->paginate(50); $listcount = OrderModel::where('uid',$activeuser['uid'])->count(); } // 订单列表 $this->assign('listcount', $listcount); $this->assign('list', $list); // 模板列表 $templatelist = TplModel::where('uid',$activeuser['uid'])->order('tid', 'desc')->select(); $this->assign('templatelist', $templatelist); // 订单合计 $sum_oamount = OrderModel::where('uid',$activeuser['uid'])->where('ap',$srchap)->sum('oamount'); $this->assign('sum_oamount', $sum_oamount); // 当月分摊 $sum_damount = OrderModel::where('uid',$activeuser['uid'])->where('ap',$srchap)->sum('damount'); $this->assign('sum_damount', $sum_damount); return $this->fetch(); ~~~ 模板文件: /apps/index/view/order/index.html ~~~ {layout name="layout" /} <div class="container"> <div id="orderlist" class="grid"> {load href="__PUBLIC__/js/order_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/order/add/';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/order/index/">全部账期</a></li> <li class="option" value="1"><a href="http://127.0.0.1/tp5/public/index.php/index/order/index/ap/1">上月<span></span></a></li> <li class="option" value="2"><a href="http://127.0.0.1/tp5/public/index.php/index/order/index/ap/2">前三月</a></li> <li class="option" value="3"><a href="http://127.0.0.1/tp5/public/index.php/index/order/index/ap/3">前四月</a></li> <li class="option" value="4"><a href="http://127.0.0.1/tp5/public/index.php/index/order/index/ap/4">前五月</a></li> </ol> </div> <div class="ui8-select"> <span class="active-option">当前账户:<em>{$activeuser}</em> 共<em>{$listcount}</em>条记录{if condition="($ap>0)"} 订单总额<em>{$sum_oamount}</em> 当月分摊<em>{$sum_damount}</em>{/if}</span> </div> </div> <form method="post" autocomplete="off" name="moderate" id="moderate" action="http://127.0.0.1/tp5/public/index.php/index/order/"> <table class="listbox" cellpadding="1" cellspacing="0"> <tbody> <tr class="ttr"> <td class="ap">账期</td> <td class="tname">模板</td> <td class="oamount">订单金额</td> <td class="chk">选择</td> <td class="buyer">卖家</td> <td class="onum">订单</td> <td class="buytime">订购时间</td> <td class="nick">设计师</td> </tr> </tbody> {volist name="list" id="order" } <tbody id="order{$order.oid}"> <tr class="{if condition="$mod neq 1"}tr1{else /}tr2{/if}"> <td><cite>{$order.ap}</cite></td> <td><cite style="color:{$order.template.highlight_color};">{$order.template.tname}</cite></td> <td><cite>{$order.oamount}</cite></td> <td><input onclick="tmodclick(this)" type="checkbox" name="moderate[]" value="{$order.oid}"></td> <td><cite>{$order.bnick}</cite></td> <td><cite>{$order.onum}</cite></td> <td><cite>{$order.stime}</cite></td> <td><cite>{$order.snick}</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> <table class="formbox" cellpadding="10" cellspacing="0"> <tbody> <tr> <td colspan="2"> <select name="templateid" id="templateid"> <option value="0">&nbsp;</option> {volist name="templatelist" id="tpl" } <option value="{$tpl.tid}" style="color:{$tpl.highlight_color};">{$tpl.tname}</option> {/volist} </select> </td> </tr> <tr> <td> <button type="button" onclick="tmodorders(2, 'changetemplate');return false;" tabindex="104" class="pn pnc btn btn-small btn-green"><strong>选择模板</strong></button> </td> <td> <button type="button" onclick="tmodorders(3, 'delete');return false;" name="delsubmit" id="delsubmit" value="delsubmit" tabindex="105" class="pn pnc btn btn-small btn-red"><strong>删除</strong></button> </td> </tr> </tbody> </table> </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/order/ 页面输出类似 ![](https://box.kancloud.cn/2016-07-28_579970f6cdd80.png)