thinkPHP交易详情查询功能详解


Posted in PHP onDecember 02, 2016

本文实例分析了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('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>状态</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>
      <div class="page text-right">
        {sh:$page}
      </div>
    </div>
</body>
</html>

效果,多看看别人的设计,多学学,最重要的就是界面展示,一切的数据都是基于几面展示,所以先确定好需要什么数据,然后获取他们。

thinkPHP交易详情查询功能详解

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

PHP 相关文章推荐
聊天室php&amp;mysql(三)
Oct 09 PHP
php遍历目录viewDir函数
Dec 15 PHP
PHP 批量更新网页内容实现代码
Jan 05 PHP
探讨PHP JSON中文乱码的解决方法详解
Jun 06 PHP
PHP获取MSN好友列表类的实现代码
Jun 23 PHP
删除html标签得到纯文本可处理嵌套的标签
Apr 28 PHP
PHP调用C#开发的dll类库方法
Jul 28 PHP
php获取指定日期之间的各个周和月的起止时间
Nov 24 PHP
PHP registerXPathNamespace()函数讲解
Feb 03 PHP
PHP经典设计模式之依赖注入定义与用法详解
May 21 PHP
PHP的静态方法与普通方法用法实例分析
Sep 26 PHP
Laravel5.1 框架控制器基础用法实例分析
Jan 04 PHP
php变量与数组相互转换的方法(extract与compact)
Dec 02 #PHP
php图像处理函数imagecopyresampled用法详解
Dec 02 #PHP
PHP面向对象继承用法详解(优化与减少代码重复)
Dec 02 #PHP
PHP面向对象程序设计高级特性详解(接口,继承,抽象类,析构,克隆等)
Dec 02 #PHP
PHP面向对象程序设计之命名空间与自动加载类详解
Dec 02 #PHP
PHP面向对象程序设计之类与反射API详解
Dec 02 #PHP
PHP面向对象程序设计之对象生成方法详解
Dec 02 #PHP
You might like
PHP第一季视频教程(李炎恢+php100 不断更新)
2011/05/29 PHP
如何用phpmyadmin设置mysql数据库用户的权限
2012/01/09 PHP
PHP字符过滤函数去除字符串最后一个逗号(rtrim)
2013/03/26 PHP
PHP实现linux命令tail -f
2016/02/22 PHP
功能强大的php文件上传类
2016/08/29 PHP
PHP与jquery实时显示网站在线人数实例详解
2016/12/02 PHP
CentOS 上搭建 PHP7 开发测试环境
2017/02/26 PHP
Laravel5.5 视图 - 创建视图和数据传递示例
2019/10/21 PHP
jQuery 获取URL参数的插件
2010/03/04 Javascript
利用try-catch判断变量是已声明未声明还是未赋值
2014/03/12 Javascript
js数组方法扩展实现数组统计函数
2014/04/09 Javascript
javascript中var的重要性分析
2015/02/11 Javascript
zepto中使用swipe.js制作轮播图附swipeUp,swipeDown不起效果问题
2015/08/27 Javascript
JS工作中的小贴士之”闭包“与事件委托的”阻止冒泡“
2016/06/16 Javascript
Angularjs CURD 详解及实例代码
2016/09/14 Javascript
炫酷的js手风琴效果
2016/10/13 Javascript
详解基于vue-cli配置移动端自适应
2018/01/13 Javascript
vue组件之间数据传递的方法实例分析
2019/02/12 Javascript
Vue中CSS动画原理的实现
2019/02/13 Javascript
Vuejs学习笔记之使用指令v-model完成表单的数据双向绑定
2019/04/29 Javascript
vue 在服务器端直接修改请求的接口地址
2020/12/19 Vue.js
[29:59]完美世界DOTA2联赛PWL S3 Forest vs access 第二场 12.11
2020/12/13 DOTA
python使用sorted函数对列表进行排序的方法
2015/04/04 Python
python爬虫实战之爬取京东商城实例教程
2017/04/24 Python
python中日志logging模块的性能及多进程详解
2017/07/18 Python
Python键盘输入转换为列表的实例
2018/06/23 Python
django中嵌套的try-except实例
2020/05/21 Python
Abe’s of Maine:自1979以来销售相机和电子产品
2016/11/21 全球购物
以设计师精品品质提供快速时尚:PopJulia
2018/01/09 全球购物
Lookfantastic台湾:英国彩妆美发保养购物网
2018/03/26 全球购物
司法局火灾防控方案
2014/06/05 职场文书
节能环保标语
2014/06/12 职场文书
应届生求职信范文
2014/06/30 职场文书
党支部班子“四风”问题自我剖析材料
2014/09/28 职场文书
公司离职证明标准样本
2014/10/05 职场文书
用Python将GIF动图分解成多张静态图片
2021/06/11 Python