creditmanage.ctrl.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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('mc_creditmanage');
  8. $_W['page']['title'] = '积分列表 - 会员积分管理 - 会员中心';
  9. $dos = array('display', 'manage', 'modal', 'credit_record', 'stat');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. $creditnames = uni_setting($_W['uniacid'], array('creditnames'));
  12. $creditnames = $creditnames['creditnames'];
  13. if($creditnames) {
  14. foreach($creditnames as $index => $creditname) {
  15. if(empty($creditname['enabled'])) {
  16. unset($creditnames[$index]);
  17. }
  18. }
  19. $select_credit = implode(', ', array_keys($creditnames));
  20. } else {
  21. $select_credit = '';
  22. }
  23. if($do == 'display') {
  24. $where = ' WHERE uniacid = :uniacid ';
  25. $params = array(':uniacid' => $_W['uniacid']);
  26. $type = intval($_GPC['type']);
  27. if(!$type) {
  28. $type = intval($_GPC['cookietype']);
  29. } else {
  30. isetcookie('cookietype', $type, 86400 * 7);
  31. }
  32. $keyword = trim($_GPC['keyword']);
  33. if($type == 1 || $type == '') {
  34. $keyword = intval($_GPC['keyword']);
  35. if ($keyword > 0) {
  36. $where .= ' AND uid = :uid';
  37. $params[':uid'] = $keyword;
  38. }
  39. } elseif($type == 2) {
  40. if ($keyword) {
  41. $where .= " AND mobile LIKE :mobile";
  42. $params[':mobile'] = "%{$keyword}%";
  43. }
  44. } elseif($type == 4) {
  45. if ($keyword) {
  46. $where .= " AND realname LIKE :realname";
  47. $params[':realname'] = "%{$keyword}%";
  48. }
  49. } elseif($type == 3) {
  50. if ($keyword) {
  51. $where .= " AND nickname LIKE :nickname";
  52. $params[':nickname'] = "%{$keyword}%";
  53. }
  54. }
  55. if (!empty($_GPC['minimal'])) {
  56. $where .= ' AND `credit1` > :minimal';
  57. $params[':minimal'] = sprintf('%.2f', $_GPC['minimal']);
  58. }
  59. if (!empty($_GPC['maximal'])) {
  60. $where .= ' AND `credit1` < :maximal';
  61. $params[':maximal'] = sprintf('%.2f', $_GPC['maximal']);
  62. }
  63. $pindex = max(1, intval($_GPC['page']));
  64. $psize = 20;
  65. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('mc_members') . $where, $params);
  66. $list = pdo_fetchall("SELECT uid, uniacid, email, nickname, realname, mobile, {$select_credit} FROM " . tablename('mc_members') . $where . ' ORDER BY uid DESC LIMIT ' . ($pindex - 1) * $psize .',' . $psize, $params);
  67. $pager = pagination($total, $pindex, $psize);
  68. if(count($list) == 1 && $list[0]['uid'] && !empty($keyword)) {
  69. $status = 1;
  70. $uid = $list[0]['uid'];
  71. } else {
  72. foreach($list as &$li) {
  73. if(empty($li['email']) || (!empty($li['email']) && substr($li['email'], -6) == 'we7.cc' && strlen($li['email']) == 39)) {
  74. $li['email'] = '未完善';
  75. }
  76. }
  77. $status = 0;
  78. }
  79. }
  80. if($do == 'manage') {
  81. load()->model('mc');
  82. $clerk = pdo_get('activity_clerks', array('uniacid' => $_W['uniacid'], 'password' => trim($_GPC['password'])));
  83. if(empty($clerk)) {
  84. message('店员密码错误');
  85. }
  86. $uid = intval($_GPC['uid']);
  87. if($uid) {
  88. foreach($creditnames as $index => $creditname) {
  89. if(($_GPC[$index . '_type'] == 1 || $_GPC[$index . '_type'] == 2) && $_GPC[$index . '_value']) {
  90. $value = $_GPC[$index . '_type'] == 1 ? $_GPC[$index . '_value'] : - $_GPC[$index . '_value'];
  91. $return = mc_credit_update($uid, $index, $value, array($_W['uid'], trim($_GPC['remark']), 'system', $clerk['id'], $clerk['store_id']));
  92. if(is_error($return)) {
  93. message($return['message']);
  94. }
  95. $openid = pdo_fetchcolumn('SELECT openid FROM ' . tablename('mc_mapping_fans') . ' WHERE acid = :acid AND uid = :uid', array(':acid' => $_W['acid'], ':uid' => $uid));
  96. if(!empty($openid)) {
  97. if($index == 'credit1') {
  98. mc_notice_credit1($openid, $uid, $value, '管理员后台操作积分');
  99. }
  100. if($index == 'credit2') {
  101. if($value > 0) {
  102. mc_notice_recharge($openid, $uid, $value, '', "管理员后台操作余额,增加{$value}余额");
  103. } else {
  104. mc_notice_credit2($openid, $uid, $value, 0, "管理员后台操作余额,减少{$value}余额");
  105. }
  106. }
  107. }
  108. } else {
  109. continue;
  110. }
  111. }
  112. message('会员积分操作成功', url('mc/creditmanage/display'));
  113. } else {
  114. message('未找到指定用户', url('mc/creditmanage/display'), 'error');
  115. }
  116. }
  117. if($do == 'modal') {
  118. if($_W['isajax']) {
  119. $uid = intval($_GPC['uid']);
  120. $data = pdo_fetch("SELECT uid, nickname, realname, email, mobile, uniacid, {$select_credit} FROM " . tablename('mc_members') . ' WHERE uid = :uid AND uniacid = :uniacid', array(':uniacid' => $_W['uniacid'], ':uid' => $uid));
  121. if(empty($data['email']) || (!empty($data['email']) && substr($data['email'], -6) == 'we7.cc' && strlen($data['email']) == 39)) {
  122. $data['email'] = '未完善';
  123. }
  124. $data ? template('mc/modal') : exit('dataerr');
  125. exit();
  126. }
  127. }
  128. if($do == 'credit_record') {
  129. $uid = intval($_GPC['uid']);
  130. $credits = array_keys($creditnames);
  131. $type = trim($_GPC['type']) ? trim($_GPC['type']) : $credits[0];
  132. $pindex = max(1, intval($_GPC['page']));
  133. $psize = 50;
  134. $total = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('mc_credits_record') . ' WHERE uid = :uid AND uniacid = :uniacid AND credittype = :credittype ', array(':uniacid' => $_W['uniacid'], ':uid' => $uid, ':credittype' => $type));
  135. $data = pdo_fetchall("SELECT r.*, u.username FROM " . tablename('mc_credits_record') . ' AS r LEFT JOIN ' .tablename('users') . ' AS u ON r.operator = u.uid ' . ' WHERE r.uid = :uid AND r.uniacid = :uniacid AND r.credittype = :credittype ORDER BY id DESC LIMIT ' . ($pindex - 1) * $psize .',' . $psize, array(':uniacid' => $_W['uniacid'], ':uid' => $uid, ':credittype' => $type));
  136. $pager = pagination($total, $pindex, $psize);
  137. $modules = pdo_getall('modules', array('issystem' => 0), array('title', 'name'), 'name');
  138. $modules['card'] = array('title' => '会员卡', 'name' => 'card');
  139. template('mc/credit_record');
  140. exit;
  141. }
  142. if($do == 'stat') {
  143. $uid = intval($_GPC['uid']);
  144. $credits = array_keys($creditnames);
  145. $count = 5 - count($creditnames);
  146. for($i = $count; $i > 0; $i--) {
  147. $creditnames[] = array('title' => '***');
  148. }
  149. $type = intval($_GPC['type']);
  150. $starttime = strtotime('-7 day');
  151. $endtime = strtotime('7 day');
  152. if($type == 1) {
  153. $starttime = strtotime(date('Y-m-d'));
  154. $endtime = TIMESTAMP;
  155. } elseif($type == -1) {
  156. $starttime = strtotime('-1 day');
  157. $endtime = strtotime(date('Y-m-d'));
  158. } else{
  159. $starttime = strtotime($_GPC['datelimit']['start']);
  160. $endtime = strtotime($_GPC['datelimit']['end']) + 86399;
  161. }
  162. if(!empty($credits)) {
  163. $data = array();
  164. foreach($credits as $li) {
  165. $data[$li]['add'] = round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :id AND uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num > 0', array(':id' => $_W['uniacid'], ':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $li)),2);
  166. $data[$li]['del'] = abs(round(pdo_fetchcolumn('SELECT SUM(num) FROM ' . tablename('mc_credits_record') . ' WHERE uniacid = :id AND uid = :uid AND createtime > :start AND createtime < :end AND credittype = :type AND num < 0', array(':id' => $_W['uniacid'], ':uid' => $uid, ':start' => $starttime, ':end' => $endtime, ':type' => $li)),2));
  167. $data[$li]['end'] = $data[$key]['add'] - $data[$key]['del'];
  168. }
  169. }
  170. template('mc/credit_record');
  171. exit();
  172. }
  173. template('mc/creditmanage');