HomeController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Auth;
  5. use Hash;
  6. use App\Models\Category;
  7. use App\Models\FlashDeal;
  8. use App\Models\Brand;
  9. use App\Models\Product;
  10. use App\Models\CustomerProduct;
  11. use App\Models\PickupPoint;
  12. use App\Models\CustomerPackage;
  13. use App\Models\User;
  14. use App\Models\Seller;
  15. use App\Models\Shop;
  16. use App\Models\Order;
  17. use App\Models\BusinessSetting;
  18. use App\Models\Coupon;
  19. use Cookie;
  20. use Illuminate\Support\Str;
  21. use App\Mail\SecondEmailVerifyMailManager;
  22. use App\Models\AffiliateConfig;
  23. use App\Models\Page;
  24. use App\Models\ProductQuery;
  25. use Mail;
  26. use Illuminate\Auth\Events\PasswordReset;
  27. use Cache;
  28. use Illuminate\Support\Facades\Response;
  29. use Illuminate\Support\Facades\View;
  30. use function dd;
  31. use function print_r;
  32. class HomeController extends Controller
  33. {
  34. /**
  35. * Show the application frontend home.
  36. *
  37. * @return \Illuminate\Http\Response
  38. */
  39. public function viewcron()
  40. {
  41. $shops = Shop::all();
  42. foreach($shops as $shop )
  43. {
  44. $shop = Shop::findOrFail($shop->id);
  45. if( $shop->views_up_time < strtotime(date("Ymd")))
  46. {
  47. $shop->views = $shop->view_base_num;
  48. $shop->view_today_num = 0;
  49. }
  50. $shop->views_up_time = time();
  51. $shop->save();
  52. if( $shop-> view_today_num < $shop->view_inc_num )
  53. {
  54. #$t = mt_rand(1,intval( 1440 / $shop->view_inc_num ) );
  55. $t = mt_rand(1, 14 );
  56. if( $t % 13 == 0 )
  57. {
  58. $shop->view_today_num = $shop->view_today_num+1;
  59. $shop->views = $shop->views+1;
  60. $shop->save();
  61. }
  62. }
  63. }
  64. echo 'ok';
  65. }
  66. public function index()
  67. {
  68. $featured_categories = Cache::rememberForever('featured_categories', function () {
  69. return Category::where('featured', 1)->get();
  70. });
  71. $todays_deal_products = Cache::rememberForever('todays_deal_products', function () {
  72. return filter_products(Product::query()->from("products as p")->where('published', 1)->where('todays_deal', '1'))->get();
  73. });
  74. $newest_products = Cache::remember('newest_products', 3600, function () {
  75. return filter_products(Product::query()->from("products as p")->latest())->limit(12)->get();
  76. });
  77. return view('frontend.index', compact('featured_categories', 'todays_deal_products', 'newest_products'));
  78. }
  79. public function login()
  80. {
  81. if (Auth::check()) {
  82. return redirect()->route('home');
  83. }
  84. return view('frontend.user_login');
  85. }
  86. public function registration(Request $request)
  87. {
  88. if (Auth::check()) {
  89. return redirect()->route('home');
  90. }
  91. if ($request->has('referral_code') && addon_is_activated('affiliate_system')) {
  92. try {
  93. $affiliate_validation_time = AffiliateConfig::where('type', 'validation_time')->first();
  94. $cookie_minute = 30 * 24;
  95. if ($affiliate_validation_time) {
  96. $cookie_minute = $affiliate_validation_time->value * 60;
  97. }
  98. Cookie::queue('referral_code', $request->referral_code, $cookie_minute);
  99. $referred_by_user = User::where('referral_code', $request->referral_code)->first();
  100. $affiliateController = new AffiliateController;
  101. $affiliateController->processAffiliateStats($referred_by_user->id, 1, 0, 0, 0);
  102. } catch (\Exception $e) {
  103. }
  104. }
  105. return view('frontend.user_registration');
  106. }
  107. public function cart_login(Request $request)
  108. {
  109. $user = null;
  110. if ($request->get('phone') != null) {
  111. $user = User::whereIn('user_type', ['customer', 'seller'])->where('phone', "+{$request['country_code']}{$request['phone']}")->first();
  112. } elseif ($request->get('email') != null) {
  113. $user = User::whereIn('user_type', ['customer', 'seller'])->where('email', $request->email)->first();
  114. }
  115. if ($user != null) {
  116. if (Hash::check($request->password, $user->password)) {
  117. if ($request->has('remember')) {
  118. auth()->login($user, true);
  119. } else {
  120. auth()->login($user, false);
  121. }
  122. } else {
  123. flash(translate('Invalid email or password!'))->warning();
  124. }
  125. } else {
  126. flash(translate('Invalid email or password!'))->warning();
  127. }
  128. return back();
  129. }
  130. /**
  131. * Create a new controller instance.
  132. *
  133. * @return void
  134. */
  135. public function __construct()
  136. {
  137. //$this->middleware('auth');
  138. }
  139. /**
  140. * Show the customer/seller dashboard.
  141. *
  142. * @return \Illuminate\Http\Response
  143. */
  144. public function dashboard(Request $request)
  145. {
  146. if (Auth::user()->user_type == 'seller') {
  147. return redirect()->route('seller.dashboard');
  148. } elseif (Auth::user()->user_type == 'customer') {
  149. return view('frontend.user.customer.dashboard');
  150. } elseif (Auth::user()->user_type == 'delivery_boy') {
  151. return view('delivery_boys.frontend.dashboard');
  152. } elseif (Auth::user()->user_type == 'salesman') {
  153. $url = $request->root().'/shops/create?leader_id='.Auth::user()->id;
  154. return view('salesman.dashboard', compact('url'));
  155. } else {
  156. abort(404);
  157. }
  158. }
  159. public function profile(Request $request)
  160. {
  161. if (Auth::user()->user_type == 'seller') {
  162. return redirect()->route('seller.profile.index');
  163. } elseif (Auth::user()->user_type == 'delivery_boy') {
  164. return view('delivery_boys.frontend.profile');
  165. } elseif (Auth::user()->user_type == 'salesman') {
  166. return view('salesman.profile.index');
  167. } else {
  168. return view('frontend.user.profile');
  169. }
  170. }
  171. public function userProfileUpdate(Request $request)
  172. {
  173. if (env('DEMO_MODE') == 'On') {
  174. flash(translate('Sorry! the action is not permitted in demo '))->error();
  175. return back();
  176. }
  177. $user = Auth::user();
  178. $user->name = $request->name;
  179. $user->address = $request->address;
  180. $user->country = $request->country;
  181. $user->city = $request->city;
  182. $user->postal_code = $request->postal_code;
  183. $user->phone = $request->phone;
  184. $user->cash_on_delivery_status = $request->cash_on_delivery_status;
  185. $user->bank_payment_status = $request->bank_payment_status;
  186. $user->bank_name = $request->bank_name;
  187. $user->bank_acc_name = $request->bank_acc_name;
  188. $user->bank_acc_no = $request->bank_acc_no;
  189. $user->bank_routing_no = $request->bank_routing_no;
  190. // $user->transactional_type = $request->transactional_type;
  191. $user->usdt_address = $request->usdt_address;
  192. $user->usdt_payment_status = $request->usdt_payment_status;
  193. $user->usdt_type = $request->usdt_type;
  194. if ($request->customer_service_link) $user->customer_service_link = $request->customer_service_link;
  195. if ($request->new_password != null && ($request->new_password == $request->confirm_password)) {
  196. $user->password = Hash::make($request->new_password);
  197. }
  198. $user->avatar_original = $request->photo;
  199. $user->save();
  200. flash(translate('Your Profile has been updated successfully!'))->success();
  201. return back();
  202. }
  203. public function flash_deal_details($slug)
  204. {
  205. $flash_deal = FlashDeal::where('slug', $slug)->first();
  206. if ($flash_deal != null)
  207. return view('frontend.flash_deal_details', compact('flash_deal'));
  208. else {
  209. abort(404);
  210. }
  211. }
  212. public function load_featured_section()
  213. {
  214. return view('frontend.partials.featured_products_section');
  215. }
  216. public function load_best_selling_section()
  217. {
  218. return view('frontend.partials.best_selling_section');
  219. }
  220. public function load_auction_products_section()
  221. {
  222. if (!addon_is_activated('auction')) {
  223. return;
  224. }
  225. return view('auction.frontend.auction_products_section');
  226. }
  227. public function load_home_categories_section()
  228. {
  229. return view('frontend.partials.home_categories_section');
  230. }
  231. public function load_best_sellers_section()
  232. {
  233. return view('frontend.partials.best_sellers_section');
  234. }
  235. public function trackOrder(Request $request)
  236. {
  237. if ($request->has('order_code')) {
  238. $order = Order::where('code', $request->order_code)->first();
  239. if ($order != null) {
  240. return view('frontend.track_order', compact('order'));
  241. }
  242. }
  243. return view('frontend.track_order');
  244. }
  245. public function product(Request $request, $slug)
  246. {
  247. $detailedProduct = Product::with('reviews', 'brand', 'stocks', 'user', 'user.shop')->where('auction_product', 0)->where('slug', $slug)->where('approved', 1)->first();
  248. if ($detailedProduct != null && $detailedProduct->published) {
  249. $product_queries = ProductQuery::where('product_id', $detailedProduct->id)->where('customer_id', '!=', Auth::id())->latest('id')->paginate(10);
  250. $total_query = ProductQuery::where('product_id', $detailedProduct->id)->count();
  251. // Pagination using Ajax
  252. if (request()->ajax()) {
  253. return Response::json(View::make('frontend.partials.product_query_pagination', array('product_queries' => $product_queries))->render());
  254. }
  255. // End of Pagination using Ajax
  256. if ($request->has('product_referral_code') && addon_is_activated('affiliate_system')) {
  257. $affiliate_validation_time = AffiliateConfig::where('type', 'validation_time')->first();
  258. $cookie_minute = 30 * 24;
  259. if ($affiliate_validation_time) {
  260. $cookie_minute = $affiliate_validation_time->value * 60;
  261. }
  262. Cookie::queue('product_referral_code', $request->product_referral_code, $cookie_minute);
  263. Cookie::queue('referred_product_id', $detailedProduct->id, $cookie_minute);
  264. $referred_by_user = User::where('referral_code', $request->product_referral_code)->first();
  265. $affiliateController = new AffiliateController;
  266. $affiliateController->processAffiliateStats($referred_by_user->id, 1, 0, 0, 0);
  267. }
  268. if ( Auth::id() != $detailedProduct->user->id){
  269. if ($detailedProduct->user){
  270. if ($detailedProduct->user->shop){
  271. $detailedProduct->user->shop->views += 1;
  272. $detailedProduct->user->shop->save();
  273. }
  274. }
  275. }
  276. // if($detailedProduct->reviews_url){
  277. // $pingjia['url'] = "https://xiapi.xiapibuy.com/api/v2/item/get_ratings?filter=0&flag=1&itemid=15491005726&offset=0&shopid=805825070&type=0";
  278. // $file = file_get_contents($detailedProduct->reviews_url);
  279. // $lists= json_decode($file,1); //商品列表
  280. // $lists = $lists['data']['ratings'];
  281. // } else {
  282. $lists = array();
  283. //}
  284. if ($detailedProduct->digital == 1) {
  285. return view('frontend.digital_product_details', compact('detailedProduct', 'product_queries', 'total_query','lists'));
  286. } else {
  287. return view('frontend.product_details', compact('detailedProduct', 'product_queries', 'total_query','lists'));
  288. }
  289. }
  290. abort(404);
  291. }
  292. public function shop($slug)
  293. {
  294. $shop = Shop::where('slug', $slug)->first();
  295. if ($shop != null) {
  296. if ($shop->verification_status != 0) {
  297. return view('frontend.seller_shop', compact('shop'));
  298. } else {
  299. return view('frontend.seller_shop_without_verification', compact('shop'));
  300. }
  301. }
  302. abort(404);
  303. }
  304. public function filter_shop($slug, $type)
  305. {
  306. $shop = Shop::where('slug', $slug)->first();
  307. if ($shop != null && $type != null) {
  308. return view('frontend.seller_shop', compact('shop', 'type'));
  309. }
  310. abort(404);
  311. }
  312. public function all_categories(Request $request)
  313. {
  314. $categories = Category::where('level', 0)->orderBy('order_level', 'desc')->get();
  315. return view('frontend.all_category', compact('categories'));
  316. }
  317. public function all_brands(Request $request)
  318. {
  319. $categories = Category::all();
  320. return view('frontend.all_brand', compact('categories'));
  321. }
  322. public function home_settings(Request $request)
  323. {
  324. return view('home_settings.index');
  325. }
  326. public function top_10_settings(Request $request)
  327. {
  328. foreach (Category::all() as $key => $category) {
  329. if (is_array($request->top_categories) && in_array($category->id, $request->top_categories)) {
  330. $category->top = 1;
  331. $category->save();
  332. } else {
  333. $category->top = 0;
  334. $category->save();
  335. }
  336. }
  337. foreach (Brand::all() as $key => $brand) {
  338. if (is_array($request->top_brands) && in_array($brand->id, $request->top_brands)) {
  339. $brand->top = 1;
  340. $brand->save();
  341. } else {
  342. $brand->top = 0;
  343. $brand->save();
  344. }
  345. }
  346. flash(translate('Top 10 categories and brands have been updated successfully'))->success();
  347. return redirect()->route('home_settings.index');
  348. }
  349. public function variant_price(Request $request)
  350. {
  351. $product = Product::find($request->id);
  352. $str = '';
  353. $quantity = 0;
  354. $tax = 0;
  355. $max_limit = 0;
  356. if ($request->has('color')) {
  357. $str = $request['color'];
  358. }
  359. if (json_decode($product->choice_options) != null) {
  360. foreach (json_decode($product->choice_options) as $key => $choice) {
  361. if ($str != null) {
  362. $str .= '-' . str_replace(' ', '', $request['attribute_id_' . $choice->attribute_id]);
  363. } else {
  364. $str .= str_replace(' ', '', $request['attribute_id_' . $choice->attribute_id]);
  365. }
  366. }
  367. }
  368. $product_stock = $product->stocks->where('variant', $str)->first();
  369. $price = $product_stock->price;
  370. if ($product->wholesale_product) {
  371. $wholesalePrice = $product_stock->wholesalePrices->where('min_qty', '<=', $request->quantity)->where('max_qty', '>=', $request->quantity)->first();
  372. if ($wholesalePrice) {
  373. $price = $wholesalePrice->price;
  374. }
  375. }
  376. $quantity = $product_stock->qty;
  377. $max_limit = $product_stock->qty;
  378. if ($quantity >= 1 && $product->min_qty <= $quantity) {
  379. $in_stock = 1;
  380. } else {
  381. $in_stock = 0;
  382. }
  383. //Product Stock Visibility
  384. if ($product->stock_visibility_state == 'text') {
  385. if ($quantity >= 1 && $product->min_qty < $quantity) {
  386. $quantity = translate('In Stock');
  387. } else {
  388. $quantity = translate('Out Of Stock');
  389. }
  390. }
  391. //discount calculation
  392. $discount_applicable = false;
  393. if ($product->discount_start_date == null) {
  394. $discount_applicable = true;
  395. } elseif (
  396. strtotime(date('d-m-Y H:i:s')) >= $product->discount_start_date &&
  397. strtotime(date('d-m-Y H:i:s')) <= $product->discount_end_date
  398. ) {
  399. $discount_applicable = true;
  400. }
  401. if ($discount_applicable) {
  402. if ($product->discount_type == 'percent') {
  403. $price -= ($price * $product->discount) / 100;
  404. } elseif ($product->discount_type == 'amount') {
  405. $price -= $product->discount;
  406. }
  407. }
  408. // taxes
  409. foreach ($product->taxes as $product_tax) {
  410. if ($product_tax->tax_type == 'percent') {
  411. $tax += ($price * $product_tax->tax) / 100;
  412. } elseif ($product_tax->tax_type == 'amount') {
  413. $tax += $product_tax->tax;
  414. }
  415. }
  416. $price += $tax;
  417. return array(
  418. 'price' => single_price($price * $request->quantity),
  419. 'quantity' => $quantity,
  420. 'digital' => $product->digital,
  421. 'variation' => $str,
  422. 'max_limit' => $max_limit,
  423. 'in_stock' => $in_stock
  424. );
  425. }
  426. public function sellerpolicy()
  427. {
  428. $page = Page::where('type', 'seller_policy_page')->first();
  429. return view("frontend.policies.sellerpolicy", compact('page'));
  430. }
  431. public function returnpolicy()
  432. {
  433. $page = Page::where('type', 'return_policy_page')->first();
  434. return view("frontend.policies.returnpolicy", compact('page'));
  435. }
  436. public function supportpolicy()
  437. {
  438. $page = Page::where('type', 'support_policy_page')->first();
  439. return view("frontend.policies.supportpolicy", compact('page'));
  440. }
  441. public function terms()
  442. {
  443. $page = Page::where('type', 'terms_conditions_page')->first();
  444. return view("frontend.policies.terms", compact('page'));
  445. }
  446. public function privacypolicy()
  447. {
  448. $page = Page::where('type', 'privacy_policy_page')->first();
  449. return view("frontend.policies.privacypolicy", compact('page'));
  450. }
  451. public function get_pick_up_points(Request $request)
  452. {
  453. $pick_up_points = PickupPoint::all();
  454. return view('frontend.partials.pick_up_points', compact('pick_up_points'));
  455. }
  456. public function get_category_items(Request $request)
  457. {
  458. $category = Category::findOrFail($request->id);
  459. return view('frontend.partials.category_elements', compact('category'));
  460. }
  461. public function premium_package_index()
  462. {
  463. $customer_packages = CustomerPackage::all();
  464. return view('frontend.user.customer_packages_lists', compact('customer_packages'));
  465. }
  466. // public function new_page()
  467. // {
  468. // $user = User::where('user_type', 'admin')->first();
  469. // auth()->login($user);
  470. // return redirect()->route('admin.dashboard');
  471. // }
  472. public function transaction()
  473. {
  474. $user = Auth::user();
  475. return view('frontend.user.transaction', compact("user"));
  476. }
  477. public function tpwd(Request $request)
  478. {
  479. $user = Auth::user();
  480. $userModel = User::findOrFail($user->id);
  481. if ($_POST["type"] == 1) {
  482. if ($user->tpwd) {
  483. flash(translate('You have set a trading password .'))->error();
  484. return back();
  485. }
  486. // 设置密码
  487. if (!$_POST["password"]) {
  488. flash(translate('password empty.'))->error();
  489. return back();
  490. }
  491. if (!$_POST["confirm_password"]) {
  492. flash(translate('confirm password empty.'))->error();
  493. return back();
  494. }
  495. if ($_POST["confirm_password"] != $_POST["password"]) {
  496. flash(translate('Password does not match.'))->error();
  497. return back();
  498. }
  499. $reg = "/^[0-9]{6}$/";
  500. $result = preg_match($reg, $_POST["password"]);
  501. if (!$result) {
  502. flash(translate('The transaction password is a six-digit pure number .'))->error();
  503. return back();
  504. }
  505. $pwd = md5($_POST["password"]);
  506. $userModel->tpwd = $pwd;
  507. $userModel->save();
  508. flash(translate('Your password has been updated successfully!'))->success();
  509. return back();
  510. } else {
  511. if (!$_POST["spwd"]) {
  512. flash(translate('original password empty.'))->error();
  513. return back();
  514. }
  515. if (md5($_POST["spwd"]) != $user->tpwd) {
  516. flash(translate('original password error.'))->error();
  517. return back();
  518. }
  519. // 设置密码
  520. if (!$_POST["password"]) {
  521. flash(translate('password empty.'))->error();
  522. return back();
  523. }
  524. if (!$_POST["confirm_password"]) {
  525. flash(translate('confirm password empty.'))->error();
  526. return back();
  527. }
  528. if ($_POST["confirm_password"] != $_POST["password"]) {
  529. flash(translate('Password does not match.'))->error();
  530. return back();
  531. }
  532. $reg = "/^[0-9]{6}$/";
  533. $result = preg_match($reg, $_POST["password"]);
  534. if (!$result) {
  535. flash(translate('The transaction password is a six-digit pure number .'))->error();
  536. return back();
  537. }
  538. $pwd = md5($_POST["password"]);
  539. $userModel->tpwd = $pwd;
  540. $userModel->save();
  541. flash(translate('Your password has been updated successfully!'))->success();
  542. return back();
  543. }
  544. }
  545. // Ajax call
  546. public function new_verify(Request $request)
  547. {
  548. $email = $request->email;
  549. if (isUnique($email) == '0') {
  550. $response['status'] = 2;
  551. $response['message'] = 'Email already exists!';
  552. return json_encode($response);
  553. }
  554. $response = $this->send_email_change_verification_mail($request, $email);
  555. return json_encode($response);
  556. }
  557. // Form request
  558. public function update_email(Request $request)
  559. {
  560. $email = $request->email;
  561. if (isUnique($email)) {
  562. $this->send_email_change_verification_mail($request, $email);
  563. flash(translate('A verification mail has been sent to the mail you provided us with.'))->success();
  564. return back();
  565. }
  566. flash(translate('Email already exists!'))->warning();
  567. return back();
  568. }
  569. public function send_email_change_verification_mail($request, $email)
  570. {
  571. $response['status'] = 0;
  572. $response['message'] = 'Unknown';
  573. $verification_code = Str::random(32);
  574. $array['subject'] = 'Email Verification';
  575. $array['from'] = env('MAIL_FROM_ADDRESS');
  576. $array['content'] = 'Verify your account';
  577. $array['link'] = route('email_change.callback') . '?new_email_verificiation_code=' . $verification_code . '&email=' . $email;
  578. $array['sender'] = Auth::user()->name;
  579. $array['details'] = "Email Second";
  580. $user = Auth::user();
  581. $user->new_email_verificiation_code = $verification_code;
  582. $user->save();
  583. try {
  584. Mail::to($email)->queue(new SecondEmailVerifyMailManager($array));
  585. $response['status'] = 1;
  586. $response['message'] = translate("Your verification mail has been Sent to your email.");
  587. } catch (\Exception $e) {
  588. // return $e->getMessage();
  589. $response['status'] = 0;
  590. $response['message'] = $e->getMessage();
  591. }
  592. return $response;
  593. }
  594. public function email_change_callback(Request $request)
  595. {
  596. if ($request->has('new_email_verificiation_code') && $request->has('email')) {
  597. $verification_code_of_url_param = $request->input('new_email_verificiation_code');
  598. $user = User::where('new_email_verificiation_code', $verification_code_of_url_param)->first();
  599. if ($user != null) {
  600. $user->email = $request->input('email');
  601. $user->new_email_verificiation_code = null;
  602. $user->save();
  603. auth()->login($user, true);
  604. flash(translate('Email Changed successfully'))->success();
  605. if ($user->user_type == 'seller') {
  606. return redirect()->route('seller.dashboard');
  607. }
  608. return redirect()->route('dashboard');
  609. }
  610. }
  611. flash(translate('Email was not verified. Please resend your mail!'))->error();
  612. return redirect()->route('dashboard');
  613. }
  614. public function reset_password_with_code(Request $request)
  615. {
  616. if (($user = User::where('email', $request->email)->where('verification_code', $request->code)->first()) != null) {
  617. if ($request->password == $request->password_confirmation) {
  618. $user->password = Hash::make($request->password);
  619. $user->email_verified_at = date('Y-m-d h:m:s');
  620. $user->save();
  621. event(new PasswordReset($user));
  622. auth()->login($user, true);
  623. flash(translate('Password updated successfully'))->success();
  624. if (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff') {
  625. return redirect()->route('admin.dashboard');
  626. }
  627. return redirect()->route('home');
  628. } else {
  629. flash("Password and confirm password didn't match")->warning();
  630. return redirect()->route('password.request');
  631. }
  632. } else {
  633. flash("Verification code mismatch")->error();
  634. return redirect()->route('password.request');
  635. }
  636. }
  637. public function all_flash_deals()
  638. {
  639. $today = strtotime(date('Y-m-d H:i:s'));
  640. $data['all_flash_deals'] = FlashDeal::where('status', 1)
  641. ->where('start_date', "<=", $today)
  642. ->where('end_date', ">", $today)
  643. ->orderBy('created_at', 'desc')
  644. ->get();
  645. return view("frontend.flash_deal.all_flash_deal_list", $data);
  646. }
  647. public function all_seller(Request $request)
  648. {
  649. $shops = Shop::whereIn('user_id', verified_sellers_id())->where('home_display', 1)
  650. ->paginate(15);
  651. return view('frontend.shop_listing', compact('shops'));
  652. }
  653. public function all_coupons(Request $request)
  654. {
  655. $coupons = Coupon::where('start_date', '<=', strtotime(date('d-m-Y')))->where('end_date', '>=', strtotime(date('d-m-Y')))->paginate(15);
  656. return view('frontend.coupons', compact('coupons'));
  657. }
  658. public function inhouse_products(Request $request)
  659. {
  660. $products = filter_products(Product::query()->from("products as p")->where('added_by', 'admin'))->with('taxes')->paginate(12)->appends(request()->query());
  661. return view('frontend.inhouse_products', compact('products'));
  662. }
  663. }