Nuevos cambios hechos de diseño

This commit is contained in:
ellecio2
2023-08-23 17:33:44 -04:00
parent 7a806f84ff
commit d2e9ba53ab
3485 changed files with 691106 additions and 0 deletions

View File

@@ -0,0 +1,322 @@
<?php
namespace App\Services;
use App\Models\Cart;
use App\Models\Product;
use App\Models\ProductStock;
use App\Models\ProductTax;
use App\Models\ProductTranslation;
use Artisan;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class AuctionService
{
public function store(Request $request){
$product = new Product;
$product->name = $request->name;
$product->added_by = $request->added_by;
if(Auth::user()->user_type == 'seller'){
$product->user_id = Auth::user()->id;
if(get_setting('product_approve_by_admin') == 1) {
$product->approved = 0;
}
}
else{
$product->user_id = \App\Models\User::where('user_type', 'admin')->first()->id;
}
$product->auction_product = 1;
$product->category_id = $request->category_id;
$product->brand_id = $request->brand_id;
$product->barcode = $request->barcode;
$product->starting_bid = $request->starting_bid;
if (addon_is_activated('refund_request')) {
if ($request->refundable != null) {
$product->refundable = 1;
}
else {
$product->refundable = 0;
}
}
$product->photos = $request->photos;
$product->thumbnail_img = $request->thumbnail_img;
// $product->min_qty = 1;
// $product->stock_visibility_state = '';
$tags = array();
if($request->tags[0] != null){
foreach (json_decode($request->tags[0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$product->tags = implode(',', $tags);
$product->description = $request->description;
$product->video_provider = $request->video_provider;
$product->video_link = $request->video_link;
if ($request->auction_date_range != null) {
$date_var = explode(" to ", $request->auction_date_range);
$product->auction_start_date = strtotime($date_var[0]);
$product->auction_end_date = strtotime($date_var[1]);
}
$product->shipping_type = $request->shipping_type;
$product->est_shipping_days = $request->est_shipping_days;
if (addon_is_activated('club_point')) {
if($request->earn_point) {
$product->earn_point = $request->earn_point;
}
}
if ($request->has('shipping_type')) {
if($request->shipping_type == 'free'){
$product->shipping_cost = 0;
}
elseif ($request->shipping_type == 'flat_rate') {
$product->shipping_cost = $request->flat_shipping_cost;
}
elseif ($request->shipping_type == 'product_wise') {
$product->shipping_cost = json_encode($request->shipping_cost);
}
}
if ($request->has('is_quantity_multiplied')) {
$product->is_quantity_multiplied = 1;
}
$product->meta_title = $request->meta_title;
$product->meta_description = $request->meta_description;
if($request->has('meta_img')){
$product->meta_img = $request->meta_img;
} else {
$product->meta_img = $product->thumbnail_img;
}
if($product->meta_title == null) {
$product->meta_title = $product->name;
}
if($product->meta_description == null) {
$product->meta_description = strip_tags($product->description);
}
if($product->meta_img == null) {
$product->meta_img = $product->thumbnail_img;
}
if($request->hasFile('pdf')){
$product->pdf = $request->pdf->store('uploads/products/pdf');
}
$product->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->name)).'-'.Str::random(5);
$product->colors = json_encode(array());
$product->attributes = json_encode(array());
$product->choice_options = json_encode(array(), JSON_UNESCAPED_UNICODE);
if ($request->has('cash_on_delivery')) {
$product->cash_on_delivery = 1;
}
if ($request->has('todays_deal')) {
$product->todays_deal = 1;
}
$product->cash_on_delivery = 0;
if ($request->cash_on_delivery) {
$product->cash_on_delivery = 1;
}
$product->save();
//VAT & Tax
if($request->tax_id) {
foreach ($request->tax_id as $key => $val) {
$product_tax = new ProductTax;
$product_tax->tax_id = $val;
$product_tax->product_id = $product->id;
$product_tax->tax = $request->tax[$key];
$product_tax->tax_type = $request->tax_type[$key];
$product_tax->save();
}
}
//Generates the combinations of customer choice options
$product_stock = new ProductStock;
$product_stock->product_id = $product->id;
$product_stock->variant = '';
$product_stock->price = 0;
$product_stock->sku = $request->sku;
$product_stock->qty = 1;
$product_stock->save();
//combinations end
$product->save();
// Product Translations
$product_translation = ProductTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'product_id' => $product->id]);
$product_translation->name = $request->name;
$product_translation->unit = $request->unit;
$product_translation->description = $request->description;
$product_translation->save();
flash(translate('Product has been inserted successfully'))->success();
Artisan::call('view:clear');
Artisan::call('cache:clear');
}
public function update(Request $request , $id){
$product = Product::findOrFail($id);
$product->category_id = $request->category_id;
$product->brand_id = $request->brand_id;
$product->barcode = $request->barcode;
$product->cash_on_delivery = 0;
$product->is_quantity_multiplied = 0;
if (addon_is_activated('refund_request')) {
if ($request->refundable != null) {
$product->refundable = 1;
}
else {
$product->refundable = 0;
}
}
if($request->lang == env("DEFAULT_LANGUAGE")){
$product->name = $request->name;
$product->unit = $request->unit;
$product->description = $request->description;
$product->slug = strtolower($request->slug);
}
$product->photos = $request->photos;
$product->thumbnail_img = $request->thumbnail_img;
$tags = array();
if($request->tags[0] != null){
foreach (json_decode($request->tags[0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$product->tags = implode(',', $tags);
$product->video_provider = $request->video_provider;
$product->video_link = $request->video_link;
$product->starting_bid = $request->starting_bid;
if ($request->auction_date_range != null) {
$date_var = explode(" to ", $request->auction_date_range);
$product->auction_start_date = strtotime($date_var[0]);
$product->auction_end_date = strtotime( $date_var[1]);
}
$product->shipping_type = $request->shipping_type;
$product->est_shipping_days = $request->est_shipping_days;
if (addon_is_activated('club_point')) {
if($request->earn_point) {
$product->earn_point = $request->earn_point;
}
}
if ($request->has('shipping_type')) {
if($request->shipping_type == 'free'){
$product->shipping_cost = 0;
}
elseif ($request->shipping_type == 'flat_rate') {
$product->shipping_cost = $request->flat_shipping_cost;
}
elseif ($request->shipping_type == 'product_wise') {
$product->shipping_cost = json_encode($request->shipping_cost);
}
}
if ($request->has('is_quantity_multiplied')) {
$product->is_quantity_multiplied = 1;
}
if ($request->has('cash_on_delivery')) {
$product->cash_on_delivery = 1;
}
$product->meta_title = $request->meta_title;
$product->meta_description = $request->meta_description;
$product->meta_img = $request->meta_img;
if($product->meta_title == null) {
$product->meta_title = $product->name;
}
if($product->meta_description == null) {
$product->meta_description = strip_tags($product->description);
}
if($product->meta_img == null) {
$product->meta_img = $product->thumbnail_img;
}
$product->pdf = $request->pdf;
$product->colors = json_encode(array());
$product->attributes = json_encode(array());
$product->choice_options = json_encode(array(), JSON_UNESCAPED_UNICODE);
$product->save();
//VAT & Tax
if($request->tax_id) {
ProductTax::where('product_id', $product->id)->delete();
foreach ($request->tax_id as $key => $val) {
$product_tax = new ProductTax;
$product_tax->tax_id = $val;
$product_tax->product_id = $product->id;
$product_tax->tax = $request->tax[$key];
$product_tax->tax_type = $request->tax_type[$key];
$product_tax->save();
}
}
// Product Translations
$product_translation = ProductTranslation::firstOrNew(['lang' => $request->lang, 'product_id' => $product->id]);
$product_translation->name = $request->name;
$product_translation->unit = $request->unit;
$product_translation->description = $request->description;
$product_translation->save();
flash(translate('Product has been updated successfully'))->success();
Artisan::call('view:clear');
Artisan::call('cache:clear');
}
public function destroy($id){
$product = Product::findOrFail($id);
foreach ($product->product_translations as $key => $product_translations) {
$product_translations->delete();
}
foreach ($product->bids as $key => $bid) {
$bid->delete();
}
if(Product::destroy($id)){
Cart::where('product_id', $id)->delete();
flash(translate('Product has been deleted successfully'))->success();
Artisan::call('view:clear');
Artisan::call('cache:clear');
}
else{
flash(translate('Something went wrong'))->error();
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Fast2sms implements SendSms {
public function send($to, $from, $text, $template_id)
{
if (strpos($to, '+91') !== false) {
$to = substr($to, 3);
}
if (env("ROUTE") == 'dlt_manual') {
$fields = array(
"sender_id" => env("SENDER_ID"),
"message" => $text,
"template_id" => $template_id,
"entity_id" => env("ENTITY_ID"),
"language" => env("LANGUAGE"),
"route" => env("ROUTE"),
"numbers" => $to,
);
} else {
$fields = array(
"sender_id" => env("SENDER_ID"),
"message" => $text,
"language" => env("LANGUAGE"),
"route" => env("ROUTE"),
"numbers" => $to,
);
}
$auth_key = env('AUTH_KEY');
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.fast2sms.com/dev/bulkV2",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($fields),
CURLOPT_HTTPHEADER => array(
"authorization: $auth_key",
"accept: */*",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
return $response;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
use App\Utility\MimoUtility;
class Mimo implements SendSms{
public function send($to, $from, $text, $template_id)
{
$token = MimoUtility::getToken();
MimoUtility::sendMessage($text, $to, $token);
MimoUtility::logout($token);
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Mimsms implements SendSms{
public function send($to, $from, $text, $template_id)
{
$url = env('MIM_BASE_URL') . "/smsapi";
$data = [
"api_key" => env('MIM_API_KEY'),
"type" => "text",
"contacts" => $to,
"senderid" => env('MIM_SENDER_ID'),
"msg" => $text,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Msegat implements SendSms {
public function send($to, $from, $text, $template_id)
{
$url = "https://www.msegat.com/gw/sendsms.php";
$data = [
"apiKey" => env('MSEGAT_API_KEY'),
"numbers" => $to,
"userName" => env('MSEGAT_USERNAME'),
"userSender" => env('MSEGAT_USER_SENDER'),
"msg" => $text
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Nexmo implements SendSms {
public function send($to, $from, $text, $template_id) {
$api_key = env("NEXMO_KEY"); //put ssl provided api_token here
$api_secret = env("NEXMO_SECRET"); // put ssl provided sid here
$params = [
"api_key" => $api_key,
"api_secret" => $api_secret,
"from" => env("NEXMO_SENDER_ID"),
"text" => $text,
"to" => $to
];
$url = "https://rest.nexmo.com/sms/json";
$params = json_encode($params);
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params),
'accept:application/json'
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Sparrow implements SendSms {
public function send($to, $from, $text, $template_id)
{
$url = "http://api.sparrowsms.com/v2/sms/";
$args = http_build_query(array(
"token" => env('SPARROW_TOKEN'),
"from" => env('MESSGAE_FROM'),
"to" => $to,
"text" => $text
));
# Make the call using API.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Response
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class SslWireless implements SendSms {
public function send($to, $from, $text, $template_id)
{
$token = env("SSL_SMS_API_TOKEN"); //put ssl provided api_token here
$sid = env("SSL_SMS_SID"); // put ssl provided sid here
$params = [
"api_token" => $token,
"sid" => $sid,
"msisdn" => $to,
"sms" => $text,
"csms_id" => date('dmYhhmi') . rand(10000, 99999)
];
$url = env("SSL_SMS_URL");
$params = json_encode($params);
$ch = curl_init(); // Initialize cURL
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($params),
'accept:application/json'
));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
use Twilio\Rest\Client;
class Twillo implements SendSms
{
public function send($to, $from, $text, $template_id)
{
$sid = env("TWILIO_SID"); // Your Account SID from www.twilio.com/console
$token = env("TWILIO_AUTH_TOKEN"); // Your Auth Token from www.twilio.com/console
$type = env("TWILLO_TYPE"); // sms type
$client = new Client($sid, $token);
try {
$client->messages->create(
($type == 1) ? $to : "whatsapp:" . $to, // Text this number
array(
'from' => ($type == 1) ? env('VALID_TWILLO_NUMBER') : "whatsapp:" . env('VALID_TWILLO_NUMBER'), // From a valid Twilio number
'body' => $text
)
);
} catch (\Exception $e) {
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Services\OTP;
use App\Contracts\SendSms;
class Zender implements SendSms {
public function send($to, $from, $text, $template_id)
{
if (empty(env('ZENDER_SERVICE')) || env('ZENDER_SERVICE') < 2) {
if (!empty(env('ZENDER_DEVICE'))) {
$mode = "devices";
} else {
$mode = "credits";
}
if ($mode == "devices") {
$params = [
"secret" => env('ZENDER_APIKEY'),
"mode" => "devices",
"device" => env('ZENDER_DEVICE'),
"phone" => $to,
"message" => $text,
"sim" => env('ZENDER_SIM') < 2 ? 1 : 2
];
} else {
$params = [
"secret" => env('ZENDER_APIKEY'),
"mode" => "credits",
"gateway" => env('ZENDER_GATEWAY'),
"phone" => $to,
"message" => $text
];
}
$apiurl = env('ZENDER_SITEURL') . "/api/send/sms";
} else {
$params = [
"secret" => env('ZENDER_APIKEY'),
"account" => env('ZENDER_WHATSAPP'),
"type" => "text",
"recipient" => $to,
"message" => $text
];
$apiurl = env('ZENDER_SITEURL') . "/api/send/whatsapp";
}
$args = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Response
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -0,0 +1,151 @@
<?php
namespace App\Services;
use Illuminate\Http\Request;
use App\Models\Order;
use App\Models\ProductStock;
use App\Models\SmsTemplate;
use App\Models\User;
use App\Utility\NotificationUtility;
use App\Utility\SmsUtility;
class OrderService{
public function handle_delivery_status(Request $request)
{
$order = Order::findOrFail($request->order_id);
$order->delivery_viewed = '0';
$order->delivery_status = $request->status;
$order->save();
if ($request->status == 'cancelled' && $order->payment_type == 'wallet') {
$user = User::where('id', $order->user_id)->first();
$user->balance += $order->grand_total;
$user->save();
}
foreach ($order->orderDetails as $key => $orderDetail) {
$orderDetail->delivery_status = $request->status;
$orderDetail->save();
if ($request->status == 'cancelled') {
product_restock($orderDetail);
}
if (addon_is_activated('affiliate_system') && auth()->user()->user_type == 'admin') {
if (($request->status == 'delivered' || $request->status == 'cancelled') &&
$orderDetail->product_referral_code
) {
$no_of_delivered = 0;
$no_of_canceled = 0;
if ($request->status == 'delivered') {
$no_of_delivered = $orderDetail->quantity;
}
if ($request->status == 'cancelled') {
$no_of_canceled = $orderDetail->quantity;
}
$referred_by_user = User::where('referral_code', $orderDetail->product_referral_code)->first();
$affiliateController = new AffiliateController;
$affiliateController->processAffiliateStats($referred_by_user->id, 0, 0, $no_of_delivered, $no_of_canceled);
}
}
}
if (addon_is_activated('otp_system') && SmsTemplate::where('identifier', 'delivery_status_change')->first()->status == 1) {
try {
SmsUtility::delivery_status_change(json_decode($order->shipping_address)->phone, $order);
} catch (\Exception $e) {
}
}
//sends Notifications to user
NotificationUtility::sendNotification($order, $request->status);
if (get_setting('google_firebase') == 1 && $order->user->device_token != null) {
$request->device_token = $order->user->device_token;
$request->title = "Order updated !";
$status = str_replace("_", "", $order->delivery_status);
$request->text = " Your order {$order->code} has been {$status}";
$request->type = "order";
$request->id = $order->id;
$request->user_id = $order->user->id;
NotificationUtility::sendFirebaseNotification($request);
}
if (addon_is_activated('delivery_boy')) {
if (auth()->user()->user_type == 'delivery_boy') {
$deliveryBoyController = new DeliveryBoyController;
$deliveryBoyController->store_delivery_history($order);
}
}
}
public function handle_payment_status(Request $request)
{
$order = Order::findOrFail($request->order_id);
$order->payment_status_viewed = '0';
$order->save();
if (auth()->user()->user_type == 'seller') {
foreach ($order->orderDetails->where('seller_id', auth()->user()->id) as $key => $orderDetail) {
$orderDetail->payment_status = $request->status;
$orderDetail->save();
}
} else {
foreach ($order->orderDetails as $key => $orderDetail) {
$orderDetail->payment_status = $request->status;
$orderDetail->save();
}
}
$status = 'paid';
foreach ($order->orderDetails as $key => $orderDetail) {
if ($orderDetail->payment_status != 'paid') {
$status = 'unpaid';
}
}
$order->payment_status = $status;
$order->save();
if ($order->payment_status == 'paid' && $order->commission_calculated == 0) {
calculateCommissionAffilationClubPoint($order);
}
//sends Notifications to user
NotificationUtility::sendNotification($order, $request->status);
if (get_setting('google_firebase') == 1 && $order->user->device_token != null) {
$request->device_token = $order->user->device_token;
$request->title = "Order updated !";
$status = str_replace("_", "", $order->payment_status);
$request->text = " Your order {$order->code} has been {$status}";
$request->type = "order";
$request->id = $order->id;
$request->user_id = $order->user->id;
NotificationUtility::sendFirebaseNotification($request);
}
if (addon_is_activated('otp_system') && SmsTemplate::where('identifier', 'payment_status_change')->first()->status == 1) {
try {
SmsUtility::payment_status_change(json_decode($order->shipping_address)->phone, $order);
} catch (\Exception $e) {
}
}
return 1;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Services;
use App\Models\FlashDeal;
use App\Models\FlashDealProduct;
use App\Models\Product;
class ProductFlashDealService
{
public function store(array $data, Product $product)
{
$collection = collect($data);
if ($collection['flash_deal_id']) {
$flash_deal_product = FlashDealProduct::firstOrNew([
'flash_deal_id' => $collection['flash_deal_id'],
'product_id' => $product->id]
);
$flash_deal_product->flash_deal_id = $collection['flash_deal_id'];
$flash_deal_product->product_id = $product->id;
$flash_deal_product->save();
$flash_deal = FlashDeal::findOrFail($collection['flash_deal_id']);
$product->discount = $collection['flash_discount'];
$product->discount_type = $collection['flash_discount_type'];
$product->discount_start_date = $flash_deal->start_date;
$product->discount_end_date = $flash_deal->end_date;
$product->save();
}
}
}

View File

@@ -0,0 +1,304 @@
<?php
namespace App\Services;
use AizPackages\CombinationGenerate\Services\CombinationService;
use App\Models\Color;
use App\Models\Product;
use App\Models\User;
use App\Utility\ProductUtility;
use Combinations;
use Illuminate\Support\Str;
class ProductService
{
public function store(array $data)
{
$collection = collect($data);
$approved = 1;
if (auth()->user()->user_type == 'seller') {
$user_id = auth()->user()->id;
if (get_setting('product_approve_by_admin') == 1) {
$approved = 0;
}
} else {
$user_id = User::where('user_type', 'admin')->first()->id;
}
$tags = array();
if ($collection['tags'][0] != null) {
foreach (json_decode($collection['tags'][0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$collection['tags'] = implode(',', $tags);
$discount_start_date = null;
$discount_end_date = null;
if ($collection['date_range'] != null) {
$date_var = explode(" to ", $collection['date_range']);
$discount_start_date = strtotime($date_var[0]);
$discount_end_date = strtotime($date_var[1]);
}
unset($collection['date_range']);
if ($collection['meta_title'] == null) {
$collection['meta_title'] = $collection['name'];
}
if ($collection['meta_description'] == null) {
$collection['meta_description'] = strip_tags($collection['description']);
}
if ($collection['meta_img'] == null) {
$collection['meta_img'] = $collection['thumbnail_img'];
}
$shipping_cost = 0;
if (isset($collection['shipping_type'])) {
if ($collection['shipping_type'] == 'free') {
$shipping_cost = 0;
} elseif ($collection['shipping_type'] == 'flat_rate') {
$shipping_cost = $collection['flat_shipping_cost'];
}
}
unset($collection['flat_shipping_cost']);
$slug = Str::slug($collection['name']);
$same_slug_count = Product::where('slug', 'LIKE', $slug . '%')->count();
$slug_suffix = $same_slug_count ? '-' . $same_slug_count + 1 : '';
$slug .= $slug_suffix;
$colors = json_encode(array());
if (
isset($collection['colors_active']) &&
$collection['colors_active'] &&
$collection['colors'] &&
count($collection['colors']) > 0
) {
$colors = json_encode($collection['colors']);
}
$options = ProductUtility::get_attribute_options($collection);
$combinations = (new CombinationService())->generate_combination($options);
if (count($combinations) > 0) {
foreach ($combinations as $key => $combination) {
$str = ProductUtility::get_combination_string($combination, $collection);
unset($collection['price_' . str_replace('.', '_', $str)]);
unset($collection['sku_' . str_replace('.', '_', $str)]);
unset($collection['qty_' . str_replace('.', '_', $str)]);
unset($collection['img_' . str_replace('.', '_', $str)]);
}
}
unset($collection['colors_active']);
$choice_options = array();
if (isset($collection['choice_no']) && $collection['choice_no']) {
$str = '';
$item = array();
foreach ($collection['choice_no'] as $key => $no) {
$str = 'choice_options_' . $no;
$item['attribute_id'] = $no;
$attribute_data = array();
// foreach (json_decode($request[$str][0]) as $key => $eachValue) {
foreach ($collection[$str] as $key => $eachValue) {
// array_push($data, $eachValue->value);
array_push($attribute_data, $eachValue);
}
unset($collection[$str]);
$item['values'] = $attribute_data;
array_push($choice_options, $item);
}
}
$choice_options = json_encode($choice_options, JSON_UNESCAPED_UNICODE);
if (isset($collection['choice_no']) && $collection['choice_no']) {
$attributes = json_encode($collection['choice_no']);
unset($collection['choice_no']);
} else {
$attributes = json_encode(array());
}
$published = 1;
if ($collection['button'] == 'unpublish' || $collection['button'] == 'draft') {
$published = 0;
}
unset($collection['button']);
$data = $collection->merge(compact(
'user_id',
'approved',
'discount_start_date',
'discount_end_date',
'shipping_cost',
'slug',
'colors',
'choice_options',
'attributes',
'published',
))->toArray();
return Product::create($data);
}
public function update(array $data, Product $product)
{
$collection = collect($data);
$slug = Str::slug($collection['name']);
$slug = $collection['slug'] ? Str::slug($collection['slug']) : Str::slug($collection['name']);
$same_slug_count = Product::where('slug', 'LIKE', $slug . '%')->count();
$slug_suffix = $same_slug_count > 1 ? '-' . $same_slug_count + 1 : '';
$slug .= $slug_suffix;
if(addon_is_activated('refund_request') && !isset($collection['refundable'])){
$collection['refundable'] = 0;
}
if(!isset($collection['is_quantity_multiplied'])){
$collection['is_quantity_multiplied'] = 0;
}
if(!isset($collection['cash_on_delivery'])){
$collection['cash_on_delivery'] = 0;
}
if(!isset($collection['featured'])){
$collection['featured'] = 0;
}
if(!isset($collection['todays_deal'])){
$collection['todays_deal'] = 0;
}
$tags = array();
if ($collection['tags'][0] != null) {
foreach (json_decode($collection['tags'][0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$collection['tags'] = implode(',', $tags);
$discount_start_date = null;
$discount_end_date = null;
if ($collection['date_range'] != null) {
$date_var = explode(" to ", $collection['date_range']);
$discount_start_date = strtotime($date_var[0]);
$discount_end_date = strtotime($date_var[1]);
}
unset($collection['date_range']);
if ($collection['meta_title'] == null) {
$collection['meta_title'] = $collection['name'];
}
if ($collection['meta_description'] == null) {
$collection['meta_description'] = strip_tags($collection['description']);
}
if ($collection['meta_img'] == null) {
$collection['meta_img'] = $collection['thumbnail_img'];
}
if ($collection['lang'] != env("DEFAULT_LANGUAGE")) {
unset($collection['name']);
unset($collection['unit']);
unset($collection['description']);
}
unset($collection['lang']);
$shipping_cost = 0;
if (isset($collection['shipping_type'])) {
if ($collection['shipping_type'] == 'free') {
$shipping_cost = 0;
} elseif ($collection['shipping_type'] == 'flat_rate') {
$shipping_cost = $collection['flat_shipping_cost'];
}
}
unset($collection['flat_shipping_cost']);
$colors = json_encode(array());
if (
isset($collection['colors_active']) &&
$collection['colors_active'] &&
$collection['colors'] &&
count($collection['colors']) > 0
) {
$colors = json_encode($collection['colors']);
}
$options = ProductUtility::get_attribute_options($collection);
$combinations = (new CombinationService())->generate_combination($options);
if (count($combinations) > 0) {
foreach ($combinations as $key => $combination) {
$str = ProductUtility::get_combination_string($combination, $collection);
unset($collection['price_' . str_replace('.', '_', $str)]);
unset($collection['sku_' . str_replace('.', '_', $str)]);
unset($collection['qty_' . str_replace('.', '_', $str)]);
unset($collection['img_' . str_replace('.', '_', $str)]);
}
}
unset($collection['colors_active']);
$choice_options = array();
if (isset($collection['choice_no']) && $collection['choice_no']) {
$str = '';
$item = array();
foreach ($collection['choice_no'] as $key => $no) {
$str = 'choice_options_' . $no;
$item['attribute_id'] = $no;
$attribute_data = array();
// foreach (json_decode($request[$str][0]) as $key => $eachValue) {
foreach ($collection[$str] as $key => $eachValue) {
// array_push($data, $eachValue->value);
array_push($attribute_data, $eachValue);
}
unset($collection[$str]);
$item['values'] = $attribute_data;
array_push($choice_options, $item);
}
}
$choice_options = json_encode($choice_options, JSON_UNESCAPED_UNICODE);
if (isset($collection['choice_no']) && $collection['choice_no']) {
$attributes = json_encode($collection['choice_no']);
unset($collection['choice_no']);
} else {
$attributes = json_encode(array());
}
unset($collection['button']);
$data = $collection->merge(compact(
'discount_start_date',
'discount_end_date',
'shipping_cost',
'slug',
'colors',
'choice_options',
'attributes',
))->toArray();
$product->update($data);
return $product;
}
public function product_duplicate_store($product)
{
$product_new = $product->replicate();
$product_new->slug = $product_new->slug . '-' . Str::random(5);
$product_new->approved = (get_setting('product_approve_by_admin') == 1 && $product->added_by != 'admin') ? 0 : 1;
$product_new->save();
return $product_new;
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Services;
use AizPackages\CombinationGenerate\Services\CombinationService;
use App\Models\ProductStock;
use App\Utility\ProductUtility;
class ProductStockService
{
public function store(array $data, $product)
{
$collection = collect($data);
$options = ProductUtility::get_attribute_options($collection);
//Generates the combinations of customer choice options
$combinations = (new CombinationService())->generate_combination($options);
$variant = '';
if (count($combinations) > 0) {
$product->variant_product = 1;
$product->save();
foreach ($combinations as $key => $combination) {
$str = ProductUtility::get_combination_string($combination, $collection);
$product_stock = new ProductStock();
$product_stock->product_id = $product->id;
$product_stock->variant = $str;
$product_stock->price = request()['price_' . str_replace('.', '_', $str)];
$product_stock->sku = request()['sku_' . str_replace('.', '_', $str)];
$product_stock->qty = request()['qty_' . str_replace('.', '_', $str)];
$product_stock->image = request()['img_' . str_replace('.', '_', $str)];
$product_stock->save();
}
} else {
unset($collection['colors_active'], $collection['colors'], $collection['choice_no']);
$qty = $collection['current_stock'];
$price = $collection['unit_price'];
unset($collection['current_stock']);
$data = $collection->merge(compact('variant', 'qty', 'price'))->toArray();
ProductStock::create($data);
}
}
public function product_duplicate_store($product_stocks , $product_new)
{
foreach ($product_stocks as $key => $stock) {
$product_stock = new ProductStock;
$product_stock->product_id = $product_new->id;
$product_stock->variant = $stock->variant;
$product_stock->price = $stock->price;
$product_stock->sku = $stock->sku;
$product_stock->qty = $stock->qty;
$product_stock->save();
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Services;
use App\Models\ProductTax;
class ProductTaxService
{
public function store(array $data)
{
$collection = collect($data);
if ($collection['tax_id']) {
foreach ($collection['tax_id'] as $key => $val) {
$product_tax = new ProductTax();
$product_tax->tax_id = $val;
$product_tax->product_id = $collection['product_id'];
$product_tax->tax = $collection['tax'][$key];
$product_tax->tax_type = $collection['tax_type'][$key];
$product_tax->save();
}
}
}
public function product_duplicate_store($product_taxes , $product_new)
{
foreach ($product_taxes as $key => $tax) {
$product_tax = new ProductTax;
$product_tax->product_id = $product_new->id;
$product_tax->tax_id = $tax->tax_id;
$product_tax->tax = $tax->tax;
$product_tax->tax_type = $tax->tax_type;
$product_tax->save();
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Services\Revoke;
use Illuminate\Support\Facades\Http;
class AppleRevoke implements ProviderRevoke
{
public function apply()
{
$grant_type = "refresh_token";
$refresh_token = auth()->user()->refresh_token;
$client_id = env('SIGN_IN_WITH_APPLE_CLIENT_ID');
$client_secret = env('SIGN_IN_WITH_APPLE_CLIENT_SECRET');
$redirect_uri = env('SIGN_IN_WITH_APPLE_REDIRECT');
$server_output = Http::asForm()->post('https://appleid.apple.com/auth/token', [
'client_id' => $client_id,
'client_secret' => $client_secret,
'grant_type' => $grant_type,
'refresh_token' => $refresh_token,
'redirect_uri' => $redirect_uri,
]);
$access_token = $server_output->object()->access_token;
$revoke_output = Http::asForm()->post('https://appleid.apple.com/auth/revoke', [
'client_id' => $client_id,
'client_secret' => $client_secret,
'token_type_hint' => $grant_type,
'token' => $access_token,
]);
return $revoke_output->ok();
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Services\Revoke;
use GuzzleHttp\Client;
class FacebookRevoke implements ProviderRevoke
{
public function apply()
{
$token = auth()->user()->access_token;
$http = new Client();
$response = $http->delete("https://graph.facebook.com/v3.0/".auth()->user()->provider_id."/permissions?access_token={$token}");
return $response->getStatusCode();
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Services\Revoke;
class GoogleRevoke implements ProviderRevoke
{
public function apply()
{
$token = auth()->user()->access_token;
$ch = curl_init("https://oauth2.googleapis.com/revoke?token={$token}");
$header = array(
'Content-Type:application/x-www-form-urlencoded'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
$resultdata = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
return $response['http_code'];
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Services\Revoke;
interface ProviderRevoke
{
/**
* Apply a given search value to the builder instance.
*
* @param Builder $builder
* @param mixed $value
* @return Builder $builder
*/
public function apply();
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Services\Revoke;
class TwitterRevoke implements ProviderRevoke
{
public function apply()
{
$token = auth()->user()->access_token;
$client_id = env('TWITTER_CLIENT_ID');
$request_data = array('client_id' => $client_id, 'token' => $token);
$request_data_json = json_encode($request_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.twitter.com/2/oauth2/revoke?client_id=' . $client_id . '&token=' . $token . '&token_type_hint=access_token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_data_json);
$header = array(
'Content-Type:application/x-www-form-urlencoded'
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
return $response['http_code'];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Services;
use App\Models\OtpConfiguration;
class SendSmsService
{
public function sendSMS($to, $from, $text, $template_id)
{
$otp = OtpConfiguration::where('value', 1)->first()->type;
$otp_class = __NAMESPACE__ . '\\OTP\\' . str_replace(' ', '', ucwords(str_replace('_', ' ', $otp)));
if (class_exists($otp_class)) {
return (new $otp_class)->send($to, $from, $text, $template_id);
} else {
return;
}
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Services;
use Illuminate\Http\Request;
class SocialRevoke {
public function apply($provider)
{
$provider_class = __NAMESPACE__ . '\\Revoke\\' . str_replace(' ', '', ucwords(str_replace('_', ' ', $provider.'Revoke')));
if (class_exists($provider_class)) {
return (new $provider_class)->apply();
}
$revoke = new $provider_class();
return $revoke->apply();
}
}

View File

@@ -0,0 +1,265 @@
<?php
namespace App\Services;
use App\Models\Cart;
use App\Models\FlashDealProduct;
use App\Models\ProductStock;
use App\Models\ProductTax;
use App\Models\ProductTranslation;
use App\Models\Product;
use App\Models\User;
use App\Models\WholesalePrice;
use Artisan;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class WholesaleService
{
public function store(array $data)
{
$collection = collect($data);
$tags = array();
if ($collection['tags'][0] != null) {
foreach (json_decode($collection['tags'][0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$collection['tags'] = implode(',', $tags);
if ($collection['meta_title'] == null) {
$collection['meta_title'] = $collection['name'];
}
if ($collection['meta_description'] == null) {
$collection['meta_description'] = strip_tags($collection['description']);
}
if ($collection['meta_img'] == null) {
$collection['meta_img'] = $collection['thumbnail_img'];
}
$data = $collection->toArray();
$product = Product::create($data);
$product_stock = new ProductStock;
$product_stock->product_id = $product->id;
$product_stock->variant = '';
$product_stock->price = $collection['unit_price'];
$product_stock->sku = $collection['sku'];
$product_stock->qty = $collection['current_stock'];
$product_stock->save();
if(request()->has('wholesale_price')){
foreach(request()->wholesale_price as $key => $price){
$wholesale_price = new WholesalePrice;
$wholesale_price->product_stock_id = $product_stock->id;
$wholesale_price->min_qty = request()->wholesale_min_qty[$key];
$wholesale_price->max_qty = request()->wholesale_max_qty[$key];
$wholesale_price->price = $price;
$wholesale_price->save();
}
}
return $product;
}
public function update(Request $request , $id){
$product = Product::findOrFail($id);
$product->category_id = $request->category_id;
$product->brand_id = $request->brand_id;
$product->barcode = $request->barcode;
$product->cash_on_delivery = 0;
$product->featured = 0;
$product->todays_deal = 0;
$product->is_quantity_multiplied = 0;
if (addon_is_activated('refund_request')) {
if ($request->refundable != null) {
$product->refundable = 1;
}
else {
$product->refundable = 0;
}
}
if($request->lang == env("DEFAULT_LANGUAGE")){
$product->name = $request->name;
$product->unit = $request->unit;
$product->description = $request->description;
$product->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower($request->slug)));
}
if($request->slug == null){
$product->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower($request->name)));
}
$product->photos = $request->photos;
$product->thumbnail_img = $request->thumbnail_img;
$product->min_qty = $request->min_qty;
$product->low_stock_quantity = $request->low_stock_quantity;
$product->stock_visibility_state = $request->stock_visibility_state;
$tags = array();
if($request->tags[0] != null){
foreach (json_decode($request->tags[0]) as $key => $tag) {
array_push($tags, $tag->value);
}
}
$product->tags = implode(',', $tags);
$product->video_provider = $request->video_provider;
$product->video_link = $request->video_link;
$product->unit_price = $request->unit_price;
$product->discount = $request->discount;
$product->discount_type = $request->discount_type;
if ($request->date_range != null) {
$date_var = explode(" to ", $request->date_range);
$product->discount_start_date = strtotime($date_var[0]);
$product->discount_end_date = strtotime( $date_var[1]);
}
$product->shipping_type = $request->shipping_type;
$product->est_shipping_days = $request->est_shipping_days;
if (addon_is_activated('club_point')) {
if($request->earn_point) {
$product->earn_point = $request->earn_point;
}
}
if ($request->has('shipping_type')) {
if($request->shipping_type == 'free'){
$product->shipping_cost = 0;
}
elseif ($request->shipping_type == 'flat_rate') {
$product->shipping_cost = $request->flat_shipping_cost;
}
elseif ($request->shipping_type == 'product_wise') {
$product->shipping_cost = json_encode($request->shipping_cost);
}
}
if ($request->has('is_quantity_multiplied')) {
$product->is_quantity_multiplied = 1;
}
if ($request->has('cash_on_delivery')) {
$product->cash_on_delivery = 1;
}
if ($request->has('featured')) {
$product->featured = 1;
}
if ($request->has('todays_deal')) {
$product->todays_deal = 1;
}
$product->meta_title = $request->meta_title;
$product->meta_description = $request->meta_description;
$product->meta_img = $request->meta_img;
if($product->meta_title == null) {
$product->meta_title = $product->name;
}
if($product->meta_description == null) {
$product->meta_description = strip_tags($product->description);
}
if($product->meta_img == null) {
$product->meta_img = $product->thumbnail_img;
}
$product->pdf = $request->pdf;
$colors = array();
$product->colors = json_encode($colors);
$choice_options = array();
$product->choice_options = json_encode($choice_options, JSON_UNESCAPED_UNICODE);
$product_stock = $product->stocks->first();
$product_stock->price = $request->unit_price;
$product_stock->sku = $request->sku;
$product_stock->qty = $request->current_stock;
$product_stock->save();
$product->save();
foreach ($product->stocks->first()->wholesalePrices as $key => $wholesalePrice) {
$wholesalePrice->delete();
}
if($request->has('wholesale_price')){
foreach($request->wholesale_price as $key => $price){
$wholesale_price = new WholesalePrice;
$wholesale_price->product_stock_id = $product_stock->id;
$wholesale_price->min_qty = $request->wholesale_min_qty[$key];
$wholesale_price->max_qty = $request->wholesale_max_qty[$key];
$wholesale_price->price = $price;
$wholesale_price->save();
}
}
//Flash Deal
if($request->flash_deal_id) {
if($product->flash_deal_product){
$flash_deal_product = FlashDealProduct::findOrFail($product->flash_deal_product->id);
if(!$flash_deal_product) {
$flash_deal_product = new FlashDealProduct;
}
} else {
$flash_deal_product = new FlashDealProduct;
}
$flash_deal_product->flash_deal_id = $request->flash_deal_id;
$flash_deal_product->product_id = $product->id;
$flash_deal_product->discount = $request->flash_discount;
$flash_deal_product->discount_type = $request->flash_discount_type;
$flash_deal_product->save();
}
//VAT & Tax
if($request->tax_id) {
ProductTax::where('product_id', $product->id)->delete();
foreach ($request->tax_id as $key => $val) {
$product_tax = new ProductTax;
$product_tax->tax_id = $val;
$product_tax->product_id = $product->id;
$product_tax->tax = $request->tax[$key];
$product_tax->tax_type = $request->tax_type[$key];
$product_tax->save();
}
}
// Product Translations
$product_translation = ProductTranslation::firstOrNew(['lang' => $request->lang, 'product_id' => $product->id]);
$product_translation->name = $request->name;
$product_translation->unit = $request->unit;
$product_translation->description = $request->description;
$product_translation->save();
}
public function destroy($id){
$product = Product::findOrFail($id);
foreach ($product->product_translations as $key => $product_translations) {
$product_translations->delete();
}
foreach ($product->stocks as $key => $stock) {
$stock->delete();
}
Product::destroy($id);
Cart::where('product_id', $id)->delete();
}
}