User.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\green\controller;
  3. use app\common\model\SystemUser;
  4. use app\green\model\GreenUserLog;
  5. use app\green\model\GreenUser;
  6. use think\facade\Request;
  7. use think\helper\Time;
  8. class User extends Common{
  9. public function initialize(){
  10. parent::initialize();
  11. $this->assign('pathMaps',[['name'=>'用户管理','url'=>url("green/user/index")]]);
  12. }
  13. /**
  14. * 列表
  15. */
  16. public function index(){
  17. $condition = [];
  18. $time = Request::param('time/d',0);
  19. $starttime = Request::param('starttime/s');
  20. $endtime = Request::param('endtime/s');
  21. if($time){
  22. switch ($time) {
  23. case 2:
  24. list($start, $end) = Time::yesterday();
  25. break;
  26. case 30:
  27. list($start, $end) = Time::month();
  28. break;
  29. case 60:
  30. list($start, $end) = Time::lastMonth();
  31. break;
  32. default:
  33. list($start, $end) = Time::today();
  34. break;
  35. }
  36. $condition[] = ['create_time','>=',$start];
  37. $condition[] = ['create_time','<=',$end];
  38. }else{
  39. if($starttime){
  40. $condition[] = ['create_time','>=',strtotime($starttime)];
  41. }
  42. if($endtime){
  43. $condition[] = ['create_time','<=',strtotime($endtime)];
  44. }
  45. }
  46. $uid = Request::param('uid/d');
  47. $where = !empty($uid) ? ['uid' => $uid] : [];
  48. $view['weight_sum'] = GreenUserLog::where($this->mini_program)->where($condition)->where($where)->sum('weight');
  49. if (!empty($uid)) {
  50. $condition[] = ['id', '=', $uid];
  51. }
  52. $view['user_sum'] = SystemUser::where($this->mini_program)->where($condition)->count();
  53. $list = SystemUser::where($this->mini_program)->where($condition)->order('id desc')->paginate(20, false, ['query' => ['starttime' => $starttime, 'endtime' => $endtime, 'time' => $time]]);
  54. foreach ($list as $key => $value) {
  55. $list[$key]->user = GreenUser::where($this->mini_program)->where($condition)->where(['uid' => $value->id])->find();
  56. }
  57. $view['lists'] = $list;
  58. $view['uid'] = $uid;
  59. $view['time'] = $time;
  60. $view['starttime'] = $starttime;
  61. $view['endtime'] = $endtime;
  62. return view()->assign($view);
  63. }
  64. /**
  65. * 投递列表
  66. */
  67. public function userLog(int $id = 0){
  68. $view['lists'] = GreenUserLog::where($this->mini_program)->where(['uid' => $id])->order('create_time desc')->paginate(20, false, ['query' => ['id' => $id]]);
  69. return view()->assign($view);
  70. }
  71. }