User_smsgroup_adminAction.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * 客户分组
  4. */
  5. require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');
  6. require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');
  7. class User_smsgroup_adminAction extends Action{
  8. public function __construct(){
  9. parent::__construct();
  10. if(empty($_SESSION['mds_user'])){
  11. header("Location:/?a=index&m=admin_login");
  12. exit();
  13. }
  14. }
  15. function index(){
  16. $admin = new AdvertAdminAction();
  17. $where = "where uid='{$_SESSION['user_infos']['id']}'";
  18. $uname = $_SESSION['user_infos']['uname'];
  19. $info = $_REQUEST['info'];
  20. $error = $_REQUEST['error'];
  21. $list = $admin->select_sms_user_group($where);
  22. foreach($list as &$item) {
  23. $condition = "where uid='{$_SESSION['user_infos']['id']}' and group_name='{$item['name']}'";
  24. $count = $admin->selectSmsCustomerCount($condition);
  25. $count = empty($count) ? 0 : $count;
  26. $item['count'] = $count;
  27. }
  28. $this->assign('info',$info);
  29. $this->assign('error',$error);
  30. $this->assign('list',$list);
  31. $this->assign('uname',$uname);
  32. $this->display('index.html');
  33. }
  34. function add(){
  35. $admin = new AdvertAdminAction();
  36. $data['uid'] = $_SESSION['user_infos']['id'];
  37. $data['name'] = trim($_POST['name']);
  38. if(!empty($_POST['name']) ){
  39. $is_exist = $admin->select_usergroup_byName($data['name'],$data['uid']);
  40. if(!empty($is_exist)){
  41. $info = "该客户分组名已存在";
  42. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  43. exit();
  44. }else{
  45. $add = $admin->add_sms_user_group($data);
  46. if($add){
  47. $info = "添加客户分组成功";
  48. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  49. exit();
  50. }else{
  51. $info = "添加客户分组失败";
  52. }
  53. }
  54. }else{
  55. $info = "客户分组名称不能为空";
  56. }
  57. $this->assign('info',$info);
  58. $this->display('add.html');
  59. }
  60. function update(){
  61. $admin = new AdvertAdminAction();
  62. $id = $_REQUEST['id'];
  63. $uid = $_SESSION['user_infos']['id'];
  64. $one_info = $admin->select_usergroup_byId($id,$uid);
  65. $data['name'] = trim($_POST['name']);
  66. $data['position'] = trim($_POST['position']);
  67. if($_POST['name']){
  68. if(!empty($_POST['name'])){
  69. $is_exist = $admin->select_usergroup_byName($data['name'],$uid);
  70. if(!empty($is_exist) && $one_info['name']!=$data['name']){
  71. $info = "修改客户分组失败:分组名已存在";
  72. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  73. exit();
  74. }else{
  75. $update = $admin->update_sms_user_group($data, $id,$uid);
  76. if($update){
  77. $info = "修改客户分组成功";
  78. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  79. exit();
  80. }else{
  81. $info = "修改失败";
  82. }
  83. }
  84. }else{
  85. $info = "客户分组不能为空";
  86. }
  87. }
  88. $one_info = $admin->select_usergroup_byId($id,$uid);
  89. $this->assign('id',$id);
  90. $this->assign('one_info',$one_info);
  91. $this->assign('info',$info);
  92. $this->display('update.html');
  93. }
  94. public function delete(){
  95. $admin = new AdvertAdminAction();
  96. $id = $_REQUEST['id'];
  97. $uid = $_SESSION['user_infos']['id'];
  98. $group_name = trim($_REQUEST['group_name']);
  99. if(!empty($id)){
  100. $where = " uid = '$uid' and id='$id'";
  101. $delete = $admin->deleteSmsUserGroupMsg($where);
  102. //删除对应的客户信息
  103. $delete_c = $admin->deleteSmsCustomerByGroup($group_name, $uid);
  104. $info = "删除客户分组成功";
  105. }else{
  106. $error = "删除客户分组失败";
  107. }
  108. header("Location:/?a=user_smsgroup_admin&m=index&info=$info&error=$error");
  109. exit();
  110. }
  111. //批量删除用户分组
  112. public function batch_delete(){
  113. $admin = new AdvertAdminAction();
  114. $uid = $_SESSION['user_infos']['id'];
  115. $id_array = $_POST['id_array'];
  116. $count = count($id_array);
  117. if($count==1){
  118. $id = $id_array[0];
  119. $where = " uid = '$uid' and id='$id'";
  120. $one_info = $admin->select_usergroup_byId($id, $uid);
  121. $delete = $admin->deleteSmsUserGroupMsg($where);
  122. $delete_c = $admin->deleteSmsCustomerByGroup($one_info['name'], $uid);
  123. $info = "删除成功";
  124. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  125. exit();
  126. }else if($count>1){
  127. $in_array = implode(',',$id_array);
  128. $group_name_list = $admin->select_batch_sms_group($in_array, $uid);
  129. foreach($group_name_list as $nlist){
  130. $delete_c = $admin->deleteSmsCustomerByGroup($nlist['name'], $uid);
  131. }
  132. $delete = $admin->deleteBatchSmsUserGroup($in_array,$uid);
  133. $info = "删除成功";
  134. header("Location:/?a=user_smsgroup_admin&m=index&info=$info");
  135. exit();
  136. }
  137. }
  138. //end
  139. }
  140. ?>