SellerPackagePaymentController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\User;
  4. use App\Models\Wallet;
  5. use App\Models\BusinessSetting;
  6. use App\Models\AffiliateLog;
  7. use Auth;
  8. use Illuminate\Http\Request;
  9. use App\Models\SellerPackagePayment;
  10. use App\Models\SellerPackage;
  11. use function array_column;
  12. use function compact;
  13. use function view;
  14. class SellerPackagePaymentController extends Controller
  15. {
  16. /**
  17. * Display a listing of the resource.
  18. *
  19. * @return \Illuminate\Http\Response
  20. */
  21. public function index()
  22. {
  23. //
  24. }
  25. public function offline_payment_request(){
  26. $package_payment_requests = SellerPackagePayment::where('offline_payment',1)->orderBy('id', 'desc')->paginate(10);
  27. if (Auth::user()->user_type == 'salesman') {
  28. $userIds = User::where('pid', Auth::user()->id)->get()->toArray();
  29. $package_payment_requests = SellerPackagePayment::where('offline_payment', 1)->whereIn('user_id', array_column($userIds, 'id'))->orderBy('id', 'desc')->paginate(10);
  30. return view('manual_payment_methods.seller_package_payment_request_salesman', compact('package_payment_requests'));
  31. }
  32. return view('manual_payment_methods.seller_package_payment_request', compact('package_payment_requests'));
  33. }
  34. public function offline_payment_approval(Request $request)
  35. {
  36. $package_payment = SellerPackagePayment::findOrFail($request->id);
  37. $package_details = SellerPackage::findOrFail($package_payment->seller_package_id);
  38. $package_payment->approval = $request->status;
  39. if($package_payment->save()){
  40. if($request->status==1){ //通过
  41. $user= User::where('id', $package_payment->user_id)->get();
  42. $user=$user[0];
  43. $money=$package_details->amount;
  44. $osn = $package_payment->payment_details;
  45. if($user->invit_1 != null && $money>0){ //一级分佣
  46. $invit_1=BusinessSetting::where('type', 'commission_store_level_1')->first()->value;
  47. $invit_1=sprintf("%.2f",$money*$invit_1/100);
  48. User::where('id', $user->invit_1)->increment('balance', $invit_1);
  49. //写入日志
  50. $affiliate_log = new AffiliateLog;
  51. $affiliate_log->user_id = $user->id;
  52. $affiliate_log->referred_by_user = $user->invit_1;
  53. $affiliate_log->amount = $invit_1;
  54. $affiliate_log->order_id = $osn;
  55. $affiliate_log->note = $user->name.'('.$user->email.') Upgrade shop,First level commission bonus $'.$invit_1;
  56. $affiliate_log->affiliate_type = 'upgrade_shop';
  57. $affiliate_log->save();
  58. if($user->invit_2 != null){ //二级分佣
  59. $invit_2=BusinessSetting::where('type', 'commission_store_level_2')->first()->value;
  60. $invit_2=sprintf("%.2f",$money*$invit_2/100);
  61. User::where('id', $user->invit_2)->increment('balance', $invit_2);
  62. //写入日志
  63. $affiliate_log = new AffiliateLog;
  64. $affiliate_log->user_id = $user->id;
  65. $affiliate_log->referred_by_user = $user->invit_2;
  66. $affiliate_log->amount = $invit_2;
  67. $affiliate_log->order_id = $osn;
  68. $affiliate_log->note = $user->name.'('.$user->email.') Upgrade shop,Second level commission bonus $'.$invit_2;
  69. $affiliate_log->affiliate_type = 'upgrade_shop';
  70. $affiliate_log->save();
  71. if($user->invit_3 != null){ //三级分佣
  72. $invit_3=BusinessSetting::where('type', 'commission_store_level_3')->first()->value;
  73. $invit_3=sprintf("%.2f",$money*$invit_3/100);
  74. User::where('id', $user->invit_3)->increment('balance', $invit_3);
  75. //写入日志
  76. $affiliate_log = new AffiliateLog;
  77. $affiliate_log->user_id = $user->id;
  78. $affiliate_log->referred_by_user = $user->invit_3;
  79. $affiliate_log->amount = $invit_3;
  80. $affiliate_log->order_id = $osn;
  81. $affiliate_log->note = $user->name.'('.$user->email.') Upgrade shop,Three level commission bonus $'.$invit_3;
  82. $affiliate_log->affiliate_type = 'upgrade_shop';
  83. $affiliate_log->save();
  84. }
  85. }
  86. }
  87. }
  88. $seller = $package_payment->user->shop;
  89. $seller->seller_package_id = $package_payment->seller_package_id;
  90. $seller->product_upload_limit = $package_details->product_upload_limit;
  91. $seller->package_invalid_at = date('Y-m-d', strtotime( $seller->package_invalid_at. ' +'. $package_details->duration .'days'));
  92. if($seller->save()){
  93. return 1;
  94. }
  95. }
  96. return 0;
  97. }
  98. /**
  99. * Show the form for creating a new resource.
  100. *
  101. * @return \Illuminate\Http\Response
  102. */
  103. public function create()
  104. {
  105. //
  106. }
  107. /**
  108. * Store a newly created resource in storage.
  109. *
  110. * @param \Illuminate\Http\Request $request
  111. * @return \Illuminate\Http\Response
  112. */
  113. public function store(Request $request)
  114. {
  115. //
  116. }
  117. /**
  118. * Display the specified resource.
  119. *
  120. * @param int $id
  121. * @return \Illuminate\Http\Response
  122. */
  123. public function show($id)
  124. {
  125. //
  126. }
  127. /**
  128. * Show the form for editing the specified resource.
  129. *
  130. * @param int $id
  131. * @return \Illuminate\Http\Response
  132. */
  133. public function edit($id)
  134. {
  135. //
  136. }
  137. /**
  138. * Update the specified resource in storage.
  139. *
  140. * @param \Illuminate\Http\Request $request
  141. * @param int $id
  142. * @return \Illuminate\Http\Response
  143. */
  144. public function update(Request $request, $id)
  145. {
  146. //
  147. }
  148. /**
  149. * Remove the specified resource from storage.
  150. *
  151. * @param int $id
  152. * @return \Illuminate\Http\Response
  153. */
  154. public function destroy($id)
  155. {
  156. //
  157. }
  158. }