thinkphp Transaction Details Inquiry function detailed _php example

Source: Internet
Author: User
Tags php template codeigniter zend framework

This article analyzes the thinkphp transaction details query function. Share to everyone for your reference, specific as follows:

Trading details

Usually monthly, inclusive, transaction date, transaction amount, transaction status (optional)
Total turnover and so on.
If there is more data, it is better to be able to pagination.
It is best to find out which merchant is specific.

1. Simulate SQL to implement query function

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 to a.ID = b.user_id left
  join Sh_order c on b.id = c.store_id
  WHERE a.open er_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
  L EFT JOIN sh_order c on b.id = c.store_id
  WHERE a.opener_id = 1 and a. ' Status ' = 1 and c.status = 1;

SQL query out, basically done, the rest is to use php,thinkphp to implement this query function, add some logic and conditions.

Merchant Transactions 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 ') {//Get previous month if ($s _month==1) {$useYear = $s _year-1;
    $useMonth = 12;
     }else{$useYear = $s _year;
    $useMonth = $s _month-1;
     } if ($type = = ' Next ') {//Get next month 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{//Get current date $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; Legal user $where [' c.status '] = 1;
  Legal order $where [' c.paytime '] = 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 Tot
  Alprice ')->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.payti
  Me,c.sendtime,c.receivetime ')->select ();  foreach ($list as $k => $v) {if ($v [' sendtime '] = 0 && $v [' receivetime '] = = 0) {$list [$k] [' progress '] = ' 1 '; Paid, Pending shipment} if ($v [' sendtime '] > 0 && $v [' receivetime '] = = 0) {$list [$k] [' progress '] = ' 2 ';//Shipped, pending 
  Receive} if ($v [' sendtime '] > 0 && $v [' receivetime '] > 0) {$list [$k] [' progress '] = ' 3 ';//Transaction Complete}} Get the extension user $user _list = M (' user ')->where (Array (' opener_id ' => $this->opener_id))->field (' Id,u
  Sername ')->select ();
  $this->assign (' user_list ', $user _list);
  $this->assign (' Totalprice ', $totalprice);
  $this->assign (' page ', $Page->show ());
  $this->assign (' list ', $list);
$this->display ();

 }

HTML part

<include file= "Public:head" title= "Trading Details"/> <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/java Script > 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-d Ate "> <ul class=" pager "> <li class=" Previous "><a onclick=" Lastmonth (); " ><span aria-hidden= "true" >←</span> </a></li> <span class= "Date-txt" ><strong&gt ; {sh: $s _year}. {sh: $s _month}</strong> <present name= "Paymentdata" ><span class= "Glyphicon glyphicon-ok-sign" aria-h Idden= "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" > <opt Ion Value= "" > All Merchants </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> &L t;/volist> </select> </div> <div id= "Total" class= "img-circle" > <div class= "Te Xt-center Money-txt ">  

effect, look at other people's design, learn more, the most important thing is the interface display, all the data are based on several aspects of the display, so first determine what data need, and then get them.

More interested readers of thinkphp related content can view the website topic: "thinkphp Introductory Course", "thinkphp template Operation Skill Summary", "thinkphp Common Method Summary", "The CodeIgniter Introductory Course", "CI ( CodeIgniter) Framework Advanced tutorials, introductory tutorials for the Zend framework Framework, Smarty Templates Primer tutorial, and PHP template technology summary.

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.