123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- namespace App\Http\Controllers;
- use App\Models\User;
- use App\Models\Wallet;
- use App\Models\BusinessSetting;
- use App\Models\AffiliateLog;
- use Auth;
- use Illuminate\Http\Request;
- use App\Models\SellerSpreadPackagePayment;
- use App\Models\SellerSpreadPackage;
- use function array_column;
- use function compact;
- use function date;
- use function strtotime;
- use function time;
- use function view;
- class SellerSpreadPackagePaymentController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index() {
- //
- }
- public function role() {
- return $this->belongsTo(SellerSpreadPackage::class, 'seller_spread_package_id', 'id');
- }
- public function offline_payment_request() {
- $package_payment_requests = SellerSpreadPackagePayment::where('offline_payment', 1)->orderBy('id', 'desc')->paginate(10);
- return view('manual_payment_methods.seller_spread_package_payment_request', compact('package_payment_requests'));
- }
- public function offline_payment_approval( Request $request ) {
- $package_payment = SellerSpreadPackagePayment::findOrFail($request->id);
-
- $package_details = SellerSpreadPackage::findOrFail($package_payment->seller_spread_package_id);
-
- $package_payment->approval = $request->status;
- $package_payment->expire_at = time()+86400*$package_details->duration;
- $package_payment->product_spread_limit = $package_details->product_upload_limit;
- if ( $package_payment->save() ){
- if($request->status==1){ //通过
- $user= User::where('id', $package_payment->user_id)->get();
- $user=$user[0];
- $money=$package_details->amount;
- $osn = $package_payment->payment_details;
- if($user->invit_1 != null && $money>0){ //一级分佣
- $invit_1=BusinessSetting::where('type', 'commission_train_level_1')->first()->value;
- $invit_1=sprintf("%.2f",$money*$invit_1/100);
- User::where('id', $user->invit_1)->increment('balance', $invit_1);
- //写入日志
- $affiliate_log = new AffiliateLog;
- $affiliate_log->user_id = $user->id;
- $affiliate_log->referred_by_user = $user->invit_1;
- $affiliate_log->amount = $invit_1;
- $affiliate_log->order_id = $osn;
- $affiliate_log->note = $user->name.'('.$user->email.') Purchase through train,First level commission bonus $'.$invit_1;
- $affiliate_log->affiliate_type = 'purchase_through_train';
- $affiliate_log->save();
- if($user->invit_2 != null){ //二级分佣
- $invit_2=BusinessSetting::where('type', 'commission_train_level_2')->first()->value;
- $invit_2=sprintf("%.2f",$money*$invit_2/100);
- User::where('id', $user->invit_2)->increment('balance', $invit_2);
- //写入日志
- $affiliate_log = new AffiliateLog;
- $affiliate_log->user_id = $user->id;
- $affiliate_log->referred_by_user = $user->invit_2;
- $affiliate_log->amount = $invit_2;
- $affiliate_log->order_id = $osn;
- $affiliate_log->note = $user->name.'('.$user->email.') Purchase through train,Second level commission bonus $'.$invit_2;
- $affiliate_log->affiliate_type = 'purchase_through_train';
- $affiliate_log->save();
- if($user->invit_3 != null){ //三级分佣
- $invit_3=BusinessSetting::where('type', 'commission_train_level_3')->first()->value;
- $invit_3=sprintf("%.2f",$money*$invit_3/100);
- User::where('id', $user->invit_3)->increment('balance', $invit_3);
- //写入日志
- $affiliate_log = new AffiliateLog;
- $affiliate_log->user_id = $user->id;
- $affiliate_log->referred_by_user = $user->invit_3;
- $affiliate_log->amount = $invit_3;
- $affiliate_log->order_id = $osn;
- $affiliate_log->note = $user->name.'('.$user->email.') Purchase through train,Three level commission bonus $'.$invit_3;
- $affiliate_log->affiliate_type = 'purchase_through_train';
- $affiliate_log->save();
- }
- }
- }
- }
- $seller = $package_payment->user->shop;
- $seller->seller_spread_package_id = $package_payment->seller_spread_package_id;
- $seller->product_spread_limit = $package_details->product_upload_limit;
- if ($seller->spread_package_invalid_at){
- if (strtotime($seller->spread_package_invalid_at) < time()) $seller->spread_package_invalid_at = date('Y-m-d');
- }
- $seller->spread_package_invalid_at = date('Y-m-d', strtotime($seller->spread_package_invalid_at . ' +' . $package_details->duration . 'days'));
- if ( $seller->save() )
- {
- return 1;
- }
- }
- return 0;
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create() {
- //
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- *
- * @return \Illuminate\Http\Response
- */
- public function store( Request $request ) {
- //
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function show( $id ) {
- //
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function edit( $id ) {
- //
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function update( Request $request, $id ) {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- *
- * @return \Illuminate\Http\Response
- */
- public function destroy( $id ) {
- //
- }
- }
|