SellerWithdrawRequestController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Order;
  4. use Illuminate\Http\Request;
  5. use App\Models\SellerWithdrawRequest;
  6. use App\Models\User;
  7. use Auth;
  8. use function compact;
  9. use function count;
  10. use function dd;
  11. use function get_setting;
  12. use function view;
  13. class SellerWithdrawRequestController extends Controller
  14. {
  15. /**
  16. * Display a listing of the resource.
  17. *
  18. * @return \Illuminate\Http\Response
  19. */
  20. public function index()
  21. {
  22. $seller_withdraw_requests = SellerWithdrawRequest::where('t_type',1)->latest()->paginate(15);
  23. return view('backend.sellers.seller_withdraw_requests.index', compact('seller_withdraw_requests'));
  24. }
  25. /**
  26. * Display a listing of the resource.
  27. *
  28. * @return \Illuminate\Http\Response
  29. */
  30. public function index_by_user( Request $request)
  31. {
  32. $seller_withdraw_requests = SellerWithdrawRequest::where('user_id',$request->user_id )->get();
  33. # $seller_withdraw_requests = SellerWithdrawRequest::latest()->paginate(15);
  34. return view('backend.sellers.seller_withdraw_requests_all_by_user.index', compact('seller_withdraw_requests'));
  35. }
  36. public function index_by_customer( Request $request)
  37. {
  38. $seller_withdraw_requests = SellerWithdrawRequest::where('t_type',2)->latest()->paginate(15);
  39. # $seller_withdraw_requests = SellerWithdrawRequest::latest()->paginate(15);
  40. return view('backend.sellers.seller_withdraw_requests_all_by_user.index2', compact('seller_withdraw_requests'));
  41. }
  42. /**
  43. * Show the form for creating a new resource.
  44. *
  45. * @return \Illuminate\Http\Response
  46. */
  47. public function create()
  48. {
  49. //
  50. }
  51. /**
  52. * Store a newly created resource in storage.
  53. *
  54. * @param \Illuminate\Http\Request $request
  55. * @return \Illuminate\Http\Response
  56. */
  57. public function store(Request $request)
  58. {
  59. $user = Auth::user();
  60. if ($request->amount > $user->balance) {
  61. flash(translate('You do not have enough balance to send withdraw request'))->error();
  62. return back();
  63. }
  64. $seller_withdraw_request = new SellerWithdrawRequest;
  65. $seller_withdraw_request->user_id = $user->id;
  66. $seller_withdraw_request->amount = $request->amount;
  67. $seller_withdraw_request->message = $request->message;
  68. $seller_withdraw_request->status = '0';
  69. $seller_withdraw_request->viewed = '0';
  70. if ($seller_withdraw_request->save()) {
  71. flash(translate('Request has been sent successfully'))->success();
  72. return redirect()->route('withdraw_requests.index');
  73. }
  74. else{
  75. flash(translate('Something went wrong'))->error();
  76. return back();
  77. }
  78. }
  79. /**
  80. * Display the specified resource.
  81. *
  82. * @param int $id
  83. * @return \Illuminate\Http\Response
  84. */
  85. public function show($id)
  86. {
  87. //
  88. }
  89. /**
  90. * Show the form for editing the specified resource.
  91. *
  92. * @param int $id
  93. * @return \Illuminate\Http\Response
  94. */
  95. public function edit($id)
  96. {
  97. //
  98. }
  99. /**
  100. * Update the specified resource in storage.
  101. *
  102. * @param \Illuminate\Http\Request $request
  103. * @param int $id
  104. * @return \Illuminate\Http\Response
  105. */
  106. public function update(Request $request, $id)
  107. {
  108. //
  109. }
  110. /**
  111. * Remove the specified resource from storage.
  112. *
  113. * @param int $id
  114. * @return \Illuminate\Http\Response
  115. */
  116. public function destroy($id)
  117. {
  118. //
  119. }
  120. public function payment_modal(Request $request)
  121. {
  122. $user = User::findOrFail($request->id);
  123. $seller_withdraw_request = SellerWithdrawRequest::where('id', $request->seller_withdraw_request_id)->first();
  124. $user2 = $user;
  125. $seller_withdraw_request_id = $request->seller_withdraw_request_id;
  126. return view('backend.sellers.seller_withdraw_requests.payment_modal', compact('user','seller_withdraw_request','seller_withdraw_request_id','user2'));
  127. }
  128. public function refuse_modal(Request $request)
  129. {
  130. $user = User::findOrFail($request->id);
  131. $seller_withdraw_request = SellerWithdrawRequest::where('id', $request->seller_withdraw_request_id)->first();
  132. $id = $request->seller_withdraw_request_id;
  133. return view('backend.sellers.seller_withdraw_requests.refuse_modal', compact('user','seller_withdraw_request','id'));
  134. }
  135. public function message_modal(Request $request)
  136. {
  137. $seller_withdraw_request = SellerWithdrawRequest::findOrFail($request->id);
  138. if (Auth::user()->user_type == 'seller') {
  139. return view('frontend.partials.withdraw_message_modal', compact('seller_withdraw_request'));
  140. }
  141. elseif (Auth::user()->user_type == 'admin' || Auth::user()->user_type == 'staff') {
  142. return view('backend.sellers.seller_withdraw_requests.withdraw_message_modal', compact('seller_withdraw_request'));
  143. }
  144. elseif (Auth::user()->user_type == 'salesman' ) {
  145. return view('salesman.seller_withdraw_requests.withdraw_message_modal', compact('seller_withdraw_request'));
  146. }
  147. }
  148. /**
  149. * Display a listing of the resource.
  150. *
  151. * @return \Illuminate\Http\Response
  152. */
  153. public function salesman_index()
  154. {
  155. $userIds = [];
  156. $users_1 = User::where('pid', '=', Auth::user()->id)->where('user_type', '=', 'seller')->get();//下一级商家
  157. foreach ( $users_1 as $user_1 )
  158. {
  159. $userIds[] = $user_1->id;
  160. $users_2 = User::where('pid', '=', $user_1->id)->where('user_type', '=', 'seller')->get();//下二级商家
  161. foreach ( $users_2 as $user_2 )
  162. {
  163. $userIds[] = $user_2->id;
  164. $users_3 = User::where('pid', '=', $user_2->id)->where('user_type', '=', 'seller')->get();//下二级商家
  165. foreach ( $users_3 as $user_3 )
  166. {
  167. $userIds[] = $user_3->id;
  168. }
  169. }
  170. }
  171. $seller_withdraw_requests = SellerWithdrawRequest::latest()->whereIn('user_id', $userIds)->paginate(15);
  172. return view('salesman.seller_withdraw_requests.index', compact('seller_withdraw_requests'));
  173. }
  174. }