User_group_adminAction.class.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_group_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_user_group($where);
  22. foreach($list as &$ls){
  23. $condition = "where uid='{$_SESSION['user_infos']['id']}' and group_name='{$ls['name']}'";
  24. $count = $admin->select_usergroup_count($condition);
  25. $count = empty($count) ? 0 : $count;
  26. $ls['count'] = $count;
  27. $ls['add_time'] = date('Y-m-d H:i:s',$ls['add_time']);
  28. $ls['update_time'] = date('Y-m-d H:i:s',$ls['update_time']);
  29. }
  30. $this->assign('info',$info);
  31. $this->assign('error',$error);
  32. $this->assign('list',$list);
  33. $this->assign('uname',$uname);
  34. $this->display('index.html');
  35. }
  36. function add(){
  37. $admin = new AdvertAdminAction();
  38. $data['uid'] = $_SESSION['user_infos']['id'];
  39. $data['name'] = trim($_POST['name']);
  40. $data['add_time'] = time();
  41. $data['update_time'] = time();
  42. if($_POST['name']){
  43. if(!empty($_POST['name']) ){
  44. $is_exist = $admin->select_group_byName($data['name'],$data['uid']);
  45. if(!empty($is_exist)){
  46. $info = "该客户分组名已存在";
  47. header("Location:/?a=user_group_admin&m=index&info=$info");
  48. exit();
  49. }else{
  50. $add = $admin->add_user_group($data);
  51. if($add){
  52. $info = "添加客户分组成功";
  53. header("Location:/?a=user_group_admin&m=index&info=$info");
  54. exit();
  55. }else{
  56. $info = "添加客户分组失败";
  57. }
  58. }
  59. }else{
  60. $info = "客户分组名称不能为空";
  61. }
  62. }
  63. $this->assign('info',$info);
  64. $this->display('add.html');
  65. }
  66. function update(){
  67. $admin = new AdvertAdminAction();
  68. $id = $_REQUEST['id'];
  69. $uid = $_SESSION['user_infos']['id'];
  70. $one_info = $admin->select_one_user_group($id,$uid);
  71. $data['name'] = trim($_POST['name']);
  72. $data['update_time'] = time();
  73. if($_POST['name']){
  74. if(!empty($_POST['name'])){
  75. $is_exist = $admin->select_group_byName($data['name'],$uid);
  76. if(!empty($is_exist) && $one_info['name']!=$data['name']){
  77. $info = "修改客户分组失败:分组名已存在";
  78. header("Location:/?a=user_group_admin&m=index&info=$info");
  79. exit();
  80. }else{
  81. $update = $admin->update_user_group($data, $id,$uid);
  82. if($update){
  83. $info = "修改客户分组成功";
  84. header("Location:/?a=user_group_admin&m=index&info=$info");
  85. exit();
  86. }else{
  87. $info = "修改失败";
  88. }
  89. }
  90. }else{
  91. $info = "客户分组不能为空";
  92. }
  93. }
  94. $one_info = $admin->select_one_user_group($id,$uid);
  95. $this->assign('id',$id);
  96. $this->assign('one_info',$one_info);
  97. $this->assign('info',$info);
  98. $this->display('update.html');
  99. }
  100. //客户分组详情
  101. public function group_list(){
  102. require_once (ONU_ROOT . "frame/Page.class.php");
  103. $admin = new AdvertAdminAction();
  104. $uid = $_SESSION['user_infos']['id'];
  105. $info = $_REQUEST['info'];
  106. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  107. $pageSize = 20;
  108. $n = ($page-1)*$pageSize;
  109. $limit = " $n,$pageSize";
  110. $user_group_id = $_REQUEST['id'];
  111. $group_name = $_REQUEST['gname'];
  112. $where = " where uid='$uid' and group_name='$group_name' ";
  113. $username = $_REQUEST['username'];
  114. if(!empty($username)){
  115. $where.=" and uname='$username'";
  116. }
  117. $all_total = $admin->select_usergroup_count($where);
  118. $all_total = $all_total['count'];
  119. $p = new Page($all_total,$pageSize);
  120. $pp = $p->fpage();
  121. //查询客户分组里的所有客户
  122. $order_list = $admin->select_usergroup_info($where,$limit);
  123. //分组名
  124. $user_group_name = $admin->select_user_group("where id='$user_group_id'");
  125. $user_group_name = $user_group_name[0]['name'];
  126. $this->assign('info',$info);
  127. $this->assign('user_group_name',$user_group_name);
  128. $this->assign('user_group_id',$user_group_id);
  129. $this->assign('page',$page);
  130. $this->assign('list',$order_list);
  131. $this->assign("show",$pp);
  132. $this->assign("username",$username);
  133. $this->display('group_list.html');
  134. }
  135. public function delete(){
  136. $admin = new AdvertAdminAction();
  137. $id = $_REQUEST['id'];
  138. $uid = $_SESSION['user_infos']['id'];
  139. $group_name = trim($_REQUEST['group_name']);
  140. if(!empty($id)){
  141. $where = " uid = '$uid' and id='$id'";
  142. $delete = $admin->deleteUserGroupMsg($where);
  143. //删除对应的客户信息
  144. $delete_c = $admin->deleteCustomerByGroup($group_name,$uid);
  145. $info = "删除客户分组成功";
  146. }else{
  147. $error = "删除客户分组失败";
  148. }
  149. header("Location:/?a=user_group_admin&m=index&info=$info&error=$error");
  150. exit();
  151. }
  152. //批量删除用户分组
  153. public function batch_delete(){
  154. $admin = new AdvertAdminAction();
  155. $uid = $_SESSION['user_infos']['id'];
  156. $id_array = $_POST['id_array'];
  157. $count = count($id_array);
  158. if($count==1){
  159. $id = $id_array[0];
  160. $where = " uid = '$uid' and id='$id'";
  161. $one_info = $admin->select_one_user_group($id,$uid);
  162. $delete = $admin->deleteUserGroupMsg($where);
  163. $group_name = $one_info['name'];
  164. //删除对应的客户信息
  165. $delete_c = $admin->deleteCustomerByGroup($group_name,$uid);
  166. $info = "删除成功";
  167. header("Location:/?a=user_group_admin&m=index&info=$info");
  168. exit();
  169. }else if($count>1){
  170. $in_array = implode(',',$id_array);
  171. $group_name_list = $admin->select_batch_user_group($in_array,$uid);
  172. foreach($group_name_list as $nlist){
  173. $delete_c = $admin->deleteCustomerByGroup($nlist['name'],$uid);
  174. }
  175. $delete = $admin->deleteBatchUserGroup($in_array,$uid);
  176. $info = "删除成功";
  177. header("Location:/?a=user_group_admin&m=index&info=$info");
  178. exit();
  179. }
  180. }
  181. //end
  182. }
  183. ?>