User.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. $group_list = model('Group')->getCache('group_list');
  74. foreach($res['list'] as $k=>$v){
  75. $res['list'][$k]['group_name'] = $group_list[$v['group_id']]['group_name'];
  76. }
  77. $where2=[];
  78. $where2['user_pid'] = ['eq', $param['uid']];
  79. $level_cc_1 = Db::name('User')->where($where2)->count();
  80. $where3 = [];
  81. $where3['user_id'] = $param['uid'];
  82. $where3['plog_type'] = 4;
  83. $points_cc_1 = Db::name('Plog')->where($where3)->sum('plog_points');
  84. $where2=[];
  85. $where2['user_pid_2'] = ['eq', $param['uid']];
  86. $level_cc_2 = Db::name('User')->where($where2)->count();
  87. $where3 = [];
  88. $where3['user_id'] = $param['uid'];
  89. $where3['plog_type'] = 5;
  90. $points_cc_2 = Db::name('Plog')->where($where3)->sum('plog_points');
  91. $where2=[];
  92. $where2['user_pid_3'] = ['eq', $param['uid']];
  93. $level_cc_3 = Db::name('User')->where($where2)->count();
  94. $where3 = [];
  95. $where3['user_id'] = $param['uid'];
  96. $where3['plog_type'] = 6;
  97. $points_cc_3 = Db::name('Plog')->where($where3)->sum('plog_points');
  98. $data=[];
  99. $data['level_cc_1'] = intval($level_cc_1);
  100. $data['level_cc_2'] = intval($level_cc_2);
  101. $data['level_cc_3'] = intval($level_cc_3);
  102. $data['points_cc_1'] = intval($points_cc_1);
  103. $data['points_cc_2'] = intval($points_cc_2);
  104. $data['points_cc_3'] = intval($points_cc_3);
  105. $this->assign('data',$data);
  106. $this->assign('list',$res['list']);
  107. $this->assign('total',$res['total']);
  108. $this->assign('page',$res['page']);
  109. $this->assign('limit',$res['limit']);
  110. $param['page'] = '{page}';
  111. $param['limit'] = '{limit}';
  112. $this->assign('param',$param);
  113. $this->assign('title',lang('admin/user/title'));
  114. return $this->fetch('admin@user/reward');
  115. }
  116. public function info()
  117. {
  118. if (Request()->isPost()) {
  119. $param = input('post.');
  120. $res = model('User')->saveData($param);
  121. if($res['code']>1){
  122. return $this->error($res['msg']);
  123. }
  124. return $this->success($res['msg']);
  125. }
  126. $id = input('id');
  127. $where=[];
  128. $where['user_id'] = ['eq',$id];
  129. $res = model('User')->infoData($where);
  130. $this->assign('info',$res['info']);
  131. $order='group_id asc';
  132. $where=[];
  133. $res = model('Group')->listData($where,$order);
  134. $this->assign('group_list',$res['list']);
  135. $this->assign('title',lang('admin/user/title'));
  136. return $this->fetch('admin@user/info');
  137. }
  138. public function del()
  139. {
  140. $param = input();
  141. $ids = $param['ids'];
  142. if(!empty($ids)){
  143. $where=[];
  144. $where['user_id'] = ['in',$ids];
  145. $res = model('User')->delData($where);
  146. if($res['code']>1){
  147. return $this->error($res['msg']);
  148. }
  149. return $this->success($res['msg']);
  150. }
  151. return $this->error(lang('param_err'));
  152. }
  153. public function field()
  154. {
  155. $param = input();
  156. $ids = $param['ids'];
  157. $col = $param['col'];
  158. $val = $param['val'];
  159. if(!empty($ids) && in_array($col,['user_status']) && in_array($val,['0','1'])){
  160. $where=[];
  161. $where['user_id'] = ['in',$ids];
  162. $res = model('User')->fieldData($where,$col,$val);
  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. }