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.

156 lines
4.6 KiB

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