人人商城

credit2.ctrl.php 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. load()->model('mc');
  8. uni_user_permission_check('stat_credit2');
  9. $dos = array('index', 'chart');
  10. $do = in_array($do, $dos) ? $do : 'index';
  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' => 'credit2', ':starttime' => $starttime, ':endtime' => $endtime);
  18. if(intval($_W['user']['clerk_type']) == ACCOUNT_OPERATE_CLERK) {
  19. $condition .= ' AND clerk_id = :clerk_id';
  20. $params[':clerk_id'] = $_W['user']['clerk_id'];
  21. }
  22. $num = intval($_GPC['num']);
  23. if($num > 0) {
  24. if($num == 1) {
  25. $condition .= ' AND num >= 0';
  26. } else {
  27. $condition .= ' AND num <= 0';
  28. }
  29. }
  30. $min = intval($_GPC['min']);
  31. if($min > 0 ) {
  32. $condition .= ' AND abs(num) >= :minnum';
  33. $params[':minnum'] = $min;
  34. }
  35. $max = intval($_GPC['max']);
  36. if($max > 0 ) {
  37. $condition .= ' AND abs(num) <= :maxnum';
  38. $params[':maxnum'] = $max;
  39. }
  40. $user = trim($_GPC['user']);
  41. if(!empty($user)) {
  42. $condition .= ' AND (uid IN (SELECT uid FROM '.tablename('mc_members').' WHERE uniacid = :uniacid AND (realname LIKE :username OR uid = :uid OR mobile LIKE :mobile)))';
  43. $params[':username'] = "%{$user}%";
  44. $params[':uid'] = intval($user);
  45. $params[':mobile'] = "%{$user}%";
  46. }
  47. $psize = 30;
  48. $pindex = max(1, intval($_GPC['page']));
  49. $limit = " ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ", {$psize}";
  50. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('mc_credits_record') . $condition, $params);
  51. $data = pdo_fetchall('SELECT * FROM ' . tablename('mc_credits_record') . $condition . $limit, $params);
  52. if(!empty($data)) {
  53. $uids = array();
  54. foreach($data as &$da) {
  55. if(!in_array($da['uid'], $uids)) {
  56. $uids[] = $da['uid'];
  57. }
  58. }
  59. $uids = implode(',', $uids);
  60. $users = pdo_fetchall('SELECT mobile,uid,realname FROM ' . tablename('mc_members') . " WHERE uniacid = :uniacid AND uid IN ($uids)", array(':uniacid' => $_W['uniacid']), 'uid');
  61. }
  62. $pager = pagination($total, $pindex, $psize);
  63. if ($_GPC['export'] != '') {
  64. $exports = pdo_fetchall('SELECT * FROM '.tablename('mc_credits_record'). $condition . ' ORDER BY id DESC', $params);
  65. if(!empty($exports)) {
  66. load()->model('clerk');
  67. $uids = array();
  68. foreach($exports as &$da) {
  69. if(!in_array($da['uid'], $uids)) {
  70. $uids[] = $da['uid'];
  71. }
  72. }
  73. $uids = implode(',', $uids);
  74. $user = pdo_fetchall('SELECT mobile,uid,realname FROM ' . tablename('mc_members') . " WHERE uniacid = :uniacid AND uid IN ($uids)", array(':uniacid' => $_W['uniacid']), 'uid');
  75. }
  76. $html = "\xEF\xBB\xBF";
  77. $filter = array(
  78. 'uid' => '会员编号',
  79. 'name' => '姓名',
  80. 'phone' => '手机',
  81. 'type' => '类型',
  82. 'num' => '数量',
  83. 'createtime' => '操作时间 ',
  84. 'remark' => '备注'
  85. );
  86. foreach ($filter as $title) {
  87. $html .= $title . "\t,";
  88. }
  89. $html .= "\n";
  90. foreach ($exports as $k => $v) {
  91. foreach ($filter as $key => $title) {
  92. if ($key == 'name') {
  93. $html .= $user[$v['uid']]['realname']. "\t, ";
  94. } elseif ($key == 'phone') {
  95. $html .= $user[$v['uid']]['mobile']. "\t, ";
  96. }elseif ($key == 'type') {
  97. if ($v['num'] > 0) {
  98. $html .= "充值\t, ";
  99. } else {
  100. $html .= "消费\t, ";
  101. }
  102. }elseif ($key == 'num') {
  103. $html .= abs($v[$key]). "\t, ";
  104. }elseif ($key == 'createtime') {
  105. $html .= date('Y-m-d H:i', $v['createtime']). "\t, ";
  106. }elseif ($key == 'remark') {
  107. $html .= cutstr($v['remark'], '30', '...'). "\t, ";
  108. }else {
  109. $html .= $v[$key]. "\t, ";
  110. }
  111. }
  112. $html .= "\n";
  113. }
  114. header("Content-type:text/csv");
  115. header("Content-Disposition:attachment; filename=全部数据.csv");
  116. echo $html;
  117. exit();
  118. }
  119. }
  120. if($do == 'chart') {
  121. $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' => 'credit2', ':starttime' => strtotime(date('Y-m-d')), ':endtime' => TIMESTAMP)));
  122. $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' => 'credit2', ':starttime' => strtotime(date('Y-m-d')), ':endtime' => TIMESTAMP)));
  123. $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' => 'credit2', ':starttime' => $starttime, ':endtime' => $endtime)));
  124. $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' => 'credit2', ':starttime' => $starttime, ':endtime' => $endtime)));
  125. if($_W['isajax']) {
  126. $stat = array();
  127. for($i = 0; $i < $num; $i++) {
  128. $time = $i * 86400 + $starttime;
  129. $key = date('m-d', $time);
  130. $stat['consume'][$key] = 0;
  131. $stat['recharge'][$key] = 0;
  132. }
  133. $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' => 'credit2', ':starttime' => $starttime, ':endtime' => $endtime));
  134. if(!empty($data)) {
  135. foreach($data as $da) {
  136. $key = date('m-d', $da['createtime']);
  137. if($da['num'] > 0) {
  138. $stat['recharge'][$key] += $da['num'];
  139. } else {
  140. $stat['consume'][$key] += abs($da['num']);
  141. }
  142. }
  143. }
  144. $out['label'] = array_keys($stat['consume']);
  145. $out['datasets'] = array('recharge' => array_values($stat['recharge']), 'consume' => array_values($stat['consume']));
  146. exit(json_encode($out));
  147. }
  148. }
  149. template('stat/credit2');