You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.2 KiB

8 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Admin\CommonController;
  4. use DB;
  5. use App\Http\Model\User;
  6. use App\Common\Helper;
  7. class UserController extends CommonController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function index()
  14. {
  15. $posts = parent::pageList('user');
  16. if($posts)
  17. {
  18. foreach($posts as $k=>$v)
  19. {
  20. $posts[$k]->sex_text = User::getSexText(['sex'=>$v->sex]);
  21. $posts[$k]->status_text = User::getStatusText(['status'=>$v->status]);
  22. }
  23. }
  24. $data['posts'] = $posts;
  25. return view('admin.user.index', $data);
  26. }
  27. //会员账户记录
  28. public function money()
  29. {
  30. $where = '';
  31. if(isset($_REQUEST["user_id"]))
  32. {
  33. $where['user_id'] = $_REQUEST["user_id"];
  34. }
  35. $posts = parent::pageList('user_money',$where);
  36. if($posts)
  37. {
  38. foreach($posts as $k=>$v)
  39. {
  40. $posts[$k]->user = DB::table('user')->where('id', $v->user_id)->first();
  41. }
  42. }
  43. $data['posts'] = $posts;
  44. return view('admin.user.money', $data);
  45. }
  46. //人工充值
  47. public function manualRecharge()
  48. {
  49. if(Helper::isPostRequest())
  50. {
  51. if(!is_numeric($_POST["money"]) || $_POST["money"]==0){error_jump('金额格式不正确');}
  52. unset($_POST["_token"]);
  53. if($_POST["money"]>0)
  54. {
  55. DB::table('user')->where(['id'=>$_POST["id"]])->increment('money', $_POST["money"]);
  56. $user_money['type'] = 0;
  57. }
  58. else
  59. {
  60. DB::table('user')->where(['id'=>$_POST["id"]])->decrement('money', abs($_POST["money"]));
  61. $user_money['type'] = 1;
  62. }
  63. $user_money['user_id'] = $_POST["id"];
  64. $user_money['add_time'] = time();
  65. $user_money['money'] = abs($_POST["money"]);
  66. $user_money['des'] = '后台充值';
  67. $user_money['user_money'] = DB::table('user')->where(array('id'=>$_POST["id"]))->value('money');
  68. //添加用户余额记录
  69. DB::table('user_money')->insert($user_money);
  70. success_jump('操作成功', route('admin_user'));
  71. }
  72. $data['user'] = object_to_array(DB::table('user')->select('user_name', 'mobile', 'money', 'id')->where('id', $_REQUEST["user_id"])->first(), 1);
  73. if(!$data['user']){error_jump('参数错误');}
  74. return view('admin.user.manualRecharge', $data);
  75. }
  76. public function add()
  77. {
  78. return view('admin.user.add');
  79. }
  80. public function doadd()
  81. {
  82. unset($_POST["_token"]);
  83. if(DB::table('user')->insert($_POST))
  84. {
  85. success_jump('添加成功!', route('admin_user'));
  86. }
  87. else
  88. {
  89. error_jump('添加失败!请修改后重新添加');
  90. }
  91. }
  92. public function edit()
  93. {
  94. if(Helper::isPostRequest())
  95. {
  96. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  97. unset($_POST["_token"]);
  98. if(DB::table('user')->where('id', $id)->update($_POST))
  99. {
  100. success_jump('修改成功!', route('admin_user'));
  101. }
  102. else
  103. {
  104. error_jump('修改失败!');
  105. }
  106. }
  107. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  108. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  109. $data['id'] = $id;
  110. $data['post'] = object_to_array(DB::table('user')->where('id', $id)->first(), 1);
  111. return view('admin.user.edit', $data);
  112. }
  113. public function del()
  114. {
  115. if(!empty($_GET["id"])){$id = $_GET["id"];}else{error_jump('删除失败!请重新提交');}
  116. if(DB::table('user')->whereIn("id", explode(',', $id))->update(['status' => 2]))
  117. {
  118. success_jump('删除成功');
  119. }
  120. else
  121. {
  122. error_jump('删除失败!请重新提交');
  123. }
  124. }
  125. }