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.

93 lines
2.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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\UserWithdraw;
  6. use App\Common\ReturnData;
  7. class UserWithdrawController extends CommonController
  8. {
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. }
  13. public function index()
  14. {
  15. $posts = parent::pageList('user_withdraw',array('is_delete'=>0));
  16. if($posts)
  17. {
  18. foreach($posts as $k=>$v)
  19. {
  20. $posts[$k]->user = DB::table('user')->where('id', $v->user_id)->first();
  21. $posts[$k]->status_text = UserWithdraw::getStatusText(['status'=>$v->status]);
  22. }
  23. }
  24. $data['posts'] = $posts;
  25. return view('admin.UserWithdraw.index', $data);
  26. }
  27. public function edit()
  28. {
  29. if(!empty($_GET["id"])){$id = $_GET["id"];}else{$id="";}
  30. if(preg_match('/[0-9]*/',$id)){}else{exit;}
  31. $data['id'] = $id;
  32. $data['post'] = object_to_array(DB::table('user_withdraw')->where('id', $id)->first(), 1);
  33. return view('admin.UserWithdraw.edit', $data);
  34. }
  35. public function doedit()
  36. {
  37. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  38. unset($_POST["_token"]);
  39. if(DB::table('user_withdraw')->where('id', $id)->update($_POST))
  40. {
  41. success_jump('修改成功!', route('admin_user'));
  42. }
  43. else
  44. {
  45. error_jump('修改失败!');
  46. }
  47. }
  48. public function changeStatus()
  49. {
  50. if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
  51. unset($_POST["_token"]);
  52. if(!isset($_POST["type"])){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  53. $user_withdraw = DB::table('user_withdraw')->where(['id'=>$id,'status'=>0])->first();
  54. if(!$user_withdraw){return ReturnData::create(ReturnData::PARAMS_ERROR);}
  55. //0拒绝,1成功
  56. if($_POST["type"]==0)
  57. {
  58. $data['status'] = 4;
  59. //增加用户余额
  60. DB::table('user')->where(array('id'=>$user_withdraw->user_id))->increment('money', $user_withdraw->money);
  61. //添加用户余额记录
  62. DB::table('user_money')->insert(array('user_id'=>$user_withdraw->user_id,'type'=>0,'money'=>$user_withdraw->money,'des'=>'提现失败-返余额','user_money'=>DB::table('user')->where(array('id'=>$user_withdraw->user_id))->value('money'),'add_time'=>time()));
  63. }
  64. elseif($_POST["type"]==1)
  65. {
  66. $data['status'] = 2;
  67. }
  68. if(isset($data))
  69. {
  70. $res = DB::table('user_withdraw')->where('id', $id)->update($data);
  71. if(!$res){return ReturnData::create(ReturnData::SYSTEM_FAIL);}
  72. }
  73. return ReturnData::create(ReturnData::SUCCESS);
  74. }
  75. }