/
home
/
old_henza
/
server
/
app
/
Http
/
Controllers
/
Site
/
File Upload :
llllll
Current File: /home/old_henza/server/app/Http/Controllers/Site/SiteController.php
<?php namespace App\Http\Controllers\Site; use App\Http\Controllers\Adm\SmsController; use App\Http\Controllers\Controller; use App\Jobs\SendSmsJob; use App\Models\Category; use App\Models\ConfigStatic; use App\Models\Customer; use App\Models\Product; use App\Models\ProductTags; use App\Models\ProductVariant; use App\Models\SingleCustomer; use App\Models\Sms; use App\Models\WebServiceGold; use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Http; use Morilog\Jalali\Jalalian; use Rooyesh\Wallet\interfaces\TransactionInterface; use Rooyesh\Wallet\interfaces\WalletInterface; use Rooyesh\Wallet\models\Transaction; class SiteController extends Controller { public function products(Request $request) { $products = Product::site()->with([ 'variants', 'brand']); 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', '=', 0); }); } 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->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 getCustomer(){ // $c = Customer::whereHas('orderOne')->select('id')->get()->pluck('id')->toArray(); // $customer = Customer::whereNotIn('id',$c)->select(['mobile'])->get()->pluck('mobile'); $mobiles[] = '09136982135'; $mobiles[] = '09016096380'; $mobiles[] = '09382507041'; $mobiles[] = '09128081392'; $message = 'الان وقتشه...'."\n". '%name'."\n". 'شما می توانید ار تاریخ 13 تا 26 بهمن ماه با اولین ثبت سفارش از 1% تخفیف بهره مند شوید. '."\n". 'تامینت را به ما بسپار!'."\n". 'اپلیکیشن طلای هنزا'; foreach($mobiles as $mobile){ $customer = Customer::where('mobile',$mobile)->first(); if (str_contains($message,'name')){ $message = str_replace("%", ' ', $message); if (!is_null($customer) && !is_null($customer->name)){ $message = str_replace("name", ' '.$customer->name.' گرامی ', $message); }else{ $message = str_replace("name", ' مشتری گرامی ', $message); } } SendSmsJob::dispatch($mobile,$message,$customer->id,auth()->id())->onConnection('database'); } return response()->json($customer); } public function getProduct(Request $request) { $product = Product::site()->findOrFail($request->id); $related_before = Product::site()->with(['variants'=>function($v){ return $v->where('is_active',true); }]) ->where('id', '!=', $product->id)->where('min_gram','>',$product->min_gram - 5)->where('min_gram','<=',$product->min_gram)->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(20)->get(); $related = $related_before; $related_after = Product::site()->where('id', '!=', $product->id)->where('min_gram','<',$product->min_gram + 5)->where('min_gram','>=',$product->min_gram)->orderBy('min_gram', 'asc') ->whereHas('collect', function ($q) use ($product) { return $q->where('collection_id_id', $product->collect->first()->collection_id_id); })->take(20)->get()->filter(function ($product) { if (count($product->variants) > 0) return $product; }); foreach ($related_after as $item){ $related[] = $item; } $product['related'] = $related; $product->increment('count_view'); return response()->json($product); } public function addTag(){ $product = Product::where('title','like','%'.'انگشتر'.'%') ->where('min_gram','<',3) ->get(); // $product = Product::whereHas('collect',function ($q){ // return $q->whereIn('collection_id_id',[36,34,28,25,22,20,14]); // }) // ->where('min_gram','<',3) // ->get(); foreach ($product as $p){ ProductTags::create([ 'product_id'=>$p->id, 'const_id'=>93, ]); } return $product->count(); } public function getBirthday(){ $value = ConfigStatic::where('key','birthday_credit')->first()->val; $expire = ConfigStatic::where('key','birthday_expire')->first()->val; $customers = SingleCustomer::whereDay('birth_day',now()->format('d')) ->whereMonth('birth_day', now()->format('m')) ->get(); foreach ($customers as $cu){ Sms::Send($cu->phone , 'سلام'."\n" .$cu->fname.' '.$cu->lname.' گرامی '."\n" .'زادروزتان مبارک'."\n" .'گالري طلاي هنزا برای هديه تولد شما، بن خرید '.$value.' هزارتومانی در نظر گرفته است.'."\n" .'با ارزوی بهترین ها برای شما'."\n" .'بازدید و سفارش محصولات www.henzagold.com'."\n" .'هنزا لحظات درخشان زندگی شما' ); $wallet_interface = new WalletInterface($cu->id, 1); $transaction = new TransactionInterface($wallet_interface, $_inp = [ "value" => $value, "note"=>"for birthday", 'expire_at'=>now()->addDays($expire), ], 2, true); } } public function serviceGold(){ $data=ConfigStatic::where('key','gold_price')->first(); $service = Http::get('https://api.ratebox.ir/apijson.php?token=41e58ccc0d6faa6adbd1e5122d38c3b6') ->json(); $array['mesghal'] = $service[4]; $array['mesghal']['slug'] = 'mesghal'; $array['mesghal']['uaj'] = Jalalian::forge($array['mesghal']['updated_at'])->format('Y/m/d - h:i'); $array['geram18'] = $service[5]; $array['geram18']['slug'] = "geram18"; $array['geram18']['uaj'] = Jalalian::forge($array['geram18']['updated_at'])->format('Y/m/d - h:i'); $array['geram24'] = $service[6]; $array['geram24']['slug'] = "geram24"; $array['geram24']['uaj'] = Jalalian::forge($array['geram24']['updated_at'])->format('Y/m/d - h:i'); return response()->json($array); } public function test123(){ $customers = SingleCustomer::all(); // foreach ($customers as $customer){ $transactions_expired_credit = Transaction::whereDate('expire_at', '<', now()->format('Y-m-d')) ->where('transaction_type', 2) ->where('wallet', 3) ->sum('value'); $transactions_expired_gold = Transaction::whereDate('expire_at', '<', now()->format('Y-m-d')) ->where('transaction_type', 1) ->where('wallet', 3) ->sum('value'); $transaction_gold = Transaction::where('value', '<', 0) ->where('transaction_type', 1) ->where('wallet', 3) ->sum('value'); $transaction_credit = Transaction::where('value', '<', 0) ->where('transaction_type', 2) ->where('wallet', 3) ->sum('value'); $total_gold = $transactions_expired_gold - abs($transaction_gold); $total_credit = $transactions_expired_credit - abs($transaction_credit); if ($total_gold > 0 || $total_credit > 0){ $wallet_interface = new WalletInterface(244, 1); if ($total_gold > 0){ new TransactionInterface($wallet_interface, $_inp = [ "value" => $total_gold, "note"=>"for expire system", ], 1, false); } if ($total_credit > 0){ new TransactionInterface($wallet_interface, $_inp = [ "value" => $total_gold, "note"=>"for expire system", ], 2, false); } } // } } public function searchDeactive(){ $p = Product::whereHas('variantsAll',function ($q){ return $q->where('is_active',false); })->where('is_active',true)->get(); return response()->json($p); } public function testG(){ $service = Http::get('https://api.ratebox.ir/apijson.php?token='.env('WEBSERVICE_TOKEN')) ->json(); if (!is_null($service)){ $service['uaj'] = Jalalian::forge(now())->format('Y/m/d - H:i:s'); $filtered =Arr::except($service, [7,8,9,10,20,21,22,23,24,25,26,27,28,29]); } return $service; } }
Copyright ©2k19 -
Hexid
|
Tex7ure