SellerSpreadPackagePaymentController.php 6.6 KB

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