ordersha.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class ordersha extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $kw = $this->req->get('kw');
  12. $fdate = $this->req->get('fdate');
  13. $tdate = $this->req->get('tdate');
  14. $fdate = isset($_GET['fdate']) ? $fdate : date('Y-m-d');
  15. $tdate = isset($_GET['tdate']) ? $tdate : date('Y-m-d');
  16. $superid = $this->req->get('superid');
  17. $sort = $this->req->get('sort');
  18. $by = $this->req->get('by');
  19. $accid = $this->req->get('accid');
  20. $orderby = 'agentid desc';
  21. if ($by) {
  22. $orderby = $sort ? $by . ' desc' : $by . ' asc';
  23. }
  24. $cons = 'agentid<>?';
  25. $consOR = '';
  26. $consArr = array(0);
  27. if ($kw) {
  28. $user = $this->model()->select('id')->from('users')->where(array('fields' => 'username = ?', 'values' => array($kw)))->fetchRow();
  29. if ($user) {
  30. $consOR .= $consOR ? ' or ' : '';
  31. $consOR .= 'agentid=?';
  32. $consArr[] = $user['id'];
  33. }
  34. }
  35. if ($kw) {
  36. $consOR .= $consOR ? ' or ' : '';
  37. $consOR .= 'agentid = ?';
  38. $consArr[] = $kw;
  39. }
  40. if ($consOR) {
  41. $cons .= $cons ? ' and ' : '';
  42. $cons .= '(' . $consOR . ')';
  43. }
  44. if ($fdate) {
  45. $cons .= $cons ? ' and ' : '';
  46. $cons .= 'addtime>=?';
  47. $consArr[] = strtotime($fdate);
  48. }
  49. if ($tdate) {
  50. $cons .= $cons ? ' and ' : '';
  51. $cons .= 'addtime<=?';
  52. $consArr[] = strtotime($tdate . ' 23:59:59');
  53. }
  54. if ($accid) {
  55. $cons .= $cons ? ' and ' : '';
  56. $cons .= 'channelid=?';
  57. $consArr[] = $accid;
  58. }
  59. $page = $this->req->get('p');
  60. $page = $page ? $page : 1;
  61. $pagesize = 20;
  62. $data = $this->model()->select('agentid')->from('orders')->groupby('agentid')->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  63. $totalsize = count($data);
  64. $lists = $total_count = array();
  65. if ($totalsize) {
  66. $totalpage = ceil($totalsize / $pagesize);
  67. $page = $page > $totalpage ? $totalpage : $page;
  68. $offset = ($page - 1) * $pagesize;
  69. $lists = $this->model()->select('agentid,sum(total_fee) as total_fee,count(userid) as total_orders,sum(realmoney*(gprice-uprice)) as total_income,sum((wprice-IF(gprice>0,gprice,uprice))*realmoney) as pt_income')->from('orders')->offset($offset)->limit($pagesize)->groupby('agentid')->orderby($orderby)->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  70. $total_count = $this->model()->select('agentid,sum(total_fee) as total_fee,count(userid) as total_orders,sum(realmoney*(gprice-uprice)) as total_income,sum((wprice-IF(gprice>0,gprice,uprice))*realmoney) as pt_income')->from('orders')->groupby('agentid')->orderby($orderby)->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  71. }
  72. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?kw=' . $kw . '&accid=' . $accid . '&sort=' . $sort . '&by=' . $by . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  73. $acc = $this->model()->select()->from('acc')->fetchAll();
  74. $data = array('title' => '通道分析', 'lists' => $lists, 'total_count' => $total_count, 'pagelist' => $pagelist, 'search' => array('kw' => $kw, 'fdate' => $fdate, 'tdate' => $tdate, 'accid' => $accid), 'by' => $by, 'sort' => $sort, 'acc' => $acc);
  75. $this->put('ordersha.php', $data);
  76. }
  77. }