人人商城

credit1.ctrl.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. uni_user_permission_check('stat_credit1');
  8. $dos = array('index', 'chart');
  9. $do = in_array($do, $dos) ? $do : 'index';
  10. load()->model('mc');
  11. $_W['page']['title'] = "积分统计-会员中心";
  12. $starttime = empty($_GPC['time']['start']) ? mktime(0, 0, 0, date('m') , 1, date('Y')) : strtotime($_GPC['time']['start']);
  13. $endtime = empty($_GPC['time']['end']) ? TIMESTAMP : strtotime($_GPC['time']['end']) + 86399;
  14. $num = ($endtime + 1 - $starttime) / 86400;
  15. if($do == 'index') {
  16. $condition = ' WHERE uniacid = :uniacid AND credittype = :credittype AND createtime >= :starttime AND createtime <= :endtime';
  17. $params = array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => $starttime, ':endtime' => $endtime);
  18. $num = intval($_GPC['num']);
  19. if($num > 0) {
  20. if($num == 1) {
  21. $condition .= ' AND num >= 0';
  22. } else {
  23. $condition .= ' AND num <= 0';
  24. }
  25. }
  26. $min = intval($_GPC['min']);
  27. if($min > 0 ) {
  28. $condition .= ' AND abs(num) >= :minnum';
  29. $params[':minnum'] = $min;
  30. }
  31. $max = intval($_GPC['max']);
  32. if($max > 0 ) {
  33. $condition .= ' AND abs(num) <= :maxnum';
  34. $params[':maxnum'] = $max;
  35. }
  36. $user = trim($_GPC['user']);
  37. if(!empty($user)) {
  38. $condition .= ' AND (uid IN (SELECT uid FROM '.tablename('mc_members').' WHERE uniacid = :uniacid AND (realname LIKE :username OR uid = :uid OR mobile LIKE :mobile)))';
  39. $params[':username'] = "%{$user}%";
  40. $params[':uid'] = intval($user);
  41. $params[':mobile'] = "%{$user}%";
  42. }
  43. $psize = 30;
  44. $pindex = max(1, intval($_GPC['page']));
  45. $limit = " ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ", {$psize}";
  46. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_credits_record') . $condition, $params);
  47. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_credits_record') . $condition . $limit, $params);
  48. if(!empty($data)) {
  49. $uids = array();
  50. foreach($data as &$da) {
  51. if(!in_array($da['uid'], $uids)) {
  52. $uids[] = $da['uid'];
  53. }
  54. }
  55. $uids = implode(',', $uids);
  56. $users = pdo_fetchall('SELECT mobile,uid,realname FROM ' . tablename('mc_members') . " WHERE uniacid = :uniacid AND uid IN ($uids)", array(':uniacid' => $_W['uniacid']), 'uid');
  57. }
  58. $pager = pagination($total, $pindex, $psize);
  59. if ($_GPC['export'] != '') {
  60. $exports = pdo_fetchall('SELECT * FROM ' . tablename('mc_credits_record') . $condition . " ORDER BY id DESC", $params);
  61. if(!empty($exports)) {
  62. $uids = array();
  63. foreach($exports as &$da) {
  64. if(!in_array($da['uid'], $uids)) {
  65. $uids[] = $da['uid'];
  66. }
  67. }
  68. $uids = implode(',', $uids);
  69. $users = pdo_fetchall('SELECT mobile,uid,realname FROM ' . tablename('mc_members') . " WHERE uniacid = :uniacid AND uid IN ($uids)", array(':uniacid' => $_W['uniacid']), 'uid');
  70. }
  71. $html = "\xEF\xBB\xBF";
  72. $filter = array(
  73. 'uid' => '会员编号',
  74. 'name' => '姓名',
  75. 'phone' => '手机',
  76. 'type' => '类型',
  77. 'num' => '数量',
  78. 'createtime' => '操作时间 ',
  79. 'remark' => '备注'
  80. );
  81. foreach ($filter as $title) {
  82. $html .= $title . "\t,";
  83. }
  84. $html .= "\n";
  85. foreach ($exports as $k => $v) {
  86. foreach ($filter as $key => $title) {
  87. if ($key == 'name') {
  88. $html .= $users[$v['uid']]['realname']. "\t, ";
  89. } elseif ($key == 'phone') {
  90. $html .= $users[$v['uid']]['mobile']. "\t, ";
  91. }elseif ($key == 'type') {
  92. if ($v['num'] > 0) {
  93. $html .= "充值\t, ";
  94. } else {
  95. $html .= "消费\t, ";
  96. }
  97. }elseif ($key == 'num') {
  98. $html .= abs($v[$key]). "\t, ";
  99. }elseif ($key == 'createtime') {
  100. $html .= date('Y-m-d H:i', $v['createtime']). "\t, ";
  101. }elseif ($key == 'remark') {
  102. $html .= cutstr($v['remark'], '30', '...'). "\t, ";
  103. }else {
  104. $html .= $v[$key]. "\t, ";
  105. }
  106. }
  107. $html .= "\n";
  108. }
  109. header("Content-type:text/csv");
  110. header("Content-Disposition:attachment; filename=全部数据.csv");
  111. echo $html;
  112. exit();
  113. }
  114. }
  115. if($do == 'chart') {
  116. $today_recharge = floatval(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :uniacid AND credittype = :credittype AND num > 0 AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => strtotime(date('Y-m-d')), ':endtime' => TIMESTAMP)));
  117. $today_consume = floatval(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :uniacid AND credittype = :credittype AND num < 0 AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => strtotime(date('Y-m-d')), ':endtime' => TIMESTAMP)));
  118. $total_recharge = floatval(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :uniacid AND credittype = :credittype AND num > 0 AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => $starttime, ':endtime' => $endtime)));
  119. $total_consume = floatval(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :uniacid AND credittype = :credittype AND num < 0 AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => $starttime, ':endtime' => $endtime)));
  120. if($_W['isajax']) {
  121. $stat = array();
  122. for($i = 0; $i < $num; $i++) {
  123. $time = $i * 86400 + $starttime;
  124. $key = date('m-d', $time);
  125. $stat['consume'][$key] = 0;
  126. $stat['recharge'][$key] = 0;
  127. }
  128. $data = pdo_fetchall('SELECT id,num,credittype,createtime,uniacid FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :uniacid AND credittype = :credittype AND createtime >= :starttime AND createtime <= :endtime', array(':uniacid' => $_W['uniacid'], ':credittype' => 'credit1', ':starttime' => $starttime, ':endtime' => $endtime));
  129. if(!empty($data)) {
  130. foreach($data as $da) {
  131. $key = date('m-d', $da['createtime']);
  132. if($da['num'] > 0) {
  133. $stat['recharge'][$key] += $da['num'];
  134. } else {
  135. $stat['consume'][$key] += abs($da['num']);
  136. }
  137. }
  138. }
  139. $out['label'] = array_keys($stat['consume']);
  140. $out['datasets'] = array('recharge' => array_values($stat['recharge']), 'consume' => array_values($stat['consume']));
  141. exit(json_encode($out));
  142. }
  143. }
  144. template('stat/credit1');