1
0

User.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class User extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function data()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  15. if($param['page'] ==1){
  16. model('User')->expire();
  17. }
  18. $where=[];
  19. if(in_array($param['status'],['0','1'],true)){
  20. $where['user_status'] = $param['status'];
  21. }
  22. if(!empty($param['group'])){
  23. $where['group_id'] = $param['group'];
  24. }
  25. if(!empty($param['wd'])){
  26. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  27. $where['user_name'] = ['like','%'.$param['wd'].'%'];
  28. }
  29. $order='user_id desc';
  30. $res = model('User')->listData($where,$order,$param['page'],$param['limit']);
  31. $group_list = model('Group')->getCache('group_list');
  32. foreach($res['list'] as $k=>$v){
  33. $group_ids = explode(',', $v['group_id']);
  34. $names = [];
  35. foreach($group_ids as $gid){
  36. if(isset($group_list[$gid])){
  37. $names[] = $group_list[$gid]['group_name'];
  38. }
  39. }
  40. $res['list'][$k]['group_name'] = implode(',', $names);
  41. }
  42. $this->assign('list',$res['list']);
  43. $this->assign('total',$res['total']);
  44. $this->assign('page',$res['page']);
  45. $this->assign('limit',$res['limit']);
  46. $param['page'] = '{page}';
  47. $param['limit'] = '{limit}';
  48. $this->assign('param',$param);
  49. $this->assign('group_list',$group_list);
  50. $this->assign('title',lang('admin/user/title'));
  51. return $this->fetch('admin@user/index');
  52. }
  53. public function reward()
  54. {
  55. $param = input();
  56. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  57. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  58. $param['uid'] = intval($param['uid']);
  59. $where=[];
  60. if(!empty($param['level'])){
  61. if($param['level']=='1'){
  62. $where['user_pid'] = ['eq', $param['uid']];
  63. }
  64. elseif($param['level']=='2'){
  65. $where['user_pid_2'] = ['eq', $param['uid']];
  66. }
  67. elseif($param['level']=='3'){
  68. $where['user_pid_3'] = ['eq', $param['uid']];
  69. }
  70. }
  71. else{
  72. $where['user_pid|user_pid_2|user_pid_3'] = ['eq', intval($param['uid']) ];
  73. }
  74. if(!empty($param['wd'])){
  75. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  76. $where['user_name'] = ['like','%'.$param['wd'].'%'];
  77. }
  78. $order='user_id desc';
  79. $res = model('User')->listData($where,$order,$param['page'],$param['limit']);
  80. $group_list = model('Group')->getCache('group_list');
  81. foreach($res['list'] as $k=>$v){
  82. $res['list'][$k]['group_name'] = $group_list[$v['group_id']]['group_name'];
  83. }
  84. $where2=[];
  85. $where2['user_pid'] = ['eq', $param['uid']];
  86. $level_cc_1 = Db::name('User')->where($where2)->count();
  87. $where3 = [];
  88. $where3['user_id'] = $param['uid'];
  89. $where3['plog_type'] = 4;
  90. $points_cc_1 = Db::name('Plog')->where($where3)->sum('plog_points');
  91. $where2=[];
  92. $where2['user_pid_2'] = ['eq', $param['uid']];
  93. $level_cc_2 = Db::name('User')->where($where2)->count();
  94. $where3 = [];
  95. $where3['user_id'] = $param['uid'];
  96. $where3['plog_type'] = 5;
  97. $points_cc_2 = Db::name('Plog')->where($where3)->sum('plog_points');
  98. $where2=[];
  99. $where2['user_pid_3'] = ['eq', $param['uid']];
  100. $level_cc_3 = Db::name('User')->where($where2)->count();
  101. $where3 = [];
  102. $where3['user_id'] = $param['uid'];
  103. $where3['plog_type'] = 6;
  104. $points_cc_3 = Db::name('Plog')->where($where3)->sum('plog_points');
  105. $data=[];
  106. $data['level_cc_1'] = intval($level_cc_1);
  107. $data['level_cc_2'] = intval($level_cc_2);
  108. $data['level_cc_3'] = intval($level_cc_3);
  109. $data['points_cc_1'] = intval($points_cc_1);
  110. $data['points_cc_2'] = intval($points_cc_2);
  111. $data['points_cc_3'] = intval($points_cc_3);
  112. $this->assign('data',$data);
  113. $this->assign('list',$res['list']);
  114. $this->assign('total',$res['total']);
  115. $this->assign('page',$res['page']);
  116. $this->assign('limit',$res['limit']);
  117. $param['page'] = '{page}';
  118. $param['limit'] = '{limit}';
  119. $this->assign('param',$param);
  120. $this->assign('title',lang('admin/user/title'));
  121. return $this->fetch('admin@user/reward');
  122. }
  123. public function info()
  124. {
  125. if (Request()->isPost()) {
  126. $param = input('post.');
  127. if(isset($param['group_id']) && is_array($param['group_id'])) {
  128. $param['group_id'] = implode(',', $param['group_id']);
  129. }
  130. $res = model('User')->saveData($param);
  131. if($res['code']>1){
  132. return $this->error($res['msg']);
  133. }
  134. return $this->success($res['msg']);
  135. }
  136. $id = input('id/d');
  137. $where=[];
  138. $where['user_id'] = ['eq',$id];
  139. $res = model('User')->infoData($where);
  140. $info = $res['info'];
  141. $group_list = model('Group')->getCache('group_list');
  142. $group_ids = isset($info['group_id']) ? explode(',', $info['group_id']) : [];
  143. $has_vip_group = false;
  144. foreach($group_ids as $gid){
  145. if(intval($gid) > 2){
  146. $has_vip_group = true;
  147. break;
  148. }
  149. }
  150. $this->assign('info', $info);
  151. $this->assign('group_list', $group_list);
  152. $this->assign('has_vip_group', $has_vip_group);
  153. return $this->fetch('admin@user/info');
  154. }
  155. public function del()
  156. {
  157. $param = input();
  158. $ids = $param['ids'];
  159. if(!empty($ids)){
  160. $where=[];
  161. $where['user_id'] = ['in',$ids];
  162. $res = model('User')->delData($where);
  163. if($res['code']>1){
  164. return $this->error($res['msg']);
  165. }
  166. return $this->success($res['msg']);
  167. }
  168. return $this->error(lang('param_err'));
  169. }
  170. public function field()
  171. {
  172. $param = input();
  173. $ids = $param['ids'];
  174. $col = $param['col'];
  175. $val = $param['val'];
  176. if(!empty($ids) && in_array($col,['user_status']) && in_array($val,['0','1'])){
  177. $where=[];
  178. $where['user_id'] = ['in',$ids];
  179. $res = model('User')->fieldData($where,$col,$val);
  180. if($res['code']>1){
  181. return $this->error($res['msg']);
  182. }
  183. return $this->success($res['msg']);
  184. }
  185. return $this->error(lang('param_err'));
  186. }
  187. }