人人商城

paycenter.ctrl.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_credit2');
  8. $dos = array('index', 'chart', 'detail');
  9. $do = in_array($do, $dos) ? $do : 'index';
  10. load()->model('mc');
  11. $_W['page']['title'] = "收银台收银统计-统计中心";
  12. load()->model('paycenter');
  13. load()->model('mc');
  14. if($do == 'index') {
  15. $clerks = pdo_getall('activity_clerks', array('uniacid' => $_W['uniacid']), array('id', 'name'), 'id');
  16. $stores = pdo_getall('activity_stores', array('uniacid' => $_W['uniacid']), array('id', 'business_name', 'branch_name'), 'id');
  17. $pindex = max(1, intval($_GPC['page']));
  18. $psize = 20;
  19. $condition = ' WHERE uniacid = :uniacid AND status = 1';
  20. $params = array(':uniacid' => $_W['uniacid']);
  21. $clerk_id = intval($_GPC['clerk_id']);
  22. if (!empty($clerk_id)) {
  23. $condition .= ' AND clerk_id = :clerk_id';
  24. $params[':clerk_id'] = $clerk_id;
  25. }
  26. $store_id = trim($_GPC['store_id']);
  27. if (!empty($store_id)) {
  28. $condition .= ' AND store_id = :store_id';
  29. $params[':store_id'] = $store_id;
  30. }
  31. $limit = " ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ", {$psize}";
  32. $total = pdo_fetchcolumn('SELECT COUNT(*) FROM' . tablename('paycenter_order') . $condition, $params);
  33. $orders = pdo_fetchall('SELECT * FROM ' . tablename('paycenter_order') . $condition . $limit, $params);
  34. $pager = pagination($total, $pindex, $psize);
  35. $status = paycenter_order_status();
  36. if(!empty($orders)) {
  37. foreach ($orders as &$value) {
  38. $operator = mc_account_change_operator($value['clerk_type'], $value['store_id'], $value['clerk_id']);
  39. $value['clerk_cn'] = $operator['clerk_cn'];
  40. $value['store_cn'] = $operator['store_cn'];
  41. }
  42. }
  43. }
  44. if($do == 'detail') {
  45. if($_W['isajax']) {
  46. $id = intval($_GPC['id']);
  47. $order = pdo_get('paycenter_order', array('uniacid' => $_W['uniacid'], 'id' => $id));
  48. if(empty($order)) {
  49. $info = '订单不存在';
  50. } elseif($order['status'] == 0) {
  51. $info = '订单尚未支付';
  52. } else {
  53. $types = paycenter_order_types();
  54. $trade_types = paycenter_order_trade_types();
  55. $status = paycenter_order_status();
  56. $info = template('paycenter/payinfo', TEMPLATE_FETCH);
  57. }
  58. message(error(0, $info), '', 'ajax');
  59. }
  60. }
  61. if($do == 'chart') {
  62. $today_starttime = strtotime(date('Y-m-d'));
  63. $today_endtime = $today_starttime + 86400;
  64. $yesterday_starttime = $today_starttime - 86400;
  65. $yesterday_endtime = $today_starttime;
  66. $month_starttime = date('Y-m-01', strtotime(date("Y-m-d")));
  67. $month_endtime = strtotime("$month_starttime + 1month - 1day");
  68. $today_fee = floatval(pdo_fetchcolumn('SELECT SUM(final_fee) FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $today_starttime, ':endtime' => $today_endtime)));
  69. $yesterday_fee = floatval(pdo_fetchcolumn('SELECT SUM(final_fee) FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $yesterday_starttime, ':endtime' => $yesterday_endtime)));
  70. $month_fee = floatval(pdo_fetchcolumn('SELECT SUM(final_fee) FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => strtotime($month_starttime), ':endtime' => $month_endtime)));
  71. $type = trim($_GPC['type']);
  72. if($_W['isajax']) {
  73. if($type == 'date') {
  74. $now = strtotime(date('Y-m-d'));
  75. $starttime = empty($_GPC['start']) ? $now - 30*86400 : strtotime($_GPC['start']);
  76. $endtime = empty($_GPC['end']) ? TIMESTAMP : strtotime($_GPC['end']) + 86399;
  77. $num = ($endtime + 1 - $starttime) / 86400;
  78. $stat = array(
  79. 'flow1' => array()
  80. );
  81. for($i = 0; $i < $num; $i++) {
  82. $time = $i * 86400 + $starttime;
  83. $key = date('m-d', $time);
  84. $stat['flow1'][$key] = 0;
  85. }
  86. $data = pdo_fetchall('SELECT id, final_fee, paytime, uniacid FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $starttime, ':endtime' => $endtime));
  87. if(!empty($data)) {
  88. foreach($data as $da) {
  89. $key = date('m-d', $da['paytime']);
  90. $stat['flow1'][$key] += $da['final_fee'];
  91. }
  92. }
  93. $total = floatval(pdo_fetchcolumn('SELECT SUM(final_fee) FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $starttime, ':endtime' => $endtime)));
  94. $out['total'] = $total;
  95. $out['label'] = array_keys($stat['flow1']);
  96. $out['datasets']['flow1'] = array_values($stat['flow1']);
  97. exit(json_encode($out));
  98. } elseif($type == 'month') {
  99. $now = mktime(0,0,0,date('m'),date('t'),date('Y'));
  100. $end = mktime(23,59,59,date('m'),date('t'),date('Y'));
  101. $starttime = empty($_GPC['start']) ? strtotime('-6months', $now) : strtotime($_GPC['start']);
  102. $endtime = empty($_GPC['end']) ? $end : strtotime($_GPC['end']) + date('t', strtotime($_GPC['end'])) * 86400 - 1;
  103. $num = ($endtime + 1 - $starttime) / 86400;
  104. $stat = array(
  105. 'flow1' => array()
  106. );
  107. for($i = 0; $i < $num; $i++) {
  108. $time = $i * 86400 + $starttime;
  109. $key = date('Y-m', $time);
  110. $stat['flow1'][$key] = 0;
  111. }
  112. $data = pdo_fetchall('SELECT id, final_fee, paytime, uniacid FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $starttime, ':endtime' => $endtime));
  113. if(!empty($data)) {
  114. foreach($data as $da) {
  115. $key = date('Y-m', $da['paytime']);
  116. $stat['flow1'][$key] += $da['final_fee'];
  117. }
  118. }
  119. $total = floatval(pdo_fetchcolumn('SELECT SUM(final_fee) FROM ' . tablename('paycenter_order') . ' WHERE uniacid = :uniacid AND status = 1 AND paytime >= :starttime AND paytime <= :endtime', array(':uniacid' => $_W['uniacid'], ':starttime' => $starttime, ':endtime' => $endtime)));
  120. $out['total'] = $total;
  121. $out['label'] = array_keys($stat['flow1']);
  122. $out['datasets']['flow1'] = array_values($stat['flow1']);
  123. exit(json_encode($out));
  124. }
  125. }
  126. }
  127. template('stat/paycenter');