首頁 後端開發 php教程 thinkPHP交易詳情查詢功能

thinkPHP交易詳情查詢功能

Jun 07, 2018 am 11:51 AM
thinkphp 查詢

這篇文章主要介紹了thinkPHP交易詳情查詢功能,結合實例形式分析了thinkPHP資料庫查詢功能及視圖輸出相關操作技巧,需要的朋友可以參考下

本文實例分析了thinkPHP交易詳情查詢功能。分享給大家供大家參考,具體如下:

交易詳情

一般都是按月的,包含,交易日期,交易金額,交易狀態(可有可無)
總交易額等等。
如果資料多的話,最好能夠分頁。
最好能夠查詢具體的哪一個商家。

1.模擬sql實作查詢功能

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實作這個查詢功能,加入一些邏輯與條件。

// 商户交易
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{
   // 获取当前年 月
   $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'; // 已付款,待发货
   }
   if($v['sendtime'] > 0 && $v['receivetime'] == 0){
    $list[$k]['progress'] = '2'; // 已发货,待签收
   }
   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(&#39;last&#39;);
}
function nextMonth(){
  todo(&#39;next&#39;);
}
function selectUser(){
  todo(&#39;selectuser&#39;);
}
function todo(type){
  var s_year = $(&#39;#s_year&#39;).val();
  var s_month = $(&#39;#s_month&#39;).val();
  var s_user_id = $(&#39;#s_user_id&#39;).val();
  window.location.href="{sh::U(&#39;User/trade&#39;)}&s_year="+s_year+"&s_month="+s_month+"&s_user_id="+s_user_id+"&type="+type;
}
</script>
<body>
  <p data-example-id="list-group-btns" class="bs-example">
    <p 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>
    </p>
    <p 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>
    </p>
    <p id="total" class="img-circle">
      <p class="text-center money-txt">
        <h3>总交易金额</h3>
        <h2>¥{sh:$totalprice}</h2>
      </p>
    </p>
    <p id="datalist">
      <table class="table table-striped">
        <thead>
          <tr>
            <th>商户</th>
            <th>日期</th>
            <th>交易金额</th>
            <!-- <th>状态</th> -->
          </tr>
        </thead>
        <tbody>
        <empty name="list"><tr><td class="text-center" colspan="4">暂无数据</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">待发货</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>
      <p class="page text-right">
        {sh:$page}
      </p>
    </p>
</body>
</html>
登入後複製

效果,多看看別人的設計,多學學,最重要的就是介面展示,一切的數據都是基於幾面展示,所以先確定好需要什麼數據,然後再取得他們。

相關推薦:

PHP簡單實作記錄網站訪問量的功能

以上是thinkPHP交易詳情查詢功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

thinkphp專案怎麼運行 thinkphp專案怎麼運行 Apr 09, 2024 pm 05:33 PM

執行 ThinkPHP 專案需要:安裝 Composer;使用 Composer 建立專案;進入專案目錄,執行 php bin/console serve;造訪 http://localhost:8000 查看歡迎頁面。

thinkphp有幾個版本 thinkphp有幾個版本 Apr 09, 2024 pm 06:09 PM

ThinkPHP 擁有多個版本,針對不同 PHP 版本而設計。主要版本包括 3.2、5.0、5.1 和 6.0,而次要版本用於修復 bug 和提供新功能。目前最新穩定版本為 ThinkPHP 6.0.16。在選擇版本時,需考慮 PHP 版本、功能需求和社群支援。建議使用最新穩定版本以獲得最佳性能和支援。

12306怎麼查詢歷史購票紀錄 查看歷史購票紀錄的方法 12306怎麼查詢歷史購票紀錄 查看歷史購票紀錄的方法 Mar 28, 2024 pm 03:11 PM

12306訂票app下載最新版是一款大家非常滿意的出行購票軟體,想去哪裡就去那裡非常方便,軟體內提供的票源非常多,只需要通過實名認證就能在線購票,所有用戶的出行車票機票都可以輕鬆買到,享受不同的優惠折扣。還能提前開啟預約搶票,預約飯店、專車接送都是可以的,有了它想去哪裡就去那裡一鍵購票,出行更加簡單方便,讓大家的出行體驗更舒服,現在小編在線詳細為12306用戶帶來查看歷史購票記錄的方法。  1.打開鐵路12306,點擊右下角我的,點擊我的訂單  2.在訂單頁面點擊已支付。  3.在已支付頁

學信網如何查詢自己的學歷 學信網如何查詢自己的學歷 Mar 28, 2024 pm 04:31 PM

學信網如何查詢自己的學歷?在學信網中是可以查詢到自己的學歷,很多用戶都不知道如何在學信網中查詢到自己的學歷,接下來就是小編為用戶帶來的學信網查詢自己學歷方法圖文教程,感興趣的用戶快來一起看看吧!學信網使用教程學信網如何查詢自己的學歷一、學信網入口:https://www.chsi.com.cn/二、網站查詢:第一步:點選上方學信網位址,進入首頁點選【學歷查詢】;第二步:在最新的網頁中點選如下圖箭頭所示的【查詢】;第三步:之後在新頁面點選【的登陸學信檔案】;第四步:在登陸頁面輸入資料點選【登陸】;

thinkphp怎麼運行 thinkphp怎麼運行 Apr 09, 2024 pm 05:39 PM

ThinkPHP Framework 的本機運作步驟:下載並解壓縮 ThinkPHP Framework 到本機目錄。建立虛擬主機(可選),指向 ThinkPHP 根目錄。配置資料庫連線參數。啟動 Web 伺服器。初始化 ThinkPHP 應用程式。存取 ThinkPHP 應用程式 URL 運行。

laravel和thinkphp哪個好 laravel和thinkphp哪個好 Apr 09, 2024 pm 03:18 PM

Laravel 和 ThinkPHP 框架的效能比較:ThinkPHP 效能通常優於 Laravel,專注於最佳化和快取。 Laravel 性能良好,但對於複雜應用程序,ThinkPHP 可能更適合。

thinkphp怎麼安裝 thinkphp怎麼安裝 Apr 09, 2024 pm 05:42 PM

ThinkPHP 安裝步驟:準備 PHP、Composer、MySQL 環境。使用 Composer 建立專案。安裝 ThinkPHP 框架及相依性。配置資料庫連線。產生應用程式碼。啟動應用程式並造訪 http://localhost:8000。

MySQL與PL/SQL的異同比較 MySQL與PL/SQL的異同比較 Mar 16, 2024 am 11:15 AM

MySQL與PL/SQL是兩種不同的資料庫管理系統,分別代表了關係型資料庫和過程化語言的特性。本文將比較MySQL和PL/SQL的異同點,並附帶具體的程式碼範例進行說明。 MySQL是一種流行的關聯式資料庫管理系統,採用結構化查詢語言(SQL)來管理和操作資料庫。而PL/SQL是Oracle資料庫特有的過程化語言,用於編寫預存程序、觸發器和函數等資料庫物件。相同

See all articles