首页 后端开发 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脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热工具

记事本++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 查看欢迎页面。

12306怎么查询历史购票记录 查看历史购票记录的方法 12306怎么查询历史购票记录 查看历史购票记录的方法 Mar 28, 2024 pm 03:11 PM

  12306订票app下载最新版是一款大家非常满意的出行购票软件,想去哪里就去那里非常方便,软件内提供的票源非常多,只需要通过实名认证就能在线购票,所有用户的出行车票机票都可以轻松买到,享受不同的优惠折扣。还能提前开启预约抢票,预约酒店、专车接送都是可以的,有了它想去哪里就去那里一键购票,出行更加简单方便,让大家的出行体验更舒服,现在小编在线详细为12306用户们带来查看历史购票记录的方法。  1.打开铁路12306,点击右下角我的,点击我的订单  2.在订单页面点击已支付。  3.在已支付页

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 版本、功能需求和社区支持。建议使用最新稳定版本以获得最佳性能和支持。

学信网如何查询自己的学历 学信网如何查询自己的学历 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