人人商城

group.ctrl.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. permission_check_account_user('mc_member_group');
  8. $dos = array('display', 'change_group_level', 'save_group', 'get_group', 'set_default', 'del_group');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. if ($do == 'display') {
  11. $_W['page']['title'] = '会员 - 会员组 ';
  12. $group_level_setting = pdo_get('uni_settings', array('uniacid' => $_W['uniacid']), array('grouplevel'));
  13. $group_level = empty($group_level_setting['grouplevel']) ? 0 : $group_level_setting['grouplevel'];
  14. $group_list = pdo_getall('mc_groups', array('uniacid' => $_W['uniacid']), array(), 'groupid',array(' isdefault DESC', ' credit ASC'));
  15. $group_person_count = pdo_fetchall('SELECT groupid,COUNT(*) AS num FROM ' . tablename('mc_members') . ' WHERE uniacid = :uniacid GROUP BY groupid', array(':uniacid' => $_W['uniacid']), 'groupid');
  16. $default_group = pdo_get('mc_groups', array('uniacid' => $_W['uniacid'], 'isdefault' => 1));
  17. if (empty($default_group)) {
  18. $default_group = array();
  19. }
  20. }
  21. if ($do == 'change_group_level') {
  22. $group_level = intval($_GPC['group_level']);
  23. pdo_update('uni_settings', array('grouplevel' => $group_level), array('uniacid' => $_W['uniacid']));
  24. cache_delete(cache_system_key('unisetting', array('uniacid' =>$_W['uniacid'])));
  25. iajax(0, '');
  26. }
  27. if ($do == 'save_group') {
  28. $group = $_GPC['group'];
  29. if (empty($group)) {
  30. iajax(1, '编辑失败', '');
  31. }
  32. $data = array(
  33. 'title' => $group['title'],
  34. 'credit' => $group['credit']
  35. );
  36. if (empty($data['title'])) {
  37. iajax(1, '请填写会员组名称', '');
  38. }
  39. if (!empty($group['groupid'])) {
  40. pdo_update('mc_groups', $data, array('groupid' => $group['groupid']));
  41. iajax(2, '修改成功', '');
  42. } else {
  43. $data['uniacid'] = $_W['uniacid'];
  44. $default_group = pdo_get('mc_groups', array('uniacid' => $_W['uniacid'], 'isdefault' => 1));
  45. $data['isdefault'] = empty($default_group) ? 1 : 0;
  46. pdo_insert('mc_groups', $data);
  47. $data['groupid'] = pdo_insertid();
  48. iajax(3, $data, '');
  49. }
  50. }
  51. if ($do == 'get_group') {
  52. $group_id = intval($_GPC['group_id']);
  53. if (empty($group_id)) {
  54. $data = array(
  55. 'title' => '',
  56. 'is_default' => 0,
  57. 'credit' => 0
  58. );
  59. iajax(0, $data, '');
  60. }
  61. $group_info = pdo_get('mc_groups', array('groupid' => $group_id));
  62. if (empty($group_info)) {
  63. iajax(1, '会员组不存在', '');
  64. } else {
  65. iajax(0, $group_info, '');
  66. }
  67. }
  68. if ($do == 'set_default') {
  69. $group_id = intval($_GPC['group_id']);
  70. pdo_update('mc_groups', array('isdefault' => 0), array('uniacid' => $_W['uniacid']));
  71. pdo_update('mc_groups', array('isdefault' => 1), array('groupid' => $group_id));
  72. iajax(0, '');
  73. }
  74. if ($do == 'del_group') {
  75. $group_id = intval($_GPC['group_id']);
  76. pdo_delete('mc_groups', array('groupid' => $group_id));
  77. iajax(0, '');
  78. }
  79. template('mc/group');