count.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace WY\app\controller\agent;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class count extends CheckUser
  8. {
  9. public function index()
  10. {
  11. $cons = 'agentid=? and is_state=?';
  12. $consArr = array($_SESSION['login_agentid'], 1);
  13. $fdate = $this->req->get('fdate');
  14. $tdate = $this->req->get('tdate');
  15. $fdate = isset($_GET['fdate']) ? $fdate : date('Y-m-d');
  16. $tdate = isset($_GET['tdate']) ? $tdate : date('Y-m-d');
  17. $day = $this->req->get('day');
  18. if ($day == '1') {
  19. $fdate = date('Y-m-d');
  20. $tdate = date('Y-m-d');
  21. }
  22. if ($day == '2') {
  23. $fdate = date('Y-m-d', time() - 60 * 60 * 24);
  24. $tdate = date('Y-m-d', time() - 60 * 60 * 24);
  25. }
  26. if ($day == '7') {
  27. $fdate = date('Y-m-d', time() - 60 * 60 * 24 * 6);
  28. $tdate = date('Y-m-d');
  29. }
  30. if ($day == '30') {
  31. $fdate = date('Y-m-d', time() - 60 * 60 * 24 * 29);
  32. $tdate = date('Y-m-d');
  33. }
  34. if ($fdate) {
  35. $cons .= $cons ? ' and ' : '';
  36. $cons .= 'addtime>=?';
  37. $consArr[] = strtotime($fdate);
  38. }
  39. if ($tdate) {
  40. $cons .= $cons ? ' and ' : '';
  41. $cons .= 'addtime<=?';
  42. $consArr[] = strtotime($tdate . ' 23:59:59');
  43. }
  44. $where = $cons ? array('fields' => $cons, 'values' => $consArr) : array();
  45. $page = $this->req->get('p');
  46. $page = $page ? intval($page) : 1;
  47. $pagesize = 20;
  48. $lists = array();
  49. if ($totalsize = $this->model()->select()->from('orders')->where($where)->count()) {
  50. $totalpage = ceil($totalsize / $pagesize);
  51. $page = $page > $totalpage ? $totalpage : $page;
  52. $offset = ($page - 1) * $pagesize;
  53. $lists = $this->model()->select()->from('orders')->limit($pagesize)->offset($offset)->orderby('id desc')->where($where)->fetchAll();
  54. }
  55. $sumArr = array('total_money' => 'realmoney', 'user_money' => 'realmoney*uprice', 'agent_money' => 'IF(gprice>0,realmoney*(gprice-uprice),0)');
  56. $count = $this->model()->select($sumArr)->from('orders')->where($where)->sum();
  57. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?day=' . $day . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  58. $data = array('title' => '收入统计', 'lists' => $lists, 'pagelist' => $pagelist, 'count' => $count, 'search' => array('fdate' => $fdate, 'tdate' => $tdate, 'day' => $day));
  59. $this->put('count.php', $data);
  60. }
  61. }