/** * Execute the console command. * * @return mixed */ public function handle() { $instagram = new InstagramAPI(); foreach (\App\Supplier::all() as $supplier) { $instagram->setAccessToken($supplier->instagramAccount->access_token); foreach ($supplier->products()->where('is_active', true)->get() as $product) { $comments = $instagram->getMediaComments($product->instagram->id); if ($comments->meta->code == 200) { $lastScannedComment = null; for ($i = count($comments->data) - 1; $i >= 0; $i--) { $comment = $comments->data[$i]; if ($lastScannedComment == null) { $lastScannedComment = $comment->id; } if ($product->instagram->last_scanned_comment >= $comment->id) { break; } if (strpos(mb_strtolower($comment->text, 'UTF-8'), 'sepete at') !== false) { if ($customer = \App\InstagramAccount::where('instagram_id', $comment->from->id)->first()) { if ($customer->isCustomer()) { $customer = $customer->instagramable; \App\WishedProduct::create(['customer_id' => $customer->id, 'product_id' => $product->id, 'count' => 1]); } } } } if ($lastScannedComment != null) { $productInstagram = $product->instagram; $productInstagram->last_scanned_comment = $lastScannedComment; $productInstagram->update(); } } } } }
Route::get('/supplierRegister', function () { return view('dashboard.supplierRegister'); }); Route::get('/waitingPaymentDetail', function () { return view('dashboard.waitingPaymentDetail'); }); Route::get('/customerRegister', function () { return view('dashboard.customerRegister'); }); Route::get('/supplierProfileEdit', function () { return view('dashboard.supplierProfileEdit'); }); Route::get('getMediaComments', function () { }); Route::get('setsubscriptions', function () { $faruk = new InstagramAPI(); print_r($faruk->setUserMediaSubscription('https://koalashop.eu1.frbit.net/instagramsubscriptioncallback')); return null; }); Route::get('testing', function () { if (strpos(mb_strtolower("Sepete at ", 'UTF-8'), 'sepete at') !== false) { echo "true"; } else { echo "false"; } }); Route::get('register', 'AuthenticationController@showRegister'); Route::post('login', 'AuthenticationController@doLogin'); Route::get('logout', 'AuthenticationController@doLogout'); Route::get('loginviainstagram', 'AuthenticationController@loginviainstagram'); Route::group(['prefix' => 'dashboard', 'middleware' => 'auth'], function () {
public function registercustomerviainstagram() { Session::put('instagram_operation', ['operation' => 'register', 'user_type' => 'customer']); $instagram = new InstagramAPI(); return Redirect::to($instagram->getLoginUrl()); }
public function callback(Request $request) { if (Session::get('instagram_operation')) { $instagramOperation = Session::pull('instagram_operation'); if ($instagramOperation['operation'] == 'login') { if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); $instagramAccount = InstagramAccount::where(['username' => $data->user->username, 'access_token' => $data->access_token])->first(); if ($instagramAccount) { if (Auth::loginUsingId($instagramAccount->instagramable->user->id)) { if ($instagramAccount->instagramable->user->isSupplier()) { return redirect()->action('Dashboard\\SupplierController@show'); } if ($instagramAccount->instagramable->user->isCustomer()) { return redirect()->action('Dashboard\\CustomerController@show'); } } } else { return redirect()->action('AuthenticationController@showRegister')->withErrors(['messages' => "Kayıtlı Kullanıcı Bulunamadı"]); } } } if ($instagramOperation['operation'] == 'register') { if ($instagramOperation['user_type'] == 'supplier') { if (Session::has('user_instagram_info')) { Session::forget('user_instagram_info'); } if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); Session::put('user_instagram_info', $data); return Redirect::action('Dashboard\\SupplierController@create'); } } if ($instagramOperation['user_type'] == 'customer') { if (Session::has('user_instagram_info')) { Session::forget('user_instagram_info'); } if ($request->get('code')) { $code = $request->get('code'); $instagram = new InstagramAPI(); $data = $instagram->getOAuthToken($code); Session::put('user_instagram_info', $data); return Redirect::action('Dashboard\\CustomerController@create'); } } } } }