人人商城

cash.ctrl.php 6.3KB

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