User_group_adminAction.class.php 6.0 KB

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