User.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. $res['list'][$k]['group_name'] = $group_list[$v['group_id']]['group_name'];
  34. }
  35. $this->assign('list',$res['list']);
  36. $this->assign('total',$res['total']);
  37. $this->assign('page',$res['page']);
  38. $this->assign('limit',$res['limit']);
  39. $param['page'] = '{page}';
  40. $param['limit'] = '{limit}';
  41. $this->assign('param',$param);
  42. $this->assign('group_list',$group_list);
  43. $this->assign('title',lang('admin/user/title'));
  44. return $this->fetch('admin@user/index');
  45. }
  46. public function reward()
  47. {
  48. $param = input();
  49. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  50. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  51. $param['uid'] = intval($param['uid']);
  52. $where=[];
  53. if(!empty($param['level'])){
  54. if($param['level']=='1'){
  55. $where['user_pid'] = ['eq', $param['uid']];
  56. }
  57. elseif($param['level']=='2'){
  58. $where['user_pid_2'] = ['eq', $param['uid']];
  59. }
  60. elseif($param['level']=='3'){
  61. $where['user_pid_3'] = ['eq', $param['uid']];
  62. }
  63. }
  64. else{
  65. $where['user_pid|user_pid_2|user_pid_3'] = ['eq', intval($param['uid']) ];
  66. }
  67. if(!empty($param['wd'])){
  68. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  69. $where['user_name'] = ['like','%'.$param['wd'].'%'];
  70. }
  71. $order='user_id desc';
  72. $res = model('User')->listData($where,$order,$param['page'],$param['limit']);
  73. $list=[];
  74. $where2=[];
  75. $where2['user_pid'] = ['eq', $param['uid']];
  76. $user_ids_1 = Db::name('User')->where($where2)->column('user_id');
  77. $level_cc_1 = count($user_ids_1);
  78. $where3=[];
  79. $where3['user_id_1'] = ['in',$user_ids_1];
  80. $points_cc_1 = Db::name('Plog')->where($where3)->sum('plog_points');
  81. $where2=[];
  82. $where2['user_pid_2'] = ['eq', $param['uid']];
  83. $user_ids_2 = Db::name('User')->where($where2)->column('user_id');
  84. $level_cc_2 = count($user_ids_2);
  85. $where3=[];
  86. $where3['user_id_1'] = ['in',$user_ids_2];
  87. $points_cc_2 = Db::name('Plog')->where($where3)->sum('plog_points');
  88. $where2=[];
  89. $where2['user_pid_3'] = ['eq', $param['uid']];
  90. $user_ids_3 = Db::name('User')->where($where2)->column('user_id');
  91. $level_cc_3 = count($user_ids_3);
  92. $where3=[];
  93. $where3['user_id_1'] = ['in',$user_ids_3];
  94. $points_cc_3 = Db::name('Plog')->where($where3)->sum('plog_points');
  95. $data=[];
  96. $data['level_cc_1'] = intval($level_cc_1);
  97. $data['level_cc_2'] = intval($level_cc_2);
  98. $data['level_cc_3'] = intval($level_cc_3);
  99. $data['points_cc_1'] = intval($points_cc_1);
  100. $data['points_cc_2'] = intval($points_cc_2);
  101. $data['points_cc_3'] = intval($points_cc_3);
  102. $this->assign('data',$data);
  103. $this->assign('list',$res['list']);
  104. $this->assign('total',$res['total']);
  105. $this->assign('page',$res['page']);
  106. $this->assign('limit',$res['limit']);
  107. $param['page'] = '{page}';
  108. $param['limit'] = '{limit}';
  109. $this->assign('param',$param);
  110. $this->assign('title',lang('admin/user/title'));
  111. return $this->fetch('admin@user/reward');
  112. }
  113. public function info()
  114. {
  115. if (Request()->isPost()) {
  116. $param = input('post.');
  117. $res = model('User')->saveData($param);
  118. if($res['code']>1){
  119. return $this->error($res['msg']);
  120. }
  121. return $this->success($res['msg']);
  122. }
  123. $id = input('id');
  124. $where=[];
  125. $where['user_id'] = ['eq',$id];
  126. $res = model('User')->infoData($where);
  127. $this->assign('info',$res['info']);
  128. $order='group_id asc';
  129. $where=[];
  130. $res = model('Group')->listData($where,$order);
  131. $this->assign('group_list',$res['list']);
  132. $this->assign('title',lang('admin/user/title'));
  133. return $this->fetch('admin@user/info');
  134. }
  135. public function del()
  136. {
  137. $param = input();
  138. $ids = $param['ids'];
  139. if(!empty($ids)){
  140. $where=[];
  141. $where['user_id'] = ['in',$ids];
  142. $res = model('User')->delData($where);
  143. if($res['code']>1){
  144. return $this->error($res['msg']);
  145. }
  146. return $this->success($res['msg']);
  147. }
  148. return $this->error(lang('param_err'));
  149. }
  150. public function field()
  151. {
  152. $param = input();
  153. $ids = $param['ids'];
  154. $col = $param['col'];
  155. $val = $param['val'];
  156. if(!empty($ids) && in_array($col,['user_status']) && in_array($val,['0','1'])){
  157. $where=[];
  158. $where['user_id'] = ['in',$ids];
  159. $res = model('User')->fieldData($where,$col,$val);
  160. if($res['code']>1){
  161. return $this->error($res['msg']);
  162. }
  163. return $this->success($res['msg']);
  164. }
  165. return $this->error(lang('param_err'));
  166. }
  167. }