User_group_adminAction.class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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['position'] = trim($_POST['position']);
  74. $data['update_time'] = time();
  75. if($_POST['name']){
  76. if(!empty($_POST['name'])){
  77. $is_exist = $admin->select_group_byName($data['name'],$uid);
  78. if(!empty($is_exist) && $one_info['name']!=$data['name']){
  79. $info = "修改客户分组失败:分组名已存在";
  80. header("Location:/?a=user_group_admin&m=index&info=$info");
  81. exit();
  82. }else{
  83. $update = $admin->update_user_group($data, $id,$uid);
  84. if($update){
  85. $info = "修改客户分组成功";
  86. header("Location:/?a=user_group_admin&m=index&info=$info");
  87. exit();
  88. }else{
  89. $info = "修改失败";
  90. }
  91. }
  92. }else{
  93. $info = "客户分组不能为空";
  94. }
  95. }
  96. $one_info = $admin->select_one_user_group($id,$uid);
  97. $this->assign('id',$id);
  98. $this->assign('one_info',$one_info);
  99. $this->assign('info',$info);
  100. $this->display('update.html');
  101. }
  102. //客户分组详情
  103. public function group_list(){
  104. require_once (ONU_ROOT . "frame/Page.class.php");
  105. $admin = new AdvertAdminAction();
  106. $uid = $_SESSION['user_infos']['id'];
  107. $info = $_REQUEST['info'];
  108. $page = $_REQUEST['page']?$_REQUEST['page']:1;
  109. $pageSize = 20;
  110. $n = ($page-1)*$pageSize;
  111. $limit = " $n,$pageSize";
  112. $user_group_id = $_REQUEST['id'];
  113. $group_name = $_REQUEST['gname'];
  114. $where = " where uid='$uid' and group_name='$group_name' ";
  115. $username = $_REQUEST['username'];
  116. if(!empty($username)){
  117. $where.=" and uname='$username'";
  118. }
  119. $all_total = $admin->select_usergroup_count($where);
  120. $all_total = $all_total['count'];
  121. $p = new Page($all_total,$pageSize);
  122. $pp = $p->fpage();
  123. //查询客户分组里的所有客户
  124. $order_list = $admin->select_usergroup_info($where,$limit);
  125. //分组名
  126. $user_group_name = $admin->select_user_group("where id='$user_group_id'");
  127. $user_group_name = $user_group_name[0]['name'];
  128. $this->assign('info',$info);
  129. $this->assign('user_group_name',$user_group_name);
  130. $this->assign('user_group_id',$user_group_id);
  131. $this->assign('page',$page);
  132. $this->assign('list',$order_list);
  133. $this->assign("show",$pp);
  134. $this->assign("username",$username);
  135. $this->display('group_list.html');
  136. }
  137. public function delete(){
  138. $admin = new AdvertAdminAction();
  139. $id = $_REQUEST['id'];
  140. $uid = $_SESSION['user_infos']['id'];
  141. $group_name = trim($_REQUEST['group_name']);
  142. if(!empty($id)){
  143. $where = " uid = '$uid' and id='$id'";
  144. $delete = $admin->deleteUserGroupMsg($where);
  145. //删除对应的客户信息
  146. $delete_c = $admin->deleteCustomerByGroup($group_name,$uid);
  147. $info = "删除客户分组成功";
  148. }else{
  149. $error = "删除客户分组失败";
  150. }
  151. header("Location:/?a=user_group_admin&m=index&info=$info&error=$error");
  152. exit();
  153. }
  154. //批量删除用户分组
  155. public function batch_delete(){
  156. $admin = new AdvertAdminAction();
  157. $uid = $_SESSION['user_infos']['id'];
  158. $id_array = $_POST['id_array'];
  159. $count = count($id_array);
  160. if($count==1){
  161. $id = $id_array[0];
  162. $where = " uid = '$uid' and id='$id'";
  163. $one_info = $admin->select_one_user_group($id,$uid);
  164. $delete = $admin->deleteUserGroupMsg($where);
  165. $group_name = $one_info['name'];
  166. //删除对应的客户信息
  167. $delete_c = $admin->deleteCustomerByGroup($group_name,$uid);
  168. $info = "删除成功";
  169. header("Location:/?a=user_group_admin&m=index&info=$info");
  170. exit();
  171. }else if($count>1){
  172. $in_array = implode(',',$id_array);
  173. $group_name_list = $admin->select_batch_user_group($in_array,$uid);
  174. foreach($group_name_list as $nlist){
  175. $delete_c = $admin->deleteCustomerByGroup($nlist['name'],$uid);
  176. }
  177. $delete = $admin->deleteBatchUserGroup($in_array,$uid);
  178. $info = "删除成功";
  179. header("Location:/?a=user_group_admin&m=index&info=$info");
  180. exit();
  181. }
  182. }
  183. //end
  184. }
  185. ?>