/
home
/
old_henza
/
server
/
app
/
Http
/
Controllers
/
Api
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Http/Controllers/Api/SiteController.php
<?php namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use App\Models\ApkLog; use App\Models\Category; use App\Models\Collect; use App\Models\ConfigStatic; use App\Models\Link; use App\Models\Product; use App\Models\ProductBrand; use App\Models\ProductImage; use App\Models\ProductVariant; use App\Models\PromotionProduct; use App\Models\RequestFashion; use App\Models\WebServiceGold; use Corcel\Model\Post; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Ramsey\Collection\Collection; use Rooyesh\Wallet\interfaces\WalletInterface; use Rooyesh\Wallet\interfaces\TransactionInterface; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class SiteController extends Controller { public function getConfig() { Log::info('getConfig '); $config = []; ProductVariant::$goldPrice = WebServiceGold::getPriceGold18Ayar(); $config['popular'] = Product::site()->with(['collect', 'image', 'gallery', 'brand', 'variants' => function ($q) { // return $q->'price'="99999"; }])->orderBy('id', 'DESC') ->whereHas('collect', function ($q) { return $q->where('collection_id_id', 14); })->take(20) ->get()->filter(function ($product) { if (count($product->variants) > 0) return $product; }); $config['angoshtar'] = Product::site()->with(['collect', 'image', 'gallery', 'variants', 'brand'])->orderBy('id', 'DESC') ->whereHas('collect', function ($q) { return $q->where('collection_id_id', 14); })->take(20) ->get()->filter(function ($product) { if (count($product->variants) > 0) return $product; }); $config['dastband'] = Product::site()->with(['collect', 'gallery', 'image', 'variants', 'brand'])->orderBy('id', 'DESC') ->whereHas('collect', function ($q) { return $q->where('collection_id_id', 2); })->take(20) ->get()->filter(function ($product) { if (count($product->variants) > 0) return $product; }); $config['service'] = Product::site()->with(['collect', 'gallery', 'image', 'variants', 'brand'])->orderBy('id', 'DESC') ->whereHas('collect', function ($q) { return $q->where('collection_id_id', 7); })->take(20) ->get()->filter(function ($product) { if (count($product->variants) > 0) return $product; }); //Filter value $config['color'] = ProductVariant::$COLOR_STR; //$config['filterBrand']=ConfigStatic::where('key','brand')->get(); $config['filterBrand'] = ProductBrand::orderBy('priority','desc')->get(); $config['filterGram'] = []; $config['filterGram'][] = ProductVariant::min('grams'); $config['filterGram'][] = ProductVariant::max('grams'); $config['filterPercentPay'] = []; $config['filterPercentPay'][] = ProductVariant::min('percentage_pay'); $config['filterPercentPay'][] = ProductVariant::max('percentage_pay'); //$config['filterBrand']=ConfigStatic::where('key','brand')->get(); return new JsonResponse($config); } /*public static $MENU = [ 1 => [ ], ];*/ public function config(Request $request) { /* $this->validate( $request, [ 'uEmail' => 'required', 'uPassword' => 'required' ], [ 'uEmail.required' => 'Please Provide Your Email Address For Better Communication, Thank You.', 'uEmail.unique' => 'Sorry, This Email Address Is Already Used By Another User. Please Try With Different One, Thank You.', 'uPassword.required' => 'Password Is Required For Your Information Safety, Thank You.', 'uPassword.min' => 'Password Length Should Be More Than 8 Character Or Digit Or Mix, Thank You.', ] );*/ /* $this->validate( $request, ['thing' => 'required'], ['thing.required' => 'this is my custom error message for required'] );*/ $goldPrice = WebServiceGold::getPriceGold18Ayar(); $config = []; $config['menu'] = Category::desktop()->whereNull('parent_id_id')->with(['childs'])->orderBy('priority')->get(); $config['filterGram'][] = ProductVariant::min('grams'); $config['filterGram'][] = ProductVariant::max('grams'); $config['filterPrice'][] = floor(($config['filterGram'][0] * $goldPrice) / 1000) * 1000; $config['filterPrice'][] = floor(($config['filterGram'][1] * $goldPrice) / 1000) * 1000; //$config['brands']=ConfigStatic::where('key','brand')->get(); $config['brands'] = ProductBrand::orderBy('priority','desc')->get(); $config['colors'] = ProductVariant::$COLOR_STR; $config['category'] = Category::whereIn('type',[1,3])->get(); $config['price'] = WebServiceGold::getAllPrice(); $config['site'] = json_decode(ConfigStatic::getValue('site'),true) ; return new JsonResponse($config); } public function newConfig(Request $request) { $goldPrice = WebServiceGold::getPriceGold18Ayar(); $config = []; $config['menu'] = Category::desktop()->whereNull('parent_id_id')->with(['childs'])->orderBy('priority')->get(); $config['filterGram'][] = ProductVariant::min('grams'); $config['filterGram'][] = ProductVariant::max('grams'); $config['filterPrice'][] = floor(($config['filterGram'][0] * $goldPrice) / 1000) * 1000; $config['filterPrice'][] = floor(($config['filterGram'][1] * $goldPrice) / 1000) * 1000; //$config['brands']=ConfigStatic::where('key','brand')->get(); $config['brands'] = ProductBrand::orderBy('priority','desc')->get(); $config['colors'] = ProductVariant::$COLOR_STR; $config['category'] = Category::whereIn('type',[1,3])->get(); $config['price'] = WebServiceGold::getAllPrice(); $config['site'] = json_decode(ConfigStatic::getValue('site'),true) ; if (isset($request->products_id)){ $this->sendDiscount(); $config['products'] = Product::with(['promotion','collect.collection', 'image', 'variants.promotion', 'gallery'])->whereIn('id', $request->products_id)->get(); } return response()->json($config); } public function getMenu() { //$menu=Config::where('key','menu')->orderBy('id','asc')->get()->toArray(); // return new JsonResponse($menu); } public function getProduct(Request $request) { $goldPrice =$this->sendDiscount(); $product = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery', 'tags', 'file'])->findOrFail($request->id); $related_before = Product::site()->where('id', '!=', $product->id) ->where('min_gram','>',$product->min_gram - 5) ->where('min_gram','<=',$product->min_gram) ->with(['collect', 'image', 'brand', 'gallery', 'variants'=>function($v){ return $v->where('is_active',true); }])->orderBy('min_gram', 'desc') ->whereHas('collect', function ($q) use ($product) { return $q->where('collection_id_id', $product->collect->first()->collection_id_id); })->whereHas('variantOne')->take(10)->get(); $related_after = Product::site()->where('id', '!=', $product->id) ->where('min_gram','<',$product->min_gram + 5) ->where('min_gram','>=',$product->min_gram) ->with(['collect', 'image', 'brand', 'gallery', 'variants'=>function($v){ return $v->where('is_active',true); }])->orderBy('min_gram', 'asc') ->whereHas('collect', function ($q) use ($product) { return $q->where('collection_id_id', $product->collect->first()->collection_id_id); })->whereHas('variantOne')->take(10)->get(); $related = array_reverse($related_before->toArray()); foreach ($related_after as $item){ $related[] = $item; } $product['related'] = $related; $product['goldPrice'] = $goldPrice; $product->increment('count_view'); return response()->json($product); } public function sendDiscount(){ Log::info('sendDiscount '); $goldPrice = WebServiceGold::getPriceGold18Ayar(); ProductVariant::$goldPrice = $goldPrice; $dis = PromotionProduct::where('active',true) ->where('start_at','<=',now()) ->where('end_at','>=',now()) ->orderBy('discount','desc') ->get() ->toArray(); ProductVariant::$dis_product = $dis; return $goldPrice; } public function products(Request $request) { Log::info('products '); $goldPrice =$this->sendDiscount(); $products = Product::site() // ->whereHas('variants',function($q){ // return $q->where('is_active',true); // }) ->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']); if ($request->cats) { $children = Category::where('parent_id_id',$request->cats)->select('id')->get()->pluck('id')->toArray(); $products->whereHas('collect', function ($q) use ($request,$children) { if (isset($children) && count($children)>0){ return $q->whereIn('collection_id_id', $children); } return $q->where('collection_id_id', $request->cats); }); } $products->whereRaw('lower(`title`) like ?', ['%' . strtolower($request->search_text) . '%']); if ($request->brands) { $products->where('brand_id', $request->brands); } if ($request->colors != null) { $products->whereHas('variants', function ($q) use ($request) { return $q->where('color', '=', $request->colors); }); } if ($request->weight) { $products->whereHas('variants', function ($q) use ($request) { return $q->whereBetween('grams', $request->weight); }); } if ($request->price_range) { $gram = array_map(function ($item) use ($goldPrice) { return $item / $goldPrice; }, $request->price_range); $products->whereHas('variants', function ($q) use ($gram) { return $q->whereBetween('grams', $gram); }); } if($request->has('ready')){ $products->whereHas('variants',function ($q){ return $q->where('qty','>',0); }); } if($request->has('offer_day')){ $products->where('offer_day',1); } if ($request->tags && is_array($request->tags) && sizeof($request->tags) > 0) { $products->whereHas('tags', function ($q) use ($request) { return $q->whereIn('const_id', $request->tags); }); } if ($request->has('order_field')){ if ($request->order_field == 'grams'){ if ($request->order_by == 'asc'){ $products->orderBy('min_gram',$request->order_by); } else{ $products->orderBy('max_gram',$request->order_by); } }else{ $products->orderBy($request->order_field,$request->order_by); } }else{ $products->orderBy('id', 'desc'); } $export = []; $export['page'] = $request->page ?? 1; $export['limit'] = $request->limit ?? 12; $export['count'] = $products->count(); if ($export['count'] < $export['limit'] * ($export['page'] - 1)) { $export['page'] = 1; } $export['rows'] = $products->limit($export['limit'])->offset($export['limit'] * ($export['page'] - 1))->get(); return response()->json($export); } public function searchProduct(Request $request) { Log::info('searchProduct'); $this->validate($request, [ 'text' => 'required' ]); $products = Product::site()->where('title', 'like', '%' . $request->text . '%') ->with(['collect.collection', 'image', 'variants', 'brand', 'gallery']) ->take(10) ->get(); //->where()->take(10); return response()->json($products); } public function ّFront(Request $request) { Log::info('ّFront'); $front = []; $goldPrice =$this->sendDiscount(); //set gold price // $goldPrice = WebServiceGold::getPriceGold18Ayar(); // ProductVariant::$goldPrice = $goldPrice; //new method // $front['new_products'] = []; // $front['new_products'] = Product::site()->whereHas('tags',function ($q){ // return $q->where('const_id',110); // })->orderBy('id', 'DESC')->limit(10)->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery'])->get(); // // $front['new_products'][] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->orderBy('created_at', 'desc') // ->whereHas('collect.collection', function ($q) { // return $q->where('id', 2)->orWhere('id', 23); // })->first(); // // $front['new_products'][] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->orderBy('created_at', 'desc') // ->whereHas('collect.collection', function ($q) { // return $q->where('id', 15); // })->first(); // $front['new_products'][] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->orderBy('created_at', 'desc') // ->whereHas('collect.collection', function ($q) { // return $q->where('id', 18); // })->first(); // $front['top_products'] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->whereIn('id', [758, 723, 503])->get(); $front['category'] =Category::with(['image' , 'icon'])->get(); /*$front['analysis_category'] = []; $front['analysis_category']['angoshtar'] = Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [20, 14]); })->count(); $front['analysis_category']['service'] = Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [7, 19]); })->count(); $front['analysis_category']['dastband'] = Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [2, 23]); })->count(); $front['analysis_category']['gardanband'] = Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [15]); })->count(); $front['analysis_category']['goshvare'] = Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [18]); })->count(); $front['analysis_category']['ro_lebasi'] =Product::site()->whereHas('collect',function ($q){ return $q->whereIn('collection_id_id', [22]); })->count();*/ /*$front['analysis_category']['angoshtar'] = Collect::whereIn('collection_id_id', [20, 14])->count(); $front['analysis_category']['service'] = Collect::whereIn('collection_id_id', [7, 19])->count(); $front['analysis_category']['dastband'] = Collect::whereIn('collection_id_id', [2, 23])->count(); $front['analysis_category']['gardanband'] = Collect::whereIn('collection_id_id', [15])->count(); $front['analysis_category']['goshvare'] = Collect::whereIn('collection_id_id', [18])->count(); $front['analysis_category']['ro_lebasi'] = Collect::whereIn('collection_id_id', [22])->count();*/ // $front['featured_products'] = []; // $front['featured_products']['service'] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->where('brand_id', 32) // ->whereHas('collect', function ($q) { // return $q->whereIn('collection_id_id', [14]); // })->limit(3)->get(); // // $front['featured_products']['gardanband'] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->where('brand_id', 32) // ->whereHas('collect', function ($q) { // return $q->whereIn('collection_id_id', [15]); // })->limit(3)->get(); // // $front['featured_products']['goshvare'] = Product::site()->with(['promotion','collect.collection', 'image', 'variants', 'brand', 'gallery']) // ->where('brand_id', 32) // ->whereHas('collect', function ($q) { // return $q->whereIn('collection_id_id', [18]); // })->limit(3)->get(); $blogs = Post::status('publish')->type('post')->newest()->limit(3)->get(); foreach ($blogs as $blog){ $array["post_title"] = $blog['post_title']; $array["title"] = $blog['title']; $array["image"] = $blog['image']; $array["ID"] = $blog['ID']; $array["guid"] = $blog['guid']; $array["post_name"] = $blog['post_name']; $front['new_blog'][] = $array; } $const = ConfigStatic::where('key','topProductsId')->first(); $const = json_decode($const->val,true); $top_products = Product::with(['promotion','collect.collection', 'image', 'variants.promotion', 'gallery'])->whereIn('id', $const)->get(); $front['top_products'] = $top_products; $front['offer'] = Product::site()->with(['promotion','collect.collection', 'image', 'variants.promotion', 'gallery']) ->where('offer_day', 1)->get(); //get random products $front['random'] = $this->getRandomProduct(); return response()->json($front); } public function getProductsVaraints(Request $request) { Log::info('getProductsVaraints'); // $goldPrice = WebServiceGold::getPriceGold18Ayar(); // ProductVariant::$goldPrice = $goldPrice; $goldPrice =$this->sendDiscount(); //$varints=ProductVariant::whereIn('id',$request->varinat)->get(); $products = Product::with(['promotion','collect.collection', 'image', 'variants.promotion', 'gallery'])->whereIn('id', $request->products_id)->get(); return new JsonResponse($products); /* $products=Product::with(['collect.collection','image','variants'])->whereHas('variants',function ($q) use($request){ $q->whereIn('id',$request->varinat); }); return new JsonResponse($products->get());*/ /* $varaints=[]; foreach ($request->varinat as $varinatId) { $productId=ProductVariant::findOrFail($varinatId)->product_id_id; $p=Product::with(['collect.collection','image','variants'=>function($q) use($varinatId){ return $q->where('id',$varinatId); }])->where('id',$productId)->get(); array_push($varaints,$p); } return new JsonResponse($varaints);*/ } public function test() { $wallet_interface = new WalletInterface(1, 1); $transaction = new TransactionInterface($wallet_interface, $_inp = [ "value" => "1000", 'expire_at'=>now()->addYear(), ], 2, true); dd($transaction); } function downloadApk(Request $request) { Log::info('downloadApk'); ApkLog::create(['ip' => $request->ip(), 'version' => env('APK_VERSION', 0)]); $path = env('APK_PATH', storage_path('app/public/henza.apk')); return response()->download($path); } public function counterInstagram(){ $config = ConfigStatic::where('key','counter_instagram')->increment('val'); return response()->json(true); } public function getRandomProduct(){ $this->sendDiscount(); $parent = Category::whereNull('parent_id_id') ->where('type',1) ->where('total','>',0) ->get(); $array = []; $ids = []; foreach ($parent as $item){ $collection = Category::where('parent_id_id',$item->id) ->where('type',1) ->where('total','>',0) ->select('id')->get()->pluck('id')->toArray(); $collection[] = $item->id; $products = Product::site()->whereHas('collect',function ($q)use($collection){ return $q->whereIn('collection_id_id',$collection); })-> whereHas('variantOne',function ($q)use($collection){ return $q->where('qty','>',0); }) ->limit(20)->orderBy('id','desc')->get(); if (count($products)>0){ $random = $products[rand(0,count($products)-1)] ; if (!in_array($random->id,$ids)){ $ids[] = $random->id; $array[] = Product::site()->with(['promotion','collect', 'image', 'gallery', 'variants', 'brand'])->find($random->id); } } } return $array; } public function counterActive(){ Link::set('https://henzagold.com/app'); // ConfigStatic::where('key','counter_active')->increment('val'); return redirect()->to('https://henzagold.com/app'); } public function counterLanding(){ Link::set('https://henzagold.com/landing'); return redirect()->to('https://henzagold.com/landing'); } public function setRequestFashion(Request $request){ $fashion = RequestFashion::where('mobile',$request->mobile)->first(); if (is_null($fashion)){ RequestFashion::create($request->all()); }else{ return response()->json('شما قبلا ثبت نام کرده اید',422); } return response()->json(true); } public function readySend(){ $products = Product::site()->with(['promotion','collect.collection', 'image', 'variants.promotion', 'gallery'])->whereHas('variantOne',function ($q){ return $q->where('qty','>',0); })->get(); return response()->json($products); } }
Copyright ©2k19 -
Hexid
|
Tex7ure