thinkPHP交易詳情查詢功能詳解
本文實(shí)例分析了thinkPHP交易詳情查詢功能。分享給大家供大家參考,具體如下:
交易詳情
一般都是按月的,包含,交易日期,交易金額,交易狀態(tài)(可有可無)
總交易額等等。
如果數(shù)據(jù)多的話,最好能夠分頁。
最好能夠查詢具體的哪一個(gè)商戶。
1.模擬sql實(shí)現(xiàn)查詢功能
SELECT a.id as user_id,a.username,b.name as store_name,c.id as order_id,c.price,c.paytime,c.sendtime,c.receivetime FROM sh_user a LEFT JOIN sh_store b on a.id = b.user_id LEFT JOIN sh_order c ON b.id = c.store_id WHERE a.opener_id = 1 and a.`status` = 1 and c.status = 1 ORDER BY c.id desc; SELECT count(b.id) as count ,sum(c.price) as total_price FROM sh_user a LEFT JOIN sh_store b on a.id = b.user_id LEFT JOIN sh_order c ON b.id = c.store_id WHERE a.opener_id = 1 and a.`status` = 1 and c.status = 1;
sql查詢出來了,基本上就搞定了,剩下的就是用php,thinkphp實(shí)現(xiàn)這個(gè)查詢功能,加入一些邏輯與條件。
// 商戶交易
public function trade(){
if($type = $this->_request('type','trim')){
$s_year = $this->_request('s_year','trim');
$s_month = $this->_request('s_month','trim');
$s_user_id = $this->_request('s_user_id','trim,intval');
$this->assign('s_user_id',$s_user_id);
if($type == 'last'){ // 獲取上一月
if($s_month==1){
$useYear = $s_year-1;
$useMonth = 12;
}else{
$useYear = $s_year;
$useMonth = $s_month-1;
}
}
if($type == 'next'){ // 獲取下一月
if($s_month==12){
$useYear = $s_year+1;
$useMonth = 1;
}else{
$useYear = $s_year;
$useMonth = $s_month+1;
}
}
if ($type == 'selectuser'){
$useYear = $s_year;
$useMonth = $s_month;
}
}else{
// 獲取當(dāng)前年 月
$useYear = date('Y');
$useMonth = date('m');
}
$this->assign('s_year',$useYear);
$this->assign('s_month',$useMonth);
$b_time = strtotime($useYear.'-'.$useMonth.'-'.'1');
$e_time = strtotime($useYear.'-'.$useMonth.'-'.date('t',strtotime($b_time)).' 23:59:59');
if(isset($s_user_id) && $s_user_id > 0){
$where['a.id'] = $s_user_id;
}
$where['a.opener_id'] = $this->opener_id;
$where['a.status'] = 1; // 合法的用戶
$where['c.status'] = 1; // 合法的訂單
$where['c.paytime'] = array(array('gt',$b_time),array('lt',$e_time),'and');
$count_and_totalprice = M()->table('sh_user a')
->join('sh_store b on a.id = b.user_id')
->join('sh_order c on b.id = c.store_id')
->where($where)
->field('count(b.id) as count ,sum(c.price) as totalprice')
->find();
$count = $count_and_totalprice['count'];
$totalprice = $count_and_totalprice['totalprice'] ? $count_and_totalprice['totalprice'] : 0;
$Page = new Page($count, 10);
$list = M()->table('sh_user a')
->join('sh_store b on a.id = b.user_id')
->join('sh_order c on b.id = c.store_id')
->where($where)
->order('c.id desc')
->limit($Page->firstRow.','.$Page->listRows)
->field('a.id as user_id,a.username,b.name as store_name,c.id as order_id,c.price,c.paytime,c.sendtime,c.receivetime')
->select();
foreach ($list as $k => $v) {
if($v['sendtime'] == 0 && $v['receivetime'] == 0){
$list[$k]['progress'] = '1'; // 已付款,待發(fā)貨
}
if($v['sendtime'] > 0 && $v['receivetime'] == 0){
$list[$k]['progress'] = '2'; // 已發(fā)貨,待簽收
}
if($v['sendtime'] > 0 && $v['receivetime'] > 0){
$list[$k]['progress'] = '3'; // 交易完成
}
}
// 獲取拓展員用戶
$user_list = M('User')
->where(array('opener_id'=>$this->opener_id))
->field('id,username')
->select();
$this->assign('user_list',$user_list);
$this->assign('totalprice',$totalprice);
$this->assign('page',$Page->show());
$this->assign('list', $list);
$this->display();
}
html部分
<include file="Public:head" title="交易詳情" />
<style>
.top {
background-color: #eee;
height: 50px;
line-height: 50px;
font-size: 18px;
border-bottom: #ddd 1px solid;
margin-bottom: -1px;
}
.list-group{
border: 1px solid #DDDDDD;
}
.list-group .list-group-item {
text-align: left;
line-height: 25px;
border: none;
background-color: #F9F9F9;
font-size: 14px;
}
#select-date {
padding: 0px 10px;
}
#select-date .date-txt {
font-size: 18px;
}
#total {
width: 140px;
height: 140px;
background-color: #EC6C00;
margin: auto;
}
#total .money-txt {
color: white;
padding-top: 10px;
}
#datalist {
margin-top: 30px;
}
#relief .form-control{
margin-top: 10px;
margin-bottom: 10px;
/*background-color: #FFCE42;*/
}
.page{
margin-right: 10px;
margin-bottom: 20px;
}
.table th {
color: #C4C4C4;
}
.table tbody tr td+td+td {
color: #D3964F;
}
</style>
<script type="text/javascript">
function lastMonth(){
todo('last');
}
function nextMonth(){
todo('next');
}
function selectUser(){
todo('selectuser');
}
function todo(type){
var s_year = $('#s_year').val();
var s_month = $('#s_month').val();
var s_user_id = $('#s_user_id').val();
window.location.href="{sh::U('User/trade')}&s_year="+s_year+"&s_month="+s_month+"&s_user_id="+s_user_id+"&type="+type;
}
</script>
<body>
<div data-example-id="list-group-btns" class="bs-example">
<div id="select-date">
<ul class="pager">
<li class="previous"><a onclick="lastMonth();"><span aria-hidden="true">←</span> </a></li>
<span class="date-txt"><strong>{sh:$s_year}.{sh:$s_month}</strong>
<present name="paymentData"><span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span></present>
</span>
<input type="text" id="s_year" value="{sh:$s_year}" hidden="hidden">
<input type="text" id="s_month" value="{sh:$s_month}" hidden="hidden">
<li class="next"><a onclick="nextMonth();"><span aria-hidden="true">→</span></a></li>
</ul>
</div>
<div id="relief">
<select id="s_user_id" onchange="selectUser();" class="form-control btn-success">
<option value="">全部商戶</option>
<volist name="user_list" id="vo">
<option value="{sh:$vo.id}" <eq name="vo.id" value="$s_user_id">selected="selected"</eq>>{sh:$vo.username}</option>
</volist>
</select>
</div>
<div id="total" class="img-circle">
<div class="text-center money-txt">
<h3>總交易金額</h3>
<h2>¥{sh:$totalprice}</h2>
</div>
</div>
<div id="datalist">
<table class="table table-striped">
<thead>
<tr>
<th>商戶</th>
<th>日期</th>
<th>交易金額</th>
<!-- <th>狀態(tài)</th> -->
</tr>
</thead>
<tbody>
<empty name="list"><tr><td class="text-center" colspan="4">暫無數(shù)據(jù)</td></tr></empty>
<volist name="list" id="vo">
<tr>
<td>{sh:$vo.username}</td>
<td>{sh:$vo.paytime|date="Y-m-d H:i",###}</td>
<td>{sh:$vo.price}</td>
<!-- <td>
<if condition="$vo.progress eq 1"><span class="text-primary">待發(fā)貨</span>
<elseif condition="$vo.progress eq 2"/><span class="text-danger">待簽收</span>
<elseif condition="$vo.progress eq 3"/><span class="text-success"><strong>已完成</strong></span>
</if>
</td> -->
</tr>
</volist>
</tbody>
</table>
<div class="page text-right">
{sh:$page}
</div>
</div>
</body>
</html>
效果,多看看別人的設(shè)計(jì),多學(xué)學(xué),最重要的就是界面展示,一切的數(shù)據(jù)都是基于幾面展示,所以先確定好需要什么數(shù)據(jù),然后獲取他們。

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
- php+mysql+jquery實(shí)現(xiàn)日歷簽到功能
- ThinkPHP+jquery實(shí)現(xiàn)“加載更多”功能代碼
- Thinkphp整合微信支付功能
- thinkphp實(shí)現(xiàn)分頁顯示功能
- thinkPHP統(tǒng)計(jì)排行與分頁顯示功能示例
- thinkPHP商城公告功能開發(fā)問題分析
- thinkPHP訂單數(shù)字提醒功能的實(shí)現(xiàn)方法
- Thinkphp實(shí)現(xiàn)短信驗(yàn)證注冊功能
- thinkphp框架實(shí)現(xiàn)數(shù)據(jù)添加和顯示功能
- ThinkPHP3.2.2實(shí)現(xiàn)持久登錄(記住我)功能的方法
- thinkPHP實(shí)現(xiàn)MemCache分布式緩存功能
- thinkphp實(shí)現(xiàn)圖片上傳功能
- thinkPHP實(shí)現(xiàn)簽到功能的方法
相關(guān)文章
PHP使用星號替代用戶名手機(jī)和郵箱的實(shí)現(xiàn)代碼
這篇文章主要介紹了PHP使用星號替代用戶名手機(jī)和郵箱的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-02-02
解決PHPstudy Apache無法啟動(dòng)的問題【親測有效】
這篇文章主要介紹了PHPstudy Apache無法啟動(dòng)的問題及解決方法【親測有效】,本文給大家總結(jié)了三種方法供大家參考,需要的朋友可以參考下2020-10-10
用PHP寫的一個(gè)冒泡排序法的函數(shù)簡單實(shí)例
下面小編就為大家?guī)硪黄肞HP寫的一個(gè)冒泡排序法的函數(shù)簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05
php獲取目標(biāo)函數(shù)執(zhí)行時(shí)間示例
這篇文章主要介紹了php獲取目標(biāo)函數(shù)執(zhí)行時(shí)間示例,需要的朋友可以參考下2014-03-03

