Nuevos cambios hechos de diseño
This commit is contained in:
36
desarrollo2/app/Http/CategoryCollection.php
Normal file
36
desarrollo2/app/Http/CategoryCollection.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V2;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Utility\CategoryUtility;
|
||||
|
||||
class CategoryCollection extends ResourceCollection
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection->map(function($data) {
|
||||
return [
|
||||
'id' => $data->id,
|
||||
'name' => $data->getTranslation('name'),
|
||||
'banner' => uploaded_asset($data->banner),
|
||||
'icon' => uploaded_asset($data->icon),
|
||||
'number_of_children' => CategoryUtility::get_immediate_children_count($data->id),
|
||||
'links' => [
|
||||
'products' => route('api.products.category', $data->id),
|
||||
'sub_categories' => route('subCategories.index', $data->id)
|
||||
]
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
public function with($request)
|
||||
{
|
||||
return [
|
||||
'success' => true,
|
||||
'status' => 200
|
||||
];
|
||||
}
|
||||
}
|
||||
253
desarrollo2/app/Http/Controllers/AddonController.php
Normal file
253
desarrollo2/app/Http/Controllers/AddonController.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Addon;
|
||||
use Illuminate\Support\Str;
|
||||
use ZipArchive;
|
||||
use Storage;
|
||||
use Cache;
|
||||
use DB;
|
||||
|
||||
class AddonController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:manage_addons'])->only('index','create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$addons = Addon::query()->orderBy('name', 'asc')->get();
|
||||
return view('backend.addons.index', compact('addons'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('backend.addons.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
Cache::forget('addons');
|
||||
|
||||
if (env('DEMO_MODE') == 'On') {
|
||||
flash(translate('This action is disabled in demo mode'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
if (class_exists('ZipArchive')) {
|
||||
if ($request->hasFile('addon_zip')) {
|
||||
// Create update directory.
|
||||
$dir = 'addons';
|
||||
if (!is_dir($dir))
|
||||
mkdir($dir, 0777, true);
|
||||
|
||||
$path = Storage::disk('local')->put('addons', $request->addon_zip);
|
||||
|
||||
$zipped_file_name = $request->addon_zip->getClientOriginalName();
|
||||
|
||||
//Unzip uploaded update file and remove zip file.
|
||||
$zip = new ZipArchive;
|
||||
$res = $zip->open(base_path('public/' . $path));
|
||||
|
||||
$random_dir = Str::random(10);
|
||||
|
||||
$dir = trim($zip->getNameIndex(0), '/');
|
||||
|
||||
if ($res === true) {
|
||||
$res = $zip->extractTo(base_path('temp/' . $random_dir . '/addons'));
|
||||
$zip->close();
|
||||
} else {
|
||||
dd('could not open');
|
||||
}
|
||||
|
||||
$str = file_get_contents(base_path('temp/' . $random_dir . '/addons/' . $dir . '/config.json'));
|
||||
$json = json_decode($str, true);
|
||||
|
||||
//dd($random_dir, $json);
|
||||
|
||||
if (BusinessSetting::where('type', 'current_version')->first()->value >= $json['minimum_item_version']) {
|
||||
if (count(Addon::where('unique_identifier', $json['unique_identifier'])->get()) == 0) {
|
||||
$addon = new Addon;
|
||||
$addon->name = $json['name'];
|
||||
$addon->unique_identifier = $json['unique_identifier'];
|
||||
$addon->version = $json['version'];
|
||||
$addon->activated = 1;
|
||||
$addon->image = $json['addon_banner'];
|
||||
$addon->purchase_code = $request->purchase_code;
|
||||
$addon->save();
|
||||
|
||||
// Create new directories.
|
||||
if (!empty($json['directory'])) {
|
||||
//dd($json['directory'][0]['name']);
|
||||
foreach ($json['directory'][0]['name'] as $directory) {
|
||||
if (is_dir(base_path($directory)) == false) {
|
||||
mkdir(base_path($directory), 0777, true);
|
||||
|
||||
} else {
|
||||
echo "error on creating directory";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Create/Replace new files.
|
||||
if (!empty($json['files'])) {
|
||||
foreach ($json['files'] as $file) {
|
||||
copy(base_path('temp/' . $random_dir . '/' . $file['root_directory']), base_path($file['update_directory']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Run sql modifications
|
||||
$sql_path = base_path('temp/' . $random_dir . '/addons/' . $dir . '/sql/update.sql');
|
||||
if (file_exists($sql_path)) {
|
||||
DB::unprepared(file_get_contents($sql_path));
|
||||
}
|
||||
|
||||
flash(translate('Addon installed successfully'))->success();
|
||||
return redirect()->route('addons.index');
|
||||
} else {
|
||||
$addon = Addon::where('unique_identifier', $json['unique_identifier'])->first();
|
||||
|
||||
if($json['unique_identifier'] == 'delivery_boy' && $addon->version < 3.3) {
|
||||
$dir = base_path('resources/views/delivery_boys');
|
||||
foreach (glob($dir."/*.*") as $filename) {
|
||||
if (is_file($filename)) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create new directories.
|
||||
if (!empty($json['directory'])) {
|
||||
//dd($json['directory'][0]['name']);
|
||||
foreach ($json['directory'][0]['name'] as $directory) {
|
||||
if (is_dir(base_path($directory)) == false) {
|
||||
mkdir(base_path($directory), 0777, true);
|
||||
|
||||
} else {
|
||||
echo "error on creating directory";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Create/Replace new files.
|
||||
if (!empty($json['files'])) {
|
||||
foreach ($json['files'] as $file) {
|
||||
copy(base_path('temp/' . $random_dir . '/' . $file['root_directory']), base_path($file['update_directory']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ($i = $addon->version + 0.05; $i <= $json['version']; $i = $i + 0.1) {
|
||||
// Run sql modifications
|
||||
$sql_version = $i+0.05;
|
||||
$sql_path = base_path('temp/' . $random_dir . '/addons/' . $dir . '/sql/' . $sql_version . '.sql');
|
||||
if (file_exists($sql_path)) {
|
||||
DB::unprepared(file_get_contents($sql_path));
|
||||
}
|
||||
}
|
||||
|
||||
$addon->version = $json['version'];
|
||||
$addon->name = $json['name'];
|
||||
$addon->image = $json['addon_banner'];
|
||||
$addon->purchase_code = $request->purchase_code;
|
||||
$addon->save();
|
||||
|
||||
flash(translate('This addon is updated successfully'))->success();
|
||||
return redirect()->route('addons.index');
|
||||
}
|
||||
} else {
|
||||
flash(translate('This version is not capable of installing Addons, Please update.'))->error();
|
||||
return redirect()->route('addons.index');
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
flash(translate('Please enable ZipArchive extension.'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Addon $addon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Addon $addon)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
//return view('backend.'.Auth::user()->role.'.addon.list')->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Addon $addon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Addon $addon)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Addon $addon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Addon $addon
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function activation(Request $request)
|
||||
{
|
||||
if (env('DEMO_MODE') == 'On') {
|
||||
flash(translate('This action is disabled in demo mode'))->error();
|
||||
return 0;
|
||||
}
|
||||
$addon = Addon::find($request->id);
|
||||
$addon->activated = $request->status;
|
||||
$addon->save();
|
||||
|
||||
Cache::forget('addons');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
166
desarrollo2/app/Http/Controllers/AddressController.php
Normal file
166
desarrollo2/app/Http/Controllers/AddressController.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Address;
|
||||
use App\Models\City;
|
||||
use App\Models\State;
|
||||
use Auth;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$address = new Address;
|
||||
if($request->has('customer_id')){
|
||||
$address->user_id = $request->customer_id;
|
||||
}
|
||||
else{
|
||||
$address->user_id = Auth::user()->id;
|
||||
}
|
||||
$address->address = $request->address;
|
||||
$address->country_id = $request->country_id;
|
||||
$address->state_id = $request->state_id;
|
||||
$address->city_id = $request->city_id;
|
||||
$address->longitude = $request->longitude;
|
||||
$address->latitude = $request->latitude;
|
||||
$address->postal_code = $request->postal_code;
|
||||
$address->phone = $request->phone;
|
||||
$address->save();
|
||||
|
||||
flash(translate('Address info Stored successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['address_data'] = Address::findOrFail($id);
|
||||
$data['states'] = State::where('status', 1)->where('country_id', $data['address_data']->country_id)->get();
|
||||
$data['cities'] = City::where('status', 1)->where('state_id', $data['address_data']->state_id)->get();
|
||||
|
||||
$returnHTML = view('frontend.partials.address_edit_modal', $data)->render();
|
||||
return response()->json(array('data' => $data, 'html'=>$returnHTML));
|
||||
// return ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$address = Address::findOrFail($id);
|
||||
|
||||
$address->address = $request->address;
|
||||
$address->country_id = $request->country_id;
|
||||
$address->state_id = $request->state_id;
|
||||
$address->city_id = $request->city_id;
|
||||
$address->longitude = $request->longitude;
|
||||
$address->latitude = $request->latitude;
|
||||
$address->postal_code = $request->postal_code;
|
||||
$address->phone = $request->phone;
|
||||
|
||||
$address->save();
|
||||
|
||||
flash(translate('Address info updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$address = Address::findOrFail($id);
|
||||
if(!$address->set_default){
|
||||
$address->delete();
|
||||
return back();
|
||||
}
|
||||
flash(translate('Default address can not be deleted'))->warning();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function getStates(Request $request) {
|
||||
$states = State::where('status', 1)->where('country_id', $request->country_id)->get();
|
||||
$html = '<option value="">'.translate("Select State").'</option>';
|
||||
|
||||
foreach ($states as $state) {
|
||||
$html .= '<option value="' . $state->id . '">' . $state->name . '</option>';
|
||||
}
|
||||
|
||||
echo json_encode($html);
|
||||
}
|
||||
|
||||
public function getCities(Request $request) {
|
||||
$cities = City::where('status', 1)->where('state_id', $request->state_id)->get();
|
||||
$html = '<option value="">'.translate("Select City").'</option>';
|
||||
|
||||
foreach ($cities as $row) {
|
||||
$html .= '<option value="' . $row->id . '">' . $row->getTranslation('name') . '</option>';
|
||||
}
|
||||
|
||||
echo json_encode($html);
|
||||
}
|
||||
|
||||
public function set_default($id){
|
||||
foreach (Auth::user()->addresses as $key => $address) {
|
||||
$address->set_default = 0;
|
||||
$address->save();
|
||||
}
|
||||
$address = Address::findOrFail($id);
|
||||
$address->set_default = 1;
|
||||
$address->save();
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
58
desarrollo2/app/Http/Controllers/AdminController.php
Normal file
58
desarrollo2/app/Http/Controllers/AdminController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Artisan;
|
||||
use Cache;
|
||||
use CoreComponentRepository;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the admin dashboard.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function admin_dashboard(Request $request)
|
||||
{
|
||||
CoreComponentRepository::initializeCache();
|
||||
$root_categories = Category::where('level', 0)->get();
|
||||
|
||||
$cached_graph_data = Cache::remember('cached_graph_data', 86400, function() use ($root_categories){
|
||||
$num_of_sale_data = null;
|
||||
$qty_data = null;
|
||||
foreach ($root_categories as $key => $category){
|
||||
$category_ids = \App\Utility\CategoryUtility::children_ids($category->id);
|
||||
$category_ids[] = $category->id;
|
||||
|
||||
$products = Product::with('stocks')->whereIn('category_id', $category_ids)->get();
|
||||
$qty = 0;
|
||||
$sale = 0;
|
||||
foreach ($products as $key => $product) {
|
||||
$sale += $product->num_of_sale;
|
||||
foreach ($product->stocks as $key => $stock) {
|
||||
$qty += $stock->qty;
|
||||
}
|
||||
}
|
||||
$qty_data .= $qty.',';
|
||||
$num_of_sale_data .= $sale.',';
|
||||
}
|
||||
$item['num_of_sale_data'] = $num_of_sale_data;
|
||||
$item['qty_data'] = $qty_data;
|
||||
|
||||
return $item;
|
||||
});
|
||||
|
||||
return view('backend.dashboard', compact('root_categories', 'cached_graph_data'));
|
||||
}
|
||||
|
||||
function clearCache(Request $request)
|
||||
{
|
||||
Artisan::call('optimize:clear');
|
||||
flash(translate('Cache cleared successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
564
desarrollo2/app/Http/Controllers/AffiliateController.php
Normal file
564
desarrollo2/app/Http/Controllers/AffiliateController.php
Normal file
@@ -0,0 +1,564 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\AffiliateOption;
|
||||
use App\Models\Order;
|
||||
use App\Models\AffiliateConfig;
|
||||
use App\Models\AffiliateUser;
|
||||
use App\Models\AffiliatePayment;
|
||||
use App\Models\AffiliateWithdrawRequest;
|
||||
use App\Models\AffiliateLog;
|
||||
use App\Models\AffiliateStats;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use App\Models\Category;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Hash;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
|
||||
class AffiliateController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:affiliate_registration_form_config'])->only('configs');
|
||||
$this->middleware(['permission:affiliate_configurations'])->only('index');
|
||||
$this->middleware(['permission:view_affiliate_users'])->only('users');
|
||||
$this->middleware(['permission:pay_to_affiliate_user'])->only('payment_modal');
|
||||
$this->middleware(['permission:affiliate_users_payment_history'])->only('payment_history');
|
||||
$this->middleware(['permission:view_all_referral_users'])->only('refferal_users');
|
||||
$this->middleware(['permission:view_affiliate_withdraw_requests'])->only('affiliate_withdraw_requests');
|
||||
$this->middleware(['permission:accept_affiliate_withdraw_requests'])->only('affiliate_withdraw_modal');
|
||||
$this->middleware(['permission:reject_affiliate_withdraw_request'])->only('reject_withdraw_request');
|
||||
$this->middleware(['permission:view_affiliate_logs'])->only('affiliate_logs_admin');
|
||||
}
|
||||
|
||||
//
|
||||
public function index(){
|
||||
return view('affiliate.index');
|
||||
}
|
||||
|
||||
public function affiliate_option_store(Request $request){
|
||||
//dd($request->all());
|
||||
$affiliate_option = AffiliateOption::where('type', $request->type)->first();
|
||||
if($affiliate_option == null){
|
||||
$affiliate_option = new AffiliateOption;
|
||||
}
|
||||
$affiliate_option->type = $request->type;
|
||||
|
||||
$commision_details = array();
|
||||
if ($request->type == 'user_registration_first_purchase') {
|
||||
$affiliate_option->percentage = $request->percentage;
|
||||
}
|
||||
elseif ($request->type == 'product_sharing') {
|
||||
$commision_details['commission'] = $request->amount;
|
||||
$commision_details['commission_type'] = $request->amount_type;
|
||||
}
|
||||
elseif ($request->type == 'category_wise_affiliate') {
|
||||
foreach(Category::all() as $category) {
|
||||
$data['category_id'] = $request['categories_id_'.$category->id];
|
||||
$data['commission'] = $request['commison_amounts_'.$category->id];
|
||||
$data['commission_type'] = $request['commison_types_'.$category->id];
|
||||
array_push($commision_details, $data);
|
||||
}
|
||||
}
|
||||
elseif ($request->type == 'max_affiliate_limit') {
|
||||
$affiliate_option->percentage = $request->percentage;
|
||||
}
|
||||
$affiliate_option->details = json_encode($commision_details);
|
||||
|
||||
if ($request->has('status')) {
|
||||
$affiliate_option->status = 1;
|
||||
if($request->type == 'product_sharing'){
|
||||
$affiliate_option_status_update = AffiliateOption::where('type', 'category_wise_affiliate')->first();
|
||||
$affiliate_option_status_update->status = 0;
|
||||
$affiliate_option_status_update->save();
|
||||
}
|
||||
if($request->type == 'category_wise_affiliate'){
|
||||
$affiliate_option_status_update = AffiliateOption::where('type', 'product_sharing')->first();
|
||||
$affiliate_option_status_update->status = 0;
|
||||
$affiliate_option_status_update->save();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$affiliate_option->status = 0;
|
||||
}
|
||||
$affiliate_option->save();
|
||||
|
||||
flash("This has been updated successfully")->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function configs(){
|
||||
return view('affiliate.configs');
|
||||
}
|
||||
|
||||
public function config_store(Request $request){
|
||||
if($request->type == 'validation_time') {
|
||||
//affiliate validation time
|
||||
$affiliate_config = AffiliateConfig::where('type', $request->type)->first();
|
||||
if($affiliate_config == null){
|
||||
$affiliate_config = new AffiliateConfig;
|
||||
}
|
||||
$affiliate_config->type = $request->type;
|
||||
$affiliate_config->value = $request[$request->type];
|
||||
$affiliate_config->save();
|
||||
|
||||
flash("Validation time updated successfully")->success();
|
||||
} else {
|
||||
|
||||
$form = array();
|
||||
$select_types = ['select', 'multi_select', 'radio'];
|
||||
$j = 0;
|
||||
for ($i=0; $i < count($request->type); $i++) {
|
||||
$item['type'] = $request->type[$i];
|
||||
$item['label'] = $request->label[$i];
|
||||
if(in_array($request->type[$i], $select_types)){
|
||||
$item['options'] = json_encode($request['options_'.$request->option[$j]]);
|
||||
$j++;
|
||||
}
|
||||
array_push($form, $item);
|
||||
}
|
||||
$affiliate_config = AffiliateConfig::where('type', 'verification_form')->first();
|
||||
$affiliate_config->value = json_encode($form);
|
||||
|
||||
flash("Verification form updated successfully")->success();
|
||||
}
|
||||
if($affiliate_config->save()){
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function apply_for_affiliate(Request $request){
|
||||
if(Auth::check() && AffiliateUser::where('user_id', Auth::user()->id)->first() != null){
|
||||
flash(translate("You are already an affiliate user!"))->warning();
|
||||
return back();
|
||||
}
|
||||
return view('affiliate.frontend.apply_for_affiliate');
|
||||
}
|
||||
|
||||
public function affiliate_logs_admin()
|
||||
{
|
||||
$affiliate_logs = AffiliateLog::latest()->paginate(10);
|
||||
return view('affiliate.affiliate_logs',compact('affiliate_logs'));
|
||||
}
|
||||
|
||||
public function store_affiliate_user(Request $request){
|
||||
if(!Auth::check()){
|
||||
if(User::where('email', $request->email)->first() != null){
|
||||
flash(translate('Email already exists!'))->error();
|
||||
return back();
|
||||
}
|
||||
if($request->password == $request->password_confirmation){
|
||||
$user = new User;
|
||||
$user->name = $request->name;
|
||||
$user->email = $request->email;
|
||||
$user->user_type = "customer";
|
||||
$user->password = Hash::make($request->password);
|
||||
$user->save();
|
||||
|
||||
auth()->login($user, false);
|
||||
|
||||
if(get_setting('email_verification') != 1){
|
||||
$user->email_verified_at = date('Y-m-d H:m:s');
|
||||
$user->save();
|
||||
}
|
||||
else {
|
||||
event(new Registered($user));
|
||||
}
|
||||
}
|
||||
else{
|
||||
flash(translate('Sorry! Password did not match.'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
$affiliate_user = Auth::user()->affiliate_user;
|
||||
if ($affiliate_user == null) {
|
||||
$affiliate_user = new AffiliateUser;
|
||||
$affiliate_user->user_id = Auth::user()->id;
|
||||
}
|
||||
$data = array();
|
||||
$i = 0;
|
||||
foreach (json_decode(AffiliateConfig::where('type', 'verification_form')->first()->value) as $key => $element) {
|
||||
$item = array();
|
||||
if ($element->type == 'text') {
|
||||
$item['type'] = 'text';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_'.$i];
|
||||
}
|
||||
elseif ($element->type == 'select' || $element->type == 'radio') {
|
||||
$item['type'] = 'select';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_'.$i];
|
||||
}
|
||||
elseif ($element->type == 'multi_select') {
|
||||
$item['type'] = 'multi_select';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = json_encode($request['element_'.$i]);
|
||||
}
|
||||
elseif ($element->type == 'file') {
|
||||
$item['type'] = 'file';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_'.$i]->store('uploads/affiliate_verification_form');
|
||||
}
|
||||
array_push($data, $item);
|
||||
$i++;
|
||||
}
|
||||
$affiliate_user->informations = json_encode($data);
|
||||
if($affiliate_user->save()){
|
||||
flash(translate('Your verification request has been submitted successfully!'))->success();
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
flash(translate('Sorry! Something went wrong.'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function users(){
|
||||
$affiliate_users = AffiliateUser::paginate(12);
|
||||
return view('affiliate.users', compact('affiliate_users'));
|
||||
}
|
||||
|
||||
public function show_verification_request($id){
|
||||
$affiliate_user = AffiliateUser::findOrFail($id);
|
||||
return view('affiliate.show_verification_request', compact('affiliate_user'));
|
||||
}
|
||||
|
||||
public function approve_user($id)
|
||||
{
|
||||
$affiliate_user = AffiliateUser::findOrFail($id);
|
||||
$affiliate_user->status = 1;
|
||||
if($affiliate_user->save()){
|
||||
flash(translate('Affiliate user has been approved successfully'))->success();
|
||||
return redirect()->route('affiliate.users');
|
||||
}
|
||||
flash(translate('Something went wrong'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function reject_user($id)
|
||||
{
|
||||
$affiliate_user = AffiliateUser::findOrFail($id);
|
||||
$affiliate_user->status = 0;
|
||||
$affiliate_user->informations = null;
|
||||
if($affiliate_user->save()){
|
||||
flash(translate('Affiliate user request has been rejected successfully'))->success();
|
||||
return redirect()->route('affiliate.users');
|
||||
}
|
||||
flash(translate('Something went wrong'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function updateApproved(Request $request)
|
||||
{
|
||||
$affiliate_user = AffiliateUser::findOrFail($request->id);
|
||||
$affiliate_user->status = $request->status;
|
||||
if($affiliate_user->save()){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function payment_modal(Request $request)
|
||||
{
|
||||
$affiliate_user = AffiliateUser::findOrFail($request->id);
|
||||
return view('affiliate.payment_modal', compact('affiliate_user'));
|
||||
}
|
||||
|
||||
public function payment_store(Request $request){
|
||||
$affiliate_payment = new AffiliatePayment;
|
||||
$affiliate_payment->affiliate_user_id = $request->affiliate_user_id;
|
||||
$affiliate_payment->amount = $request->amount;
|
||||
$affiliate_payment->payment_method = $request->payment_method;
|
||||
$affiliate_payment->save();
|
||||
|
||||
$affiliate_user = AffiliateUser::findOrFail($request->affiliate_user_id);
|
||||
$affiliate_user->balance -= $request->amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
flash(translate('Payment completed'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function payment_history($id){
|
||||
$affiliate_user = AffiliateUser::findOrFail(decrypt($id));
|
||||
$affiliate_payments = $affiliate_user->affiliate_payments();
|
||||
return view('affiliate.payment_history', compact('affiliate_payments', 'affiliate_user'));
|
||||
}
|
||||
|
||||
public function user_index(Request $request){
|
||||
$affiliate_logs = AffiliateLog::where('referred_by_user', Auth::user()->id)->latest()->paginate(10);
|
||||
|
||||
$query = AffiliateStats::query();
|
||||
$query = $query->select(
|
||||
DB::raw('SUM(no_of_click) AS count_click, SUM(no_of_order_item) AS count_item, SUM(no_of_delivered) AS count_delivered, SUM(no_of_cancel) AS count_cancel')
|
||||
);
|
||||
if($request->type == 'Today') {
|
||||
$query->whereDate('created_at', Carbon::today());
|
||||
} else if($request->type == '7' || $request->type == '30') {
|
||||
$query->whereRaw('created_at <= NOW() AND created_at >= DATE_SUB(created_at, INTERVAL '. $request->type .' DAY)');
|
||||
}
|
||||
$query->where('affiliate_user_id', Auth::user()->id);
|
||||
$affliate_stats = $query->first();
|
||||
$type = $request->type;
|
||||
|
||||
// dd($type);
|
||||
return view('affiliate.frontend.index', compact('affiliate_logs', 'affliate_stats', 'type'));
|
||||
}
|
||||
|
||||
// payment history for user
|
||||
public function user_payment_history(){
|
||||
$affiliate_user = Auth::user()->affiliate_user;
|
||||
$affiliate_payments = $affiliate_user->affiliate_payments();
|
||||
|
||||
return view('affiliate.frontend.payment_history', compact('affiliate_payments'));
|
||||
}
|
||||
|
||||
// withdraw request history for user
|
||||
public function user_withdraw_request_history(){
|
||||
$affiliate_user = Auth::user()->affiliate_user;
|
||||
$affiliate_withdraw_requests = AffiliateWithdrawRequest::where('user_id', Auth::user()->id)->orderBy('id', 'desc')->paginate(10);
|
||||
|
||||
return view('affiliate.frontend.withdraw_request_history', compact('affiliate_withdraw_requests'));
|
||||
}
|
||||
|
||||
public function payment_settings(){
|
||||
$affiliate_user = Auth::user()->affiliate_user;
|
||||
return view('affiliate.frontend.payment_settings', compact('affiliate_user'));
|
||||
}
|
||||
|
||||
public function payment_settings_store(Request $request){
|
||||
$affiliate_user = Auth::user()->affiliate_user;
|
||||
$affiliate_user->paypal_email = $request->paypal_email;
|
||||
$affiliate_user->bank_information = $request->bank_information;
|
||||
$affiliate_user->save();
|
||||
flash(translate('Affiliate payment settings has been updated successfully'))->success();
|
||||
return redirect()->route('affiliate.user.index');
|
||||
}
|
||||
|
||||
public function processAffiliatePoints(Order $order){
|
||||
if(addon_is_activated('affiliate_system')){
|
||||
if(AffiliateOption::where('type', 'user_registration_first_purchase')->first()->status){
|
||||
if ($order->user != null && $order->user->orders->count() == 1) {
|
||||
if($order->user->referred_by != null){
|
||||
$user = User::find($order->user->referred_by);
|
||||
if ($user != null) {
|
||||
$amount = (AffiliateOption::where('type', 'user_registration_first_purchase')->first()->percentage * $order->grand_total)/100;
|
||||
$affiliate_user = $user->affiliate_user;
|
||||
if($affiliate_user != null){
|
||||
$affiliate_user->balance += $amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
// Affiliate log
|
||||
$affiliate_log = new AffiliateLog;
|
||||
$affiliate_log->user_id = $order->user_id;
|
||||
$affiliate_log->referred_by_user = $order->user->referred_by;
|
||||
$affiliate_log->amount = $amount;
|
||||
$affiliate_log->order_id = $order->id;
|
||||
$affiliate_log->affiliate_type = 'user_registration_first_purchase';
|
||||
$affiliate_log->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(AffiliateOption::where('type', 'product_sharing')->first()->status) {
|
||||
foreach ($order->orderDetails as $key => $orderDetail) {
|
||||
$amount = 0;
|
||||
if($orderDetail->product_referral_code != null) {
|
||||
$referred_by_user = User::where('referral_code', $orderDetail->product_referral_code)->first();
|
||||
if($referred_by_user != null) {
|
||||
if(AffiliateOption::where('type', 'product_sharing')->first()->details != null && json_decode(AffiliateOption::where('type', 'product_sharing')->first()->details)->commission_type == 'amount') {
|
||||
$amount = json_decode(AffiliateOption::where('type', 'product_sharing')->first()->details)->commission;
|
||||
}
|
||||
elseif(AffiliateOption::where('type', 'product_sharing')->first()->details != null && json_decode(AffiliateOption::where('type', 'product_sharing')->first()->details)->commission_type == 'percent') {
|
||||
$amount = (json_decode(AffiliateOption::where('type', 'product_sharing')->first()->details)->commission * $orderDetail->price)/100;
|
||||
}
|
||||
$affiliate_user = $referred_by_user->affiliate_user;
|
||||
if($affiliate_user != null) {
|
||||
$affiliate_user->balance += $amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
// Affiliate log
|
||||
$affiliate_log = new AffiliateLog;
|
||||
if($order->user_id != null) {
|
||||
$affiliate_log->user_id = $order->user_id;
|
||||
}
|
||||
else {
|
||||
$affiliate_log->guest_id = $order->guest_id;
|
||||
}
|
||||
$affiliate_log->referred_by_user = $referred_by_user->id;
|
||||
$affiliate_log->amount = $amount;
|
||||
$affiliate_log->order_id = $order->id;
|
||||
$affiliate_log->order_detail_id = $orderDetail->id;
|
||||
$affiliate_log->affiliate_type = 'product_sharing';
|
||||
$affiliate_log->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif (AffiliateOption::where('type', 'category_wise_affiliate')->first()->status) {
|
||||
foreach ($order->orderDetails as $key => $orderDetail) {
|
||||
$amount = 0;
|
||||
if($orderDetail->product_referral_code != null) {
|
||||
$referred_by_user = User::where('referral_code', $orderDetail->product_referral_code)->first();
|
||||
if($referred_by_user != null) {
|
||||
if(AffiliateOption::where('type', 'category_wise_affiliate')->first()->details != null){
|
||||
foreach (json_decode(AffiliateOption::where('type', 'category_wise_affiliate')->first()->details) as $key => $value) {
|
||||
if($value->category_id == $orderDetail->product->category->id){
|
||||
if($value->commission_type == 'amount'){
|
||||
$amount = $value->commission;
|
||||
}
|
||||
else {
|
||||
$amount = ($value->commission * $orderDetail->price)/100;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$affiliate_user = $referred_by_user->affiliate_user;
|
||||
if($affiliate_user != null){
|
||||
$affiliate_user->balance += $amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
// Affiliate log
|
||||
$affiliate_log = new AffiliateLog;
|
||||
if($order->user_id != null){
|
||||
$affiliate_log->user_id = $order->user_id;
|
||||
}
|
||||
else{
|
||||
$affiliate_log->guest_id = $order->guest_id;
|
||||
}
|
||||
$affiliate_log->referred_by_user = $referred_by_user->id;
|
||||
$affiliate_log->amount = $amount;
|
||||
$affiliate_log->order_id = $order->id;
|
||||
$affiliate_log->order_detail_id = $orderDetail->id;
|
||||
$affiliate_log->affiliate_type = 'category_wise_affiliate';
|
||||
$affiliate_log->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function processAffiliateStats($affiliate_user_id, $no_click = 0, $no_item = 0, $no_delivered = 0, $no_cancel = 0) {
|
||||
$affiliate_stats = AffiliateStats::whereDate('created_at', Carbon::today())
|
||||
->where("affiliate_user_id", $affiliate_user_id)
|
||||
->first();
|
||||
|
||||
if(!$affiliate_stats) {
|
||||
$affiliate_stats = new AffiliateStats;
|
||||
$affiliate_stats->no_of_order_item = 0;
|
||||
$affiliate_stats->no_of_delivered = 0;
|
||||
$affiliate_stats->no_of_cancel = 0;
|
||||
$affiliate_stats->no_of_click = 0;
|
||||
}
|
||||
|
||||
$affiliate_stats->no_of_order_item += $no_item;
|
||||
$affiliate_stats->no_of_delivered += $no_delivered;
|
||||
$affiliate_stats->no_of_cancel += $no_cancel;
|
||||
$affiliate_stats->no_of_click += $no_click;
|
||||
$affiliate_stats->affiliate_user_id = $affiliate_user_id;
|
||||
|
||||
// dd($affiliate_stats);
|
||||
$affiliate_stats->save();
|
||||
|
||||
// foreach($order->orderDetails as $key => $orderDetail) {
|
||||
// $referred_by_user = User::where('referral_code', $orderDetail->product_referral_code)->first();
|
||||
//
|
||||
// if($referred_by_user != null) {
|
||||
// if($orderDetail->delivery_status == 'delivered') {
|
||||
// $affiliate_stats->no_of_delivered++;
|
||||
// } if($orderDetail->delivery_status == 'cancelled') {
|
||||
// $affiliate_stats->no_of_cancel++;
|
||||
// }
|
||||
//
|
||||
// $affiliate_stats->affiliate_user_id = $referred_by_user->id;
|
||||
// dd($affiliate_stats);
|
||||
// $affiliate_stats->save();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public function refferal_users()
|
||||
{
|
||||
$refferal_users = User::where('referred_by', '!=' , null)->paginate(10);
|
||||
return view('affiliate.refferal_users', compact('refferal_users'));
|
||||
}
|
||||
|
||||
// Affiliate Withdraw Request
|
||||
public function withdraw_request_store(Request $request)
|
||||
{
|
||||
$withdraw_request = new AffiliateWithdrawRequest;
|
||||
$withdraw_request->user_id = Auth::user()->id;
|
||||
$withdraw_request->amount = $request->amount;
|
||||
$withdraw_request->status = 0 ;
|
||||
|
||||
if($withdraw_request->save()){
|
||||
|
||||
$affiliate_user = AffiliateUser::where('user_id',Auth::user()->id)->first();
|
||||
$affiliate_user->balance = $affiliate_user->balance - $request->amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
flash(translate('New withdraw request created successfully'))->success();
|
||||
return redirect()->route('affiliate.user.withdraw_request_history');
|
||||
}
|
||||
else{
|
||||
flash(translate('Something went wrong'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function affiliate_withdraw_requests()
|
||||
{
|
||||
$affiliate_withdraw_requests = AffiliateWithdrawRequest::orderBy('id', 'desc')->paginate(10);
|
||||
return view('affiliate.affiliate_withdraw_requests', compact('affiliate_withdraw_requests'));
|
||||
}
|
||||
|
||||
public function affiliate_withdraw_modal(Request $request)
|
||||
{
|
||||
$affiliate_withdraw_request = AffiliateWithdrawRequest::findOrFail($request->id);
|
||||
$affiliate_user = AffiliateUser::where('user_id',$affiliate_withdraw_request->user_id)->first();
|
||||
return view('affiliate.affiliate_withdraw_modal', compact('affiliate_withdraw_request','affiliate_user'));
|
||||
}
|
||||
|
||||
public function withdraw_request_payment_store(Request $request){
|
||||
$affiliate_payment = new AffiliatePayment;
|
||||
$affiliate_payment->affiliate_user_id = $request->affiliate_user_id;
|
||||
$affiliate_payment->amount = $request->amount;
|
||||
$affiliate_payment->payment_method = $request->payment_method;
|
||||
$affiliate_payment->save();
|
||||
|
||||
if ($request->has('affiliate_withdraw_request_id')) {
|
||||
$affiliate_withdraw_request = AffiliateWithdrawRequest::findOrFail($request->affiliate_withdraw_request_id);
|
||||
$affiliate_withdraw_request->status = 1;
|
||||
$affiliate_withdraw_request->save();
|
||||
}
|
||||
|
||||
flash(translate('Payment completed'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function reject_withdraw_request($id)
|
||||
{
|
||||
$affiliate_withdraw_request = AffiliateWithdrawRequest::findOrFail($id);
|
||||
$affiliate_withdraw_request->status = 2;
|
||||
if($affiliate_withdraw_request->save()){
|
||||
|
||||
$affiliate_user = AffiliateUser::where('user_id', $affiliate_withdraw_request->user_id)->first();
|
||||
$affiliate_user->balance = $affiliate_user->balance + $affiliate_withdraw_request->amount;
|
||||
$affiliate_user->save();
|
||||
|
||||
flash(translate('Affiliate withdraw request has been rejected successfully'))->success();
|
||||
return redirect()->route('affiliate.withdraw_requests');
|
||||
}
|
||||
flash(translate('Something went wrong'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
}
|
||||
326
desarrollo2/app/Http/Controllers/AizUploadController.php
Normal file
326
desarrollo2/app/Http/Controllers/AizUploadController.php
Normal file
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Upload;
|
||||
use Response;
|
||||
use Auth;
|
||||
use Storage;
|
||||
use Image;
|
||||
use enshrined\svgSanitize\Sanitizer;
|
||||
|
||||
class AizUploadController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$all_uploads = (auth()->user()->user_type == 'seller') ? Upload::where('user_id', auth()->user()->id) : Upload::query();
|
||||
$search = null;
|
||||
$sort_by = null;
|
||||
|
||||
if ($request->search != null) {
|
||||
$search = $request->search;
|
||||
$all_uploads->where('file_original_name', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
|
||||
$sort_by = $request->sort;
|
||||
switch ($request->sort) {
|
||||
case 'newest':
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
case 'oldest':
|
||||
$all_uploads->orderBy('created_at', 'asc');
|
||||
break;
|
||||
case 'smallest':
|
||||
$all_uploads->orderBy('file_size', 'asc');
|
||||
break;
|
||||
case 'largest':
|
||||
$all_uploads->orderBy('file_size', 'desc');
|
||||
break;
|
||||
default:
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
|
||||
$all_uploads = $all_uploads->paginate(60)->appends(request()->query());
|
||||
|
||||
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.index', compact('all_uploads', 'search', 'sort_by'))
|
||||
: view('backend.uploaded_files.index', compact('all_uploads', 'search', 'sort_by'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.create')
|
||||
: view('backend.uploaded_files.create');
|
||||
}
|
||||
|
||||
|
||||
public function show_uploader(Request $request)
|
||||
{
|
||||
return view('uploader.aiz-uploader');
|
||||
}
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
"mp4" => "video",
|
||||
"mpg" => "video",
|
||||
"mpeg" => "video",
|
||||
"webm" => "video",
|
||||
"ogg" => "video",
|
||||
"avi" => "video",
|
||||
"mov" => "video",
|
||||
"flv" => "video",
|
||||
"swf" => "video",
|
||||
"mkv" => "video",
|
||||
"wmv" => "video",
|
||||
"wma" => "audio",
|
||||
"aac" => "audio",
|
||||
"wav" => "audio",
|
||||
"mp3" => "audio",
|
||||
"zip" => "archive",
|
||||
"rar" => "archive",
|
||||
"7z" => "archive",
|
||||
"doc" => "document",
|
||||
"txt" => "document",
|
||||
"docx" => "document",
|
||||
"pdf" => "document",
|
||||
"csv" => "document",
|
||||
"xml" => "document",
|
||||
"ods" => "document",
|
||||
"xlr" => "document",
|
||||
"xls" => "document",
|
||||
"xlsx" => "document"
|
||||
);
|
||||
|
||||
if ($request->hasFile('aiz_file')) {
|
||||
$upload = new Upload;
|
||||
$extension = strtolower($request->file('aiz_file')->getClientOriginalExtension());
|
||||
|
||||
if (
|
||||
env('DEMO_MODE') == 'On' &&
|
||||
isset($type[$extension]) &&
|
||||
$type[$extension] == 'archive'
|
||||
) {
|
||||
return '{}';
|
||||
}
|
||||
|
||||
if (isset($type[$extension])) {
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', $request->file('aiz_file')->getClientOriginalName());
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if($extension == 'svg') {
|
||||
$sanitizer = new Sanitizer();
|
||||
// Load the dirty svg
|
||||
$dirtySVG = file_get_contents($request->file('aiz_file'));
|
||||
|
||||
// Pass it to the sanitizer and get it back clean
|
||||
$cleanSVG = $sanitizer->sanitize($dirtySVG);
|
||||
|
||||
// Load the clean svg
|
||||
file_put_contents($request->file('aiz_file'), $cleanSVG);
|
||||
}
|
||||
|
||||
$path = $request->file('aiz_file')->store('uploads/all', 'local');
|
||||
$size = $request->file('aiz_file')->getSize();
|
||||
|
||||
// Return MIME type ala mimetype extension
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
|
||||
// Get the MIME type of the file
|
||||
$file_mime = finfo_file($finfo, base_path('public/') . $path);
|
||||
|
||||
if ($type[$extension] == 'image' && get_setting('disable_image_optimization') != 1) {
|
||||
try {
|
||||
$img = Image::make($request->file('aiz_file')->getRealPath())->encode();
|
||||
$height = $img->height();
|
||||
$width = $img->width();
|
||||
if ($width > $height && $width > 1500) {
|
||||
$img->resize(1500, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} elseif ($height > 1500) {
|
||||
$img->resize(null, 800, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
}
|
||||
$img->save(base_path('public/') . $path);
|
||||
clearstatcache();
|
||||
$size = $img->filesize();
|
||||
} catch (\Exception $e) {
|
||||
//dd($e);
|
||||
}
|
||||
}
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put(
|
||||
$path,
|
||||
file_get_contents(base_path('public/') . $path),
|
||||
[
|
||||
'visibility' => 'public',
|
||||
'ContentType' => $extension == 'svg' ? 'image/svg+xml' : $file_mime
|
||||
]
|
||||
);
|
||||
if ($arr[0] != 'updates') {
|
||||
unlink(base_path('public/') . $path);
|
||||
}
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $path;
|
||||
$upload->user_id = Auth::user()->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
}
|
||||
return '{}';
|
||||
}
|
||||
}
|
||||
|
||||
public function get_uploaded_files(Request $request)
|
||||
{
|
||||
$uploads = Upload::where('user_id', Auth::user()->id);
|
||||
if ($request->search != null) {
|
||||
$uploads->where('file_original_name', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
if ($request->sort != null) {
|
||||
switch ($request->sort) {
|
||||
case 'newest':
|
||||
$uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
case 'oldest':
|
||||
$uploads->orderBy('created_at', 'asc');
|
||||
break;
|
||||
case 'smallest':
|
||||
$uploads->orderBy('file_size', 'asc');
|
||||
break;
|
||||
case 'largest':
|
||||
$uploads->orderBy('file_size', 'desc');
|
||||
break;
|
||||
default:
|
||||
$uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $uploads->paginate(60)->appends(request()->query());
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$upload = Upload::findOrFail($id);
|
||||
|
||||
if (auth()->user()->user_type == 'seller' && $upload->user_id != auth()->user()->id) {
|
||||
flash(translate("You don't have permission for deleting this!"))->error();
|
||||
return back();
|
||||
}
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
public function bulk_uploaded_files_delete(Request $request)
|
||||
{
|
||||
if ($request->id) {
|
||||
foreach ($request->id as $file_id) {
|
||||
$this->destroy($file_id);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_preview_files(Request $request)
|
||||
{
|
||||
$ids = explode(',', $request->ids);
|
||||
$files = Upload::whereIn('id', $ids)->get();
|
||||
$new_file_array = [];
|
||||
foreach ($files as $file) {
|
||||
$file['file_name'] = my_asset($file->file_name);
|
||||
if ($file->external_link) {
|
||||
$file['file_name'] = $file->external_link;
|
||||
}
|
||||
$new_file_array[] = $file;
|
||||
}
|
||||
// dd($new_file_array);
|
||||
return $new_file_array;
|
||||
// return $files;
|
||||
}
|
||||
|
||||
public function all_file()
|
||||
{
|
||||
$uploads = Upload::all();
|
||||
foreach ($uploads as $upload) {
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
}
|
||||
}
|
||||
|
||||
Upload::query()->truncate();
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
//Download project attachment
|
||||
public function attachment_download($id)
|
||||
{
|
||||
$project_attachment = Upload::find($id);
|
||||
try {
|
||||
$file_path = public_path($project_attachment->file_name);
|
||||
return Response::download($file_path);
|
||||
} catch (\Exception $e) {
|
||||
flash(translate('File does not exist!'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
//Download project attachment
|
||||
public function file_info(Request $request)
|
||||
{
|
||||
$file = Upload::findOrFail($request['id']);
|
||||
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.info', compact('file'))
|
||||
: view('backend.uploaded_files.info', compact('file'));
|
||||
}
|
||||
}
|
||||
218
desarrollo2/app/Http/Controllers/Api/V2/AddressController.php
Normal file
218
desarrollo2/app/Http/Controllers/Api/V2/AddressController.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Country;
|
||||
use App\Http\Resources\V2\AddressCollection;
|
||||
use App\Models\Address;
|
||||
use App\Http\Resources\V2\CitiesCollection;
|
||||
use App\Http\Resources\V2\StatesCollection;
|
||||
use App\Http\Resources\V2\CountriesCollection;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Cart;
|
||||
use App\Models\State;
|
||||
|
||||
class AddressController extends Controller
|
||||
{
|
||||
public function addresses()
|
||||
{
|
||||
return new AddressCollection(Address::where('user_id', auth()->user()->id)->get());
|
||||
}
|
||||
|
||||
public function createShippingAddress(Request $request)
|
||||
{
|
||||
$address = new Address;
|
||||
$address->user_id = auth()->user()->id;
|
||||
$address->address = $request->address;
|
||||
$address->country_id = $request->country_id;
|
||||
$address->state_id = $request->state_id;
|
||||
$address->city_id = $request->city_id;
|
||||
$address->postal_code = $request->postal_code;
|
||||
$address->phone = $request->phone;
|
||||
$address->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Shipping information has been added successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateShippingAddress(Request $request)
|
||||
{
|
||||
$address = Address::find($request->id);
|
||||
$address->address = $request->address;
|
||||
$address->country_id = $request->country_id;
|
||||
$address->state_id = $request->state_id;
|
||||
$address->city_id = $request->city_id;
|
||||
$address->postal_code = $request->postal_code;
|
||||
$address->phone = $request->phone;
|
||||
$address->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Shipping information has been updated successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateShippingAddressLocation(Request $request)
|
||||
{
|
||||
$address = Address::find($request->id);
|
||||
$address->latitude = $request->latitude;
|
||||
$address->longitude = $request->longitude;
|
||||
$address->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Shipping location in map updated successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function deleteShippingAddress($id)
|
||||
{
|
||||
$address = Address::where('id',$id)->where('user_id',auth()->user()->id)->first();
|
||||
if($address == null) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Address not found')
|
||||
]);
|
||||
}
|
||||
$address->delete();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Shipping information has been deleted')
|
||||
]);
|
||||
}
|
||||
|
||||
public function makeShippingAddressDefault(Request $request)
|
||||
{
|
||||
Address::where('user_id', auth()->user()->id)->update(['set_default' => 0]); //make all user addressed non default first
|
||||
|
||||
$address = Address::find($request->id);
|
||||
$address->set_default = 1;
|
||||
$address->save();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Default shipping information has been updated')
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateAddressInCart(Request $request)
|
||||
{
|
||||
try {
|
||||
Cart::where('user_id', auth()->user()->id)->update(['address_id' => $request->address_id]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Could not save the address')
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Address is saved')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getShippingInCart(Request $request)
|
||||
{
|
||||
|
||||
$cart= Cart::where('user_id', auth()->user()->id)->first();
|
||||
|
||||
$address = $cart->address;
|
||||
return new AddressCollection(Address::where('id', $address->id)->get());
|
||||
// return new AddressCollection($address);
|
||||
|
||||
}
|
||||
|
||||
public function updateShippingTypeInCart(Request $request)
|
||||
{
|
||||
try {
|
||||
$carts= Cart::where('user_id', auth()->user()->id)->get();
|
||||
|
||||
|
||||
foreach ($carts as $key => $cart) {
|
||||
|
||||
$cart->shipping_cost = 0;
|
||||
|
||||
if($request->shipping_type=="pickup_point"){
|
||||
$cart->shipping_type="pickup_point";
|
||||
$cart->pickup_point=$request->shipping_id;
|
||||
$cart->carrier_id=0;
|
||||
}
|
||||
else if($request->shipping_type=="home_delivery"){
|
||||
$cart->shipping_cost = getShippingCost($carts, $key);
|
||||
$cart->shipping_type="home_delivery";
|
||||
$cart->pickup_point=0;
|
||||
$cart->carrier_id=0;
|
||||
}
|
||||
else if($request->shipping_type=="carrier_base"){
|
||||
$cart->shipping_cost = getShippingCost($carts, $key,$cart->carrier_id);
|
||||
$cart->shipping_type="carrier";
|
||||
$cart->carrier_id=$request->shipping_id;
|
||||
$cart->pickup_point=0;
|
||||
}
|
||||
$cart->save();
|
||||
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Could not save the address')
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Delivery address is saved')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getCities()
|
||||
{
|
||||
return new CitiesCollection(City::where('status', 1)->get());
|
||||
}
|
||||
|
||||
public function getStates()
|
||||
{
|
||||
return new StatesCollection(State::where('status', 1)->get());
|
||||
}
|
||||
|
||||
public function getCountries(Request $request)
|
||||
{
|
||||
$country_query = Country::where('status', 1);
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$country_query->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
$countries = $country_query->get();
|
||||
|
||||
return new CountriesCollection($countries);
|
||||
}
|
||||
|
||||
public function getCitiesByState($state_id,Request $request)
|
||||
{
|
||||
$city_query = City::where('status', 1)->where('state_id',$state_id);
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$city_query->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
$cities = $city_query->get();
|
||||
return new CitiesCollection($cities);
|
||||
}
|
||||
|
||||
public function getStatesByCountry($country_id,Request $request)
|
||||
{
|
||||
$state_query = State::where('status', 1)->where('country_id',$country_id);
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$state_query->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
$states = $state_query->get();
|
||||
return new StatesCollection($states);
|
||||
}
|
||||
}
|
||||
300
desarrollo2/app/Http/Controllers/Api/V2/AizUploadController.php
Normal file
300
desarrollo2/app/Http/Controllers/Api/V2/AizUploadController.php
Normal file
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Upload;
|
||||
use Response;
|
||||
use Auth;
|
||||
use Storage;
|
||||
use Image;
|
||||
|
||||
class AizUploadController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
||||
$all_uploads = (auth()->user()->user_type == 'seller') ? Upload::where('user_id', auth()->user()->id) : Upload::query();
|
||||
$search = null;
|
||||
$sort_by = null;
|
||||
|
||||
if ($request->search != null) {
|
||||
$search = $request->search;
|
||||
$all_uploads->where('file_original_name', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
|
||||
$sort_by = $request->sort;
|
||||
switch ($request->sort) {
|
||||
case 'newest':
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
case 'oldest':
|
||||
$all_uploads->orderBy('created_at', 'asc');
|
||||
break;
|
||||
case 'smallest':
|
||||
$all_uploads->orderBy('file_size', 'asc');
|
||||
break;
|
||||
case 'largest':
|
||||
$all_uploads->orderBy('file_size', 'desc');
|
||||
break;
|
||||
default:
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
|
||||
$all_uploads = $all_uploads->paginate(60)->appends(request()->query());
|
||||
|
||||
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.index', compact('all_uploads', 'search', 'sort_by'))
|
||||
: view('backend.uploaded_files.index', compact('all_uploads', 'search', 'sort_by'));
|
||||
}
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
"mp4" => "video",
|
||||
"mpg" => "video",
|
||||
"mpeg" => "video",
|
||||
"webm" => "video",
|
||||
"ogg" => "video",
|
||||
"avi" => "video",
|
||||
"mov" => "video",
|
||||
"flv" => "video",
|
||||
"swf" => "video",
|
||||
"mkv" => "video",
|
||||
"wmv" => "video",
|
||||
"wma" => "audio",
|
||||
"aac" => "audio",
|
||||
"wav" => "audio",
|
||||
"mp3" => "audio",
|
||||
"zip" => "archive",
|
||||
"rar" => "archive",
|
||||
"7z" => "archive",
|
||||
"doc" => "document",
|
||||
"txt" => "document",
|
||||
"docx" => "document",
|
||||
"pdf" => "document",
|
||||
"csv" => "document",
|
||||
"xml" => "document",
|
||||
"ods" => "document",
|
||||
"xlr" => "document",
|
||||
"xls" => "document",
|
||||
"xlsx" => "document"
|
||||
);
|
||||
if ($request->hasFile('aiz_file')) {
|
||||
$upload = new Upload;
|
||||
$extension = strtolower($request->file('aiz_file')->getClientOriginalExtension());
|
||||
|
||||
if (
|
||||
env('DEMO_MODE') == 'On' &&
|
||||
isset($type[$extension]) &&
|
||||
$type[$extension] == 'archive'
|
||||
) {
|
||||
return $this->failed(translate('File has been inserted successfully'));
|
||||
}
|
||||
|
||||
if (isset($type[$extension])) {
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', $request->file('aiz_file')->getClientOriginalName());
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$path = $request->file('aiz_file')->store('uploads/all', 'local');
|
||||
$size = $request->file('aiz_file')->getSize();
|
||||
|
||||
// Return MIME type ala mimetype extension
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
|
||||
// Get the MIME type of the file
|
||||
$file_mime = finfo_file($finfo, base_path('public/') . $path);
|
||||
|
||||
if ($type[$extension] == 'image' && get_setting('disable_image_optimization') != 1) {
|
||||
try {
|
||||
$img = Image::make($request->file('aiz_file')->getRealPath())->encode();
|
||||
$height = $img->height();
|
||||
$width = $img->width();
|
||||
if ($width > $height && $width > 1500) {
|
||||
$img->resize(1500, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} elseif ($height > 1500) {
|
||||
$img->resize(null, 800, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
}
|
||||
$img->save(base_path('public/') . $path);
|
||||
clearstatcache();
|
||||
$size = $img->filesize();
|
||||
} catch (\Exception $e) {
|
||||
//dd($e);
|
||||
}
|
||||
}
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put(
|
||||
$path,
|
||||
file_get_contents(base_path('public/') . $path),
|
||||
[
|
||||
'visibility' => 'public',
|
||||
'ContentType' => $extension == 'svg' ? 'image/svg+xml' : $file_mime
|
||||
]
|
||||
);
|
||||
if ($arr[0] != 'updates') {
|
||||
unlink(base_path('public/') . $path);
|
||||
}
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $path;
|
||||
$upload->user_id = Auth::user()->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
}
|
||||
return $this->success(translate('File has been inserted successfully'));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_uploaded_files(Request $request)
|
||||
{
|
||||
$uploads = Upload::where('user_id', Auth::user()->id);
|
||||
if ($request->search != null) {
|
||||
$uploads->where('file_original_name', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
if ($request->sort != null) {
|
||||
switch ($request->sort) {
|
||||
case 'newest':
|
||||
$uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
case 'oldest':
|
||||
$uploads->orderBy('created_at', 'asc');
|
||||
break;
|
||||
case 'smallest':
|
||||
$uploads->orderBy('file_size', 'asc');
|
||||
break;
|
||||
case 'largest':
|
||||
$uploads->orderBy('file_size', 'desc');
|
||||
break;
|
||||
default:
|
||||
$uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $uploads->paginate(60)->appends(request()->query());
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$upload = Upload::findOrFail($id);
|
||||
|
||||
if (auth()->user()->user_type == 'seller' && $upload->user_id != auth()->user()->id) {
|
||||
flash(translate("You don't have permission for deleting this!"))->error();
|
||||
return back();
|
||||
}
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
public function bulk_uploaded_files_delete(Request $request)
|
||||
{
|
||||
if ($request->id) {
|
||||
foreach ($request->id as $file_id) {
|
||||
$this->destroy($file_id);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_preview_files(Request $request)
|
||||
{
|
||||
$ids = explode(',', $request->ids);
|
||||
$files = Upload::whereIn('id', $ids)->get();
|
||||
$new_file_array = [];
|
||||
foreach ($files as $file) {
|
||||
$file['file_name'] = my_asset($file->file_name);
|
||||
if ($file->external_link) {
|
||||
$file['file_name'] = $file->external_link;
|
||||
}
|
||||
$new_file_array[] = $file;
|
||||
}
|
||||
// dd($new_file_array);
|
||||
return $new_file_array;
|
||||
// return $files;
|
||||
}
|
||||
|
||||
public function all_file()
|
||||
{
|
||||
$uploads = Upload::all();
|
||||
foreach ($uploads as $upload) {
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
}
|
||||
}
|
||||
|
||||
Upload::query()->truncate();
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
//Download project attachment
|
||||
public function attachment_download($id)
|
||||
{
|
||||
$project_attachment = Upload::find($id);
|
||||
try {
|
||||
$file_path = public_path($project_attachment->file_name);
|
||||
return Response::download($file_path);
|
||||
} catch (\Exception $e) {
|
||||
flash(translate('File does not exist!'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
//Download project attachment
|
||||
public function file_info(Request $request)
|
||||
{
|
||||
$file = Upload::findOrFail($request['id']);
|
||||
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.info', compact('file'))
|
||||
: view('backend.uploaded_files.info', compact('file'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\AuctionBidMailManager;
|
||||
use App\Models\AuctionProductBid;
|
||||
use App\Models\Product;
|
||||
use Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Mail;
|
||||
|
||||
class AuctionProductBidController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
$bid = AuctionProductBid::where('product_id', $request->product_id)->where('user_id', Auth::user()->id)->first();
|
||||
if ($bid == null) {
|
||||
$bid = new AuctionProductBid;
|
||||
$bid->user_id = Auth::user()->id;
|
||||
}
|
||||
$bid->product_id = $request->product_id;
|
||||
$bid->amount = $request->amount;
|
||||
if ($bid->save()) {
|
||||
$secound_max_bid = AuctionProductBid::where('product_id', $request->product_id)->orderBy('amount', 'desc')->skip(1)->first();
|
||||
if ($secound_max_bid != null) {
|
||||
if ($secound_max_bid->user->email != null) {
|
||||
$product = Product::where('id', $request->product_id)->first();
|
||||
$array['view'] = 'emails.auction_bid';
|
||||
$array['subject'] = translate('Auction Bid');
|
||||
$array['from'] = env('MAIL_FROM_ADDRESS');
|
||||
$array['content'] = 'Hi! A new user bidded more then you for the product, ' . $product->name . '. ' . 'Highest bid amount: ' . $bid->amount;
|
||||
$array['link'] = route('auction-product', $product->slug);
|
||||
try {
|
||||
Mail::to($secound_max_bid->user->email)->queue(new AuctionBidMailManager($array));
|
||||
} catch (\Exception $e) {
|
||||
//dd($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Bid Placed Successfully.'),
|
||||
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Something Went Wrong'),
|
||||
], 201);
|
||||
}
|
||||
return back();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\V2\AuctionMiniCollection;
|
||||
use App\Http\Resources\V2\AuctionProductDetailCollection;
|
||||
use App\Http\Resources\V2\ProductMiniCollection;
|
||||
use App\Models\Product;
|
||||
use Request;
|
||||
|
||||
|
||||
class AuctionProductController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$products = Product::latest()->where('published', 1)->where('auction_product', 1);
|
||||
if (get_setting('seller_auction_product') == 0) {
|
||||
$products = $products->where('added_by', 'admin');
|
||||
}
|
||||
$products = $products->where('auction_start_date', '<=', strtotime("now"))->where('auction_end_date', '>=', strtotime("now"));
|
||||
|
||||
|
||||
return new AuctionMiniCollection($products->paginate(10));
|
||||
}
|
||||
|
||||
|
||||
public function details_auction_product(Request $request, $id)
|
||||
{
|
||||
$detailedProduct = Product::where('id', $id)->get();
|
||||
return new AuctionProductDetailCollection($detailedProduct);
|
||||
}
|
||||
}
|
||||
382
desarrollo2/app/Http/Controllers/Api/V2/AuthController.php
Normal file
382
desarrollo2/app/Http/Controllers/Api/V2/AuthController.php
Normal file
@@ -0,0 +1,382 @@
|
||||
<?php
|
||||
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\OTPVerificationController;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Customer;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use App\Notifications\AppEmailVerificationNotification;
|
||||
use Hash;
|
||||
use GeneaLabs\LaravelSocialiter\Facades\Socialiter;
|
||||
use Socialite;
|
||||
use App\Models\Cart;
|
||||
use App\Rules\Recaptcha;
|
||||
use App\Services\SocialRevoke;
|
||||
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Laravel\Sanctum\PersonalAccessToken;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function signup(Request $request)
|
||||
{
|
||||
$messages = array(
|
||||
'name.required' => translate('Name is required'),
|
||||
'email_or_phone.required' => $request->register_by == 'email' ? translate('Email is required') : translate('Phone is required'),
|
||||
'email_or_phone.email' => translate('Email must be a valid email address'),
|
||||
'email_or_phone.numeric' => translate('Phone must be a number.'),
|
||||
'email_or_phone.unique' => $request->register_by == 'email' ? translate('The email has already been taken') : translate('The phone has already been taken'),
|
||||
'password.required' => translate('Password is required'),
|
||||
'password.confirmed' => translate('Password confirmation does not match'),
|
||||
'password.min' => translate('Minimum 6 digits required for password')
|
||||
);
|
||||
$validator = Validator::make($request->all(), [
|
||||
'name' => 'required',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
'email_or_phone' => [
|
||||
'required',
|
||||
Rule::when($request->register_by === 'email', ['email', 'unique:users,email']),
|
||||
Rule::when($request->register_by === 'phone', ['numeric', 'unique:users,phone']),
|
||||
],
|
||||
'g-recaptcha-response' => [
|
||||
Rule::when(get_setting('google_recaptcha') == 1, ['required', new Recaptcha()], ['sometimes'])
|
||||
]
|
||||
], $messages);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $validator->errors()
|
||||
]);
|
||||
}
|
||||
|
||||
$user = new User([
|
||||
'name' => $request->name,
|
||||
'email' => $request->register_by == 'email' ? $request->email_or_phone : '',
|
||||
'phone' => $request->register_by == 'phone' ? $request->email_or_phone : '',
|
||||
'password' => bcrypt($request->password),
|
||||
'verification_code' => rand(100000, 999999)
|
||||
]);
|
||||
|
||||
$user->email_verified_at = null;
|
||||
if ($user->email != null) {
|
||||
if (BusinessSetting::where('type', 'email_verification')->first()->value != 1) {
|
||||
$user->email_verified_at = date('Y-m-d H:m:s');
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->email_verified_at == null) {
|
||||
if ($request->register_by == 'email') {
|
||||
try {
|
||||
$user->notify(new AppEmailVerificationNotification());
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
} else {
|
||||
$otpController = new OTPVerificationController();
|
||||
$otpController->send_code($user);
|
||||
}
|
||||
}
|
||||
|
||||
$user->save();
|
||||
//create token
|
||||
$user->createToken('tokens')->plainTextToken;
|
||||
|
||||
return $this->loginSuccess($user);
|
||||
}
|
||||
|
||||
public function resendCode()
|
||||
{
|
||||
$user = auth()->user();
|
||||
$user->verification_code = rand(100000, 999999);
|
||||
|
||||
if ($user->email) {
|
||||
try {
|
||||
$user->notify(new AppEmailVerificationNotification());
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
} else {
|
||||
$otpController = new OTPVerificationController();
|
||||
$otpController->send_code($user);
|
||||
}
|
||||
|
||||
$user->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Verification code is sent again'),
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function confirmCode(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->verification_code == $request->verification_code) {
|
||||
$user->email_verified_at = date('Y-m-d H:i:s');
|
||||
$user->verification_code = null;
|
||||
$user->save();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Your account is now verified'),
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Code does not match, you can request for resending the code'),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function login(Request $request)
|
||||
{
|
||||
/*$request->validate([
|
||||
'email' => 'required|string|email',
|
||||
'password' => 'required|string',
|
||||
'remember_me' => 'boolean'
|
||||
]);*/
|
||||
|
||||
$delivery_boy_condition = $request->has('user_type') && $request->user_type == 'delivery_boy';
|
||||
$seller_condition = $request->has('user_type') && $request->user_type == 'seller';
|
||||
|
||||
if ($delivery_boy_condition) {
|
||||
$user = User::whereIn('user_type', ['delivery_boy'])
|
||||
->where('email', $request->email)
|
||||
->orWhere('phone', $request->email)
|
||||
->first();
|
||||
} elseif ($seller_condition) {
|
||||
$user = User::whereIn('user_type', ['seller'])
|
||||
->where('email', $request->email)
|
||||
->orWhere('phone', $request->email)
|
||||
->first();
|
||||
} else {
|
||||
$user = User::whereIn('user_type', ['customer'])
|
||||
->where('email', $request->email)
|
||||
->orWhere('phone', $request->email)
|
||||
->first();
|
||||
}
|
||||
|
||||
// if (!$delivery_boy_condition) {
|
||||
if (!$delivery_boy_condition && !$seller_condition) {
|
||||
if (\App\Utility\PayhereUtility::create_wallet_reference($request->identity_matrix) == false) {
|
||||
return response()->json(['result' => false, 'message' => 'Identity matrix error', 'user' => null], 401);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user != null) {
|
||||
if (!$user->banned) {
|
||||
if (Hash::check($request->password, $user->password)) {
|
||||
|
||||
if ($user->email_verified_at == null) {
|
||||
return response()->json(['result' => false, 'message' => translate('Please verify your account'), 'user' => null], 401);
|
||||
}
|
||||
return $this->loginSuccess($user);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('Unauthorized'), 'user' => null], 401);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('User is banned'), 'user' => null], 401);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('User not found'), 'user' => null], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function user(Request $request)
|
||||
{
|
||||
return response()->json($request->user());
|
||||
}
|
||||
|
||||
public function logout(Request $request)
|
||||
{
|
||||
|
||||
$user = request()->user();
|
||||
$user->tokens()->where('id', $user->currentAccessToken()->id)->delete();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Successfully logged out')
|
||||
]);
|
||||
}
|
||||
|
||||
public function socialLogin(Request $request)
|
||||
{
|
||||
if (!$request->provider) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('User not found'),
|
||||
'user' => null
|
||||
]);
|
||||
}
|
||||
|
||||
switch ($request->social_provider) {
|
||||
case 'facebook':
|
||||
$social_user = Socialite::driver('facebook')->fields([
|
||||
'name',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email'
|
||||
]);
|
||||
break;
|
||||
case 'google':
|
||||
$social_user = Socialite::driver('google')
|
||||
->scopes(['profile', 'email']);
|
||||
break;
|
||||
case 'twitter':
|
||||
$social_user = Socialite::driver('twitter');
|
||||
break;
|
||||
case 'apple':
|
||||
$social_user = Socialite::driver('sign-in-with-apple')
|
||||
->scopes(['name', 'email']);
|
||||
break;
|
||||
default:
|
||||
$social_user = null;
|
||||
}
|
||||
if ($social_user == null) {
|
||||
return response()->json(['result' => false, 'message' => translate('No social provider matches'), 'user' => null]);
|
||||
}
|
||||
|
||||
if ($request->social_provider == 'twitter') {
|
||||
$social_user_details = $social_user->userFromTokenAndSecret($request->access_token, $request->secret_token);
|
||||
} else {
|
||||
$social_user_details = $social_user->userFromToken($request->access_token);
|
||||
}
|
||||
|
||||
if ($social_user_details == null) {
|
||||
return response()->json(['result' => false, 'message' => translate('No social account matches'), 'user' => null]);
|
||||
}
|
||||
|
||||
$existingUserByProviderId = User::where('provider_id', $request->provider)->first();
|
||||
|
||||
if ($existingUserByProviderId) {
|
||||
$existingUserByProviderId->access_token = $social_user_details->token;
|
||||
if ($request->social_provider == 'apple') {
|
||||
$existingUserByProviderId->refresh_token = $social_user_details->refreshToken;
|
||||
if (!isset($social_user->user['is_private_email'])) {
|
||||
$existingUserByProviderId->email = $social_user_details->email;
|
||||
}
|
||||
}
|
||||
$existingUserByProviderId->save();
|
||||
return $this->loginSuccess($existingUserByProviderId);
|
||||
} else {
|
||||
$existing_or_new_user = User::firstOrNew(
|
||||
[['email', '!=', null], 'email' => $social_user_details->email]
|
||||
);
|
||||
|
||||
$existing_or_new_user->user_type = 'customer';
|
||||
$existing_or_new_user->provider_id = $social_user_details->id;
|
||||
|
||||
if (!$existing_or_new_user->exists) {
|
||||
if ($request->social_provider == 'apple') {
|
||||
if ($request->name) {
|
||||
$existing_or_new_user->name = $request->name;
|
||||
} else {
|
||||
$existing_or_new_user->name = 'Apple User';
|
||||
}
|
||||
} else {
|
||||
$existing_or_new_user->name = $social_user_details->name;
|
||||
}
|
||||
$existing_or_new_user->email = $social_user_details->email;
|
||||
$existing_or_new_user->email_verified_at = date('Y-m-d H:m:s');
|
||||
}
|
||||
|
||||
$existing_or_new_user->save();
|
||||
|
||||
return $this->loginSuccess($existing_or_new_user);
|
||||
}
|
||||
}
|
||||
|
||||
public function loginSuccess($user, $token = null)
|
||||
{
|
||||
|
||||
if (!$token) {
|
||||
$token = $user->createToken('API Token')->plainTextToken;
|
||||
}
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Successfully logged in'),
|
||||
'access_token' => $token,
|
||||
'token_type' => 'Bearer',
|
||||
'expires_at' => null,
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'type' => $user->user_type,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'avatar' => $user->avatar,
|
||||
'avatar_original' => uploaded_asset($user->avatar_original),
|
||||
'phone' => $user->phone,
|
||||
'email_verified' => $user->email_verified_at != null
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
protected function loginFailed()
|
||||
{
|
||||
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Login Failed'),
|
||||
'access_token' => '',
|
||||
'token_type' => '',
|
||||
'expires_at' => null,
|
||||
'user' => [
|
||||
'id' => 0,
|
||||
'type' => '',
|
||||
'name' => '',
|
||||
'email' => '',
|
||||
'avatar' => '',
|
||||
'avatar_original' => '',
|
||||
'phone' => ''
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function account_deletion()
|
||||
{
|
||||
if (auth()->user()) {
|
||||
Cart::where('user_id', auth()->user()->id)->delete();
|
||||
}
|
||||
|
||||
// if (auth()->user()->provider && auth()->user()->provider != 'apple') {
|
||||
// $social_revoke = new SocialRevoke;
|
||||
// $revoke_output = $social_revoke->apply(auth()->user()->provider);
|
||||
|
||||
// if ($revoke_output) {
|
||||
// }
|
||||
// }
|
||||
|
||||
$auth_user = auth()->user();
|
||||
$auth_user->tokens()->where('id', $auth_user->currentAccessToken()->id)->delete();
|
||||
$auth_user->customer_products()->delete();
|
||||
|
||||
User::destroy(auth()->user()->id);
|
||||
|
||||
return response()->json([
|
||||
"result" => true,
|
||||
"message" => translate('Your account deletion successfully done')
|
||||
]);
|
||||
}
|
||||
|
||||
public function getUserInfoByAccessToken(Request $request)
|
||||
{
|
||||
$token = PersonalAccessToken::findToken($request->access_token);
|
||||
if (!$token) {
|
||||
return $this->loginFailed();
|
||||
}
|
||||
$user = $token->tokenable;
|
||||
|
||||
if ($user == null) {
|
||||
return $this->loginFailed();
|
||||
}
|
||||
|
||||
return $this->loginSuccess($user, $request->access_token);
|
||||
}
|
||||
}
|
||||
14
desarrollo2/app/Http/Controllers/Api/V2/BannerController.php
Normal file
14
desarrollo2/app/Http/Controllers/Api/V2/BannerController.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\BannerCollection;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return new BannerCollection(json_decode(get_setting('home_banner1_images'), true));
|
||||
}
|
||||
}
|
||||
271
desarrollo2/app/Http/Controllers/Api/V2/BkashController.php
Normal file
271
desarrollo2/app/Http/Controllers/Api/V2/BkashController.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
use phpDocumentor\Reflection\Types\This;
|
||||
|
||||
class BkashController extends Controller
|
||||
{
|
||||
private $base_url;
|
||||
public function __construct()
|
||||
{
|
||||
if (get_setting('bkash_sandbox', 1)) {
|
||||
$this->base_url = "https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/";
|
||||
} else {
|
||||
$this->base_url = "https://tokenized.pay.bka.sh/v1.2.0-beta/tokenized/";
|
||||
}
|
||||
}
|
||||
|
||||
public function begin(Request $request)
|
||||
{
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
|
||||
try {
|
||||
$token = $this->getToken();
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$amount = $combined_order->grand_total;
|
||||
}
|
||||
if (
|
||||
$payment_type == 'wallet_payment' ||
|
||||
$payment_type == 'seller_package_payment' ||
|
||||
$payment_type == 'customer_package_payment'
|
||||
) {
|
||||
$amount = $request->amount;
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'token' => $token,
|
||||
'result' => true,
|
||||
'url' => route('api.bkash.webpage', ["token" => $token, "amount" => $amount]),
|
||||
'message' => translate('Payment page is found')
|
||||
]);
|
||||
} catch (\Exception $exception) {
|
||||
return response()->json([
|
||||
'token' => '',
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function webpage($token, $amount)
|
||||
{
|
||||
return view('frontend.payment.bkash_app', compact('token', 'amount'));
|
||||
}
|
||||
|
||||
public function checkout($token, $amount)
|
||||
{
|
||||
$auth = $token;
|
||||
|
||||
$callbackURL = route('home');
|
||||
$requestbody = array(
|
||||
'mode' => '0011',
|
||||
'payerReference' => ' ',
|
||||
'callbackURL' => route('api.bkash.callback'),
|
||||
'amount' => $amount,
|
||||
'currency' => 'BDT',
|
||||
'intent' => 'sale',
|
||||
'merchantInvoiceNumber' => "Inv" . Date('YmdH') . rand(1000, 10000)
|
||||
);
|
||||
$requestbodyJson = json_encode($requestbody);
|
||||
|
||||
$header = array(
|
||||
'Content-Type:application/json',
|
||||
'Authorization:' . $auth,
|
||||
'X-APP-Key:' . env('BKASH_CHECKOUT_APP_KEY')
|
||||
);
|
||||
|
||||
$url = curl_init($this->base_url . 'checkout/create');
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $requestbodyJson);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
return redirect(json_decode($resultdata)->bkashURL);
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$allRequest = $request->all();
|
||||
if (isset($allRequest['status']) && $allRequest['status'] == 'failure') {
|
||||
return $this->failed("Payment Failed");
|
||||
} else if (isset($allRequest['status']) && $allRequest['status'] == 'cancel') {
|
||||
return $this->failed("Payment Cancelled");
|
||||
} else {
|
||||
return response()->json([
|
||||
"result" => true,
|
||||
"paymentID" => $allRequest['paymentID']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
|
||||
$resultdata = $this->execute($request->token, $request->payment_id);
|
||||
|
||||
$result_data_array = json_decode($resultdata, true);
|
||||
|
||||
if (array_key_exists("statusCode", $result_data_array) && $result_data_array['statusCode'] != '0000') {
|
||||
return $this->failed($result_data_array['statusMessage']);
|
||||
} else if (array_key_exists("statusMessage", $result_data_array)) {
|
||||
|
||||
// if execute api failed to response
|
||||
sleep(1);
|
||||
$resultdata = $this->query($request->token, $request->payment_id);
|
||||
$resultdata = json_decode($resultdata);
|
||||
if($resultdata->transactionStatus == 'Initiated'){
|
||||
return $this->failed("Something is wrong try agin");
|
||||
}
|
||||
}
|
||||
return $this->process($request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getToken()
|
||||
{
|
||||
$request_data = array('app_key' => env('BKASH_CHECKOUT_APP_KEY'), 'app_secret' => env('BKASH_CHECKOUT_APP_SECRET'));
|
||||
$request_data_json = json_encode($request_data);
|
||||
|
||||
$header = array(
|
||||
'Content-Type:application/json',
|
||||
'username:' . env('BKASH_CHECKOUT_USER_NAME'),
|
||||
'password:' . env('BKASH_CHECKOUT_PASSWORD')
|
||||
);
|
||||
|
||||
$url = curl_init($this->base_url . 'checkout/token/grant');
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $request_data_json);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
$token = json_decode($resultdata)->id_token;
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function execute($token, $paymentID)
|
||||
{
|
||||
|
||||
$auth = $token;
|
||||
|
||||
$requestbody = array(
|
||||
'paymentID' => $paymentID
|
||||
);
|
||||
$requestbodyJson = json_encode($requestbody);
|
||||
|
||||
$header = array(
|
||||
'Content-Type:application/json',
|
||||
'Authorization:' . $auth,
|
||||
'X-APP-Key:' . env('BKASH_CHECKOUT_APP_KEY')
|
||||
);
|
||||
|
||||
$url = curl_init($this->base_url . 'checkout/execute');
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $requestbodyJson);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
return $resultdata;
|
||||
}
|
||||
|
||||
public function query($token, $paymentID){
|
||||
|
||||
$auth = $token;
|
||||
|
||||
$requestbody = array(
|
||||
'paymentID' => $paymentID
|
||||
);
|
||||
$requestbodyJson = json_encode($requestbody);
|
||||
|
||||
$header = array(
|
||||
'Content-Type:application/json',
|
||||
'Authorization:' . $auth,
|
||||
'X-APP-Key:'.env('BKASH_CHECKOUT_APP_KEY')
|
||||
);
|
||||
|
||||
$url = curl_init($this->base_url.'checkout/payment/status');
|
||||
curl_setopt($url, CURLOPT_HTTPHEADER, $header);
|
||||
curl_setopt($url, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($url, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($url, CURLOPT_POSTFIELDS, $requestbodyJson);
|
||||
curl_setopt($url, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($url, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
|
||||
$resultdata = curl_exec($url);
|
||||
curl_close($url);
|
||||
|
||||
return $resultdata;
|
||||
}
|
||||
|
||||
public function process(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, $request->payment_id);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Bkash', $request->payment_id);
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Bkash', $request->payment_id);
|
||||
}
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
// public function payment_success(Request $request)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'result' => true,
|
||||
// 'message' => translate('Payment Success'),
|
||||
// 'payment_details' => $request->payment_details
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function fail(Request $request)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Payment Failed'),
|
||||
'payment_details' => $request->payment_details
|
||||
]);
|
||||
}
|
||||
}
|
||||
29
desarrollo2/app/Http/Controllers/Api/V2/BrandController.php
Normal file
29
desarrollo2/app/Http/Controllers/Api/V2/BrandController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\BrandCollection;
|
||||
use App\Models\Brand;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utility\SearchUtility;
|
||||
use Cache;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$brand_query = Brand::query();
|
||||
if($request->name != "" || $request->name != null){
|
||||
$brand_query->where('name', 'like', '%'.$request->name.'%');
|
||||
SearchUtility::store($request->name);
|
||||
}
|
||||
return new BrandCollection($brand_query->paginate(10));
|
||||
}
|
||||
|
||||
public function top()
|
||||
{
|
||||
return Cache::remember('app.top_brands', 86400, function(){
|
||||
return new BrandCollection(Brand::where('top', 1)->get());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\BusinessSettingCollection;
|
||||
use App\Models\BusinessSetting;
|
||||
|
||||
class BusinessSettingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new BusinessSettingCollection(BusinessSetting::all());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\Carrier;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\V2\CarrierCollection;
|
||||
use App\Models\Country;
|
||||
|
||||
class CarrierController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$seller_wise_carrier_list = array();
|
||||
$carts = Cart::where('user_id', auth()->user()->id)->get();
|
||||
if (count($carts) > 0) {
|
||||
$zone = $carts[0]['address'] ? Country::where('id',$carts[0]['address']['country_id'])->first()->zone_id : null;
|
||||
$carrier_query = Carrier::query();
|
||||
$carrier_query->whereIn('id',function ($query) use ($zone) {
|
||||
$query->select('carrier_id')->from('carrier_range_prices')
|
||||
->where('zone_id', $zone);
|
||||
})->orWhere('free_shipping', 1);
|
||||
$carriers_list = $carrier_query->active()->get();
|
||||
foreach($carts->unique('owner_id') as $cart) {
|
||||
$new_carrier_list = [];
|
||||
foreach($carriers_list as $carrier_list) {
|
||||
$new_carrier_list['id'] = $carrier_list->id;
|
||||
$new_carrier_list['name'] = $carrier_list->name;
|
||||
$new_carrier_list['logo'] = uploaded_asset($carrier_list->logo);
|
||||
$new_carrier_list['transit_time'] = (integer) $carrier_list->transit_time;
|
||||
$new_carrier_list['free_shipping'] = $carrier_list->free_shipping == 1 ? true : false;
|
||||
$new_carrier_list['transit_price'] = carrier_base_price($carts, $carrier_list->id, $cart->owner_id);
|
||||
|
||||
$seller_wise_carrier_list[$cart->owner_id][] = $new_carrier_list;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response()->json([
|
||||
'data' => $seller_wise_carrier_list,
|
||||
'success' => true,
|
||||
'status' => 200
|
||||
]);
|
||||
// return (new CarrierCollection($carrier_list))->extra($request->owner_id);
|
||||
}
|
||||
}
|
||||
274
desarrollo2/app/Http/Controllers/Api/V2/CartController.php
Normal file
274
desarrollo2/app/Http/Controllers/Api/V2/CartController.php
Normal file
@@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\Product;
|
||||
use App\Models\Shop;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
public function summary()
|
||||
{
|
||||
//$user = User::where('id', auth()->user()->id)->first();
|
||||
$items = auth()->user()->carts;
|
||||
if ($items->isEmpty()) {
|
||||
return response()->json([
|
||||
'sub_total' => format_price(0.00),
|
||||
'tax' => format_price(0.00),
|
||||
'shipping_cost' => format_price(0.00),
|
||||
'discount' => format_price(0.00),
|
||||
'grand_total' => format_price(0.00),
|
||||
'grand_total_value' => 0.00,
|
||||
'coupon_code' => "",
|
||||
'coupon_applied' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$sum = 0.00;
|
||||
$subtotal = 0.00;
|
||||
$tax = 0.00;
|
||||
foreach ($items as $cartItem) {
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
$subtotal += cart_product_price($cartItem, $product, false, false) * $cartItem['quantity'];
|
||||
$tax += cart_product_tax($cartItem, $product, false) * $cartItem['quantity'];
|
||||
}
|
||||
|
||||
$shipping_cost = $items->sum('shipping_cost');
|
||||
$sum = $subtotal + $tax + $shipping_cost;
|
||||
|
||||
return response()->json([
|
||||
'sub_total' => format_price($subtotal),
|
||||
'tax' => format_price($tax),
|
||||
'shipping_cost' => format_price($shipping_cost ),
|
||||
'discount' => format_price($items->sum('discount')),
|
||||
'grand_total' => format_price($sum),
|
||||
'grand_total_value' => convert_price($sum),
|
||||
'coupon_code' => $items[0]->coupon_code,
|
||||
'coupon_applied' => $items[0]->coupon_applied == 1,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function count()
|
||||
{
|
||||
$items = auth()->user()->carts;
|
||||
|
||||
return response()->json([
|
||||
'count' => sizeof($items),
|
||||
'status' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getList()
|
||||
{
|
||||
$owner_ids = Cart::where('user_id', auth()->user()->id)->select('owner_id')->groupBy('owner_id')->pluck('owner_id')->toArray();
|
||||
$currency_symbol = currency_symbol();
|
||||
$shops = [];
|
||||
if (!empty($owner_ids)) {
|
||||
foreach ($owner_ids as $owner_id) {
|
||||
$shop = array();
|
||||
$shop_items_raw_data = Cart::where('user_id', auth()->user()->id)->where('owner_id', $owner_id)->get()->toArray();
|
||||
$shop_items_data = array();
|
||||
if (!empty($shop_items_raw_data)) {
|
||||
foreach ($shop_items_raw_data as $shop_items_raw_data_item) {
|
||||
$product = Product::where('id', $shop_items_raw_data_item["product_id"])->first();
|
||||
$shop_items_data_item["id"] = intval($shop_items_raw_data_item["id"]) ;
|
||||
$shop_items_data_item["owner_id"] =intval($shop_items_raw_data_item["owner_id"]) ;
|
||||
$shop_items_data_item["user_id"] =intval($shop_items_raw_data_item["user_id"]) ;
|
||||
$shop_items_data_item["product_id"] =intval($shop_items_raw_data_item["product_id"]) ;
|
||||
$shop_items_data_item["product_name"] = $product->getTranslation('name');
|
||||
$shop_items_data_item["product_thumbnail_image"] = uploaded_asset($product->thumbnail_img);
|
||||
$shop_items_data_item["variation"] = $shop_items_raw_data_item["variation"];
|
||||
$shop_items_data_item["price"] =(double) cart_product_price($shop_items_raw_data_item, $product, false, false);
|
||||
$shop_items_data_item["currency_symbol"] = $currency_symbol;
|
||||
$shop_items_data_item["tax"] =(double) cart_product_tax($shop_items_raw_data_item, $product,false);
|
||||
$shop_items_data_item["shipping_cost"] =(double) $shop_items_raw_data_item["shipping_cost"];
|
||||
$shop_items_data_item["quantity"] =intval($shop_items_raw_data_item["quantity"]) ;
|
||||
$shop_items_data_item["lower_limit"] = intval($product->min_qty) ;
|
||||
$shop_items_data_item["upper_limit"] = intval($product->stocks->where('variant', $shop_items_raw_data_item['variation'])->first()->qty) ;
|
||||
|
||||
$shop_items_data[] = $shop_items_data_item;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$shop_data = Shop::where('user_id', $owner_id)->first();
|
||||
if ($shop_data) {
|
||||
$shop['name'] = $shop_data->name;
|
||||
$shop['owner_id'] =(int) $owner_id;
|
||||
$shop['cart_items'] = $shop_items_data;
|
||||
} else {
|
||||
$shop['name'] = "Inhouse";
|
||||
$shop['owner_id'] =(int) $owner_id;
|
||||
$shop['cart_items'] = $shop_items_data;
|
||||
}
|
||||
$shops[] = $shop;
|
||||
}
|
||||
}
|
||||
|
||||
//dd($shops);
|
||||
|
||||
return response()->json($shops);
|
||||
}
|
||||
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$product = Product::findOrFail($request->id);
|
||||
|
||||
$variant = $request->variant;
|
||||
$tax = 0;
|
||||
|
||||
if ($variant == '')
|
||||
$price = $product->unit_price;
|
||||
else {
|
||||
$product_stock = $product->stocks->where('variant', $variant)->first();
|
||||
$price = $product_stock->price;
|
||||
}
|
||||
|
||||
//discount calculation based on flash deal and regular discount
|
||||
//calculation of taxes
|
||||
$discount_applicable = false;
|
||||
|
||||
if ($product->discount_start_date == null) {
|
||||
$discount_applicable = true;
|
||||
}
|
||||
elseif (strtotime(date('d-m-Y H:i:s')) >= $product->discount_start_date &&
|
||||
strtotime(date('d-m-Y H:i:s')) <= $product->discount_end_date) {
|
||||
$discount_applicable = true;
|
||||
}
|
||||
|
||||
if ($discount_applicable) {
|
||||
if($product->discount_type == 'percent'){
|
||||
$price -= ($price*$product->discount)/100;
|
||||
}
|
||||
elseif($product->discount_type == 'amount'){
|
||||
$price -= $product->discount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($product->taxes as $product_tax) {
|
||||
if ($product_tax->tax_type == 'percent') {
|
||||
$tax += ($price * $product_tax->tax) / 100;
|
||||
} elseif ($product_tax->tax_type == 'amount') {
|
||||
$tax += $product_tax->tax;
|
||||
}
|
||||
}
|
||||
|
||||
if ($product->min_qty > $request->quantity) {
|
||||
return response()->json(['result' => false, 'message' => translate("Minimum")." {$product->min_qty} ".translate("item(s) should be ordered")], 200);
|
||||
}
|
||||
|
||||
$stock = $product->stocks->where('variant', $variant)->first()->qty;
|
||||
|
||||
$variant_string = $variant != null && $variant != "" ? translate("for")." ($variant)" : "";
|
||||
if ($stock < $request->quantity && $product->digital == 0) {
|
||||
if ($stock == 0) {
|
||||
return response()->json(['result' => false, 'message' => "Stock out"], 200);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate("Only") ." {$stock} ".translate("item(s) are available")." {$variant_string}"], 200);
|
||||
}
|
||||
}
|
||||
|
||||
$cart_item = Cart::where('product_id', $request->id)->where("user_id",auth()->id())->first();
|
||||
if($cart_item && $cart_item->product->digital == 1) {
|
||||
return response()->json(['result' => false, 'message' => 'Already added this product' ]);
|
||||
}
|
||||
|
||||
Cart::updateOrCreate([
|
||||
'user_id' => auth()->user()->id,
|
||||
'owner_id' => $product->user_id,
|
||||
'product_id' => $request->id,
|
||||
'variation' => $variant
|
||||
], [
|
||||
'price' => $price,
|
||||
'tax' => $tax,
|
||||
'shipping_cost' => 0,
|
||||
'quantity' => DB::raw("quantity + $request->quantity")
|
||||
]);
|
||||
|
||||
if(\App\Utility\NagadUtility::create_balance_reference($request->cost_matrix) == false){
|
||||
return response()->json(['result' => false, 'message' => 'Cost matrix error' ]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Product added to cart successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeQuantity(Request $request)
|
||||
{
|
||||
$cart = Cart::find($request->id);
|
||||
if ($cart != null) {
|
||||
|
||||
if ($cart->product->stocks->where('variant', $cart->variation)->first()->qty >= $request->quantity) {
|
||||
$cart->update([
|
||||
'quantity' => $request->quantity
|
||||
]);
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate('Cart updated')], 200);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('Maximum available quantity reached')], 200);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['result' => false, 'message' => translate('Something went wrong')], 200);
|
||||
}
|
||||
|
||||
public function process(Request $request)
|
||||
{
|
||||
$cart_ids = explode(",", $request->cart_ids);
|
||||
$cart_quantities = explode(",", $request->cart_quantities);
|
||||
|
||||
if (!empty($cart_ids)) {
|
||||
$i = 0;
|
||||
foreach ($cart_ids as $cart_id) {
|
||||
$cart_item = Cart::where('id', $cart_id)->first();
|
||||
$product = Product::where('id', $cart_item->product_id)->first();
|
||||
|
||||
if ($product->min_qty > $cart_quantities[$i]) {
|
||||
return response()->json(['result' => false, 'message' => translate("Minimum")." {$product->min_qty} ".translate("item(s) should be ordered for")." {$product->name}"], 200);
|
||||
}
|
||||
|
||||
$stock = $cart_item->product->stocks->where('variant', $cart_item->variation)->first()->qty;
|
||||
$variant_string = $cart_item->variation != null && $cart_item->variation != "" ? " ($cart_item->variation)" : "";
|
||||
if ($stock >= $cart_quantities[$i] || $product->digital == 1) {
|
||||
$cart_item->update([
|
||||
'quantity' => $cart_quantities[$i]
|
||||
]);
|
||||
|
||||
} else {
|
||||
if ($stock == 0 ) {
|
||||
return response()->json(['result' => false, 'message' => translate("No item is available for")." {$product->name}{$variant_string},".translate("remove this from cart")], 200);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate("Only")." {$stock} ".translate("item(s) are available for")." {$product->name}{$variant_string}"], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate('Cart updated')], 200);
|
||||
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('Cart is empty')], 200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
Cart::destroy($id);
|
||||
return response()->json(['result' => true, 'message' => translate('Product is successfully removed from your cart')], 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\CategoryCollection;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Category;
|
||||
use Cache;
|
||||
|
||||
class CategoryController extends Controller
|
||||
{
|
||||
|
||||
public function index($parent_id = 0)
|
||||
{
|
||||
if(request()->has('parent_id') && is_numeric (request()->get('parent_id'))){
|
||||
$parent_id = request()->get('parent_id');
|
||||
}
|
||||
|
||||
return Cache::remember("app.categories-$parent_id", 86400, function() use ($parent_id){
|
||||
return new CategoryCollection(Category::where('parent_id', $parent_id)->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function featured()
|
||||
{
|
||||
return Cache::remember('app.featured_categories', 86400, function(){
|
||||
return new CategoryCollection(Category::where('featured', 1)->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return Cache::remember('app.home_categories', 86400, function(){
|
||||
return new CategoryCollection(Category::whereIn('id', json_decode(get_setting('home_categories')))->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function top()
|
||||
{
|
||||
return Cache::remember('app.top_categories', 86400, function(){
|
||||
return new CategoryCollection(Category::whereIn('id', json_decode(get_setting('home_categories')))->limit(20)->get());
|
||||
});
|
||||
}
|
||||
}
|
||||
104
desarrollo2/app/Http/Controllers/Api/V2/ChatController.php
Normal file
104
desarrollo2/app/Http/Controllers/Api/V2/ChatController.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Conversation;
|
||||
use App\Http\Resources\V2\ConversationCollection;
|
||||
use App\Http\Resources\V2\MessageCollection;
|
||||
use App\Mail\ConversationMailManager;
|
||||
use App\Models\Message;
|
||||
use App\Models\Product;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Mail;
|
||||
|
||||
class ChatController extends Controller
|
||||
{
|
||||
|
||||
public function conversations()
|
||||
{
|
||||
$conversations = Conversation::where('sender_id', auth()->user()->id)->latest('id')->paginate(10);
|
||||
return new ConversationCollection($conversations);
|
||||
}
|
||||
|
||||
public function messages($id)
|
||||
{
|
||||
$messages = Message::where('conversation_id', $id)->latest('id')->paginate(10);
|
||||
return new MessageCollection($messages);
|
||||
}
|
||||
|
||||
public function insert_message(Request $request)
|
||||
{
|
||||
$message = new Message;
|
||||
$message->conversation_id = $request->conversation_id;
|
||||
$message->user_id = auth()->user()->id;
|
||||
$message->message = $request->message;
|
||||
$message->save();
|
||||
$conversation = $message->conversation;
|
||||
if ($conversation->sender_id == $request->user_id) {
|
||||
$conversation->receiver_viewed = "1";
|
||||
} elseif ($conversation->receiver_id == $request->user_id) {
|
||||
$conversation->sender_viewed = "1";
|
||||
}
|
||||
$conversation->save();
|
||||
$messages = Message::where('id', $message->id)->paginate(1);
|
||||
return new MessageCollection($messages);
|
||||
}
|
||||
|
||||
public function get_new_messages($conversation_id, $last_message_id)
|
||||
{
|
||||
$messages = Message::where('conversation_id', $conversation_id)->where('id', '>', $last_message_id)->latest('id')->paginate(10);
|
||||
return new MessageCollection($messages);
|
||||
}
|
||||
|
||||
public function create_conversation(Request $request)
|
||||
{
|
||||
$seller_user = Product::findOrFail($request->product_id)->user;
|
||||
$user = User::find(auth()->user()->id);
|
||||
$conversation = new Conversation;
|
||||
$conversation->sender_id = $user->id;
|
||||
$conversation->receiver_id = Product::findOrFail($request->product_id)->user->id;
|
||||
$conversation->title = $request->title;
|
||||
|
||||
if ($conversation->save()) {
|
||||
$message = new Message;
|
||||
$message->conversation_id = $conversation->id;
|
||||
$message->user_id = $user->id;
|
||||
$message->message = $request->message;
|
||||
|
||||
if ($message->save()) {
|
||||
$this->send_message_to_seller($conversation, $message, $seller_user, $user);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'conversation_id' => $conversation->id,
|
||||
'shop_name' => $conversation->receiver->user_type == 'admin' ? 'In House Product' : $conversation->receiver->shop->name,
|
||||
'shop_logo' => $conversation->receiver->user_type == 'admin' ? uploaded_asset(get_setting('header_logo')) : uploaded_asset($conversation->receiver->shop->logo),
|
||||
'title'=> $conversation->title,
|
||||
'message' => translate("Conversation created"),]);
|
||||
}
|
||||
|
||||
public function send_message_to_seller($conversation, $message, $seller_user, $user)
|
||||
{
|
||||
$array['view'] = 'emails.conversation';
|
||||
$array['subject'] = translate('Sender').':- '. $user->name;
|
||||
$array['from'] = env('MAIL_FROM_ADDRESS');
|
||||
$array['content'] = translate('Hi! You recieved a message from ') . $user->name . '.';
|
||||
$array['sender'] = $user->name;
|
||||
|
||||
if ($seller_user->type == 'admin') {
|
||||
$array['link'] = route('conversations.admin_show', encrypt($conversation->id));
|
||||
} else {
|
||||
$array['link'] = route('conversations.show', encrypt($conversation->id));
|
||||
}
|
||||
|
||||
$array['details'] = $message->message;
|
||||
|
||||
try {
|
||||
Mail::to($conversation->receiver->email)->queue(new ConversationMailManager($array));
|
||||
} catch (\Exception $e) {
|
||||
//dd($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
130
desarrollo2/app/Http/Controllers/Api/V2/CheckoutController.php
Normal file
130
desarrollo2/app/Http/Controllers/Api/V2/CheckoutController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponUsage;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Product;
|
||||
|
||||
class CheckoutController
|
||||
{
|
||||
public function apply_coupon_code(Request $request)
|
||||
{
|
||||
|
||||
$coupon = Coupon::where('code', $request->coupon_code)->first();
|
||||
if ($coupon == null) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Invalid coupon code!')
|
||||
]);
|
||||
}
|
||||
$cart_items = Cart::where('user_id', auth()->user()->id)->where('owner_id', $coupon->user_id)->get();
|
||||
|
||||
$coupon_discount = 0;
|
||||
if ($cart_items->isEmpty()) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('This coupon is not applicable to your cart products!')
|
||||
]);
|
||||
}
|
||||
|
||||
$in_range = strtotime(date('d-m-Y')) >= $coupon->start_date && strtotime(date('d-m-Y')) <= $coupon->end_date;
|
||||
|
||||
if (!$in_range) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Coupon expired!')
|
||||
]);
|
||||
}
|
||||
|
||||
$is_used = CouponUsage::where('user_id', auth()->user()->id)->where('coupon_id', $coupon->id)->first() != null;
|
||||
|
||||
if ($is_used) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('You already used this coupon!')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$coupon_details = json_decode($coupon->details);
|
||||
|
||||
|
||||
if ($coupon->type == 'cart_base') {
|
||||
$subtotal = 0;
|
||||
$tax = 0;
|
||||
$shipping = 0;
|
||||
foreach ($cart_items as $key => $cartItem) {
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
$subtotal += cart_product_price($cartItem, $product, false, false) * $cartItem['quantity'];
|
||||
$tax += cart_product_tax($cartItem, $product,false) * $cartItem['quantity'];
|
||||
$shipping += $cartItem['shipping'] * $cartItem['quantity'];
|
||||
}
|
||||
$sum = $subtotal + $tax + $shipping;
|
||||
|
||||
if ($sum >= $coupon_details->min_buy) {
|
||||
if ($coupon->discount_type == 'percent') {
|
||||
$coupon_discount = ($sum * $coupon->discount) / 100;
|
||||
if ($coupon_discount > $coupon_details->max_discount) {
|
||||
$coupon_discount = $coupon_details->max_discount;
|
||||
}
|
||||
} elseif ($coupon->discount_type == 'amount') {
|
||||
$coupon_discount = $coupon->discount;
|
||||
}
|
||||
}
|
||||
} elseif ($coupon->type == 'product_base') {
|
||||
|
||||
foreach ($cart_items as $key => $cartItem) {
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
foreach ($coupon_details as $key => $coupon_detail) {
|
||||
if ($coupon_detail->product_id == $cartItem['product_id']) {
|
||||
if ($coupon->discount_type == 'percent') {
|
||||
$coupon_discount += cart_product_price($cartItem, $product, false, false) * $coupon->discount / 100;
|
||||
} elseif ($coupon->discount_type == 'amount') {
|
||||
$coupon_discount += $coupon->discount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($coupon_discount>0){
|
||||
Cart::where('user_id', auth()->user()->id)->update([
|
||||
'discount' => $coupon_discount / count($cart_items),
|
||||
'coupon_code' => $request->coupon_code,
|
||||
'coupon_applied' => 1
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Coupon Applied')
|
||||
]);
|
||||
}else{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('This coupon is not applicable to your cart products!')
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function remove_coupon_code(Request $request)
|
||||
{
|
||||
Cart::where('user_id', auth()->user()->id)->update([
|
||||
'discount' => 0.00,
|
||||
'coupon_code' => "",
|
||||
'coupon_applied' => 0
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Coupon Removed')
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\ClubPoint;
|
||||
use App\Http\Resources\V2\ClubpointCollection;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ClubpointController extends Controller
|
||||
{
|
||||
|
||||
public function get_list()
|
||||
{
|
||||
$club_points = ClubPoint::where('user_id', auth()->user()->id)->latest()->paginate(10);
|
||||
|
||||
return new ClubpointCollection($club_points);
|
||||
}
|
||||
|
||||
public function convert_into_wallet(Request $request)
|
||||
{
|
||||
$club_point = ClubPoint::find($request->id);
|
||||
if($club_point->convert_status == 0) {
|
||||
$amount = 0;
|
||||
|
||||
foreach ($club_point->club_point_details as $club_point_detail) {
|
||||
if($club_point_detail->refunded == 0){
|
||||
$club_point_detail->converted_amount = floatval($club_point_detail->point / get_setting('club_point_convert_rate'));
|
||||
$club_point_detail->save();
|
||||
$amount += $club_point_detail->converted_amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$wallet = new Wallet;
|
||||
$wallet->user_id = auth()->user()->id;
|
||||
$wallet->amount = $amount;
|
||||
$wallet->payment_method = 'Club Point Convert';
|
||||
$wallet->payment_details = 'Club Point Convert';
|
||||
$wallet->save();
|
||||
$user = User::find(auth()->user()->id);
|
||||
$user->balance = $user->balance + $amount;
|
||||
$user->save();
|
||||
$club_point->convert_status = 1;
|
||||
$club_point->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => translate('Successfully converted')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
desarrollo2/app/Http/Controllers/Api/V2/ColorController.php
Normal file
14
desarrollo2/app/Http/Controllers/Api/V2/ColorController.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\ColorCollection;
|
||||
use App\Models\Color;
|
||||
|
||||
class ColorController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new ColorCollection(Color::all());
|
||||
}
|
||||
}
|
||||
56
desarrollo2/app/Http/Controllers/Api/V2/ConfigController.php
Normal file
56
desarrollo2/app/Http/Controllers/Api/V2/ConfigController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Addon;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Language;
|
||||
use Illuminate\Http\Request;
|
||||
use stdClass;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
public function addon_list()
|
||||
{
|
||||
$addons = Addon::all();
|
||||
|
||||
return response()->json($addons);
|
||||
}
|
||||
|
||||
public function activated_social_login()
|
||||
{
|
||||
$activated_social_login_list = BusinessSetting::whereIn('type', ['facebook_login', 'google_login', 'twitter_login'])->get();
|
||||
return response()->json($activated_social_login_list);
|
||||
}
|
||||
|
||||
public function business_settings(Request $request)
|
||||
{
|
||||
$business_settings = BusinessSetting::whereIn('type', explode(',', $request->keys))->get()->toArray();
|
||||
|
||||
// $language_object = new stdClass();
|
||||
// $language_object->id = -123123;
|
||||
// $language_object->type = 'default_lanuage';
|
||||
// $language_object->value = env('DEFAULT_LANGUAGE');
|
||||
// $language_object->lang = null;
|
||||
|
||||
// $language_info = Language::where('code', env('DEFAULT_LANGUAGE'))->first();
|
||||
// $mobile_app = new stdClass();
|
||||
// $mobile_app->id = -12312;
|
||||
// $mobile_app->type = 'mobile_app_code';
|
||||
// $mobile_app->value = $language_info->app_lang_code;
|
||||
// $mobile_app->lang = null;
|
||||
|
||||
// $rtl_object = new stdClass();
|
||||
// $rtl_object->id = -1231;
|
||||
// $rtl_object->type = 'rtl';
|
||||
// $rtl_object->value = $language_info->rtl;
|
||||
// $rtl_object->lang = null;
|
||||
|
||||
// $new_array = [$language_object, $rtl_object, $mobile_app];
|
||||
|
||||
// $settings = array_merge($business_settings, $new_array);
|
||||
|
||||
return response()->json($business_settings);
|
||||
}
|
||||
}
|
||||
29
desarrollo2/app/Http/Controllers/Api/V2/Controller.php
Normal file
29
desarrollo2/app/Http/Controllers/Api/V2/Controller.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function success($message)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
|
||||
public function failed($message)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
}
|
||||
79
desarrollo2/app/Http/Controllers/Api/V2/CouponController.php
Normal file
79
desarrollo2/app/Http/Controllers/Api/V2/CouponController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponUsage;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function apply(Request $request)
|
||||
{
|
||||
$coupon = Coupon::where('code', $request->code)->first();
|
||||
|
||||
if ($coupon != null && strtotime(date('d-m-Y')) >= $coupon->start_date && strtotime(date('d-m-Y')) <= $coupon->end_date && CouponUsage::where('user_id', auth()->user()->id)->where('coupon_id', $coupon->id)->first() == null) {
|
||||
$couponDetails = json_decode($coupon->details);
|
||||
if ($coupon->type == 'cart_base') {
|
||||
$sum = Cart::where('user_id', auth()->user()->id)->sum('price');
|
||||
if ($sum > $couponDetails->min_buy) {
|
||||
if ($coupon->discount_type == 'percent') {
|
||||
$couponDiscount = ($sum * $coupon->discount) / 100;
|
||||
if ($couponDiscount > $couponDetails->max_discount) {
|
||||
$couponDiscount = $couponDetails->max_discount;
|
||||
}
|
||||
} elseif ($coupon->discount_type == 'amount') {
|
||||
$couponDiscount = $coupon->discount;
|
||||
}
|
||||
if ($this->isCouponAlreadyApplied(auth()->user()->id, $coupon->id)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => translate('The coupon is already applied. Please try another coupon')
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'discount' => (double) $couponDiscount
|
||||
]);
|
||||
}
|
||||
}
|
||||
} elseif ($coupon->type == 'product_base') {
|
||||
$couponDiscount = 0;
|
||||
$cartItems = Cart::where('user_id',auth()->user()->id)->get();
|
||||
foreach ($cartItems as $key => $cartItem) {
|
||||
foreach ($couponDetails as $key => $couponDetail) {
|
||||
if ($couponDetail->product_id == $cartItem->product_id) {
|
||||
if ($coupon->discount_type == 'percent') {
|
||||
$couponDiscount += $cartItem->price * $coupon->discount / 100;
|
||||
} elseif ($coupon->discount_type == 'amount') {
|
||||
$couponDiscount += $coupon->discount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->isCouponAlreadyApplied(auth()->user()->id, $coupon->id)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => translate('The coupon is already applied. Please try another coupon')
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'discount' => (double) $couponDiscount,
|
||||
'message' => translate('Coupon code applied successfully')
|
||||
]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => translate('The coupon is invalid')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function isCouponAlreadyApplied($userId, $couponId) {
|
||||
return CouponUsage::where(['user_id' => $userId, 'coupon_id' => $couponId])->count() > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\CurrencyCollection;
|
||||
use App\Models\Currency;
|
||||
|
||||
class CurrencyController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new CurrencyCollection(Currency::where('status', 1)->get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\CustomerCollection;
|
||||
use App\Models\User;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
$user = User::where("id",auth()->user()->id)->where("user_type","customer")->get();
|
||||
|
||||
return new CustomerCollection($user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
use App\Http\Resources\V2\CustomerPackageResource;
|
||||
use App\Models\CustomerPackage;
|
||||
use App\Models\CustomerPackagePayment;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class CustomerPackageController extends Controller
|
||||
{
|
||||
public function customer_packages_list()
|
||||
{
|
||||
$customer_packages = CustomerPackage::all();
|
||||
return CustomerPackageResource::collection($customer_packages);
|
||||
}
|
||||
|
||||
public function purchase_package_free(Request $request)
|
||||
{
|
||||
$data['customer_package_id'] = $request->package_id;
|
||||
|
||||
|
||||
$customer_package = CustomerPackage::findOrFail($data['customer_package_id']);
|
||||
|
||||
if ($customer_package->amount == 0) {
|
||||
$user = User::findOrFail(auth()->user()->id);
|
||||
if ($user->customer_package_id != $customer_package->id) {
|
||||
|
||||
$user->customer_package_id = $data['customer_package_id'];
|
||||
$customer_package = CustomerPackage::findOrFail($data['customer_package_id']);
|
||||
$user->remaining_uploads += $customer_package->product_upload;
|
||||
$user->save();
|
||||
return $this->success(translate('Package purchasing successful'));
|
||||
} else {
|
||||
return $this->failed(translate('You can not purchase this package anymore.'));
|
||||
|
||||
}
|
||||
}
|
||||
return $this->failed(translate('Invalid input'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function purchase_package_offline(Request $request)
|
||||
{
|
||||
$customer_package = new CustomerPackagePayment();
|
||||
$customer_package->user_id = auth()->user()->id;
|
||||
$customer_package->customer_package_id = $request->package_id;
|
||||
$customer_package->payment_method = $request->payment_option;
|
||||
$customer_package->payment_details = $request->trx_id;
|
||||
$customer_package->approval = 0;
|
||||
$customer_package->offline_payment = 1;
|
||||
$customer_package->reciept = ($request->photo == null) ? '' : $request->photo;
|
||||
$customer_package->save();
|
||||
|
||||
return $this->success(translate("Submitted Successfully"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\V2\ClassifiedProductDetailCollection;
|
||||
use App\Http\Resources\V2\ClassifiedProductMiniCollection;
|
||||
use App\Models\CustomerProduct;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerProductController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
|
||||
public function all()
|
||||
{
|
||||
$products = CustomerProduct::where('status', '1')->where('published', '1')->paginate(10);
|
||||
return new ClassifiedProductMiniCollection($products);
|
||||
}
|
||||
|
||||
|
||||
public function ownProducts()
|
||||
{
|
||||
$products = CustomerProduct::where('user_id', auth()->user()->id)->paginate(20);
|
||||
return new ClassifiedProductMiniCollection($products);
|
||||
}
|
||||
|
||||
|
||||
public function relatedProducts($id)
|
||||
{
|
||||
$product = CustomerProduct::where('id', $id)->first();
|
||||
$products = CustomerProduct::where('category_id', $product->category_id)->where('id', '!=', $product->id)->where('status', '1')->where('published', '1')->paginate(10);
|
||||
return new ClassifiedProductMiniCollection($products);
|
||||
}
|
||||
|
||||
|
||||
public function productDetails($id)
|
||||
{
|
||||
return new ClassifiedProductDetailCollection(CustomerProduct::where('id', $id)->get());
|
||||
// if (Product::findOrFail($id)->digital==0) {
|
||||
// return new ProductDetailCollection(Product::where('id', $id)->get());
|
||||
// }elseif (Product::findOrFail($id)->digital==1) {
|
||||
// return new DigitalProductDetailCollection(Product::where('id', $id)->get());
|
||||
// }
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$product = CustomerProduct::where("id",$id)->where('user_id', auth()->user()->id)->delete();
|
||||
|
||||
if($product)
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Product delete successfully')
|
||||
]);
|
||||
else
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Product delete failed')
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeStatus(Request $req, $id)
|
||||
{
|
||||
$product = CustomerProduct::where("id",$id)->where('user_id', auth()->user()->id)->first();
|
||||
|
||||
$product->status = $req->status;
|
||||
$product->save();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Product has updated successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\OTPVerificationController;
|
||||
use App\Http\Resources\V2\PurchaseHistoryMiniCollection;
|
||||
use App\Http\Resources\V2\DeliveryBoyPurchaseHistoryMiniCollection;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Resources\V2\DeliveryBoyCollection;
|
||||
use App\Http\Resources\V2\DeliveryHistoryCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryItemsCollection;
|
||||
use Auth;
|
||||
use App\Models\DeliveryBoy;
|
||||
use App\Models\DeliveryHistory;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\User;
|
||||
use App\Models\SmsTemplate;
|
||||
use App\Utility\SmsUtility;
|
||||
|
||||
|
||||
class DeliveryBoyController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Show the list of assigned delivery by the admin.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
public function dashboard_summary($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('assign_delivery_boy', $id);
|
||||
|
||||
|
||||
$delivery_boy = DeliveryBoy::where('user_id', $id)->first();
|
||||
|
||||
|
||||
//dummy
|
||||
/* return response()->json([
|
||||
'completed_delivery' => 123,
|
||||
'pending_delivery' => 0,
|
||||
'total_collection' => format_price(154126.00),
|
||||
'total_earning' => format_price(365.00),
|
||||
'cancelled' => 5,
|
||||
'on_the_way' => 123,
|
||||
'picked' => 24,
|
||||
'assigned' => 55,
|
||||
|
||||
]);*/
|
||||
|
||||
return response()->json([
|
||||
'completed_delivery' => Order::where('assign_delivery_boy', $id)->where('delivery_status', 'delivered')->count(),
|
||||
'pending_delivery' => Order::where('assign_delivery_boy', $id)->where('delivery_status', '!=', 'delivered')->where('delivery_status', '!=', 'cancelled')->where('cancel_request', '0')->count(),
|
||||
'total_collection' => format_price($delivery_boy->total_collection),
|
||||
'total_earning' => format_price($delivery_boy->total_earning),
|
||||
'cancelled' => Order::where('assign_delivery_boy', $id)->where('delivery_status', 'cancelled')->count(),
|
||||
'on_the_way' => Order::where('assign_delivery_boy', $id)->where('delivery_status', 'on_the_way')->where('cancel_request', '0')->count(),
|
||||
'picked' => Order::where('assign_delivery_boy', $id)->where('delivery_status', 'picked_up')->where('cancel_request', '0')->count(),
|
||||
'assigned' => Order::where('assign_delivery_boy', $id)->where('delivery_status', 'pending')->where('cancel_request', '0')->count(),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function assigned_delivery($id)
|
||||
{
|
||||
// $order_query = Order::query();
|
||||
// $order_query->where('delivery_status', 'pending');
|
||||
// $order_query->where('cancel_request', '0');
|
||||
|
||||
$order_query = Order::query();
|
||||
$order_query->where('assign_delivery_boy', $id);
|
||||
$order_query->where(function ($order_query) {
|
||||
$order_query->where('delivery_status', 'pending')
|
||||
->where('cancel_request', '0');
|
||||
})->orWhere(function ($order_query) {
|
||||
$order_query->where('delivery_status', 'confirmed')
|
||||
->where('cancel_request', '0');
|
||||
});
|
||||
|
||||
return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->latest('delivery_history_date')->paginate(10));
|
||||
// return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest('delivery_history_date')->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of pickup delivery by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function picked_up_delivery($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('delivery_status', 'picked_up');
|
||||
$order_query->where('cancel_request', '0');
|
||||
|
||||
return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest('delivery_history_date')->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of pickup delivery by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function on_the_way_delivery($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('delivery_status', 'on_the_way');
|
||||
$order_query->where('cancel_request', '0');
|
||||
|
||||
return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest('delivery_history_date')->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of completed delivery by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function completed_delivery($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('delivery_status', 'delivered');
|
||||
|
||||
//dd(request()->date_range);
|
||||
|
||||
if (request()->has('date_range') && request()->date_range != null && request()->date_range != "") {
|
||||
$max_date = date('Y-m-d H:i:s');
|
||||
$min_date = date('Y-m-d 00:00:00');
|
||||
if (request()->date_range == "today") {
|
||||
$min_date = date('Y-m-d 00:00:00');
|
||||
} else if (request()->date_range == "this_week") {
|
||||
//dd("hello");
|
||||
$min_date = date('Y-m-d 00:00:00', strtotime("-7 days"));
|
||||
} else if (request()->date_range == "this_month") {
|
||||
$min_date = date('Y-m-d 00:00:00', strtotime("-30 days"));
|
||||
}
|
||||
|
||||
$order_query->where('delivery_history_date','>=',$min_date)->where('delivery_history_date','<=',$max_date);
|
||||
|
||||
}
|
||||
|
||||
if (request()->has('payment_type') && request()->payment_type != null && request()->payment_type != "") {
|
||||
|
||||
if (request()->payment_type == "cod") {
|
||||
$order_query->where('payment_type','=','cash_on_delivery');
|
||||
} else if (request()->payment_type == "non-cod") {
|
||||
$order_query->where('payment_type','!=','cash_on_delivery');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest('delivery_history_date')->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of pending delivery by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function pending_delivery($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('delivery_status', '!=', 'delivered');
|
||||
$order_query->where('delivery_status', '!=', 'cancelled');
|
||||
$order_query->where('cancel_request', '0');
|
||||
|
||||
return new DeliveryBoyPurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest('delivery_history_date')->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of cancelled delivery by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function cancelled_delivery($id)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
$order_query->where('delivery_status', 'cancelled');
|
||||
|
||||
if (request()->has('date_range') && request()->date_range != null && request()->date_range != "") {
|
||||
$max_date = date('Y-m-d H:i:s');
|
||||
$min_date = date('Y-m-d 00:00:00');
|
||||
if (request()->date_range == "today") {
|
||||
$min_date = date('Y-m-d 00:00:00');
|
||||
} else if (request()->date_range == "this_week") {
|
||||
//dd("hello");
|
||||
$min_date = date('Y-m-d 00:00:00', strtotime("-7 days"));
|
||||
} else if (request()->date_range == "this_month") {
|
||||
$min_date = date('Y-m-d 00:00:00', strtotime("-30 days"));
|
||||
}
|
||||
|
||||
$order_query->where('delivery_history_date','>=',$min_date)->where('delivery_history_date','<=',$max_date);
|
||||
|
||||
}
|
||||
|
||||
if (request()->has('payment_type') && request()->payment_type != null && request()->payment_type != "") {
|
||||
|
||||
if (request()->payment_type == "cod") {
|
||||
$order_query->where('payment_type','=','cash_on_delivery');
|
||||
} else if (request()->payment_type == "non-cod") {
|
||||
$order_query->where('payment_type','!=','cash_on_delivery');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new PurchaseHistoryMiniCollection($order_query->where('assign_delivery_boy', $id)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the list of today's collection by the delivery boy.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function collection($id)
|
||||
{
|
||||
$collection_query = DeliveryHistory::query();
|
||||
$collection_query->where('delivery_status', 'delivered');
|
||||
$collection_query->where('payment_type', 'cash_on_delivery');
|
||||
|
||||
return new DeliveryHistoryCollection($collection_query->where('delivery_boy_id', $id)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function earning($id)
|
||||
{
|
||||
$collection_query = DeliveryHistory::query();
|
||||
$collection_query->where('delivery_status', 'delivered');
|
||||
|
||||
return new DeliveryHistoryCollection($collection_query->where('delivery_boy_id', $id)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function collection_summary($id)
|
||||
{
|
||||
$collection_query = DeliveryHistory::query();
|
||||
$collection_query->where('delivery_status', 'delivered');
|
||||
$collection_query->where('payment_type', 'cash_on_delivery');
|
||||
|
||||
|
||||
$today_date = date('Y-m-d');
|
||||
$yesterday_date = date('Y-m-d', strtotime("-1 day"));
|
||||
$today_date_formatted = date('d M, Y');
|
||||
$yesterday_date_formatted = date('d M,Y', strtotime("-1 day"));
|
||||
|
||||
|
||||
$today_collection = DeliveryHistory::where('delivery_status', 'delivered')
|
||||
->where('payment_type', 'cash_on_delivery')
|
||||
->where('delivery_boy_id', $id)
|
||||
->where('created_at','like',"%$today_date%")
|
||||
->sum('collection');
|
||||
|
||||
$yesterday_collection = DeliveryHistory::where('delivery_status', 'delivered')
|
||||
->where('payment_type', 'cash_on_delivery')
|
||||
->where('delivery_boy_id', $id)
|
||||
->where('created_at','like',"%$yesterday_date%")
|
||||
->sum('collection');
|
||||
|
||||
|
||||
return response()->json([
|
||||
'today_date' => $today_date_formatted,
|
||||
'today_collection' => format_price($today_collection) ,
|
||||
'yesterday_date' => $yesterday_date_formatted,
|
||||
'yesterday_collection' => format_price($yesterday_collection) ,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function earning_summary($id)
|
||||
{
|
||||
$collection_query = DeliveryHistory::query();
|
||||
$collection_query->where('delivery_status', 'delivered');
|
||||
// $collection_query->where('payment_type', 'cash_on_delivery');
|
||||
|
||||
|
||||
$today_date = date('Y-m-d');
|
||||
$yesterday_date = date('Y-m-d', strtotime("-1 day"));
|
||||
$today_date_formatted = date('d M, Y');
|
||||
$yesterday_date_formatted = date('d M,Y', strtotime("-1 day"));
|
||||
|
||||
|
||||
$today_collection = DeliveryHistory::where('delivery_status', 'delivered')
|
||||
->where('delivery_boy_id', $id)
|
||||
->where('created_at','like',"%$today_date%")
|
||||
->sum('earning');
|
||||
|
||||
$yesterday_collection = DeliveryHistory::where('delivery_status', 'delivered')
|
||||
->where('delivery_boy_id', $id)
|
||||
->where('created_at','like',"%$yesterday_date%")
|
||||
->sum('earning');
|
||||
|
||||
|
||||
return response()->json([
|
||||
'today_date' => $today_date_formatted,
|
||||
'today_earning' => format_price($today_collection) ,
|
||||
'yesterday_date' => $yesterday_date_formatted,
|
||||
'yesterday_earning' => format_price($yesterday_collection) ,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* For only delivery boy while changing delivery status.
|
||||
* Call from order controller
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function change_delivery_status(Request $request) {
|
||||
$order = Order::find($request->order_id);
|
||||
$order->delivery_viewed = '0';
|
||||
$order->delivery_status = $request->status;
|
||||
$order->save();
|
||||
|
||||
$delivery_history = new DeliveryHistory;
|
||||
|
||||
$delivery_history->order_id = $order->id;
|
||||
$delivery_history->delivery_boy_id = $request->delivery_boy_id;
|
||||
$delivery_history->delivery_status = $order->delivery_status;
|
||||
$delivery_history->payment_type = $order->payment_type;
|
||||
|
||||
if($order->delivery_status == 'delivered') {
|
||||
foreach ($order->orderDetails as $key => $orderDetail) {
|
||||
if (addon_is_activated('affiliate_system')) {
|
||||
if ($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$delivery_boy = DeliveryBoy::where('user_id', $request->delivery_boy_id)->first();
|
||||
|
||||
if (get_setting('delivery_boy_payment_type') == 'commission') {
|
||||
$delivery_history->earning = get_setting('delivery_boy_commission');
|
||||
$delivery_boy->total_earning += get_setting('delivery_boy_commission');
|
||||
}
|
||||
if ($order->payment_type == 'cash_on_delivery') {
|
||||
$delivery_history->collection = $order->grand_total;
|
||||
$delivery_boy->total_collection += $order->grand_total;
|
||||
|
||||
$order->payment_status = 'paid';
|
||||
if ($order->commission_calculated == 0) {
|
||||
calculateCommissionAffilationClubPoint($order);
|
||||
$order->commission_calculated = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$delivery_boy->save();
|
||||
}
|
||||
$order->delivery_history_date = date("Y-m-d H:i:s");
|
||||
|
||||
$order->save();
|
||||
$delivery_history->save();
|
||||
|
||||
if (addon_is_activated('otp_system') && SmsTemplate::where('identifier','delivery_status_change')->first()->status == 1){
|
||||
try {
|
||||
SmsUtility::delivery_status_change($order->user->phone, $order);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Delivery status changed to ').ucwords(str_replace('_',' ',$request->status))
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel_request($id)
|
||||
{
|
||||
$order = Order::find($id);
|
||||
|
||||
$order->cancel_request = 1;
|
||||
$order->cancel_request_at = date('Y-m-d H:i:s');
|
||||
$order->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Requested for cancellation')
|
||||
]);
|
||||
}
|
||||
|
||||
public function details($id)
|
||||
{
|
||||
$order_detail = Order::where('id', $id)->where('assign_delivery_boy', auth()->user()->id)->get();
|
||||
// $order_query = auth()->user()->orders->where('id', $id);
|
||||
|
||||
// return new PurchaseHistoryCollection($order_query->get());
|
||||
return new PurchaseHistoryCollection($order_detail);
|
||||
}
|
||||
|
||||
public function items($id)
|
||||
{
|
||||
$order_id = Order::select('id')->where('id', $id)->where('assign_delivery_boy', auth()->user()->id)->first();
|
||||
$order_query = OrderDetail::where('order_id', $order_id->id);
|
||||
return new PurchaseHistoryItemsCollection($order_query->get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Models\Upload;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use File;
|
||||
|
||||
class DigitalProductController extends Controller
|
||||
{
|
||||
public function download(Request $request)
|
||||
{
|
||||
$product = Product::findOrFail($request->id);
|
||||
$orders = Order::select("id")->where('user_id', auth()->user()->id)->pluck('id');
|
||||
$orderDetails = OrderDetail::where("product_id",$request->id)->whereIn("order_id",$orders)->get();
|
||||
if (auth()->user()->user_type == 'admin' || auth()->user()->id == $product->user_id || $orderDetails) {
|
||||
$upload = Upload::findOrFail($product->file_name);
|
||||
if (env('FILESYSTEM_DRIVER') == "s3") {
|
||||
return \Storage::disk('s3')->download($upload->file_name, $upload->file_original_name . "." . $upload->extension);
|
||||
} else {
|
||||
if (file_exists(base_path('public/' . $upload->file_name))) {
|
||||
$file = public_path()."/$upload->file_name";
|
||||
return response()->download($file,config('app.name')."_".$upload->file_original_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return response()->download(File("dd.pdf"),"failed.jpg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
125
desarrollo2/app/Http/Controllers/Api/V2/FileController.php
Normal file
125
desarrollo2/app/Http/Controllers/Api/V2/FileController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\UploadedFileCollection;
|
||||
use App\Models\Upload;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Storage;
|
||||
class FileController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
$all_uploads = (auth()->user()->user_type == 'seller') ? Upload::where('user_id',auth()->user()->id) : Upload::query();
|
||||
|
||||
|
||||
$all_uploads = $all_uploads->paginate(20)->appends(request()->query());
|
||||
|
||||
return new UploadedFileCollection($all_uploads);
|
||||
|
||||
}
|
||||
|
||||
// any base 64 image through uploader
|
||||
public function imageUpload(Request $request)
|
||||
{
|
||||
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
);
|
||||
|
||||
try {
|
||||
$image = $request->image;
|
||||
$request->filename;
|
||||
$realImage = base64_decode($image);
|
||||
|
||||
$dir = public_path('uploads/all');
|
||||
$full_path = "$dir/$request->filename";
|
||||
|
||||
$file_put = file_put_contents($full_path, $realImage); // int or false
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("File uploading error"),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload = new Upload;
|
||||
$extension = strtolower(File::extension($full_path));
|
||||
$size = File::size($full_path);
|
||||
|
||||
if (!isset($type[$extension])) {
|
||||
unlink($full_path);
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("Only image can be uploaded"),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', File::name($full_path));
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//unlink and upload again with new name
|
||||
unlink($full_path);
|
||||
$newFileName = rand(10000000000, 9999999999) . date("YmdHis") . "." . $extension;
|
||||
$newFullPath = "$dir/$newFileName";
|
||||
|
||||
$file_put = file_put_contents($newFullPath, $realImage);
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("Uploading error"),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$newPath = "uploads/all/$newFileName";
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put($newPath, file_get_contents(base_path('public/') . $newPath));
|
||||
unlink(base_path('public/') . $newPath);
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $newPath;
|
||||
$upload->user_id = auth()->user()->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("Image updated"),
|
||||
'path' => uploaded_asset($upload->id),
|
||||
'upload_id' => $upload->id
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
126
desarrollo2/app/Http/Controllers/Api/V2/FileUploadController.php
Normal file
126
desarrollo2/app/Http/Controllers/Api/V2/FileUploadController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Upload;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Storage;
|
||||
|
||||
class FileUploadController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function image_upload(Request $request)
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("User not found."),
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
);
|
||||
|
||||
try {
|
||||
$image = $request->image;
|
||||
$request->filename;
|
||||
$realImage = base64_decode($image);
|
||||
|
||||
$dir = public_path('uploads/all');
|
||||
$full_path = "$dir/$request->filename";
|
||||
|
||||
$file_put = file_put_contents($full_path, $realImage); // int or false
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "File uploading error",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload = new Upload;
|
||||
$extension = strtolower(File::extension($full_path));
|
||||
$size = File::size($full_path);
|
||||
|
||||
if (!isset($type[$extension])) {
|
||||
unlink($full_path);
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Only image can be uploaded",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', File::name($full_path));
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//unlink and upload again with new name
|
||||
unlink($full_path);
|
||||
$newFileName = rand(10000000000, 9999999999) . date("YmdHis") . "." . $extension;
|
||||
$newFullPath = "$dir/$newFileName";
|
||||
|
||||
$file_put = file_put_contents($newFullPath, $realImage);
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Uploading error",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
$newPath = "uploads/all/$newFileName";
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put($newPath, file_get_contents(base_path('public/') . $newPath));
|
||||
unlink(base_path('public/') . $newPath);
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $newPath;
|
||||
$upload->user_id = $user->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
|
||||
$user->avatar_original = $upload->id;
|
||||
$user->save();
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("Image updated"),
|
||||
'path' => uploaded_asset($upload->id)
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
desarrollo2/app/Http/Controllers/Api/V2/FilterController.php
Normal file
33
desarrollo2/app/Http/Controllers/Api/V2/FilterController.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\BrandCollection;
|
||||
use App\Http\Resources\V2\CategoryCollection;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Category;
|
||||
use Cache;
|
||||
|
||||
class FilterController extends Controller
|
||||
{
|
||||
public function categories()
|
||||
{
|
||||
//if you want to show base categories
|
||||
return Cache::remember('app.filter_categories', 86400, function () {
|
||||
return new CategoryCollection(Category::where('parent_id', 0)->get());
|
||||
});
|
||||
|
||||
//if you want to show featured categories
|
||||
//return new CategoryCollection(Category::where('featured', 1)->get());
|
||||
}
|
||||
|
||||
public function brands()
|
||||
{
|
||||
//show only top 20 brands
|
||||
return Cache::remember('app.filter_brands', 86400, function () {
|
||||
return new BrandCollection(Brand::where('top', 1)->limit(20)->get());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\FlashDealCollection;
|
||||
use App\Http\Resources\V2\ProductCollection;
|
||||
use App\Http\Resources\V2\ProductMiniCollection;
|
||||
use App\Models\FlashDeal;
|
||||
use App\Models\Product;
|
||||
|
||||
class FlashDealController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$flash_deals = FlashDeal::where('status', 1)
|
||||
->where('start_date', '<=', strtotime(date('d-m-Y')))
|
||||
->where('end_date', '>=', strtotime(date('d-m-Y')))
|
||||
->get();
|
||||
|
||||
return new FlashDealCollection($flash_deals);
|
||||
}
|
||||
|
||||
public function products($id)
|
||||
{
|
||||
$flash_deal = FlashDeal::find($id);
|
||||
$products = collect();
|
||||
foreach ($flash_deal->flash_deal_products as $key => $flash_deal_product) {
|
||||
if (Product::find($flash_deal_product->product_id) != null) {
|
||||
$products->push(Product::find($flash_deal_product->product_id));
|
||||
}
|
||||
}
|
||||
return new ProductMiniCollection($products);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Rave as Flutterwave;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class FlutterwaveController extends Controller
|
||||
{
|
||||
|
||||
public function getUrl(Request $request)
|
||||
{
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
if (isset($request->package_id)) {
|
||||
$package_id = $request->package_id;
|
||||
}
|
||||
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
return $this->initialize($payment_type, $combined_order_id, $combined_order->grand_total, $user_id);
|
||||
} elseif ($payment_type == 'wallet_payment') {
|
||||
return $this->initialize($payment_type, $combined_order_id, $amount, $user_id);
|
||||
} elseif (
|
||||
$payment_type == 'seller_package_payment' ||
|
||||
$payment_type == 'customer_package_payment'
|
||||
) {
|
||||
return $this->initialize($payment_type, $combined_order_id, $amount, $user_id, $package_id);
|
||||
}
|
||||
}
|
||||
|
||||
public function initialize($payment_type, $combined_order_id, $amount, $user_id, $package_id = 0)
|
||||
{
|
||||
$user = User::find($user_id);
|
||||
//This generates a payment reference
|
||||
$reference = Flutterwave::generateReference();
|
||||
|
||||
// Enter the details of the payment
|
||||
$data = [
|
||||
'payment_options' => 'card,banktransfer',
|
||||
'amount' => $amount,
|
||||
'email' => $user->email,
|
||||
'tx_ref' => $reference,
|
||||
'currency' => env('FLW_PAYMENT_CURRENCY_CODE'),
|
||||
'redirect_url' => route(
|
||||
'api.flutterwave.callback',
|
||||
[
|
||||
"payment_type" => $payment_type,
|
||||
"combined_order_id" => $combined_order_id,
|
||||
"amount" => $amount,
|
||||
"user_id" => $user_id,
|
||||
'package_id' => $package_id
|
||||
]
|
||||
),
|
||||
'customer' => [
|
||||
'email' => $user->email,
|
||||
"phone_number" => $user->phone,
|
||||
"name" => $user->name
|
||||
],
|
||||
|
||||
"customizations" => [
|
||||
"title" => 'Payment',
|
||||
"description" => ""
|
||||
]
|
||||
];
|
||||
|
||||
$payment = Flutterwave::initializePayment($data);
|
||||
|
||||
|
||||
if ($payment['status'] !== 'success') {
|
||||
// notify something went wrong
|
||||
return response()->json(['result' => false, 'url' => '', 'message' => "Could not find redirect url"]);
|
||||
}
|
||||
return response()->json(['result' => true, 'url' => $payment['data']['link'], 'message' => "Url generated"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$status = $request->status;
|
||||
|
||||
//if payment is successful
|
||||
if ($status == 'successful') {
|
||||
$transactionID = Flutterwave::getTransactionIDFromCallback();
|
||||
$data = Flutterwave::verifyTransaction($transactionID);
|
||||
|
||||
try {
|
||||
$payment = $data['data'];
|
||||
|
||||
if ($payment['status'] == "successful") {
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, json_encode($payment));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Flutterwave', json_encode($payment));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Flutterwave', json_encode($payment));
|
||||
}
|
||||
if ($request->payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment is unsuccessful")]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => translate("Unsuccessful")]);
|
||||
}
|
||||
} elseif ($status == 'cancelled') {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment Cancelled")]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\FollowSellerResource;
|
||||
use App\Models\FollowSeller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FollowSellerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$followed_sellers = FollowSeller::query()
|
||||
->with('shop')
|
||||
->where('user_id', auth()->user()->id)
|
||||
->orderBy('shop_id', 'asc')
|
||||
->paginate(10);
|
||||
|
||||
return FollowSellerResource::collection($followed_sellers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store($shop_id)
|
||||
{
|
||||
if (auth()->user()->user_type == 'customer') {
|
||||
$followed_seller = FollowSeller::where('user_id', auth()->user()->id)->where('shop_id', $shop_id)->first();
|
||||
if ($followed_seller == null) {
|
||||
FollowSeller::insert([
|
||||
'user_id' => auth()->user()->id,
|
||||
'shop_id' => $shop_id
|
||||
]);
|
||||
}
|
||||
return $this->success(translate('Seller follow is successfull'));
|
||||
}
|
||||
|
||||
return $this->failed(translate('You need to login as a customer to follow this seller'));
|
||||
}
|
||||
|
||||
public function remove($shop_id)
|
||||
{
|
||||
$followed_seller = FollowSeller::where('user_id', auth()->user()->id)->where('shop_id', $shop_id)->first();
|
||||
if ($followed_seller != null) {
|
||||
FollowSeller::where('user_id', auth()->user()->id)->where('shop_id', $shop_id)->delete();
|
||||
|
||||
return $this->success(translate('Seller unfollow is successfull'));
|
||||
}
|
||||
}
|
||||
|
||||
public function checkFollow($shop_id)
|
||||
{
|
||||
$followed_seller = FollowSeller::where('user_id', auth()->user()->id)->where('shop_id', $shop_id)->first();
|
||||
if ($followed_seller != null) {
|
||||
return $this->success(translate('This seller is followed'));
|
||||
}
|
||||
return $this->failed(translate('This seller is unfollowed'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\GeneralSettingCollection;
|
||||
use App\Models\GeneralSetting;
|
||||
|
||||
class GeneralSettingController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new GeneralSettingCollection(GeneralSetting::all());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\HomeCategoryCollection;
|
||||
use App\Models\HomeCategory;
|
||||
|
||||
class HomeCategoryController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new HomeCategoryCollection(HomeCategory::all());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Api\V2\Seller\SellerPackageController as SellerSellerPackageController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\CustomerPackage;
|
||||
use App\Models\SellerPackage;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\SellerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
|
||||
|
||||
class InstamojoController extends Controller
|
||||
{
|
||||
public function pay(Request $request)
|
||||
{
|
||||
// dd(auth()->user()->phone);
|
||||
if (BusinessSetting::where('type', 'instamojo_sandbox')->first()->value == 1) {
|
||||
// testing_url
|
||||
$endPoint = 'https://test.instamojo.com/api/1.1/';
|
||||
} else {
|
||||
// live_url
|
||||
$endPoint = 'https://www.instamojo.com/api/1.1/';
|
||||
}
|
||||
|
||||
$api = new \Instamojo\Instamojo(
|
||||
env('IM_API_KEY'),
|
||||
env('IM_AUTH_TOKEN'),
|
||||
$endPoint
|
||||
);
|
||||
|
||||
|
||||
if (preg_match_all('/^(?:(?:\+|0{0,2})91(\s*[\ -]\s*)?|[0]?)?[789]\d{9}|(\d[ -]?){10}\d$/im', auth()->user()->phone)) {
|
||||
|
||||
$amount = 0;
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::findOrFail($request->combined_order_id);
|
||||
$amount = round($combined_order->grand_total);
|
||||
} elseif ($request->payment_type == 'wallet_payment') {
|
||||
$amount = round($request->wallet_amount);
|
||||
} elseif ($request->payment_type == 'customer_package_payment') {
|
||||
$customer_package = CustomerPackage::findOrFail($request->customer_package_id);
|
||||
$amount = round($customer_package->amount);
|
||||
}
|
||||
try {
|
||||
$response = $api->paymentRequestCreate(array(
|
||||
"purpose" => ucfirst(str_replace('_', ' ', $request->payment_type)),
|
||||
"amount" => $amount,
|
||||
"send_email" => false,
|
||||
"email" => auth()->user()->email,
|
||||
"phone" => auth()->user()->phone,
|
||||
"redirect_url" => url("api/v2/instamojo/success?payment_option=$request->payment_option&payment_type=$request->payment_type&combined_order_id=$request->combined_order_id&wallet_amount=$request->wallet_amount&customer_package_id=$request->customer_package_id")
|
||||
));
|
||||
return redirect($response['longurl']);
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
return redirect(url("api/v2/online-pay/failed"))->with("errors",'Please add phone number to your profile');
|
||||
}
|
||||
// success response method.
|
||||
public function success(Request $request)
|
||||
{
|
||||
try {
|
||||
if (BusinessSetting::where('type', 'instamojo_sandbox')->first()->value == 1) {
|
||||
$endPoint = 'https://test.instamojo.com/api/1.1/';
|
||||
} else {
|
||||
$endPoint = 'https://www.instamojo.com/api/1.1/';
|
||||
}
|
||||
|
||||
$api = new \Instamojo\Instamojo(
|
||||
env('IM_API_KEY'),
|
||||
env('IM_AUTH_TOKEN'),
|
||||
$endPoint
|
||||
);
|
||||
|
||||
$response = $api->paymentRequestStatus(request('payment_request_id'));
|
||||
|
||||
if (!isset($response['payments'][0]['status']) || $response['payments'][0]['status'] != 'Credit') {
|
||||
return redirect(url("api/v2/online-pay/failed"))->with("errors",translate('Payment Failed'));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return redirect(url("api/v2/online-pay/failed"))->with('errors',translate('Payment Failed'));
|
||||
}
|
||||
|
||||
$payment = json_encode($response);
|
||||
return redirect( url("api/v2/online-pay/success?payment_type=$request->payment_type&combined_order_id=$request->combined_order_id&wallet_amount=$request->wallet_amount&customer_package_id=$request->customer_package_id&payment_details=$payment"));
|
||||
// }
|
||||
}
|
||||
}
|
||||
206
desarrollo2/app/Http/Controllers/Api/V2/IyzicoController.php
Normal file
206
desarrollo2/app/Http/Controllers/Api/V2/IyzicoController.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Redirect;
|
||||
|
||||
class IyzicoController extends Controller
|
||||
{
|
||||
|
||||
public function init(Request $request)
|
||||
{
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
|
||||
$options = new \Iyzipay\Options();
|
||||
$options->setApiKey(env('IYZICO_API_KEY'));
|
||||
$options->setSecretKey(env('IYZICO_SECRET_KEY'));
|
||||
|
||||
if (get_setting('iyzico_sandbox') == 1) {
|
||||
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
|
||||
} else {
|
||||
$options->setBaseUrl("https://api.iyzipay.com");
|
||||
}
|
||||
|
||||
$iyzicoRequest = new \Iyzipay\Request\CreatePayWithIyzicoInitializeRequest();
|
||||
$iyzicoRequest->setLocale(\Iyzipay\Model\Locale::TR);
|
||||
$iyzicoRequest->setConversationId('123456789');
|
||||
|
||||
$buyer = new \Iyzipay\Model\Buyer();
|
||||
$buyer->setId("BY789");
|
||||
$buyer->setName("John");
|
||||
$buyer->setSurname("Doe");
|
||||
$buyer->setEmail("email@email.com");
|
||||
$buyer->setIdentityNumber("74300864791");
|
||||
$buyer->setRegistrationAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
|
||||
$buyer->setCity("Istanbul");
|
||||
$buyer->setCountry("Turkey");
|
||||
$iyzicoRequest->setBuyer($buyer);
|
||||
$shippingAddress = new \Iyzipay\Model\Address();
|
||||
$shippingAddress->setContactName("Jane Doe");
|
||||
$shippingAddress->setCity("Istanbul");
|
||||
$shippingAddress->setCountry("Turkey");
|
||||
$shippingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
|
||||
$iyzicoRequest->setShippingAddress($shippingAddress);
|
||||
|
||||
$billingAddress = new \Iyzipay\Model\Address();
|
||||
$billingAddress->setContactName("Jane Doe");
|
||||
$billingAddress->setCity("Istanbul");
|
||||
$billingAddress->setCountry("Turkey");
|
||||
$billingAddress->setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
|
||||
$iyzicoRequest->setBillingAddress($billingAddress);
|
||||
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$iyzicoRequest->setPrice(round($combined_order->grand_total));
|
||||
$iyzicoRequest->setPaidPrice(round($combined_order->grand_total));
|
||||
$iyzicoRequest->setCurrency(\Iyzipay\Model\Currency::TL);
|
||||
$iyzicoRequest->setBasketId(rand(000000, 999999));
|
||||
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
|
||||
$iyzicoRequest->setCallbackUrl(route('api.iyzico.callback'));
|
||||
|
||||
$basketItems = array();
|
||||
$firstBasketItem = new \Iyzipay\Model\BasketItem();
|
||||
$firstBasketItem->setId(rand(1000, 9999));
|
||||
$firstBasketItem->setName("Cart Payment");
|
||||
$firstBasketItem->setCategory1("Accessories");
|
||||
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
|
||||
$firstBasketItem->setPrice(round($combined_order->grand_total));
|
||||
$basketItems[0] = $firstBasketItem;
|
||||
|
||||
$iyzicoRequest->setBasketItems($basketItems);
|
||||
} elseif ($payment_type == 'wallet_payment') {
|
||||
$iyzicoRequest->setPrice(round($amount));
|
||||
$iyzicoRequest->setPaidPrice(round($amount));
|
||||
$iyzicoRequest->setCurrency(\Iyzipay\Model\Currency::TL);
|
||||
$iyzicoRequest->setBasketId(rand(000000, 999999));
|
||||
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
|
||||
$iyzicoRequest->setCallbackUrl(route('api.iyzico.callback'));
|
||||
|
||||
$basketItems = array();
|
||||
$firstBasketItem = new \Iyzipay\Model\BasketItem();
|
||||
$firstBasketItem->setId(rand(1000, 9999));
|
||||
$firstBasketItem->setName("Wallet Payment");
|
||||
$firstBasketItem->setCategory1("Wallet");
|
||||
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
|
||||
$firstBasketItem->setPrice(round($amount));
|
||||
$basketItems[0] = $firstBasketItem;
|
||||
|
||||
$iyzicoRequest->setBasketItems($basketItems);
|
||||
} elseif ($payment_type == 'seller_package_payment') {
|
||||
$iyzicoRequest->setPrice(round($amount));
|
||||
$iyzicoRequest->setPaidPrice(round($amount));
|
||||
$iyzicoRequest->setCurrency(\Iyzipay\Model\Currency::TL);
|
||||
$iyzicoRequest->setBasketId(rand(000000, 999999));
|
||||
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
|
||||
$iyzicoRequest->setCallbackUrl(route('api.iyzico.callback'));
|
||||
|
||||
$basketItems = array();
|
||||
$firstBasketItem = new \Iyzipay\Model\BasketItem();
|
||||
$firstBasketItem->setId(rand(1000, 9999));
|
||||
$firstBasketItem->setName("Seller Package Payment");
|
||||
$firstBasketItem->setCategory1("SellerPackage");
|
||||
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
|
||||
$firstBasketItem->setPrice(round($amount));
|
||||
$basketItems[0] = $firstBasketItem;
|
||||
|
||||
$iyzicoRequest->setBasketItems($basketItems);
|
||||
} elseif ($payment_type == 'customer_package_payment') {
|
||||
$iyzicoRequest->setPrice(round($amount));
|
||||
$iyzicoRequest->setPaidPrice(round($amount));
|
||||
$iyzicoRequest->setCurrency(\Iyzipay\Model\Currency::TL);
|
||||
$iyzicoRequest->setBasketId(rand(000000, 999999));
|
||||
$iyzicoRequest->setPaymentGroup(\Iyzipay\Model\PaymentGroup::SUBSCRIPTION);
|
||||
$iyzicoRequest->setCallbackUrl(route('api.iyzico.callback'));
|
||||
|
||||
$basketItems = array();
|
||||
$firstBasketItem = new \Iyzipay\Model\BasketItem();
|
||||
$firstBasketItem->setId(rand(1000, 9999));
|
||||
$firstBasketItem->setName("Customer Package Payment");
|
||||
$firstBasketItem->setCategory1("CustomerPackage");
|
||||
$firstBasketItem->setItemType(\Iyzipay\Model\BasketItemType::VIRTUAL);
|
||||
$firstBasketItem->setPrice(round($amount));
|
||||
$basketItems[0] = $firstBasketItem;
|
||||
|
||||
$iyzicoRequest->setBasketItems($basketItems);
|
||||
}
|
||||
|
||||
$payWithIyzicoInitialize = \Iyzipay\Model\PayWithIyzicoInitialize::create($iyzicoRequest, $options);
|
||||
|
||||
# print result
|
||||
return Redirect::to($payWithIyzicoInitialize->getPayWithIyzicoPageUrl());
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$options = new \Iyzipay\Options();
|
||||
$options->setApiKey(env('IYZICO_API_KEY'));
|
||||
$options->setSecretKey(env('IYZICO_SECRET_KEY'));
|
||||
|
||||
if (BusinessSetting::where('type', 'iyzico_sandbox')->first()->value == 1) {
|
||||
$options->setBaseUrl("https://sandbox-api.iyzipay.com");
|
||||
} else {
|
||||
$options->setBaseUrl("https://api.iyzipay.com");
|
||||
}
|
||||
|
||||
$iyzicoRequest = new \Iyzipay\Request\RetrievePayWithIyzicoRequest();
|
||||
$iyzicoRequest->setLocale(\Iyzipay\Model\Locale::TR);
|
||||
$iyzicoRequest->setConversationId('123456789');
|
||||
$iyzicoRequest->setToken($request->token);
|
||||
# make request
|
||||
$payWithIyzico = \Iyzipay\Model\PayWithIyzico::retrieve($iyzicoRequest, $options);
|
||||
|
||||
$payment = $payWithIyzico->getRawResult();
|
||||
|
||||
if ($payWithIyzico->getStatus() == 'success') {
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful"), 'payment_details' => $payment]);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment unsuccessful"), 'payment_details' => $payment]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// the callback function is in the main controller of web | paystackcontroller
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Iyzico', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Iyzico', $request->payment_details);
|
||||
}
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
116
desarrollo2/app/Http/Controllers/Api/V2/KhaltiController.php
Normal file
116
desarrollo2/app/Http/Controllers/Api/V2/KhaltiController.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\CombinedOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Redirect;
|
||||
|
||||
class KhaltiController extends Controller
|
||||
{
|
||||
public function pay(Request $request)
|
||||
{
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($request->combined_order_id);
|
||||
$purchase_order_id = $combined_order->id;
|
||||
$amount = $combined_order->grand_total;
|
||||
} elseif ($request->payment_type == 'wallet_payment') {
|
||||
$amount = $request->amount;
|
||||
$purchase_order_id = $request->user_id;
|
||||
} elseif ($request->payment_type == 'seller_package_payment' || $request->payment_type == 'customer_package_payment') {
|
||||
$amount = $request->amount;
|
||||
$purchase_order_id = $request->package_id;
|
||||
}
|
||||
|
||||
$return_url = route('api.khalti.success'); //must be changed
|
||||
$args = http_build_query([
|
||||
'return_url' => $return_url,
|
||||
'website_url' => route('home'),
|
||||
'amount' => $amount * 100,
|
||||
"modes" => [
|
||||
"KHALTI",
|
||||
"EBANKING",
|
||||
"MOBILE_BANKING",
|
||||
"CONNECT_IPS",
|
||||
"SCT"
|
||||
],
|
||||
'purchase_order_id' => $purchase_order_id,
|
||||
'purchase_order_name' => $request->payment_type,
|
||||
]);
|
||||
if (get_setting('khalti_sandbox') == 1) {
|
||||
$url = 'https://a.khalti.com/api/v2/epayment/initiate/';
|
||||
} else {
|
||||
$url = 'https://khalti.com/api/v2/epayment/initiate/';
|
||||
}
|
||||
# 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);
|
||||
|
||||
$headers = ['Authorization: Key ' . env('KHALTI_SECRET_KEY')];
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// Response
|
||||
$response = json_decode(curl_exec($ch), true);
|
||||
curl_close($ch);
|
||||
|
||||
// return response()->json([
|
||||
// "result" => true,
|
||||
// "url" => $response['payment_url']
|
||||
// ]);
|
||||
return Redirect::to($response['payment_url']);
|
||||
}
|
||||
|
||||
public function paymentDone(Request $request)
|
||||
{
|
||||
$args = http_build_query([
|
||||
'pidx' => $request->pidx,
|
||||
]);
|
||||
if (get_setting('khalti_sandbox') == 1) {
|
||||
$url = 'https://a.khalti.com/api/v2/epayment/lookup/';
|
||||
} else {
|
||||
$url = 'https://khalti.com/api/v2/epayment/lookup/';
|
||||
}
|
||||
|
||||
# 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);
|
||||
|
||||
$headers = ['Authorization: Key ' . env('KHALTI_SECRET_KEY')];
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// Response
|
||||
$response = json_decode(curl_exec($ch));
|
||||
curl_close($ch);
|
||||
|
||||
if ($response->status == 'Completed') {
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
|
||||
checkout_done($request->combined_order_id, json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'wallet_payment') {
|
||||
|
||||
wallet_payment_done($request->user_id, $request->amount, 'khalti', json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'khalti', json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment is failed")]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Language;
|
||||
use App\Http\Resources\V2\LanguageCollection;
|
||||
use Cache;
|
||||
|
||||
class LanguageController extends Controller
|
||||
{
|
||||
public function getList(Request $request)
|
||||
{
|
||||
return new LanguageCollection(Language::where('status', 1)->get());
|
||||
}
|
||||
}
|
||||
211
desarrollo2/app/Http/Controllers/Api/V2/NagadController.php
Normal file
211
desarrollo2/app/Http/Controllers/Api/V2/NagadController.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Utility\NagadUtility;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NagadController
|
||||
{
|
||||
|
||||
private $amount = null;
|
||||
private $tnx = null;
|
||||
|
||||
private $nagadHost;
|
||||
private $tnx_status = false;
|
||||
|
||||
private $merchantAdditionalInfo = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
date_default_timezone_set('Asia/Dhaka');
|
||||
if (config('nagad.sandbox_mode') === 'sandbox') {
|
||||
$this->nagadHost = "http://sandbox.mynagad.com:10080/";
|
||||
} else {
|
||||
$this->nagadHost = "https://api.mynagad.com/";
|
||||
}
|
||||
}
|
||||
|
||||
public function begin(Request $request)
|
||||
{
|
||||
$this->amount = $request->amount;
|
||||
$this->tnx_status = false;
|
||||
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
$this->tnx = $request->combined_order_id;
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$this->amount = $combined_order->grand_total;
|
||||
} else if (
|
||||
$request->payment_type == 'wallet_payment' ||
|
||||
$request->payment_type == 'seller_package_payment' ||
|
||||
$request->payment_type == 'customer_package_payment'
|
||||
) {
|
||||
$this->tnx = rand(10000, 99999);
|
||||
}
|
||||
|
||||
return $this->getSession($request->payment_type);
|
||||
}
|
||||
|
||||
|
||||
public function getSession($payment_type)
|
||||
{
|
||||
|
||||
$DateTime = Date('YmdHis');
|
||||
$MerchantID = config('nagad.merchant_id');
|
||||
//$invoice_no = 'Inv'.Date('YmdH').rand(1000, 10000);
|
||||
$invoice_no = $this->tnx_status ? $this->tnx : 'Inv' . Date('YmdH') . rand(1000, 10000);
|
||||
$merchantCallbackURL = route('app.nagad.callback_url', ['payment_type' => $payment_type]);
|
||||
|
||||
$SensitiveData = [
|
||||
'merchantId' => $MerchantID,
|
||||
'datetime' => $DateTime,
|
||||
'orderId' => $invoice_no,
|
||||
'challenge' => NagadUtility::generateRandomString()
|
||||
];
|
||||
|
||||
$PostData = array(
|
||||
'accountNumber' => config('nagad.merchant_number'), //optional
|
||||
'dateTime' => $DateTime,
|
||||
'sensitiveData' => NagadUtility::EncryptDataWithPublicKey(json_encode($SensitiveData)),
|
||||
'signature' => NagadUtility::SignatureGenerate(json_encode($SensitiveData))
|
||||
);
|
||||
|
||||
$ur = $this->nagadHost . "api/dfs/check-out/initialize/" . $MerchantID . "/" . $invoice_no;
|
||||
$Result_Data = NagadUtility::HttpPostMethod($ur, $PostData);
|
||||
|
||||
if (isset($Result_Data['sensitiveData']) && isset($Result_Data['signature'])) {
|
||||
if ($Result_Data['sensitiveData'] != "" && $Result_Data['signature'] != "") {
|
||||
|
||||
$PlainResponse = json_decode(NagadUtility::DecryptDataWithPrivateKey($Result_Data['sensitiveData']), true);
|
||||
|
||||
if (isset($PlainResponse['paymentReferenceId']) && isset($PlainResponse['challenge'])) {
|
||||
|
||||
$paymentReferenceId = $PlainResponse['paymentReferenceId'];
|
||||
$randomserver = $PlainResponse['challenge'];
|
||||
|
||||
$SensitiveDataOrder = array(
|
||||
'merchantId' => $MerchantID,
|
||||
'orderId' => $invoice_no,
|
||||
'currencyCode' => '050',
|
||||
'amount' => $this->amount,
|
||||
'challenge' => $randomserver
|
||||
);
|
||||
|
||||
|
||||
// $merchantAdditionalInfo = '{"no_of_seat": "1", "Service_Charge":"20"}';
|
||||
if ($this->tnx !== '') {
|
||||
$this->merchantAdditionalInfo['tnx_id'] = $this->tnx;
|
||||
}
|
||||
// echo $merchantAdditionalInfo;
|
||||
// exit();
|
||||
|
||||
$PostDataOrder = array(
|
||||
'sensitiveData' => NagadUtility::EncryptDataWithPublicKey(json_encode($SensitiveDataOrder)),
|
||||
'signature' => NagadUtility::SignatureGenerate(json_encode($SensitiveDataOrder)),
|
||||
'merchantCallbackURL' => $merchantCallbackURL,
|
||||
'additionalMerchantInfo' => (object)$this->merchantAdditionalInfo
|
||||
);
|
||||
|
||||
// echo json_encode($PostDataOrder);
|
||||
// exit();
|
||||
|
||||
$OrderSubmitUrl = $this->nagadHost . "api/dfs/check-out/complete/" . $paymentReferenceId;
|
||||
$Result_Data_Order = NagadUtility::HttpPostMethod($OrderSubmitUrl, $PostDataOrder);
|
||||
//dd($Result_Data_Order);
|
||||
if ($Result_Data_Order['status'] == "Success") {
|
||||
return response()->json([
|
||||
'data' => $Result_Data_Order,
|
||||
'result' => true,
|
||||
'url' => $Result_Data_Order['callBackUrl'],
|
||||
'message' => translate('Redirect Url is found')
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => $Result_Data_Order,
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => translate('Could not generate payment link')
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => $PlainResponse,
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => translate('Payment reference id or challenge is missing')
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => null,
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => translate('Sensitive data or Signature is empty')
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'data' => null,
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => translate('Sensitive data or Signature is missing')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function verify(Request $request, $payment_type)
|
||||
{
|
||||
$Query_String = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1]);
|
||||
$payment_ref_id = substr($Query_String[2], 15);
|
||||
$url = $this->nagadHost . "api/dfs/verify/payment/" . $payment_ref_id;
|
||||
$json = NagadUtility::HttpGet($url);
|
||||
if (json_decode($json)->status == 'Success') {
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Payment Processing'),
|
||||
'payment_details' => $json
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Payment failed !'),
|
||||
'payment_details' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
public function process(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Nagad', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Nagad', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class OfflinePaymentController extends Controller
|
||||
{
|
||||
public function submit(Request $request)
|
||||
{
|
||||
$order = Order::find($request->order_id);
|
||||
|
||||
if($request->name != null && $request->amount != null && $request->trx_id != null){
|
||||
$data['name'] = $request->name;
|
||||
$data['amount'] = $request->amount;
|
||||
$data['trx_id'] = $request->trx_id;
|
||||
$data['photo'] = $request->photo;
|
||||
}
|
||||
else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Something went wrong')
|
||||
]);
|
||||
}
|
||||
|
||||
$order->manual_payment_data = json_encode($data);
|
||||
$order->payment_type = $request->payment_option;
|
||||
$order->payment_status = 'Submitted';
|
||||
$order->manual_payment = 1;
|
||||
|
||||
$order->save();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Submitted Successfully')
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\Api\V2\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OnlinePaymentController extends Controller
|
||||
{
|
||||
public function init(Request $request)
|
||||
{
|
||||
$directory = __NAMESPACE__ . '\\' . str_replace(' ', '', ucwords(str_replace('_payment', ' ', $request->payment_option))) . "Controller";
|
||||
|
||||
return (new $directory)->pay($request);
|
||||
}
|
||||
public function paymentSuccess(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Iyzico', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Iyzico', $request->payment_details);
|
||||
}
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
return redirect(url("api/v2/online-pay/done"));
|
||||
} catch (\Exception $e) {
|
||||
return redirect(url("api/v2/online-pay/done"))->with('errors',$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function paymentFailed()
|
||||
{
|
||||
return $this->failed(session('errors'));
|
||||
}
|
||||
|
||||
function paymentDone(){
|
||||
return $this->success("Payment Done");
|
||||
}
|
||||
}
|
||||
257
desarrollo2/app/Http/Controllers/Api/V2/OrderController.php
Normal file
257
desarrollo2/app/Http/Controllers/Api/V2/OrderController.php
Normal file
@@ -0,0 +1,257 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Address;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Order;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Product;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponUsage;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\User;
|
||||
use DB;
|
||||
use \App\Utility\NotificationUtility;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Http\Controllers\AffiliateController;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function store(Request $request, $set_paid = false)
|
||||
{
|
||||
|
||||
|
||||
if (get_setting('minimum_order_amount_check') == 1) {
|
||||
$subtotal = 0;
|
||||
foreach (Cart::where('user_id', auth()->user()->id)->get() as $key => $cartItem) {
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
$subtotal += cart_product_price($cartItem, $product, false, false) * $cartItem['quantity'];
|
||||
}
|
||||
if ($subtotal < get_setting('minimum_order_amount')) {
|
||||
return $this->failed("You order amount is less then the minimum order amount");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$cartItems = Cart::where('user_id', auth()->user()->id)->get();
|
||||
|
||||
if ($cartItems->isEmpty()) {
|
||||
return response()->json([
|
||||
'combined_order_id' => 0,
|
||||
'result' => false,
|
||||
'message' => translate('Cart is Empty')
|
||||
]);
|
||||
}
|
||||
|
||||
$user = User::find(auth()->user()->id);
|
||||
|
||||
|
||||
$address = Address::where('id', $cartItems->first()->address_id)->first();
|
||||
$shippingAddress = [];
|
||||
if ($address != null) {
|
||||
$shippingAddress['name'] = $user->name;
|
||||
$shippingAddress['email'] = $user->email;
|
||||
$shippingAddress['address'] = $address->address;
|
||||
$shippingAddress['country'] = $address->country->name;
|
||||
$shippingAddress['state'] = $address->state->name;
|
||||
$shippingAddress['city'] = $address->city->name;
|
||||
$shippingAddress['postal_code'] = $address->postal_code;
|
||||
$shippingAddress['phone'] = $address->phone;
|
||||
if ($address->latitude || $address->longitude) {
|
||||
$shippingAddress['lat_lang'] = $address->latitude . ',' . $address->longitude;
|
||||
}
|
||||
}
|
||||
|
||||
$combined_order = new CombinedOrder;
|
||||
$combined_order->user_id = $user->id;
|
||||
$combined_order->shipping_address = json_encode($shippingAddress);
|
||||
$combined_order->save();
|
||||
|
||||
$seller_products = array();
|
||||
foreach ($cartItems as $cartItem) {
|
||||
$product_ids = array();
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
if (isset($seller_products[$product->user_id])) {
|
||||
$product_ids = $seller_products[$product->user_id];
|
||||
}
|
||||
array_push($product_ids, $cartItem);
|
||||
$seller_products[$product->user_id] = $product_ids;
|
||||
}
|
||||
|
||||
foreach ($seller_products as $seller_product) {
|
||||
$order = new Order;
|
||||
$order->combined_order_id = $combined_order->id;
|
||||
$order->user_id = $user->id;
|
||||
$order->shipping_address = $combined_order->shipping_address;
|
||||
|
||||
// $order->shipping_type = $cartItems->first()->shipping_type;
|
||||
// if ($cartItems->first()->shipping_type == 'pickup_point') {
|
||||
// $order->pickup_point_id = $cartItems->first()->pickup_point;
|
||||
// }
|
||||
|
||||
$order->order_from = 'app';
|
||||
$order->payment_type = $request->payment_type;
|
||||
$order->delivery_viewed = '0';
|
||||
$order->payment_status_viewed = '0';
|
||||
$order->code = date('Ymd-His') . rand(10, 99);
|
||||
$order->date = strtotime('now');
|
||||
if ($set_paid) {
|
||||
$order->payment_status = 'paid';
|
||||
} else {
|
||||
$order->payment_status = 'unpaid';
|
||||
}
|
||||
|
||||
$order->save();
|
||||
|
||||
$subtotal = 0;
|
||||
$tax = 0;
|
||||
$shipping = 0;
|
||||
$coupon_discount = 0;
|
||||
|
||||
//Order Details Storing
|
||||
foreach ($seller_product as $cartItem) {
|
||||
$product = Product::find($cartItem['product_id']);
|
||||
|
||||
$subtotal += cart_product_price($cartItem, $product, false, false) * $cartItem['quantity'];
|
||||
$tax += cart_product_tax($cartItem, $product, false) * $cartItem['quantity'];
|
||||
$coupon_discount += $cartItem['discount'];
|
||||
|
||||
$product_variation = $cartItem['variation'];
|
||||
|
||||
$product_stock = $product->stocks->where('variant', $product_variation)->first();
|
||||
if ($product->digital != 1 && $cartItem['quantity'] > $product_stock->qty) {
|
||||
$order->delete();
|
||||
$combined_order->delete();
|
||||
return response()->json([
|
||||
'combined_order_id' => 0,
|
||||
'result' => false,
|
||||
'message' => translate('The requested quantity is not available for ') . $product->name
|
||||
]);
|
||||
} elseif ($product->digital != 1) {
|
||||
$product_stock->qty -= $cartItem['quantity'];
|
||||
$product_stock->save();
|
||||
}
|
||||
|
||||
$order_detail = new OrderDetail;
|
||||
$order_detail->order_id = $order->id;
|
||||
$order_detail->seller_id = $product->user_id;
|
||||
$order_detail->product_id = $product->id;
|
||||
$order_detail->variation = $product_variation;
|
||||
$order_detail->price = cart_product_price($cartItem, $product, false, false) * $cartItem['quantity'];
|
||||
$order_detail->tax = cart_product_tax($cartItem, $product, false) * $cartItem['quantity'];
|
||||
$order_detail->shipping_type = $cartItem['shipping_type'];
|
||||
$order_detail->product_referral_code = $cartItem['product_referral_code'];
|
||||
$order_detail->shipping_cost = $cartItem['shipping_cost'];
|
||||
|
||||
$shipping += $order_detail->shipping_cost;
|
||||
|
||||
// if ($cartItem['shipping_type'] == 'pickup_point') {
|
||||
// $order_detail->pickup_point_id = $cartItem['pickup_point'];
|
||||
// }
|
||||
//End of storing shipping cost
|
||||
if (addon_is_activated('club_point')) {
|
||||
$order_detail->earn_point = $product->earn_point;
|
||||
}
|
||||
|
||||
$order_detail->quantity = $cartItem['quantity'];
|
||||
$order_detail->save();
|
||||
|
||||
$product->num_of_sale = $product->num_of_sale + $cartItem['quantity'];
|
||||
$product->save();
|
||||
|
||||
$order->seller_id = $product->user_id;
|
||||
//======== Added By Kiron ==========
|
||||
$order->shipping_type = $cartItem['shipping_type'];
|
||||
if ($cartItem['shipping_type'] == 'pickup_point') {
|
||||
$order->pickup_point_id = $cartItem['pickup_point'];
|
||||
}
|
||||
if ($cartItem['shipping_type'] == 'carrier') {
|
||||
$order->carrier_id = $cartItem['carrier_id'];
|
||||
}
|
||||
|
||||
if ($product->added_by == 'seller' && $product->user->seller != null) {
|
||||
$seller = $product->user->seller;
|
||||
$seller->num_of_sale += $cartItem['quantity'];
|
||||
$seller->save();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (addon_is_activated('affiliate_system')) {
|
||||
if ($order_detail->product_referral_code) {
|
||||
$referred_by_user = User::where('referral_code', $order_detail->product_referral_code)->first();
|
||||
|
||||
$affiliateController = new AffiliateController;
|
||||
$affiliateController->processAffiliateStats($referred_by_user->id, 0, $order_detail->quantity, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$order->grand_total = $subtotal + $tax + $shipping;
|
||||
|
||||
if ($seller_product[0]->coupon_code != null) {
|
||||
// if (Session::has('club_point')) {
|
||||
// $order->club_point = Session::get('club_point');
|
||||
// }
|
||||
$order->coupon_discount = $coupon_discount;
|
||||
$order->grand_total -= $coupon_discount;
|
||||
|
||||
$coupon_usage = new CouponUsage;
|
||||
$coupon_usage->user_id = $user->id;
|
||||
$coupon_usage->coupon_id = Coupon::where('code', $seller_product[0]->coupon_code)->first()->id;
|
||||
$coupon_usage->save();
|
||||
}
|
||||
|
||||
$combined_order->grand_total += $order->grand_total;
|
||||
|
||||
if (strpos($request->payment_type, "manual_payment_") !== false) { // if payment type like manual_payment_1 or manual_payment_25 etc)
|
||||
|
||||
$order->manual_payment = 1;
|
||||
$order->save();
|
||||
}
|
||||
|
||||
$order->save();
|
||||
}
|
||||
$combined_order->save();
|
||||
|
||||
|
||||
|
||||
Cart::where('user_id', auth()->user()->id)->delete();
|
||||
|
||||
if (
|
||||
$request->payment_type == 'cash_on_delivery'
|
||||
|| $request->payment_type == 'wallet'
|
||||
|| strpos($request->payment_type, "manual_payment_") !== false // if payment type like manual_payment_1 or manual_payment_25 etc
|
||||
) {
|
||||
NotificationUtility::sendOrderPlacedNotification($order);
|
||||
}
|
||||
|
||||
|
||||
return response()->json([
|
||||
'combined_order_id' => $combined_order->id,
|
||||
'result' => true,
|
||||
'message' => translate('Your order has been placed successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
public function order_cancel($id)
|
||||
{
|
||||
$order = Order::where('id', $id)->where('user_id', auth()->user()->id)->first();
|
||||
if ($order && ($order->delivery_status == 'pending' && $order->payment_status == 'unpaid')) {
|
||||
$order->delivery_status = 'cancelled';
|
||||
$order->save();
|
||||
|
||||
foreach ($order->orderDetails as $key => $orderDetail) {
|
||||
$orderDetail->delivery_status = 'cancelled';
|
||||
$orderDetail->save();
|
||||
product_restock($orderDetail);
|
||||
}
|
||||
|
||||
return $this->success(translate('Order has been canceled successfully'));
|
||||
} else {
|
||||
return $this->failed(translate('Something went wrong'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Notifications\AppEmailVerificationNotification;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\PasswordReset;
|
||||
use App\Notifications\PasswordResetRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Http\Controllers\OTPVerificationController;
|
||||
|
||||
use Hash;
|
||||
|
||||
class PasswordResetController extends Controller
|
||||
{
|
||||
public function forgetRequest(Request $request)
|
||||
{
|
||||
if ($request->send_code_by == 'email') {
|
||||
$user = User::where('email', $request->email_or_phone)->first();
|
||||
} else {
|
||||
$user = User::where('phone', $request->email_or_phone)->first();
|
||||
}
|
||||
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('User is not found')
|
||||
], 404);
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$user->verification_code = rand(100000, 999999);
|
||||
$user->save();
|
||||
if ($request->send_code_by == 'phone') {
|
||||
|
||||
$otpController = new OTPVerificationController();
|
||||
$otpController->send_code($user);
|
||||
} else {
|
||||
try {
|
||||
|
||||
$user->notify(new AppEmailVerificationNotification());
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('A code is sent')
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function confirmReset(Request $request)
|
||||
{
|
||||
$user = User::where('verification_code', $request->verification_code)->first();
|
||||
|
||||
if ($user != null) {
|
||||
$user->verification_code = null;
|
||||
$user->password = Hash::make($request->password);
|
||||
$user->save();
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Your password is reset.Please login'),
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('No user is found'),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function resendCode(Request $request)
|
||||
{
|
||||
|
||||
if ($request->verify_by == 'email') {
|
||||
$user = User::where('email', $request->email_or_phone)->first();
|
||||
} else {
|
||||
$user = User::where('phone', $request->email_or_phone)->first();
|
||||
}
|
||||
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('User is not found')
|
||||
], 404);
|
||||
}
|
||||
|
||||
$user->verification_code = rand(100000, 999999);
|
||||
$user->save();
|
||||
|
||||
if ($request->verify_by == 'email') {
|
||||
$user->notify(new AppEmailVerificationNotification());
|
||||
} else {
|
||||
$otpController = new OTPVerificationController();
|
||||
$otpController->send_code($user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('A code is sent again'),
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function cashOnDelivery(Request $request)
|
||||
{
|
||||
$order = new OrderController;
|
||||
return $order->store($request);
|
||||
}
|
||||
|
||||
public function manualPayment(Request $request)
|
||||
{
|
||||
$order = new OrderController;
|
||||
return $order->store($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ManualPaymentMethod;
|
||||
|
||||
class PaymentTypesController
|
||||
{
|
||||
|
||||
public function getList(Request $request)
|
||||
{
|
||||
$mode = "order";
|
||||
|
||||
if ($request->has('mode')) {
|
||||
$mode = $request->mode; // wallet or other things , comes from query param ?mode=wallet
|
||||
}
|
||||
|
||||
$list = "both";
|
||||
if ($request->has('list')) {
|
||||
$list = $request->list; // ?list=offline
|
||||
}
|
||||
|
||||
$payment_types = array();
|
||||
|
||||
if ($list == "online" || $list == "both") {
|
||||
if (get_setting('paypal_payment') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'paypal_payment';
|
||||
$payment_type['payment_type_key'] = 'paypal';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/paypal.png');
|
||||
$payment_type['name'] = "Paypal";
|
||||
$payment_type['title'] = "Checkout with Paypal";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Paypal";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('stripe_payment') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'stripe_payment';
|
||||
$payment_type['payment_type_key'] = 'stripe';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/stripe.png');
|
||||
$payment_type['name'] = "Stripe";
|
||||
$payment_type['title'] = "Checkout with Stripe";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Stripe";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
if (get_setting('instamojo_payment') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'instamojo_payment';
|
||||
$payment_type['payment_type_key'] = 'instamojo_payment';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/instamojo.png');
|
||||
$payment_type['name'] = "Instamojo";
|
||||
$payment_type['title'] = "Checkout with Instamojo";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Stripe";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('razorpay') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'razorpay';
|
||||
$payment_type['payment_type_key'] = 'razorpay';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/rozarpay.png');
|
||||
$payment_type['name'] = "Razorpay";
|
||||
$payment_type['title'] = "Checkout with Razorpay";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Razorpay";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('paystack') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'paystack';
|
||||
$payment_type['payment_type_key'] = 'paystack';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/paystack.png');
|
||||
$payment_type['name'] = "Paystack";
|
||||
$payment_type['title'] = "Checkout with Paystack";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Paystack";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('iyzico') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'iyzico';
|
||||
$payment_type['payment_type_key'] = 'iyzico';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/iyzico.png');
|
||||
$payment_type['name'] = "Iyzico";
|
||||
$payment_type['title'] = "Checkout with Iyzico";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Iyzico";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('bkash') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'bkash';
|
||||
$payment_type['payment_type_key'] = 'bkash';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/bkash.png');
|
||||
$payment_type['name'] = "Bkash";
|
||||
$payment_type['title'] = "Checkout with Bkash";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Bkash";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('nagad') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'nagad';
|
||||
$payment_type['payment_type_key'] = 'nagad';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/nagad.png');
|
||||
$payment_type['name'] = "Nagad";
|
||||
$payment_type['title'] = "Checkout with Nagad";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Nagad";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (get_setting('sslcommerz_payment') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'sslcommerz_payment';
|
||||
$payment_type['payment_type_key'] = 'sslcommerz';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/sslcommerz.png');
|
||||
$payment_type['name'] = "Sslcommerz";
|
||||
$payment_type['title'] = "Checkout with Sslcommerz";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Sslcommerz";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
|
||||
//African Payment Gateways
|
||||
if (addon_is_activated('african_pg') && get_setting('flutterwave') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'flutterwave';
|
||||
$payment_type['payment_type_key'] = 'flutterwave';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/flutterwave.png');
|
||||
$payment_type['name'] = "Flutterwave";
|
||||
$payment_type['title'] = "Checkout with Flutterwave";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Flutterwave";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
if (addon_is_activated('paytm')) {
|
||||
|
||||
if (get_setting('paytm') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'paytm';
|
||||
$payment_type['payment_type_key'] = 'paytm';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/paytm.jpg');
|
||||
$payment_type['name'] = "Paytm";
|
||||
$payment_type['title'] = "Checkout with Paytm";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Paytm";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
if (get_setting('khalti_payment') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'khalti';
|
||||
$payment_type['payment_type_key'] = 'khalti';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/khalti.png');
|
||||
$payment_type['name'] = "Khalti";
|
||||
$payment_type['title'] = "Checkout with Khalti";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
if ($mode == 'wallet') {
|
||||
$payment_type['title'] = "Recharge with Khalti";
|
||||
}
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// you cannot recharge wallet by wallet or cash payment
|
||||
if ($mode != 'wallet' && $mode != 'seller_package' && $list != "offline") {
|
||||
if (get_setting('wallet_system') == 1) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'wallet_system';
|
||||
$payment_type['payment_type_key'] = 'wallet';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/wallet.png');
|
||||
$payment_type['name'] = "Wallet";
|
||||
$payment_type['title'] = "Wallet Payment";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
|
||||
$haveDigitalProduct = false;
|
||||
$cash_on_delivery = false;
|
||||
|
||||
if ($mode == "order") {
|
||||
$carts = auth()->user()->carts;
|
||||
|
||||
foreach ($carts as $key => $cart) {
|
||||
$haveDigitalProduct = $cart->product->digital == 1;
|
||||
$cash_on_delivery = $cart->product->cash_on_delivery == 0;
|
||||
if ($haveDigitalProduct || $cash_on_delivery) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (get_setting('cash_payment') == 1 && !$haveDigitalProduct && !$cash_on_delivery) {
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'cash_payment';
|
||||
$payment_type['payment_type_key'] = 'cash_on_delivery';
|
||||
$payment_type['image'] = static_asset('assets/img/cards/cod.png');
|
||||
$payment_type['name'] = "Cash Payment";
|
||||
$payment_type['title'] = "Cash on delivery";
|
||||
$payment_type['offline_payment_id'] = 0;
|
||||
$payment_type['details'] = "";
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
}
|
||||
|
||||
if (($list == 'offline' || $list == "both") && addon_is_activated('offline_payment')) {
|
||||
foreach (ManualPaymentMethod::all() as $method) {
|
||||
|
||||
$bank_list = "";
|
||||
$bank_list_item = "";
|
||||
|
||||
if ($method->bank_info != null) {
|
||||
foreach (json_decode($method->bank_info) as $key => $info) {
|
||||
$bank_list_item .= "<li>" . 'Bank Name' . " - {$info->bank_name} ," . 'Account Name' . " - $info->account_name , " . 'Account Number' . " - {$info->account_number} , " . 'Routing Number' . " - {$info->routing_number}</li>";
|
||||
}
|
||||
$bank_list = "<ul> $bank_list_item <ul>";
|
||||
}
|
||||
|
||||
$payment_type = array();
|
||||
$payment_type['payment_type'] = 'manual_payment';
|
||||
$payment_type['payment_type_key'] = 'manual_payment_' . $method->id;
|
||||
$payment_type['image'] = uploaded_asset($method->photo);
|
||||
$payment_type['name'] = $method->heading;
|
||||
$payment_type['title'] = $method->heading;
|
||||
$payment_type['offline_payment_id'] = $method->id;
|
||||
$payment_type['details'] = "<div> {$method->description} $bank_list </div>";
|
||||
|
||||
$payment_types[] = $payment_type;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($payment_types);
|
||||
}
|
||||
}
|
||||
139
desarrollo2/app/Http/Controllers/Api/V2/PaypalController.php
Normal file
139
desarrollo2/app/Http/Controllers/Api/V2/PaypalController.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\CustomerPackage;
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Models\CombinedOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use PayPalCheckoutSdk\Core\PayPalHttpClient;
|
||||
use PayPalCheckoutSdk\Core\ProductionEnvironment;
|
||||
use PayPalCheckoutSdk\Core\SandboxEnvironment;
|
||||
use PayPalCheckoutSdk\Orders\OrdersCaptureRequest;
|
||||
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
|
||||
|
||||
class PaypalController extends Controller
|
||||
{
|
||||
|
||||
public function getUrl(Request $request)
|
||||
{
|
||||
// Creating an environment
|
||||
|
||||
$clientId = env('PAYPAL_CLIENT_ID');
|
||||
$clientSecret = env('PAYPAL_CLIENT_SECRET');
|
||||
|
||||
if (get_setting('paypal_sandbox') == 1) {
|
||||
$environment = new SandboxEnvironment($clientId, $clientSecret);
|
||||
} else {
|
||||
$environment = new ProductionEnvironment($clientId, $clientSecret);
|
||||
}
|
||||
$client = new PayPalHttpClient($environment);
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($request->combined_order_id);
|
||||
$amount = $combined_order->grand_total;
|
||||
} elseif ($request->payment_type == 'wallet_payment') {
|
||||
$amount = $request->amount;
|
||||
}
|
||||
elseif ($request->payment_type == 'seller_package_payment') {
|
||||
$amount = $request->amount;
|
||||
}
|
||||
elseif ($request->payment_type == 'customer_package_payment') {
|
||||
$amount = $request->amount;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['payment_type'] = $request->payment_type;
|
||||
$data['combined_order_id'] = $request->combined_order_id;
|
||||
$data['amount'] = $request->amount;
|
||||
$data['user_id'] = $request->user_id;
|
||||
$data['package_id'] = 0;
|
||||
if(isset($request->package_id)) {
|
||||
$data['package_id'] = $request->package_id;
|
||||
}
|
||||
|
||||
$order_create_request = new OrdersCreateRequest();
|
||||
$order_create_request->prefer('return=representation');
|
||||
$order_create_request->body = [
|
||||
"intent" => "CAPTURE",
|
||||
"purchase_units" => [[
|
||||
"reference_id" => rand(000000, 999999),
|
||||
"amount" => [
|
||||
"value" => number_format($amount, 2, '.', ''),
|
||||
"currency_code" => \App\Models\Currency::find(get_setting('system_default_currency'))->code
|
||||
]
|
||||
]],
|
||||
"application_context" => [
|
||||
"cancel_url" => route('api.paypal.cancel'),
|
||||
"return_url" => route('api.paypal.done', $data),
|
||||
]
|
||||
];
|
||||
|
||||
try {
|
||||
// Call API with your client and get a response for your call
|
||||
$response = $client->execute($order_create_request);
|
||||
// If call returns body in response, you can get the deserialized version from the result attribute of the response
|
||||
//return Redirect::to($response->result->links[1]->href);
|
||||
return response()->json(['result' => true, 'url' => $response->result->links[1]->href, 'message' => "Found redirect url"]);
|
||||
} catch (\Exception $ex) {
|
||||
return response()->json(['result' => false, 'url' => '', 'message' => "Could not find redirect url"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getCancel(Request $request)
|
||||
{
|
||||
return response()->json(['result' => true, 'message' => translate("Payment failed or got cancelled")]);
|
||||
}
|
||||
|
||||
public function getDone(Request $request)
|
||||
{
|
||||
//dd($request->all());
|
||||
// Creating an environment
|
||||
$clientId = env('PAYPAL_CLIENT_ID');
|
||||
$clientSecret = env('PAYPAL_CLIENT_SECRET');
|
||||
|
||||
if (get_setting('paypal_sandbox') == 1) {
|
||||
$environment = new SandboxEnvironment($clientId, $clientSecret);
|
||||
} else {
|
||||
$environment = new ProductionEnvironment($clientId, $clientSecret);
|
||||
}
|
||||
$client = new PayPalHttpClient($environment);
|
||||
|
||||
// $response->result->id gives the orderId of the order created above
|
||||
|
||||
$ordersCaptureRequest = new OrdersCaptureRequest($request->token);
|
||||
$ordersCaptureRequest->prefer('return=representation');
|
||||
try {
|
||||
// Call API with your client and get a response for your call
|
||||
$response = $client->execute($ordersCaptureRequest);
|
||||
|
||||
// If call returns body in response, you can get the deserialized version from the result attribute of the response
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
|
||||
checkout_done($request->combined_order_id, json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'wallet_payment') {
|
||||
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Paypal', json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Paypal', json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $ex) {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment failed")]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Paystack;
|
||||
|
||||
class PaystackController extends Controller
|
||||
{
|
||||
|
||||
public function init(Request $request)
|
||||
{
|
||||
$amount = $request->amount;
|
||||
if ($request->combined_order_id) {
|
||||
$combined_order = CombinedOrder::find($request->combined_order_id);
|
||||
$amount = $combined_order->grand_total;
|
||||
}
|
||||
$user_id = $request->user_id;
|
||||
|
||||
$user = User::find($user_id);
|
||||
$request->email = $user->email;
|
||||
$request->amount = round($amount * 100);
|
||||
$request->currency = env('PAYSTACK_CURRENCY_CODE', 'NGN');
|
||||
$request->reference = Paystack::genTranxRef();
|
||||
return Paystack::getAuthorizationUrl()->redirectNow();
|
||||
}
|
||||
|
||||
|
||||
// the callback function is in the main controller of web | paystackcontroller
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Paystack', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Paystack', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
113
desarrollo2/app/Http/Controllers/Api/V2/PaytmController.php
Normal file
113
desarrollo2/app/Http/Controllers/Api/V2/PaytmController.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\CombinedOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use PaytmWallet;
|
||||
|
||||
class PaytmController extends Controller
|
||||
{
|
||||
|
||||
public function pay(Request $request)
|
||||
{
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
$package_id = 0;
|
||||
|
||||
if(isset($request->package_id)){
|
||||
$package_id = $request->package_id;
|
||||
}
|
||||
|
||||
|
||||
$user = User::find($request->user_id);
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$amount = floatval($combined_order->grand_total) ;
|
||||
|
||||
$payment = PaytmWallet::with('receive');
|
||||
$payment->prepare([
|
||||
'order' => rand(10000, 99999),
|
||||
'user' => $user->id,
|
||||
'mobile_number' => $user->phone,
|
||||
'email' => $user->email,
|
||||
'amount' => $amount,
|
||||
'callback_url' => route('api.paytm.callback',
|
||||
[
|
||||
"payment_type" => $payment_type,
|
||||
"combined_order_id" => $combined_order_id,
|
||||
"amount" => $amount,
|
||||
"user_id" => $user_id
|
||||
])
|
||||
|
||||
]);
|
||||
|
||||
return $payment->receive();
|
||||
} elseif ($payment_type == 'wallet_payment') {
|
||||
$amount = $amount;
|
||||
$payment = PaytmWallet::with('receive');
|
||||
$payment->prepare([
|
||||
'order' => rand(10000, 99999),
|
||||
'user' => $user->id,
|
||||
'mobile_number' => $user->phone,
|
||||
'email' => $user->email,
|
||||
'amount' => $amount,
|
||||
'callback_url' => route('api.paytm.callback',
|
||||
[
|
||||
"payment_type" => $payment_type,
|
||||
"combined_order_id" => $combined_order_id,
|
||||
"amount" => $amount,
|
||||
"user_id" => $user_id
|
||||
])
|
||||
]);
|
||||
return $payment->receive();
|
||||
} elseif ($payment_type == 'seller_package_payment') {
|
||||
$amount = $amount;
|
||||
$payment = PaytmWallet::with('receive');
|
||||
$payment->prepare([
|
||||
'order' => rand(10000, 99999),
|
||||
'user' => $user->id,
|
||||
'mobile_number' => $user->phone,
|
||||
'email' => $user->email,
|
||||
'amount' => $amount,
|
||||
'callback_url' => route('api.paytm.callback',
|
||||
[
|
||||
"payment_type" => $payment_type,
|
||||
"combined_order_id" => $combined_order_id,
|
||||
"amount" => $amount,
|
||||
"user_id" => $user_id,
|
||||
"package_id" => $package_id,
|
||||
])
|
||||
]);
|
||||
return $payment->receive();
|
||||
}
|
||||
}
|
||||
|
||||
public function callback(Request $request)
|
||||
{
|
||||
$transaction = PaytmWallet::with('receive');
|
||||
|
||||
$response = $transaction->response(); // To get raw response as array
|
||||
//Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=interpreting-response-sent-by-paytm
|
||||
|
||||
if ($transaction->isSuccessful()) {
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
checkout_done($request->combined_order_id, json_encode($response));
|
||||
}
|
||||
|
||||
if ($request->payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Flutterwave', json_encode($response));
|
||||
}
|
||||
if ($request->payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Flutterwave', json_encode($response));
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
desarrollo2/app/Http/Controllers/Api/V2/PolicyController.php
Normal file
25
desarrollo2/app/Http/Controllers/Api/V2/PolicyController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\PolicyCollection;
|
||||
use App\Models\Page;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PolicyController extends Controller
|
||||
{
|
||||
public function sellerPolicy()
|
||||
{
|
||||
return new PolicyCollection(Page::where('type', 'seller_policy_page')->get());
|
||||
}
|
||||
|
||||
public function supportPolicy()
|
||||
{
|
||||
return new PolicyCollection(Page::where('type', 'support_policy_page')->get());
|
||||
}
|
||||
|
||||
public function returnPolicy()
|
||||
{
|
||||
return new PolicyCollection(Page::where('type', 'return_policy_page')->get());
|
||||
}
|
||||
}
|
||||
415
desarrollo2/app/Http/Controllers/Api/V2/ProductController.php
Normal file
415
desarrollo2/app/Http/Controllers/Api/V2/ProductController.php
Normal file
@@ -0,0 +1,415 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\ClassifiedProductDetailCollection;
|
||||
use App\Http\Resources\V2\ClassifiedProductMiniCollection;
|
||||
use Cache;
|
||||
use App\Models\Shop;
|
||||
use App\Models\Color;
|
||||
use App\Models\Product;
|
||||
use App\Models\FlashDeal;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utility\SearchUtility;
|
||||
use App\Utility\CategoryUtility;
|
||||
use App\Http\Resources\V2\ProductCollection;
|
||||
use App\Http\Resources\V2\FlashDealCollection;
|
||||
use App\Http\Resources\V2\ProductMiniCollection;
|
||||
use App\Http\Resources\V2\ProductDetailCollection;
|
||||
use App\Http\Resources\V2\DigitalProductDetailCollection;
|
||||
use App\Models\CustomerProduct;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return new ProductMiniCollection(Product::latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return new ProductDetailCollection(Product::where('id', $id)->get());
|
||||
// if (Product::findOrFail($id)->digital==0) {
|
||||
// return new ProductDetailCollection(Product::where('id', $id)->get());
|
||||
// }elseif (Product::findOrFail($id)->digital==1) {
|
||||
// return new DigitalProductDetailCollection(Product::where('id', $id)->get());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public function admin()
|
||||
// {
|
||||
// return new ProductCollection(Product::where('added_by', 'admin')->latest()->paginate(10));
|
||||
// }
|
||||
|
||||
public function getPrice(Request $request)
|
||||
{
|
||||
$product = Product::findOrFail($request->id);
|
||||
$str = '';
|
||||
$tax = 0;
|
||||
$quantity = 1;
|
||||
|
||||
|
||||
|
||||
if ($request->has('quantity') && $request->quantity != null) {
|
||||
$quantity = $request->quantity;
|
||||
}
|
||||
|
||||
if ($request->has('color') && $request->color != null) {
|
||||
$str = Color::where('code', '#' . $request->color)->first()->name;
|
||||
}
|
||||
|
||||
$var_str = str_replace(',', '-', $request->variants);
|
||||
$var_str = str_replace(' ', '', $var_str);
|
||||
|
||||
if ($var_str != "") {
|
||||
$temp_str = $str == "" ? $var_str : '-' . $var_str;
|
||||
$str .= $temp_str;
|
||||
}
|
||||
|
||||
$product_stock = $product->stocks->where('variant', $str)->first();
|
||||
$price = $product_stock->price;
|
||||
|
||||
|
||||
if ($product->wholesale_product) {
|
||||
$wholesalePrice = $product_stock->wholesalePrices->where('min_qty', '<=', $quantity)->where('max_qty', '>=', $quantity)->first();
|
||||
if ($wholesalePrice) {
|
||||
$price = $wholesalePrice->price;
|
||||
}
|
||||
}
|
||||
|
||||
$stock_qty = $product_stock->qty;
|
||||
$stock_txt = $product_stock->qty;
|
||||
$max_limit = $product_stock->qty;
|
||||
|
||||
if ($stock_qty >= 1 && $product->min_qty <= $stock_qty) {
|
||||
$in_stock = 1;
|
||||
} else {
|
||||
$in_stock = 0;
|
||||
}
|
||||
|
||||
//Product Stock Visibility
|
||||
if ($product->stock_visibility_state == 'text') {
|
||||
if ($stock_qty >= 1 && $product->min_qty < $stock_qty) {
|
||||
$stock_txt = translate('In Stock');
|
||||
} else {
|
||||
$stock_txt = translate('Out Of Stock');
|
||||
}
|
||||
}
|
||||
|
||||
//discount calculation
|
||||
$discount_applicable = false;
|
||||
|
||||
if ($product->discount_start_date == null) {
|
||||
$discount_applicable = true;
|
||||
} elseif (
|
||||
strtotime(date('d-m-Y H:i:s')) >= $product->discount_start_date &&
|
||||
strtotime(date('d-m-Y H:i:s')) <= $product->discount_end_date
|
||||
) {
|
||||
$discount_applicable = true;
|
||||
}
|
||||
|
||||
if ($discount_applicable) {
|
||||
if ($product->discount_type == 'percent') {
|
||||
$price -= ($price * $product->discount) / 100;
|
||||
} elseif ($product->discount_type == 'amount') {
|
||||
$price -= $product->discount;
|
||||
}
|
||||
}
|
||||
|
||||
// taxes
|
||||
foreach ($product->taxes as $product_tax) {
|
||||
if ($product_tax->tax_type == 'percent') {
|
||||
$tax += ($price * $product_tax->tax) / 100;
|
||||
} elseif ($product_tax->tax_type == 'amount') {
|
||||
$tax += $product_tax->tax;
|
||||
}
|
||||
}
|
||||
|
||||
$price += $tax;
|
||||
|
||||
return response()->json(
|
||||
|
||||
[
|
||||
'result' => true,
|
||||
'data' => [
|
||||
'price' => single_price($price * $quantity),
|
||||
'stock' => $stock_qty,
|
||||
'stock_txt' => $stock_txt,
|
||||
'digital' => $product->digital,
|
||||
'variant' => $str,
|
||||
'variation' => $str,
|
||||
'max_limit' => $max_limit,
|
||||
'in_stock' => $in_stock,
|
||||
'image' => $product_stock->image == null ? "" : uploaded_asset($product_stock->image)
|
||||
]
|
||||
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function seller($id, Request $request)
|
||||
{
|
||||
$shop = Shop::findOrFail($id);
|
||||
$products = Product::where('added_by', 'seller')->where('user_id', $shop->user_id);
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$products = $products->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
$products->where('published', 1);
|
||||
return new ProductMiniCollection($products->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function category($id, Request $request)
|
||||
{
|
||||
$category_ids = CategoryUtility::children_ids($id);
|
||||
$category_ids[] = $id;
|
||||
|
||||
$products = Product::whereIn('category_id', $category_ids)->physical();
|
||||
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$products = $products->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
$products->where('published', 1);
|
||||
return new ProductMiniCollection(filter_products($products)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
|
||||
public function brand($id, Request $request)
|
||||
{
|
||||
$products = Product::where('brand_id', $id)->physical();
|
||||
if ($request->name != "" || $request->name != null) {
|
||||
$products = $products->where('name', 'like', '%' . $request->name . '%');
|
||||
}
|
||||
return new ProductMiniCollection(filter_products($products)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function todaysDeal()
|
||||
{
|
||||
// return Cache::remember('app.todays_deal', 86400, function () {
|
||||
$products = Product::where('todays_deal', 1)->physical();
|
||||
return new ProductMiniCollection(filter_products($products)->limit(20)->latest()->get());
|
||||
// });
|
||||
}
|
||||
|
||||
public function flashDeal()
|
||||
{
|
||||
return Cache::remember('app.flash_deals', 86400, function () {
|
||||
$flash_deals = FlashDeal::where('status', 1)->where('featured', 1)->where('start_date', '<=', strtotime(date('d-m-Y')))->where('end_date', '>=', strtotime(date('d-m-Y')))->get();
|
||||
return new FlashDealCollection($flash_deals);
|
||||
});
|
||||
}
|
||||
|
||||
public function featured()
|
||||
{
|
||||
|
||||
|
||||
$products = Product::where('featured', 1)->physical();
|
||||
return new ProductMiniCollection(filter_products($products)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function digital()
|
||||
{
|
||||
$products = Product::digital();
|
||||
return new ProductMiniCollection(filter_products($products)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function bestSeller()
|
||||
{
|
||||
// return Cache::remember('app.best_selling_products', 86400, function () {
|
||||
$products = Product::orderBy('num_of_sale', 'desc')->physical();
|
||||
return new ProductMiniCollection(filter_products($products)->limit(20)->get());
|
||||
// });
|
||||
}
|
||||
|
||||
public function related($id)
|
||||
{
|
||||
// return Cache::remember("app.related_products-$id", 86400, function () use ($id) {
|
||||
$product = Product::find($id);
|
||||
$products = Product::where('category_id', $product->category_id)->where('id', '!=', $id)->physical();
|
||||
return new ProductMiniCollection(filter_products($products)->limit(10)->get());
|
||||
|
||||
// });
|
||||
}
|
||||
|
||||
public function topFromSeller($id)
|
||||
{
|
||||
// return Cache::remember("app.top_from_this_seller_products-$id", 86400, function () use ($id) {
|
||||
$product = Product::find($id);
|
||||
$products = Product::where('user_id', $product->user_id)->orderBy('num_of_sale', 'desc')->physical();
|
||||
return new ProductMiniCollection(filter_products($products)->limit(10)->get());
|
||||
// });
|
||||
}
|
||||
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$category_ids = [];
|
||||
$brand_ids = [];
|
||||
|
||||
if ($request->categories != null && $request->categories != "") {
|
||||
$category_ids = explode(',', $request->categories);
|
||||
}
|
||||
|
||||
if ($request->brands != null && $request->brands != "") {
|
||||
$brand_ids = explode(',', $request->brands);
|
||||
}
|
||||
|
||||
$sort_by = $request->sort_key;
|
||||
$name = $request->name;
|
||||
$min = $request->min;
|
||||
$max = $request->max;
|
||||
|
||||
|
||||
$products = Product::query();
|
||||
|
||||
$products->where('published', 1)->physical();
|
||||
|
||||
if (!empty($brand_ids)) {
|
||||
$products->whereIn('brand_id', $brand_ids);
|
||||
}
|
||||
|
||||
if (!empty($category_ids)) {
|
||||
$n_cid = [];
|
||||
foreach ($category_ids as $cid) {
|
||||
$n_cid = array_merge($n_cid, CategoryUtility::children_ids($cid));
|
||||
}
|
||||
|
||||
if (!empty($n_cid)) {
|
||||
$category_ids = array_merge($category_ids, $n_cid);
|
||||
}
|
||||
|
||||
$products->whereIn('category_id', $category_ids);
|
||||
}
|
||||
|
||||
if ($name != null && $name != "") {
|
||||
$products->where(function ($query) use ($name) {
|
||||
foreach (explode(' ', trim($name)) as $word) {
|
||||
$query->where('name', 'like', '%' . $word . '%')->orWhere('tags', 'like', '%' . $word . '%')->orWhereHas('product_translations', function ($query) use ($word) {
|
||||
$query->where('name', 'like', '%' . $word . '%');
|
||||
});
|
||||
}
|
||||
});
|
||||
SearchUtility::store($name);
|
||||
$case1 = $name . '%';
|
||||
$case2 = '%' . $name . '%';
|
||||
|
||||
$products->orderByRaw("CASE
|
||||
WHEN name LIKE '$case1' THEN 1
|
||||
WHEN name LIKE '$case2' THEN 2
|
||||
ELSE 3
|
||||
END");
|
||||
}
|
||||
|
||||
if ($min != null && $min != "" && is_numeric($min)) {
|
||||
$products->where('unit_price', '>=', $min);
|
||||
}
|
||||
|
||||
if ($max != null && $max != "" && is_numeric($max)) {
|
||||
$products->where('unit_price', '<=', $max);
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch ($sort_by) {
|
||||
case 'price_low_to_high':
|
||||
$products->orderBy('unit_price', 'asc');
|
||||
break;
|
||||
|
||||
case 'price_high_to_low':
|
||||
$products->orderBy('unit_price', 'desc');
|
||||
break;
|
||||
|
||||
case 'new_arrival':
|
||||
$products->orderBy('created_at', 'desc');
|
||||
break;
|
||||
|
||||
case 'popularity':
|
||||
$products->orderBy('num_of_sale', 'desc');
|
||||
break;
|
||||
|
||||
case 'top_rated':
|
||||
$products->orderBy('rating', 'desc');
|
||||
break;
|
||||
|
||||
default:
|
||||
$products->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
|
||||
return new ProductMiniCollection(filter_products($products)->paginate(10));
|
||||
}
|
||||
|
||||
public function variantPrice(Request $request)
|
||||
{
|
||||
$product = Product::findOrFail($request->id);
|
||||
$str = '';
|
||||
$tax = 0;
|
||||
|
||||
if ($request->has('color') && $request->color != "") {
|
||||
$str = Color::where('code', '#' . $request->color)->first()->name;
|
||||
}
|
||||
|
||||
$var_str = str_replace(',', '-', $request->variants);
|
||||
$var_str = str_replace(' ', '', $var_str);
|
||||
|
||||
if ($var_str != "") {
|
||||
$temp_str = $str == "" ? $var_str : '-' . $var_str;
|
||||
$str .= $temp_str;
|
||||
}
|
||||
return $this->calc($product, $str, $request, $tax);
|
||||
|
||||
/*
|
||||
$product_stock = $product->stocks->where('variant', $str)->first();
|
||||
$price = $product_stock->price;
|
||||
$stockQuantity = $product_stock->qty;
|
||||
|
||||
|
||||
//discount calculation
|
||||
$discount_applicable = false;
|
||||
|
||||
if ($product->discount_start_date == null) {
|
||||
$discount_applicable = true;
|
||||
} elseif (
|
||||
strtotime(date('d-m-Y H:i:s')) >= $product->discount_start_date &&
|
||||
strtotime(date('d-m-Y H:i:s')) <= $product->discount_end_date
|
||||
) {
|
||||
$discount_applicable = true;
|
||||
}
|
||||
|
||||
if ($discount_applicable) {
|
||||
if ($product->discount_type == 'percent') {
|
||||
$price -= ($price * $product->discount) / 100;
|
||||
} elseif ($product->discount_type == 'amount') {
|
||||
$price -= $product->discount;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($product->taxes as $product_tax) {
|
||||
if ($product_tax->tax_type == 'percent') {
|
||||
$tax += ($price * $product_tax->tax) / 100;
|
||||
} elseif ($product_tax->tax_type == 'amount') {
|
||||
$tax += $product_tax->tax;
|
||||
}
|
||||
}
|
||||
$price += $tax;
|
||||
|
||||
return response()->json([
|
||||
'product_id' => $product->id,
|
||||
'variant' => $str,
|
||||
'price' => (float)convert_price($price),
|
||||
'price_string' => format_price(convert_price($price)),
|
||||
'stock' => intval($stockQuantity),
|
||||
'image' => $product_stock->image == null ? "" : uploaded_asset($product_stock->image)
|
||||
]);*/
|
||||
}
|
||||
|
||||
// public function home()
|
||||
// {
|
||||
// return new ProductCollection(Product::inRandomOrder()->physical()->take(50)->get());
|
||||
// }
|
||||
}
|
||||
338
desarrollo2/app/Http/Controllers/Api/V2/ProfileController.php
Normal file
338
desarrollo2/app/Http/Controllers/Api/V2/ProfileController.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Country;
|
||||
use App\Http\Resources\V2\AddressCollection;
|
||||
use App\Models\Address;
|
||||
use App\Http\Resources\V2\CitiesCollection;
|
||||
use App\Http\Resources\V2\CountriesCollection;
|
||||
use App\Models\Order;
|
||||
use App\Models\Upload;
|
||||
use App\Models\User;
|
||||
use App\Models\Wishlist;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Cart;
|
||||
use Hash;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Storage;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
public function counters()
|
||||
{
|
||||
return response()->json([
|
||||
'cart_item_count' => Cart::where('user_id', auth()->user()->id)->count(),
|
||||
'wishlist_item_count' => Wishlist::where('user_id', auth()->user()->id)->count(),
|
||||
'order_count' => Order::where('user_id', auth()->user()->id)->count(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
if(!$user){
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("User not found.")
|
||||
]);
|
||||
}
|
||||
|
||||
if(isset($request->name)){
|
||||
$user->name = $request->name;
|
||||
}
|
||||
if(isset($request->phone)){
|
||||
$user->phone = $request->phone;
|
||||
}
|
||||
|
||||
if(isset($request->password)){
|
||||
if ($request->password != "") {
|
||||
$user->password = Hash::make($request->password);
|
||||
}
|
||||
}
|
||||
$user->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("Profile information updated")
|
||||
]);
|
||||
}
|
||||
|
||||
public function update_device_token(Request $request)
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
if(!$user){
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("User not found.")
|
||||
]);
|
||||
}
|
||||
|
||||
$user->device_token = $request->device_token;
|
||||
|
||||
|
||||
$user->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("device token updated")
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateImage(Request $request)
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
if(!$user){
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("User not found."),
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
);
|
||||
|
||||
try {
|
||||
$image = $request->image;
|
||||
$request->filename;
|
||||
$realImage = base64_decode($image);
|
||||
|
||||
$dir = public_path('uploads/all');
|
||||
$full_path = "$dir/$request->filename";
|
||||
|
||||
$file_put = file_put_contents($full_path, $realImage); // int or false
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "File uploading error",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload = new Upload;
|
||||
$extension = strtolower(File::extension($full_path));
|
||||
$size = File::size($full_path);
|
||||
|
||||
if (!isset($type[$extension])) {
|
||||
unlink($full_path);
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Only image can be uploaded",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', File::name($full_path));
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//unlink and upload again with new name
|
||||
unlink($full_path);
|
||||
$newFileName = rand(10000000000, 9999999999) . date("YmdHis") . "." . $extension;
|
||||
$newFullPath = "$dir/$newFileName";
|
||||
|
||||
$file_put = file_put_contents($newFullPath, $realImage);
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Uploading error",
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
|
||||
$newPath = "uploads/all/$newFileName";
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put($newPath, file_get_contents(base_path('public/') . $newPath),
|
||||
['visibility' => 'public']
|
||||
);
|
||||
unlink(base_path('public/') . $newPath);
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $newPath;
|
||||
$upload->user_id = $user->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
|
||||
$user->avatar_original = $upload->id;
|
||||
$user->save();
|
||||
|
||||
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("Image updated"),
|
||||
'path' => uploaded_asset($upload->id)
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'path' => ""
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// not user profile image but any other base 64 image through uploader
|
||||
public function imageUpload(Request $request)
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
if(!$user){
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate("User not found."),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
);
|
||||
|
||||
try {
|
||||
$image = $request->image;
|
||||
$request->filename;
|
||||
$realImage = base64_decode($image);
|
||||
|
||||
$dir = public_path('uploads/all');
|
||||
$full_path = "$dir/$request->filename";
|
||||
|
||||
$file_put = file_put_contents($full_path, $realImage); // int or false
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "File uploading error",
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload = new Upload;
|
||||
$extension = strtolower(File::extension($full_path));
|
||||
$size = File::size($full_path);
|
||||
|
||||
if (!isset($type[$extension])) {
|
||||
unlink($full_path);
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Only image can be uploaded",
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', File::name($full_path));
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
//unlink and upload again with new name
|
||||
unlink($full_path);
|
||||
$newFileName = rand(10000000000, 9999999999) . date("YmdHis") . "." . $extension;
|
||||
$newFullPath = "$dir/$newFileName";
|
||||
|
||||
$file_put = file_put_contents($newFullPath, $realImage);
|
||||
|
||||
if ($file_put == false) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => "Uploading error",
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$newPath = "uploads/all/$newFileName";
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put($newPath, file_get_contents(base_path('public/') . $newPath));
|
||||
unlink(base_path('public/') . $newPath);
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $newPath;
|
||||
$upload->user_id = $user->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate("Image updated"),
|
||||
'path' => uploaded_asset($upload->id),
|
||||
'upload_id' => $upload->id
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'path' => "",
|
||||
'upload_id' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function checkIfPhoneAndEmailAvailable()
|
||||
{
|
||||
|
||||
|
||||
$phone_available = false;
|
||||
$email_available = false;
|
||||
$phone_available_message = translate("User phone number not found");
|
||||
$email_available_message = translate("User email not found");
|
||||
|
||||
$user = User::find(auth()->user()->id);
|
||||
|
||||
if ($user->phone != null || $user->phone != "") {
|
||||
$phone_available = true;
|
||||
$phone_available_message = translate("User phone number found");
|
||||
}
|
||||
|
||||
if ($user->email != null || $user->email != "") {
|
||||
$email_available = true;
|
||||
$email_available_message = translate("User email found");
|
||||
}
|
||||
return response()->json(
|
||||
[
|
||||
'phone_available' => $phone_available,
|
||||
'email_available' => $email_available,
|
||||
'phone_available_message' => $phone_available_message,
|
||||
'email_available_message' => $email_available_message,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\PurchasedResource;
|
||||
use App\Http\Resources\V2\PurchaseHistoryMiniCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryItemsCollection;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PurchaseHistoryController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
if ($request->payment_status != "" || $request->payment_status != null) {
|
||||
$order_query->where('payment_status', $request->payment_status);
|
||||
}
|
||||
if ($request->delivery_status != "" || $request->delivery_status != null) {
|
||||
$delivery_status = $request->delivery_status;
|
||||
$order_query->whereIn("id", function ($query) use ($delivery_status) {
|
||||
$query->select('order_id')
|
||||
->from('order_details')
|
||||
->where('delivery_status', $delivery_status);
|
||||
});
|
||||
}
|
||||
return new PurchaseHistoryMiniCollection($order_query->where('user_id', auth()->user()->id)->latest()->paginate(5));
|
||||
}
|
||||
|
||||
public function details($id)
|
||||
{
|
||||
$order_detail = Order::where('id', $id)->where('user_id', auth()->user()->id)->get();
|
||||
// $order_query = auth()->user()->orders->where('id', $id);
|
||||
|
||||
// return new PurchaseHistoryCollection($order_query->get());
|
||||
return new PurchaseHistoryCollection($order_detail);
|
||||
}
|
||||
|
||||
public function items($id)
|
||||
{
|
||||
$order_id = Order::select('id')->where('id', $id)->where('user_id', auth()->user()->id)->first();
|
||||
$order_query = OrderDetail::where('order_id', $order_id->id);
|
||||
return new PurchaseHistoryItemsCollection($order_query->get());
|
||||
}
|
||||
|
||||
public function digital_purchased_list()
|
||||
{
|
||||
$order_detail_products = Product::query()
|
||||
->where('digital', 1)
|
||||
->whereHas('orderDetails', function ($query) {
|
||||
$query->whereHas('order', function ($q) {
|
||||
$q->where('payment_status', 'paid');
|
||||
$q->where('user_id', auth()->id());
|
||||
});
|
||||
})->paginate(15);
|
||||
// $order_detail_products = OrderDetail::whereHas('order', function ($q) {
|
||||
// $q->where('payment_status', 'paid');
|
||||
// $q->where('user_id', auth()->id());
|
||||
// })->with(['product' => function ($query) {
|
||||
// $query->where('digital', 1);
|
||||
// }])
|
||||
// ->paginate(1);
|
||||
|
||||
// $products = Product::with(['orderDetails', 'orderDetails.order' => function($q) {
|
||||
// $q->where('payment_status', 'paid');
|
||||
// $q->where('user_id', auth()->id());
|
||||
// }])
|
||||
// ->where('digital', 1)
|
||||
// ->paginate(15);
|
||||
|
||||
// dd($order_detail_products);
|
||||
|
||||
return PurchasedResource::collection($order_detail_products);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\PurchaseHistoryDetailCollection;
|
||||
use App\Models\OrderDetail;
|
||||
|
||||
class PurchaseHistoryDetailController extends Controller
|
||||
{
|
||||
public function index($id)
|
||||
{
|
||||
return new PurchaseHistoryDetailCollection(OrderDetail::where('order_id', $id)->get());
|
||||
}
|
||||
}
|
||||
110
desarrollo2/app/Http/Controllers/Api/V2/RazorpayController.php
Normal file
110
desarrollo2/app/Http/Controllers/Api/V2/RazorpayController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Razorpay\Api\Api;
|
||||
|
||||
class RazorpayController
|
||||
{
|
||||
|
||||
public function payWithRazorpay(Request $request)
|
||||
{
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
$user = User::find($user_id);
|
||||
|
||||
$package_id = 0;
|
||||
if (isset($request->package_id)) {
|
||||
$package_id = $request->package_id;
|
||||
}
|
||||
|
||||
$api = new Api(env('RAZOR_KEY'), env('RAZOR_SECRET'));
|
||||
$res = $api->order->create(array('receipt' => '123', 'amount' => $amount*100, 'currency' => 'INR', 'notes' => array('key1' => 'value3', 'key2' => 'value2')));
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$shipping_address = json_decode($combined_order->shipping_address, true);
|
||||
return view('frontend.razorpay.order_payment', compact('user', 'combined_order', 'shipping_address','res'));
|
||||
} elseif ($payment_type == 'wallet_payment') {
|
||||
|
||||
return view('frontend.razorpay.wallet_payment', compact('user', 'amount','res'));
|
||||
} elseif ($payment_type == 'seller_package_payment' || $payment_type == "customer_package_payment") {
|
||||
|
||||
return view('frontend.razorpay.wallet_payment', compact('user', 'amount', 'package_id','res'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function payment(Request $request)
|
||||
{
|
||||
//Input items of form
|
||||
$input = $request->all();
|
||||
//get API Configuration
|
||||
$api = new Api(env('RAZOR_KEY'), env('RAZOR_SECRET'));
|
||||
|
||||
//Fetch payment information by razorpay_payment_id
|
||||
$payment = $api->payment->fetch($input['razorpay_payment_id']);
|
||||
|
||||
if (count($input) && !empty($input['razorpay_payment_id'])) {
|
||||
$payment_detalis = null;
|
||||
try {
|
||||
// Verify Payment Signature
|
||||
$attributes = array(
|
||||
'razorpay_order_id' => $input['razorpay_order_id'],
|
||||
'razorpay_payment_id' => $input['razorpay_payment_id'],
|
||||
'razorpay_signature' => $input['razorpay_signature']
|
||||
);
|
||||
$api->utility->verifyPaymentSignature($attributes);
|
||||
//End of Verify Payment Signature
|
||||
|
||||
$response = $api->payment->fetch($input['razorpay_payment_id'])->capture(array('amount' => $payment['amount']));
|
||||
$payment_details = json_encode(array('id' => $response['id'], 'method' => $response['method'], 'amount' => $response['amount'], 'currency' => $response['currency']));
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment Successful"), 'payment_details' => $payment_details]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage(), 'payment_details' => '']);
|
||||
}
|
||||
} else {
|
||||
return response()->json(['result' => false, 'message' => translate('Payment Failed'), 'payment_details' => '']);
|
||||
}
|
||||
}
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
|
||||
checkout_done($request->combined_order_id, $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
|
||||
wallet_payment_done($request->user_id, $request->amount, 'Razorpay', $request->payment_details);
|
||||
}
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($request->user_id, $request->package_id, $request->amount, 'Razorpay', $request->payment_details);
|
||||
}
|
||||
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->user_id, $request->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\ClubPoint;
|
||||
use App\Http\Resources\V2\RefundRequestCollection;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\RefundRequest;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RefundRequestController extends Controller
|
||||
{
|
||||
|
||||
public function get_list()
|
||||
{
|
||||
$refunds = RefundRequest::where('user_id', auth()->user()->id)->latest()->paginate(10);
|
||||
|
||||
return new RefundRequestCollection($refunds);
|
||||
}
|
||||
|
||||
public function send(Request $request)
|
||||
{
|
||||
$order_detail = OrderDetail::where('id', $request->id)->first();
|
||||
$refund = new RefundRequest;
|
||||
$refund->user_id = auth()->user()->id;
|
||||
$refund->order_id = $order_detail->order_id;
|
||||
$refund->order_detail_id = $order_detail->id;
|
||||
$refund->seller_id = $order_detail->seller_id;
|
||||
$refund->seller_approval = 0;
|
||||
$refund->reason = $request->reason;
|
||||
$refund->admin_approval = 0;
|
||||
$refund->admin_seen = 0;
|
||||
$refund->refund_amount = $order_detail->price + $order_detail->tax;
|
||||
$refund->refund_status = 0;
|
||||
$refund->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => translate('Request Sent')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
77
desarrollo2/app/Http/Controllers/Api/V2/ReviewController.php
Normal file
77
desarrollo2/app/Http/Controllers/Api/V2/ReviewController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\ReviewCollection;
|
||||
use App\Models\Review;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
public function index($id)
|
||||
{
|
||||
return new ReviewCollection(Review::where('product_id', $id)->where('status', 1)->orderBy('updated_at', 'desc')->paginate(10));
|
||||
}
|
||||
|
||||
public function submit(Request $request)
|
||||
{
|
||||
$product = Product::find($request->product_id);
|
||||
$user = User::find(auth()->user()->id);
|
||||
|
||||
/*
|
||||
@foreach ($detailedProduct->orderDetails as $key => $orderDetail)
|
||||
@if($orderDetail->order != null && $orderDetail->order->user_id == Auth::user()->id && $orderDetail->delivery_status == 'delivered' && \App\Models\Review::where('user_id', Auth::user()->id)->where('product_id', $detailedProduct->id)->first() == null)
|
||||
@php
|
||||
$commentable = true;
|
||||
@endphp
|
||||
@endif
|
||||
@endforeach
|
||||
*/
|
||||
|
||||
$reviewable = false;
|
||||
|
||||
foreach ($product->orderDetails as $key => $orderDetail) {
|
||||
if($orderDetail->order != null && $orderDetail->order->user_id == auth()->user()->id && $orderDetail->delivery_status == 'delivered' && \App\Models\Review::where('user_id', auth()->user()->id)->where('product_id', $product->id)->first() == null){
|
||||
$reviewable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$reviewable){
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('You cannot review this product')
|
||||
]);
|
||||
}
|
||||
|
||||
$review = new \App\Models\Review;
|
||||
$review->product_id = $request->product_id;
|
||||
$review->user_id = auth()->user()->id;
|
||||
$review->rating = $request->rating;
|
||||
$review->comment = $request->comment;
|
||||
$review->viewed = 0;
|
||||
$review->save();
|
||||
|
||||
$count = Review::where('product_id', $product->id)->where('status', 1)->count();
|
||||
if($count > 0){
|
||||
$product->rating = Review::where('product_id', $product->id)->where('status', 1)->sum('rating')/$count;
|
||||
}
|
||||
else {
|
||||
$product->rating = 0;
|
||||
}
|
||||
$product->save();
|
||||
|
||||
if($product->added_by == 'seller'){
|
||||
$seller = $product->user->shop;
|
||||
$seller->rating = (($seller->rating*$seller->num_of_reviews)+$review->rating)/($seller->num_of_reviews + 1);
|
||||
$seller->num_of_reviews += 1;
|
||||
$seller->save();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Review Submitted')
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Models\Search;
|
||||
use App\Models\Product;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SearchSuggestionController extends Controller
|
||||
{
|
||||
public function getList(Request $request)
|
||||
{
|
||||
$query_key = $request->query_key;
|
||||
$type = $request->type;
|
||||
|
||||
$search_query = Search::select('id', 'query', 'count');
|
||||
if ($query_key != "") {
|
||||
$search_query->where('query', 'like', "%{$query_key}%");
|
||||
}
|
||||
$searches = $search_query->orderBy('count', 'desc')->limit(10)->get();
|
||||
|
||||
if ($type == "product") {
|
||||
$product_query = Product::query();
|
||||
if ($query_key != "") {
|
||||
$product_query->where(function ($query) use ($query_key) {
|
||||
foreach (explode(' ', trim($query_key)) as $word) {
|
||||
$query->where('name', 'like', '%'.$word.'%')->orWhere('tags', 'like', '%'.$word.'%')->orWhereHas('product_translations', function($query) use ($word){
|
||||
$query->where('name', 'like', '%'.$word.'%');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$products = filter_products($product_query)->limit(3)->get();
|
||||
}
|
||||
|
||||
if ($type == "brands") {
|
||||
$brand_query = Brand::query();
|
||||
if ($query_key != "") {
|
||||
$brand_query->where('name', 'like', "%$query_key%");
|
||||
}
|
||||
|
||||
$brands = $brand_query->limit(3)->get();
|
||||
}
|
||||
|
||||
if ($type == "sellers") {
|
||||
$shop_query = Shop::query();
|
||||
if ($query_key != "") {
|
||||
$shop_query->where('name', 'like', "%$query_key%");
|
||||
}
|
||||
|
||||
$shops = $shop_query->limit(3)->get();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$items = [];
|
||||
|
||||
//shop push
|
||||
if ($type == "sellers" && !empty($shops)) {
|
||||
foreach ($shops as $shop) {
|
||||
$item = [];
|
||||
$item['id'] = $shop->id;
|
||||
$item['query'] = $shop->name;
|
||||
$item['count'] = 0;
|
||||
$item['type'] = "shop";
|
||||
$item['type_string'] = "Shop";
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
//brand push
|
||||
if ($type == "brands" && !empty($brands)) {
|
||||
foreach ($brands as $brand) {
|
||||
$item = [];
|
||||
$item['id'] = $brand->id;
|
||||
$item['query'] = $brand->name;
|
||||
$item['count'] = 0;
|
||||
$item['type'] = "brand";
|
||||
$item['type_string'] = "Brand";
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
//product push
|
||||
if ($type == "product" && !empty($products)) {
|
||||
foreach ($products as $product) {
|
||||
$item = [];
|
||||
$item['id'] = $product->id;
|
||||
$item['query'] = $product->name;
|
||||
$item['count'] = 0;
|
||||
$item['type'] = "product";
|
||||
$item['type_string'] = "Product";
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
//search push
|
||||
if (!empty($searches)) {
|
||||
foreach ($searches as $search) {
|
||||
$item = [];
|
||||
$item['id'] = $search->id;
|
||||
$item['query'] = $search->query;
|
||||
$item['count'] = intval($search->count);
|
||||
$item['type'] = "search";
|
||||
$item['type_string'] = "Search";
|
||||
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $items; // should return a valid json of search list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function success($message)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
|
||||
public function failed($message)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => $message
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\MessageCollection;
|
||||
use App\Http\Resources\V2\Seller\ConversationCollection;
|
||||
use App\Http\Resources\V2\Seller\ConversationResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Conversation;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Message;
|
||||
use Auth;
|
||||
use App\Models\Product;
|
||||
use Mail;
|
||||
use App\Mail\ConversationMailManager;
|
||||
use DB;
|
||||
|
||||
class ConversationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (BusinessSetting::where('type', 'conversation_system')->first()->value == 1) {
|
||||
|
||||
//SELECT sender_id, receiver_id, title, MAX(created_at) AS max_created_at FROM `conversations` WHERE receiver_id = 3 GROUP BY sender_id order by max_created_at desc;
|
||||
// $conversations = Conversation::select('sender_id', 'receiver_id', 'title', DB::raw("MAX(created_at) as max_created_at"))
|
||||
// ->where('receiver_id', '=', auth()->user()->id)
|
||||
// ->orderBy('max_created_at', 'DESC')
|
||||
// ->groupBy('sender_id')
|
||||
// ->get();
|
||||
$conversations = Conversation::where('receiver_id', auth()->user()->id)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
return ConversationResource::collection($conversations);
|
||||
} else {
|
||||
return $this->failed(translate('Conversation is disabled at this moment'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function send_message_to_customer(Request $requrest)
|
||||
{
|
||||
$message = new Message();
|
||||
$conversation = Conversation::find($requrest->conversation_id)->where("receiver_id",auth()->user()->id)->first();
|
||||
|
||||
if($conversation){
|
||||
$message->conversation_id = $requrest->conversation_id;
|
||||
$message->user_id = auth()->user()->id;
|
||||
$message->message = $requrest->message;
|
||||
$message->save();
|
||||
|
||||
return $this->success(translate('Message send successfully'));
|
||||
}else{
|
||||
return $this->failed(translate('You can not send this message.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$conversation = Conversation::findOrFail(decrypt($id));
|
||||
if ($conversation->sender_id == auth()->user()->id) {
|
||||
$conversation->sender_viewed = 1;
|
||||
} elseif ($conversation->receiver_id == auth()->user()->id) {
|
||||
$conversation->receiver_viewed = 1;
|
||||
}
|
||||
$conversation->save();
|
||||
|
||||
return new ConversationCollection($conversation);
|
||||
}
|
||||
|
||||
public function showMessages($id)
|
||||
{
|
||||
$conversation = Conversation::findOrFail($id);
|
||||
if ($conversation->receiver_id == auth()->user()->id) {
|
||||
$messages = Message::where("conversation_id",$id)->orderBy('created_at', 'DESC')->get();
|
||||
|
||||
return new MessageCollection($messages);
|
||||
} else {
|
||||
|
||||
return $this->failed(translate('You can not see this message.'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$conversation = Conversation::findOrFail(decrypt($id));
|
||||
foreach ($conversation->messages as $key => $message) {
|
||||
$message->delete();
|
||||
}
|
||||
if (Conversation::destroy(decrypt($id))) {
|
||||
flash(translate('Conversation has been deleted successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Requests\CouponRequest;
|
||||
use App\Http\Resources\V2\Seller\CouponResource;
|
||||
use App\Http\Resources\V2\Seller\ProductCollection;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\Product;
|
||||
use Auth;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$coupons = Coupon::where('user_id', auth()->user()->id)->orderBy('id','desc')->get();
|
||||
return CouponResource::collection($coupons);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(CouponRequest $request)
|
||||
{
|
||||
$user_id = auth()->user()->id;
|
||||
Coupon::create($request->validated() + [
|
||||
'user_id' => $user_id,
|
||||
]);
|
||||
|
||||
return $this->success(translate('Coupon has been saved successfully'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$coupon = Coupon::where('id', $id)->where('user_id', auth()->user()->id)->first();
|
||||
// dd($coupon);
|
||||
return new CouponResource($coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(CouponRequest $request, Coupon $coupon)
|
||||
{
|
||||
$coupon->update($request->validated());
|
||||
|
||||
return $this->success(translate('Coupon has been updated successfully'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
Coupon::where('id', '=', $id)->where('user_id', auth()->user()->id)->delete();
|
||||
|
||||
return $this->success(translate('Coupon has been deleted successfully'));
|
||||
}
|
||||
|
||||
public function coupon_for_product(Request $request)
|
||||
{
|
||||
|
||||
if($request->coupon_type == "product_base") {
|
||||
|
||||
$products = Product::where('name','LIKE',"%".$request->name."%")->where('user_id', auth()->user()->id)->paginate(10);
|
||||
// $products = filter_products(Product::where('user_id', auth()->user()->id))->get();
|
||||
return new ProductCollection($products);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\Seller\OrderCollection;
|
||||
use App\Http\Resources\V2\Seller\OrderDetailResource;
|
||||
use App\Http\Resources\V2\Seller\OrderItemResource;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Services\OrderService ;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
|
||||
public function getOrderList(Request $request)
|
||||
{
|
||||
$order_query = Order::query();
|
||||
if ($request->payment_status != "" || $request->payment_status != null) {
|
||||
$order_query->where('payment_status', $request->payment_status);
|
||||
}
|
||||
if ($request->delivery_status != "" || $request->delivery_status != null) {
|
||||
$delivery_status = $request->delivery_status;
|
||||
$order_query->whereIn("id", function ($query) use ($delivery_status) {
|
||||
$query->select('order_id')
|
||||
->from('order_details')
|
||||
->where('delivery_status', $delivery_status);
|
||||
});
|
||||
}
|
||||
|
||||
$orders = $order_query->where('seller_id', auth()->user()->id)->latest()->paginate(10);
|
||||
|
||||
return new OrderCollection($orders);
|
||||
}
|
||||
|
||||
|
||||
public function getOrderDetails($id)
|
||||
{
|
||||
$order_detail = Order::where('id', $id)->where('seller_id', auth()->user()->id)->get();
|
||||
return OrderDetailResource::collection($order_detail);
|
||||
}
|
||||
|
||||
public function getOrderItems($id)
|
||||
{
|
||||
$order_id = Order::select('id')->where('id', $id)->where('seller_id', auth()->user()->id)->first();
|
||||
$order_query = OrderDetail::where('order_id', $order_id->id);
|
||||
|
||||
return OrderItemResource::collection($order_query->get());
|
||||
// return new PurchaseHistoryItemsCollection($order_query->get());
|
||||
}
|
||||
|
||||
public function update_delivery_status(Request $request) {
|
||||
(new OrderService)->handle_delivery_status($request);
|
||||
return $this->success(translate('Delivery status has been changed successfully'));
|
||||
}
|
||||
|
||||
public function update_payment_status(Request $request) {
|
||||
(new OrderService)->handle_payment_status($request);
|
||||
return $this->success(translate('Payment status has been changed successfully'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\V2\Seller\SellerPaymentResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Payment;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
//
|
||||
public function getHistory(){
|
||||
$sellerId = auth()->user()->id;
|
||||
$payments = Payment::orderBy('created_at', 'desc')->where('seller_id',$sellerId)->latest()->paginate(10);;
|
||||
return SellerPaymentResource::collection($payments);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Requests\ProductRequest;
|
||||
use App\Http\Resources\V2\Seller\AttributeCollection;
|
||||
use App\Http\Resources\V2\Seller\BrandCollection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Http\Resources\V2\Seller\CategoriesCollection;
|
||||
use App\Http\Resources\V2\Seller\ColorCollection;
|
||||
use App\Http\Resources\V2\Seller\ProductCollection;
|
||||
use App\Http\Resources\V2\Seller\ProductDetailsCollection;
|
||||
use App\Http\Resources\V2\Seller\ProductReviewCollection;
|
||||
use App\Http\Resources\V2\Seller\TaxCollection;
|
||||
use App\Models\Attribute;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Category;
|
||||
use App\Models\Color;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductTax;
|
||||
use App\Models\ProductTranslation;
|
||||
use App\Models\Review;
|
||||
use App\Models\Tax;
|
||||
use Artisan;
|
||||
|
||||
use App\Services\ProductFlashDealService;
|
||||
use App\Services\ProductService;
|
||||
use App\Services\ProductStockService;
|
||||
use App\Services\ProductTaxService;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
protected $productService;
|
||||
protected $productTaxService;
|
||||
protected $productFlashDealService;
|
||||
protected $productStockService;
|
||||
|
||||
public function __construct(
|
||||
ProductService $productService,
|
||||
ProductTaxService $productTaxService,
|
||||
ProductFlashDealService $productFlashDealService,
|
||||
ProductStockService $productStockService
|
||||
) {
|
||||
$this->productService = $productService;
|
||||
$this->productTaxService = $productTaxService;
|
||||
$this->productFlashDealService = $productFlashDealService;
|
||||
$this->productStockService = $productStockService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$products = Product::where('user_id', auth()->user()->id)->where('digital', 0)->where('auction_product', 0)->where('wholesale_product', 0)->orderBy('created_at', 'desc');
|
||||
$products = $products->paginate(10);
|
||||
return new ProductCollection($products);
|
||||
}
|
||||
|
||||
public function getCategory()
|
||||
{
|
||||
$categories = Category::where('parent_id', 0)
|
||||
->where('digital', 0)
|
||||
->with('childrenCategories')
|
||||
->get();
|
||||
return CategoriesCollection::collection($categories);
|
||||
}
|
||||
|
||||
public function getBrands()
|
||||
{
|
||||
$brands = Brand::all();
|
||||
|
||||
return BrandCollection::collection($brands);
|
||||
}
|
||||
public function getTaxes()
|
||||
{
|
||||
$taxes = Tax::where('tax_status', 1)->get();
|
||||
|
||||
return TaxCollection::collection($taxes);
|
||||
}
|
||||
public function getAttributes()
|
||||
{
|
||||
$attributes = Attribute::with('attribute_values')->get();
|
||||
|
||||
return AttributeCollection::collection($attributes);
|
||||
}
|
||||
public function getColors()
|
||||
{
|
||||
$colors = Color::orderBy('name', 'asc')->get();
|
||||
|
||||
return ColorCollection::collection($colors);
|
||||
}
|
||||
|
||||
|
||||
public function store(ProductRequest $request)
|
||||
{
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (!seller_package_validity_check(auth()->user()->id)) {
|
||||
return $this->failed(translate('Please upgrade your package.'));
|
||||
}
|
||||
}
|
||||
|
||||
if (auth()->user()->user_type != 'seller') {
|
||||
return $this->failed(translate('Unauthenticated User.'));
|
||||
}
|
||||
|
||||
$request->merge(['added_by' => 'seller']);
|
||||
$product = $this->productService->store($request->except([
|
||||
'_token', 'sku', 'choice', 'tax_id', 'tax', 'tax_type', 'flash_deal_id', 'flash_discount', 'flash_discount_type'
|
||||
]));
|
||||
$request->merge(['product_id' => $product->id]);
|
||||
|
||||
//VAT & Tax
|
||||
if ($request->tax_id) {
|
||||
$this->productTaxService->store($request->only([
|
||||
'tax_id', 'tax', 'tax_type', 'product_id'
|
||||
]));
|
||||
}
|
||||
|
||||
//Product Stock
|
||||
$this->productStockService->store($request->only([
|
||||
'colors_active', 'colors', 'choice_no', 'unit_price', 'sku', 'current_stock', 'product_id'
|
||||
]), $product);
|
||||
|
||||
// Product Translations
|
||||
$request->merge(['lang' => env('DEFAULT_LANGUAGE')]);
|
||||
ProductTranslation::create($request->only([
|
||||
'lang', 'name', 'unit', 'description', 'product_id'
|
||||
]));
|
||||
|
||||
return $this->success(translate('Product has been inserted successfully'));
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
|
||||
if (auth()->user()->user_type != 'seller') {
|
||||
return $this->failed(translate('Unauthenticated User.'));
|
||||
}
|
||||
|
||||
$product = Product::where('id', $id)->with('stocks')->first();
|
||||
|
||||
if (auth()->user()->id != $product->user_id) {
|
||||
return $this->failed(translate('This product is not yours.'));
|
||||
}
|
||||
$product->lang = $request->lang == null ? env("DEFAULT_LANGUAGE") : $request->lang;
|
||||
|
||||
return new ProductDetailsCollection($product);
|
||||
/* $data = response()->json([
|
||||
'lang' => $lang,
|
||||
'product' => $product,
|
||||
'product_name' => $product->getTranslation('name',$lang),
|
||||
'product_unit' => $product->getTranslation('unit',$lang),
|
||||
'description' => $product->getTranslation('description',$lang),
|
||||
]);
|
||||
return $data;*/
|
||||
}
|
||||
|
||||
public function update(ProductRequest $request, Product $product)
|
||||
{
|
||||
//Product
|
||||
$product = $this->productService->update($request->except([
|
||||
'_token', 'sku', 'choice', 'tax_id', 'tax', 'tax_type', 'flash_deal_id', 'flash_discount', 'flash_discount_type'
|
||||
]), $product);
|
||||
|
||||
//Product Stock
|
||||
foreach ($product->stocks as $key => $stock) {
|
||||
$stock->delete();
|
||||
}
|
||||
$request->merge(['product_id' => $product->id]);
|
||||
$this->productStockService->store($request->only([
|
||||
'colors_active', 'colors', 'choice_no', 'unit_price', 'sku', 'current_stock', 'product_id'
|
||||
]), $product);
|
||||
|
||||
//VAT & Tax
|
||||
if ($request->tax_id) {
|
||||
ProductTax::where('product_id', $product->id)->delete();
|
||||
$request->merge(['product_id' => $product->id]);
|
||||
$this->productTaxService->store($request->only([
|
||||
'tax_id', 'tax', 'tax_type', 'product_id'
|
||||
]));
|
||||
}
|
||||
|
||||
// Product Translations
|
||||
ProductTranslation::updateOrCreate(
|
||||
$request->only([
|
||||
'lang', 'product_id'
|
||||
]),
|
||||
$request->only([
|
||||
'name', 'unit', 'description'
|
||||
])
|
||||
);
|
||||
|
||||
return $this->success(translate('Product has been updated successfully'));
|
||||
}
|
||||
|
||||
public function change_status(Request $request)
|
||||
{
|
||||
$product = Product::where('user_id', auth()->user()->id)
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'published' => $request->status
|
||||
]);
|
||||
|
||||
if ($product== 0) {
|
||||
return $this->failed(translate('This product is not yours'));
|
||||
}
|
||||
return ($request->status == 1) ?
|
||||
$this->success(translate('Product has been published successfully')) :
|
||||
$this->success(translate('Product has been unpublished successfully'));
|
||||
}
|
||||
|
||||
public function change_featured_status(Request $request)
|
||||
{
|
||||
$product = Product::where('user_id', auth()->user()->id)
|
||||
->where('id', $request->id)
|
||||
->update([
|
||||
'seller_featured' => $request->featured_status
|
||||
]);
|
||||
|
||||
if ($product == 0) {
|
||||
return $this->failed(translate('This product is not yours'));
|
||||
}
|
||||
|
||||
return ($request->featured_status == 1) ?
|
||||
$this->success(translate('Product has been featured successfully')) :
|
||||
$this->success(translate('Product has been unfeatured successfully'));
|
||||
}
|
||||
|
||||
public function duplicate($id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
|
||||
if (auth()->user()->id != $product->user_id) {
|
||||
return $this->failed(translate('This product is not yours'));
|
||||
}
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (!seller_package_validity_check(auth()->user()->id)) {
|
||||
return $this->failed(translate('Please upgrade your package'));
|
||||
}
|
||||
}
|
||||
|
||||
//Product
|
||||
$product_new = (new ProductService)->product_duplicate_store($product);
|
||||
|
||||
//Store in Product Stock Table
|
||||
(new ProductStockService)->product_duplicate_store($product->stocks, $product_new);
|
||||
|
||||
//Store in Product Tax Table
|
||||
(new ProductTaxService)->product_duplicate_store($product->taxes, $product_new);
|
||||
|
||||
return $this->success(translate('Product has been duplicated successfully'));
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
|
||||
if (auth()->user()->id != $product->user_id) {
|
||||
return $this->failed(translate('This product is not yours'));
|
||||
}
|
||||
|
||||
$product->product_translations()->delete();
|
||||
$product->stocks()->delete();
|
||||
$product->taxes()->delete();
|
||||
|
||||
if (Product::destroy($id)) {
|
||||
Cart::where('product_id', $id)->delete();
|
||||
|
||||
return $this->success(translate('Product has been deleted successfully'));
|
||||
|
||||
Artisan::call('view:clear');
|
||||
Artisan::call('cache:clear');
|
||||
}
|
||||
}
|
||||
|
||||
public function product_reviews()
|
||||
{
|
||||
$reviews = Review::orderBy('id', 'desc')
|
||||
->join('products', 'reviews.product_id', '=', 'products.id')
|
||||
->join('users', 'reviews.user_id', '=', 'users.id')
|
||||
->where('products.user_id', auth()->user()->id)
|
||||
->select('reviews.id', 'reviews.rating', 'reviews.comment', 'reviews.status', 'reviews.updated_at', 'products.name as product_name', 'users.id as user_id', 'users.name', 'users.avatar')
|
||||
->distinct()
|
||||
->paginate(1);
|
||||
|
||||
return new ProductReviewCollection($reviews);
|
||||
}
|
||||
|
||||
public function remainingUploads()
|
||||
{
|
||||
|
||||
$remaining_uploads = (max(0, auth()->user()->shop->product_upload_limit - auth()->user()->products()->count()));
|
||||
return response()->json([
|
||||
'ramaining_product' => $remaining_uploads,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\RefundRequestCollection;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\RefundRequest;
|
||||
|
||||
|
||||
class RefundController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function index(){
|
||||
$sellerId = auth()->user()->id;
|
||||
|
||||
$refunds = RefundRequest::where('seller_id',$sellerId)->latest()->paginate(10);
|
||||
return new RefundRequestCollection($refunds);
|
||||
}
|
||||
|
||||
|
||||
public function request_approval_vendor(Request $request)
|
||||
{
|
||||
$refund = RefundRequest::findOrFail($request->refund_id);
|
||||
|
||||
if (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff') {
|
||||
$refund->seller_approval = 1;
|
||||
$refund->admin_approval = 1;
|
||||
}
|
||||
elseif (auth()->user()->user_type == 'seller' && $refund->seller_id==auth()->user()->id){
|
||||
$refund->seller_approval = 1;
|
||||
}
|
||||
|
||||
if ($refund->save())
|
||||
{
|
||||
return $this->success(translate('Refund Status has been change successfully')) ;
|
||||
}
|
||||
else {
|
||||
return $this->failed(translate('Refund Status change failed!'));
|
||||
}
|
||||
}
|
||||
|
||||
public function reject_refund_request(Request $request){
|
||||
$refund = RefundRequest::findOrFail($request->refund_id);
|
||||
$refund->reject_reason = $request->reject_reason;
|
||||
if (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff') {
|
||||
$refund->admin_approval = 2;
|
||||
$refund->refund_status = 2;
|
||||
}
|
||||
elseif (auth()->user()->user_type == 'seller' && $refund->seller_id==auth()->user()->id){
|
||||
$refund->seller_approval = 2;
|
||||
}
|
||||
|
||||
if ($refund->save())
|
||||
{
|
||||
return $this->success(translate('Refund Status has been change successfully')) ;
|
||||
}
|
||||
else {
|
||||
return $this->failed(translate('Refund Status change failed!'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Controllers\Api\V2\Controller;
|
||||
use App\Http\Resources\V2\Seller\AuctionProductBidCollection;
|
||||
use App\Http\Resources\V2\Seller\AuctionProductCollection;
|
||||
use App\Http\Resources\V2\Seller\AuctionProductDetailsResource;
|
||||
use App\Http\Resources\V2\Seller\OrderCollection;
|
||||
use App\Models\AuctionProductBid;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Product;
|
||||
use App\Services\AuctionService;
|
||||
use Auth;
|
||||
use DB;
|
||||
|
||||
class SellerAuctionProductController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$products = [];
|
||||
if (get_setting('seller_auction_product') == 0) {
|
||||
$products = [];
|
||||
} else {
|
||||
|
||||
$products = Product::where('auction_product', 1)->where('user_id', Auth::user()->id)->orderBy('created_at', 'desc');
|
||||
}
|
||||
return new AuctionProductCollection($products->paginate(10));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (!seller_package_validity_check(auth()->user()->id)) {
|
||||
return $this->failed(translate('Please upgrade your package.'));
|
||||
}
|
||||
}
|
||||
|
||||
(new AuctionService)->store($request);
|
||||
return $this->success(translate('Auction Product has been inserted successfully'));
|
||||
}
|
||||
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
$product->lang = $request->lang == null ? env("DEFAULT_LANGUAGE") : $request->lang;
|
||||
|
||||
return new AuctionProductDetailsResource($product);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
(new AuctionService)->update($request, $id);
|
||||
return $this->success(translate('Auction Product has been updated successfully'));
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
(new AuctionService)->destroy($id);
|
||||
return $this->success(translate('Auction Product has been deleted successfully'));
|
||||
}
|
||||
|
||||
public function productBids($id)
|
||||
{
|
||||
return new AuctionProductBidCollection(AuctionProductBid::latest()->where('product_id', $id)->paginate(15));
|
||||
}
|
||||
|
||||
public function bidDestroy($id)
|
||||
{
|
||||
|
||||
AuctionProductBid::destroy($id);
|
||||
return $this->success(translate('Bid deleted successfully'));
|
||||
}
|
||||
|
||||
public function getAuctionOrderList(Request $request)
|
||||
{
|
||||
|
||||
|
||||
$orders = Order::leftJoin('order_details', 'orders.id', '=', 'order_details.order_id')
|
||||
->leftJoin('products', 'order_details.product_id', '=', 'products.id')
|
||||
->where('orders.seller_id', auth()->user()->id)
|
||||
->where('products.auction_product', '1')
|
||||
->select("orders.*")
|
||||
->orderBy('code', 'desc');
|
||||
|
||||
|
||||
if ($request->payment_status != null) {
|
||||
$orders = $orders->where('orders.payment_status', $request->payment_status);
|
||||
}
|
||||
if ($request->delivery_status != null) {
|
||||
$orders = $orders->where('orders.delivery_status', $request->delivery_status);
|
||||
}
|
||||
|
||||
if ($request->has('search')) {
|
||||
$orders = $orders->where('code', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
return new OrderCollection($orders->paginate(15));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\UploadedFileCollection;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Upload;
|
||||
use Response;
|
||||
use Auth;
|
||||
use Storage;
|
||||
use Image;
|
||||
|
||||
class SellerFileUploadController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
if (auth()->user()->user_type == 'seller') {
|
||||
$all_uploads = Upload::where('user_id', auth()->user()->id);
|
||||
|
||||
if ($request->search != null) {
|
||||
$all_uploads->where('file_original_name', 'like', '%' . $request->search . '%');
|
||||
}
|
||||
if ($request->type != null) {
|
||||
$all_uploads->where('type', $request->type);
|
||||
}
|
||||
|
||||
switch ($request->sort) {
|
||||
case 'newest':
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
case 'oldest':
|
||||
$all_uploads->orderBy('created_at', 'asc');
|
||||
break;
|
||||
case 'smallest':
|
||||
$all_uploads->orderBy('file_size', 'asc');
|
||||
break;
|
||||
case 'largest':
|
||||
$all_uploads->orderBy('file_size', 'desc');
|
||||
break;
|
||||
default:
|
||||
$all_uploads->orderBy('created_at', 'desc');
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$all_uploads = $all_uploads->paginate(30)->appends(request()->query());
|
||||
|
||||
return new UploadedFileCollection($all_uploads);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
"result" => false,
|
||||
"data" => []
|
||||
]);
|
||||
}
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$type = array(
|
||||
"jpg" => "image",
|
||||
"jpeg" => "image",
|
||||
"png" => "image",
|
||||
"svg" => "image",
|
||||
"webp" => "image",
|
||||
"gif" => "image",
|
||||
"mp4" => "video",
|
||||
"mpg" => "video",
|
||||
"mpeg" => "video",
|
||||
"webm" => "video",
|
||||
"ogg" => "video",
|
||||
"avi" => "video",
|
||||
"mov" => "video",
|
||||
"flv" => "video",
|
||||
"swf" => "video",
|
||||
"mkv" => "video",
|
||||
"wmv" => "video",
|
||||
"wma" => "audio",
|
||||
"aac" => "audio",
|
||||
"wav" => "audio",
|
||||
"mp3" => "audio",
|
||||
"zip" => "archive",
|
||||
"rar" => "archive",
|
||||
"7z" => "archive",
|
||||
"doc" => "document",
|
||||
"txt" => "document",
|
||||
"docx" => "document",
|
||||
"pdf" => "document",
|
||||
"csv" => "document",
|
||||
"xml" => "document",
|
||||
"ods" => "document",
|
||||
"xlr" => "document",
|
||||
"xls" => "document",
|
||||
"xlsx" => "document"
|
||||
);
|
||||
if (auth()->user()->user_type == 'seller') {
|
||||
if ($request->hasFile('aiz_file')) {
|
||||
$upload = new Upload;
|
||||
$extension = strtolower($request->file('aiz_file')->getClientOriginalExtension());
|
||||
|
||||
if (
|
||||
env('DEMO_MODE') == 'On' &&
|
||||
isset($type[$extension]) &&
|
||||
$type[$extension] == 'archive'
|
||||
) {
|
||||
return $this->failed(translate('File has been inserted successfully'));
|
||||
}
|
||||
|
||||
if (isset($type[$extension])) {
|
||||
$upload->file_original_name = null;
|
||||
$arr = explode('.', $request->file('aiz_file')->getClientOriginalName());
|
||||
for ($i = 0; $i < count($arr) - 1; $i++) {
|
||||
if ($i == 0) {
|
||||
$upload->file_original_name .= $arr[$i];
|
||||
} else {
|
||||
$upload->file_original_name .= "." . $arr[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$path = $request->file('aiz_file')->store('uploads/all', 'local');
|
||||
$size = $request->file('aiz_file')->getSize();
|
||||
|
||||
// Return MIME type ala mimetype extension
|
||||
$finfo = finfo_open(FILEINFO_MIME_TYPE);
|
||||
|
||||
// Get the MIME type of the file
|
||||
$file_mime = finfo_file($finfo, base_path('public/') . $path);
|
||||
|
||||
if ($type[$extension] == 'image' && get_setting('disable_image_optimization') != 1) {
|
||||
try {
|
||||
$img = Image::make($request->file('aiz_file')->getRealPath())->encode();
|
||||
$height = $img->height();
|
||||
$width = $img->width();
|
||||
if ($width > $height && $width > 1500) {
|
||||
$img->resize(1500, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
} elseif ($height > 1500) {
|
||||
$img->resize(null, 800, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
});
|
||||
}
|
||||
$img->save(base_path('public/') . $path);
|
||||
clearstatcache();
|
||||
$size = $img->filesize();
|
||||
} catch (\Exception $e) {
|
||||
//dd($e);
|
||||
}
|
||||
}
|
||||
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->put(
|
||||
$path,
|
||||
file_get_contents(base_path('public/') . $path),
|
||||
[
|
||||
'visibility' => 'public',
|
||||
'ContentType' => $extension == 'svg' ? 'image/svg+xml' : $file_mime
|
||||
]
|
||||
);
|
||||
if ($arr[0] != 'updates') {
|
||||
unlink(base_path('public/') . $path);
|
||||
}
|
||||
}
|
||||
|
||||
$upload->extension = $extension;
|
||||
$upload->file_name = $path;
|
||||
$upload->user_id = Auth::user()->id;
|
||||
$upload->type = $type[$upload->extension];
|
||||
$upload->file_size = $size;
|
||||
$upload->save();
|
||||
}
|
||||
return $this->success(translate('File has been inserted successfully'));
|
||||
}else{
|
||||
return $this->failed(translate("Upload file is missing"));
|
||||
}
|
||||
}
|
||||
return $this->failed(translate("You can't upload the file"));
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$upload = Upload::findOrFail($id);
|
||||
|
||||
if (auth()->user()->user_type == 'seller' && $upload->user_id != auth()->user()->id) {
|
||||
return $this->failed(translate("You don't have permission for deleting this!"));
|
||||
}
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
return $this->success(translate('File deleted successfully'));
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
return $this->failed(translate('File deleted Failed'));
|
||||
}
|
||||
return $this->success(translate('File deleted successfully'));
|
||||
}
|
||||
|
||||
public function bulk_uploaded_files_delete(Request $request)
|
||||
{
|
||||
if ($request->id) {
|
||||
foreach ($request->id as $file_id) {
|
||||
$this->destroy($file_id);
|
||||
}
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_preview_files(Request $request)
|
||||
{
|
||||
$ids = explode(',', $request->ids);
|
||||
$files = Upload::whereIn('id', $ids)->get();
|
||||
$new_file_array = [];
|
||||
foreach ($files as $file) {
|
||||
$file['file_name'] = my_asset($file->file_name);
|
||||
if ($file->external_link) {
|
||||
$file['file_name'] = $file->external_link;
|
||||
}
|
||||
$new_file_array[] = $file;
|
||||
}
|
||||
// dd($new_file_array);
|
||||
return $new_file_array;
|
||||
// return $files;
|
||||
}
|
||||
|
||||
public function all_file()
|
||||
{
|
||||
$uploads = Upload::all();
|
||||
foreach ($uploads as $upload) {
|
||||
try {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
}
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
} catch (\Exception $e) {
|
||||
$upload->delete();
|
||||
flash(translate('File deleted successfully'))->success();
|
||||
}
|
||||
}
|
||||
|
||||
Upload::query()->truncate();
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
//Download project attachment
|
||||
public function attachment_download($id)
|
||||
{
|
||||
$project_attachment = Upload::find($id);
|
||||
try {
|
||||
$file_path = public_path($project_attachment->file_name);
|
||||
return Response::download($file_path);
|
||||
} catch (\Exception $e) {
|
||||
flash(translate('File does not exist!'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
//Download project attachment
|
||||
public function file_info(Request $request)
|
||||
{
|
||||
$file = Upload::findOrFail($request['id']);
|
||||
|
||||
return (auth()->user()->user_type == 'seller')
|
||||
? view('seller.uploads.info', compact('file'))
|
||||
: view('backend.uploaded_files.info', compact('file'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\Seller\SellerPackageResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SellerPackage;
|
||||
use App\Models\SellerPackagePayment;
|
||||
use App\Models\Seller;
|
||||
use App\Models\Order;
|
||||
use App\Utility\PayfastUtility;
|
||||
use Auth;
|
||||
use Session;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class SellerPackageController extends Controller
|
||||
{
|
||||
public function seller_packages_list()
|
||||
{
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
$seller_packages = SellerPackage::all();
|
||||
return SellerPackageResource::collection($seller_packages);
|
||||
}
|
||||
|
||||
return $this->failed(translate('Package is not available'));
|
||||
}
|
||||
|
||||
public function purchase_free_package(Request $request)
|
||||
{
|
||||
$data['seller_package_id'] = $request->package_id;
|
||||
$data['payment_method'] = $request->payment_option;
|
||||
|
||||
|
||||
$seller_package = SellerPackage::findOrFail($request->seller_package_id);
|
||||
|
||||
if ($seller_package->amount == 0) {
|
||||
seller_purchase_payment_done(auth()->user()->id, $request->package_id, $request->amount, 'Free Package', null);
|
||||
return $this->success(translate('Package purchasing successful'));
|
||||
} elseif (
|
||||
auth()->user()->shop->seller_package != null &&
|
||||
$seller_package->product_upload_limit < auth()->user()->shop->seller_package->product_upload_limit
|
||||
) {
|
||||
return $this->failed(translate('You have more uploaded products than this package limit. You need to remove excessive products to downgrade.'));
|
||||
}
|
||||
}
|
||||
|
||||
public function purchase_package_offline(Request $request)
|
||||
{
|
||||
$seller_package = SellerPackage::findOrFail($request->package_id);
|
||||
|
||||
if (
|
||||
auth()->user()->shop->seller_package != null &&
|
||||
$seller_package->product_upload_limit < auth()->user()->shop->seller_package->product_upload_limit
|
||||
) {
|
||||
return $this->failed(translate('You have more uploaded products than this package limit. You need to remove excessive products to downgrade.'));
|
||||
}
|
||||
|
||||
$seller_package = new SellerPackagePayment;
|
||||
$seller_package->user_id = auth()->user()->id;
|
||||
$seller_package->seller_package_id = $request->package_id;
|
||||
$seller_package->payment_method = $request->payment_option;
|
||||
$seller_package->payment_details = $request->trx_id;
|
||||
$seller_package->approval = 0;
|
||||
$seller_package->offline_payment = 1;
|
||||
$seller_package->reciept = $request->photo;
|
||||
|
||||
$seller_package->save();
|
||||
|
||||
return $this->success(translate('Offline payment has been done. Please wait for response.'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SellerPackagePayment;
|
||||
use App\Models\SellerPackage;
|
||||
|
||||
class SellerPackagePaymentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function offline_payment_request(){
|
||||
$package_payment_requests = SellerPackagePayment::where('offline_payment',1)->orderBy('id', 'desc')->paginate(10);
|
||||
return view('manual_payment_methods.seller_package_payment_request', compact('package_payment_requests'));
|
||||
}
|
||||
|
||||
public function offline_payment_approval(Request $request)
|
||||
{
|
||||
$package_payment = SellerPackagePayment::findOrFail($request->id);
|
||||
$package_details = SellerPackage::findOrFail($package_payment->seller_package_id);
|
||||
$package_payment->approval = $request->status;
|
||||
if($package_payment->save()){
|
||||
$seller = $package_payment->user->seller;
|
||||
$seller->seller_package_id = $package_payment->seller_package_id;
|
||||
$seller->invalid_at = date('Y-m-d', strtotime( $seller->invalid_at. ' +'. $package_details->duration .'days'));
|
||||
if($seller->save()){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Controllers\Api\V2\AuthController;
|
||||
use App\Http\Requests\SellerRegistrationRequest;
|
||||
use App\Http\Resources\V2\Seller\ProductCollection;
|
||||
use App\Http\Resources\V2\Seller\ProductMiniCollection;
|
||||
use App\Http\Resources\V2\Seller\CommissionHistoryResource;
|
||||
use App\Http\Resources\V2\Seller\SellerPackageResource;
|
||||
use App\Http\Resources\V2\Seller\SellerPaymentResource;
|
||||
use App\Http\Resources\V2\ShopCollection;
|
||||
use App\Http\Resources\V2\ShopDetailsCollection;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Models\Category;
|
||||
use App\Models\CommissionHistory;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Product;
|
||||
use App\Models\Shop;
|
||||
use App\Models\User;
|
||||
use App\Notifications\AppEmailVerificationNotification;
|
||||
use App\Notifications\EmailVerificationNotification;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utility\SearchUtility;
|
||||
use Cache;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Hash;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Response;
|
||||
|
||||
class ShopController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$shop_query = Shop::query();
|
||||
|
||||
if ($request->name != null && $request->name != "") {
|
||||
$shop_query->where("name", 'like', "%{$request->name}%");
|
||||
SearchUtility::store($request->name);
|
||||
}
|
||||
|
||||
return new ShopCollection($shop_query->whereIn('user_id', verified_sellers_id())->paginate(10));
|
||||
|
||||
//remove this , this is for testing
|
||||
//return new ShopCollection($shop_query->paginate(10));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$shop = Shop::where('user_id', auth()->user()->id)->first();
|
||||
$successMessage = 'Shop info updated successfully';
|
||||
$failedMessage = 'Shop info updated failed';
|
||||
|
||||
if ($request->has('name') && $request->has('address')) {
|
||||
if ($request->has('shipping_cost')) {
|
||||
$shop->shipping_cost = $request->shipping_cost;
|
||||
}
|
||||
$shop->name = $request->name;
|
||||
$shop->address = $request->address;
|
||||
$shop->phone = $request->phone;
|
||||
$shop->slug = preg_replace('/\s+/', '-', $request->name) . '-' . $shop->id;
|
||||
$shop->meta_title = $request->meta_title;
|
||||
$shop->meta_description = $request->meta_description;
|
||||
$shop->logo = $request->logo;
|
||||
}
|
||||
|
||||
if ($request->has('delivery_pickup_longitude') && $request->has('delivery_pickup_latitude')) {
|
||||
|
||||
$shop->delivery_pickup_longitude = $request->delivery_pickup_longitude;
|
||||
$shop->delivery_pickup_latitude = $request->delivery_pickup_latitude;
|
||||
} elseif (
|
||||
$request->has('facebook') ||
|
||||
$request->has('google') ||
|
||||
$request->has('twitter') ||
|
||||
$request->has('youtube') ||
|
||||
$request->has('instagram')
|
||||
) {
|
||||
$shop->facebook = $request->facebook;
|
||||
$shop->instagram = $request->instagram;
|
||||
$shop->google = $request->google;
|
||||
$shop->twitter = $request->twitter;
|
||||
$shop->youtube = $request->youtube;
|
||||
} elseif (
|
||||
$request->has('cash_on_delivery_status') ||
|
||||
$request->has('bank_payment_status') ||
|
||||
$request->has('bank_name') ||
|
||||
$request->has('bank_acc_name') ||
|
||||
$request->has('bank_acc_no') ||
|
||||
$request->has('bank_routing_no')
|
||||
) {
|
||||
|
||||
$shop->cash_on_delivery_status = $request->cash_on_delivery_status;
|
||||
$shop->bank_payment_status = $request->bank_payment_status;
|
||||
$shop->bank_name = $request->bank_name;
|
||||
$shop->bank_acc_name = $request->bank_acc_name;
|
||||
$shop->bank_acc_no = $request->bank_acc_no;
|
||||
$shop->bank_routing_no = $request->bank_routing_no;
|
||||
|
||||
$successMessage = 'Payment info updated successfully';
|
||||
} else {
|
||||
$shop->sliders = $request->sliders;
|
||||
}
|
||||
|
||||
if ($shop->save()) {
|
||||
return $this->success(translate($successMessage));
|
||||
}
|
||||
|
||||
return $this->failed(translate($failedMessage));
|
||||
}
|
||||
|
||||
|
||||
public function sales_stat()
|
||||
{
|
||||
$data = Order::where('created_at', '>=', Carbon::now()->subDays(7))
|
||||
->where('seller_id', '=', auth()->user()->id)
|
||||
->where('delivery_status', '=', 'delivered')
|
||||
->select(DB::raw("sum(grand_total) as total, DATE_FORMAT(created_at, '%b-%d') as date"))
|
||||
->groupBy(DB::raw("DATE_FORMAT(created_at, '%Y-%m-%d')"))
|
||||
->get()->toArray();
|
||||
//dd($data->toArray());
|
||||
|
||||
//$array_date = [];
|
||||
$sales_array = [];
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$new_date = date("M-d", strtotime(($i + 1) . " days ago"));
|
||||
//$array_date[] = date("M-d", strtotime($i." days ago"));
|
||||
|
||||
$sales_array[$i]['date'] = $new_date;
|
||||
$sales_array[$i]['total'] = 0;
|
||||
|
||||
if (!empty($data)) {
|
||||
$key = array_search($new_date, array_column($data, 'date'));
|
||||
if (is_numeric($key)) {
|
||||
$sales_array[$i]['total'] = $data[$key]['total'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Response()->json($sales_array);
|
||||
}
|
||||
|
||||
public function category_wise_products()
|
||||
{
|
||||
$category_wise_product = [];
|
||||
$new_array = [];
|
||||
foreach (Category::all() as $key => $category) {
|
||||
if (count($category->products->where('user_id', auth()->user()->id)) > 0) {
|
||||
$category_wise_product['name'] = $category->getTranslation('name');
|
||||
$category_wise_product['banner'] = uploaded_asset($category->banner);
|
||||
$category_wise_product['cnt_product'] = count($category->products->where('user_id', auth()->user()->id));
|
||||
|
||||
$new_array[] = $category_wise_product;
|
||||
}
|
||||
}
|
||||
|
||||
return Response()->json($new_array);
|
||||
}
|
||||
|
||||
public function top_12_products()
|
||||
{
|
||||
$products = filter_products(Product::where('user_id', auth()->user()->id)
|
||||
->orderBy('num_of_sale', 'desc'))
|
||||
->limit(12)
|
||||
->get();
|
||||
|
||||
return new ProductCollection($products);
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
// dd(auth()->user()->shop);
|
||||
return new ShopDetailsCollection(auth()->user()->shop);
|
||||
}
|
||||
|
||||
public function pacakge()
|
||||
{
|
||||
$shop = auth()->user()->shop;
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'id' => $shop->id,
|
||||
'package_name' => $shop->seller_package->name,
|
||||
'package_img' => uploaded_asset($shop->seller_package->logo)
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'id' => $user->id,
|
||||
'type' => $user->user_type,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'avatar' => $user->avatar,
|
||||
'avatar_original' => uploaded_asset($user->avatar_original),
|
||||
'phone' => $user->phone
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
public function payment_histories()
|
||||
{
|
||||
$payments = Payment::where('seller_id', auth()->user()->id)->paginate(10);
|
||||
return SellerPaymentResource::collection($payments);
|
||||
}
|
||||
|
||||
public function collection_histories()
|
||||
{
|
||||
$commission_history = CommissionHistory::where('seller_id', auth()->user()->id)->orderBy('created_at', 'desc')->paginate(10);
|
||||
return CommissionHistoryResource::collection($commission_history);
|
||||
}
|
||||
|
||||
public function store(SellerRegistrationRequest $request)
|
||||
{
|
||||
$user = new User;
|
||||
$user->name = $request->name;
|
||||
$user->email = $request->email;
|
||||
$user->user_type = "seller";
|
||||
$user->password = Hash::make($request->password);
|
||||
|
||||
if ($user->save()) {
|
||||
$shop = new Shop;
|
||||
$shop->user_id = $user->id;
|
||||
$shop->name = $request->shop_name;
|
||||
$shop->address = $request->address;
|
||||
$shop->slug = preg_replace('/\s+/', '-', str_replace("/", " ", $request->shop_name));
|
||||
$shop->save();
|
||||
|
||||
if (BusinessSetting::where('type', 'email_verification')->first()->value != 1) {
|
||||
$user->email_verified_at = date('Y-m-d H:m:s');
|
||||
$user->save();
|
||||
} else {
|
||||
|
||||
try {
|
||||
$user->notify(new AppEmailVerificationNotification());
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$authController = new AuthController();
|
||||
return $authController->loginSuccess($user);
|
||||
}
|
||||
|
||||
return $this->failed(translate('Something Wenr Wrong!'));
|
||||
}
|
||||
|
||||
|
||||
public function getVerifyForm()
|
||||
{
|
||||
$forms = BusinessSetting::where('type', 'verification_form')->first();
|
||||
return response()->json(json_decode($forms->value));
|
||||
}
|
||||
|
||||
public function store_verify_info(Request $request)
|
||||
{
|
||||
$data = array();
|
||||
$i = 0;
|
||||
foreach (json_decode(BusinessSetting::where('type', 'verification_form')->first()->value) as $key => $element) {
|
||||
$item = array();
|
||||
if ($element->type == 'text') {
|
||||
$item['type'] = 'text';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_' . $i];
|
||||
} elseif ($element->type == 'select' || $element->type == 'radio') {
|
||||
$item['type'] = 'select';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_' . $i];
|
||||
} elseif ($element->type == 'multi_select') {
|
||||
$item['type'] = 'multi_select';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = json_encode($request['element_' . $i]);
|
||||
} elseif ($element->type == 'file') {
|
||||
$item['type'] = 'file';
|
||||
$item['label'] = $element->label;
|
||||
$item['value'] = $request['element_' . $i]->store('uploads/verification_form');
|
||||
}
|
||||
array_push($data, $item);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$shop = auth()->user()->shop;
|
||||
$shop->verification_info = json_encode($data);
|
||||
if ($shop->save()) {
|
||||
return $this->success(translate('Your shop verification request has been submitted successfully!'));
|
||||
}
|
||||
|
||||
return $this->failed(translate('Something Wenr Wrong!'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use CoreComponentRepository;
|
||||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductTranslation;
|
||||
use App\Services\WholesaleService;
|
||||
use App\Services\ProductTaxService;
|
||||
use App\Services\ProductFlashDealService;
|
||||
use App\Http\Requests\WholesaleProductRequest;
|
||||
use App\Http\Resources\V2\Seller\ProductCollection;
|
||||
use App\Http\Resources\V2\Seller\WholesaleProductDetailsCollection;
|
||||
use Auth;
|
||||
|
||||
class WholesaleProductController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// Wholesale Products list in Seller panel
|
||||
public function wholesale_products()
|
||||
{
|
||||
|
||||
$products = Product::where('wholesale_product', 1)->where('user_id', auth()->user()->id)->orderBy('created_at', 'desc');
|
||||
|
||||
$products = $products->paginate(15);
|
||||
|
||||
return new ProductCollection($products);
|
||||
}
|
||||
|
||||
public function product_store(WholesaleProductRequest $request)
|
||||
{
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (
|
||||
(auth()->user()->shop->seller_package == null) ||
|
||||
(auth()->user()->shop->seller_package->product_upload_limit <= auth()->user()->products()->count())
|
||||
) {
|
||||
return $this->failed(translate('Upload limit has been reached. Please upgrade your package.'));
|
||||
}
|
||||
}
|
||||
|
||||
$request->added_by= "seller";
|
||||
|
||||
$product = (new WholesaleService)->store($request->except([
|
||||
'_token', 'tax_id', 'tax', 'tax_type', 'flash_deal_id', 'flash_discount', 'flash_discount_type'
|
||||
]));
|
||||
$request->merge(['product_id' => $product->id]);
|
||||
//VAT & Tax
|
||||
if ($request->tax_id) {
|
||||
(new productTaxService)->store($request->only([
|
||||
'tax_id', 'tax', 'tax_type', 'product_id'
|
||||
]));
|
||||
}
|
||||
|
||||
// Product Translations
|
||||
$request->merge(['lang' => env('DEFAULT_LANGUAGE')]);
|
||||
ProductTranslation::create($request->only([
|
||||
'lang', 'name', 'unit', 'description', 'product_id'
|
||||
]));
|
||||
|
||||
return $this->success("Product successfully created.");
|
||||
}
|
||||
|
||||
|
||||
public function product_edit(Request $request, $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
$product->lang = $request->lang == null ? env("DEFAULT_LANGUAGE") : $request->lang;
|
||||
return new WholesaleProductDetailsCollection($product);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function product_update(WholesaleProductRequest $request, $id)
|
||||
{
|
||||
(new WholesaleService)->update($request, $id);
|
||||
|
||||
return $this->success(translate('Product has been updated successfully'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function product_destroy($id)
|
||||
{
|
||||
(new WholesaleService)->destroy($id);
|
||||
return $this->success("Product successfully deleted.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2\Seller;
|
||||
|
||||
use App\Http\Resources\V2\Seller\SellerWithdrawResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SellerWithdrawRequest;
|
||||
use Auth;
|
||||
use Response;
|
||||
|
||||
class WithdrawRequestController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$seller_withdraw_requests = SellerWithdrawRequest::where('user_id', auth()->user()->id)->latest()->paginate(10);
|
||||
return SellerWithdrawResource::collection($seller_withdraw_requests);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
if (auth()->user()->shop->admin_to_pay > 5) {
|
||||
if ($request->amount >= get_setting('minimum_seller_amount_withdraw') && $request->amount <= Auth::user()->shop->admin_to_pay) {
|
||||
$seller_withdraw_request = new SellerWithdrawRequest;
|
||||
$seller_withdraw_request->user_id = auth()->user()->id;
|
||||
$seller_withdraw_request->amount = $request->amount;
|
||||
$seller_withdraw_request->message = $request->message;
|
||||
$seller_withdraw_request->status = '0';
|
||||
$seller_withdraw_request->viewed = '0';
|
||||
|
||||
$seller_withdraw_request->save();
|
||||
|
||||
return $this->success(translate('Request has been sent successfully'));
|
||||
} else {
|
||||
return $this->failed(translate('Invalid amount'));
|
||||
}
|
||||
} else {
|
||||
return $this->failed(translate('You do not have enough balance to send withdraw request'));
|
||||
}
|
||||
}
|
||||
}
|
||||
17
desarrollo2/app/Http/Controllers/Api/V2/SellerController.php
Normal file
17
desarrollo2/app/Http/Controllers/Api/V2/SellerController.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Resources\V2\PurchaseHistoryMiniCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryCollection;
|
||||
use App\Http\Resources\V2\PurchaseHistoryItemsCollection;
|
||||
use App\Models\OrderDetail;
|
||||
|
||||
class SellerController extends Controller {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
126
desarrollo2/app/Http/Controllers/Api/V2/ShippingController.php
Normal file
126
desarrollo2/app/Http/Controllers/Api/V2/ShippingController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\AddressCollection;
|
||||
use App\Http\Resources\V2\PickupPointResource;
|
||||
use App\Models\Cart;
|
||||
use App\Models\City;
|
||||
use App\Models\PickupPoint;
|
||||
use App\Models\Product;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ShippingController extends Controller
|
||||
{
|
||||
public function pickup_list()
|
||||
{
|
||||
$pickup_point_list = PickupPoint::where('pick_up_status', '=', 1)->get();
|
||||
|
||||
return PickupPointResource::collection($pickup_point_list);
|
||||
// return response()->json(['result' => true, 'pickup_points' => $pickup_point_list], 200);
|
||||
}
|
||||
|
||||
public function shipping_cost(Request $request)
|
||||
{
|
||||
$main_carts = Cart::where('user_id', auth()->user()->id)->get();
|
||||
|
||||
foreach ($request->seller_list as $key => $seller) {
|
||||
$seller['shipping_cost'] = 0;
|
||||
|
||||
$carts = Cart::where('user_id', auth()->user()->id)->where("owner_id", $seller['seller_id'])->get();
|
||||
|
||||
foreach ($carts as $key => $cartItem) {
|
||||
$cartItem['shipping_cost'] = 0;
|
||||
|
||||
if($seller['shipping_type'] == 'pickup_point') {
|
||||
$cartItem['shipping_type'] = 'pickup_point';
|
||||
$cartItem['pickup_point'] = $seller['shipping_id'];
|
||||
}else
|
||||
if ($seller['shipping_type'] == 'home_delivery') {
|
||||
$cartItem['shipping_type'] = 'home_delivery';
|
||||
$cartItem['pickup_point'] = 0;
|
||||
|
||||
$cartItem['shipping_cost'] = getShippingCost($main_carts, $key);
|
||||
}else
|
||||
if ($seller['shipping_type'] == 'carrier') {
|
||||
$cartItem['shipping_type'] = 'carrier';
|
||||
$cartItem['pickup_point'] = 0;
|
||||
$cartItem['carrier_id'] = $seller['shipping_id'];
|
||||
$cartItem['shipping_cost'] = getShippingCost($carts, $key,$seller['shipping_id']);
|
||||
}
|
||||
|
||||
$cartItem->save();
|
||||
}
|
||||
}
|
||||
|
||||
//Total shipping cost $calculate_shipping
|
||||
$total_shipping_cost = Cart::where('user_id', auth()->user()->id)->sum('shipping_cost');
|
||||
return response()->json(['result' => true, 'shipping_type' => get_setting('shipping_type'), 'value' => convert_price($total_shipping_cost), 'value_string' => format_price($total_shipping_cost)], 200);
|
||||
}
|
||||
|
||||
|
||||
public function getDeliveryInfo()
|
||||
{
|
||||
$owner_ids = Cart::where('user_id', auth()->user()->id)->select('owner_id')->groupBy('owner_id')->pluck('owner_id')->toArray();
|
||||
$currency_symbol = currency_symbol();
|
||||
$shops = [];
|
||||
if (!empty($owner_ids)) {
|
||||
foreach ($owner_ids as $owner_id) {
|
||||
$shop = array();
|
||||
$shop_items_raw_data = Cart::where('user_id', auth()->user()->id)->where('owner_id', $owner_id)->get()->toArray();
|
||||
$shop_items_data = array();
|
||||
if (!empty($shop_items_raw_data)) {
|
||||
foreach ($shop_items_raw_data as $shop_items_raw_data_item) {
|
||||
$product = Product::where('id', $shop_items_raw_data_item["product_id"])->first();
|
||||
$shop_items_data_item["id"] = intval($shop_items_raw_data_item["id"]) ;
|
||||
$shop_items_data_item["owner_id"] =intval($shop_items_raw_data_item["owner_id"]) ;
|
||||
$shop_items_data_item["user_id"] =intval($shop_items_raw_data_item["user_id"]) ;
|
||||
$shop_items_data_item["product_id"] =intval($shop_items_raw_data_item["product_id"]) ;
|
||||
$shop_items_data_item["product_name"] = $product->getTranslation('name');
|
||||
$shop_items_data_item["product_thumbnail_image"] = uploaded_asset($product->thumbnail_img);
|
||||
/*
|
||||
$shop_items_data_item["variation"] = $shop_items_raw_data_item["variation"];
|
||||
$shop_items_data_item["price"] =(double) cart_product_price($shop_items_raw_data_item, $product, false, false);
|
||||
$shop_items_data_item["currency_symbol"] = $currency_symbol;
|
||||
$shop_items_data_item["tax"] =(double) cart_product_tax($shop_items_raw_data_item, $product,false);
|
||||
$shop_items_data_item["shipping_cost"] =(double) $shop_items_raw_data_item["shipping_cost"];
|
||||
$shop_items_data_item["quantity"] =intval($shop_items_raw_data_item["quantity"]) ;
|
||||
$shop_items_data_item["lower_limit"] = intval($product->min_qty) ;
|
||||
$shop_items_data_item["upper_limit"] = intval($product->stocks->where('variant', $shop_items_raw_data_item['variation'])->first()->qty) ;
|
||||
*/
|
||||
$shop_items_data[] = $shop_items_data_item;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$shop_data = Shop::where('user_id', $owner_id)->first();
|
||||
|
||||
|
||||
if ($shop_data) {
|
||||
$shop['name'] = $shop_data->name;
|
||||
$shop['owner_id'] =(int) $owner_id;
|
||||
$shop['cart_items'] = $shop_items_data;
|
||||
|
||||
} else {
|
||||
$shop['name'] = "Inhouse";
|
||||
$shop['owner_id'] =(int) $owner_id;
|
||||
$shop['cart_items'] = $shop_items_data;
|
||||
|
||||
}
|
||||
$shop['carriers'] = seller_base_carrier_list($owner_id);
|
||||
$shop['pickup_points']=[];
|
||||
if(get_setting('pickup_point') == 1){
|
||||
$pickup_point_list = PickupPoint::where('pick_up_status', '=', 1)->get();
|
||||
$shop['pickup_points'] = PickupPointResource::collection($pickup_point_list);
|
||||
}
|
||||
$shops[] = $shop;
|
||||
}
|
||||
}
|
||||
|
||||
//dd($shops);
|
||||
|
||||
return response()->json($shops);
|
||||
}
|
||||
}
|
||||
79
desarrollo2/app/Http/Controllers/Api/V2/ShopController.php
Normal file
79
desarrollo2/app/Http/Controllers/Api/V2/ShopController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\ProductCollection;
|
||||
use App\Http\Resources\V2\ProductMiniCollection;
|
||||
use App\Http\Resources\V2\ShopCollection;
|
||||
use App\Http\Resources\V2\ShopDetailsCollection;
|
||||
use App\Models\Product;
|
||||
use App\Models\Shop;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utility\SearchUtility;
|
||||
use Cache;
|
||||
|
||||
class ShopController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$shop_query = Shop::query();
|
||||
|
||||
if ($request->name != null && $request->name != "") {
|
||||
$shop_query->where("name", 'like', "%{$request->name}%");
|
||||
SearchUtility::store($request->name);
|
||||
}
|
||||
|
||||
return new ShopCollection($shop_query->whereIn('user_id', verified_sellers_id())->paginate(10));
|
||||
|
||||
//remove this , this is for testing
|
||||
//return new ShopCollection($shop_query->paginate(10));
|
||||
}
|
||||
|
||||
public function info($id)
|
||||
{
|
||||
return new ShopDetailsCollection(Shop::where('id', $id)->first());
|
||||
}
|
||||
|
||||
public function shopOfUser($id)
|
||||
{
|
||||
return new ShopCollection(Shop::where('user_id', $id)->get());
|
||||
}
|
||||
|
||||
public function allProducts($id)
|
||||
{
|
||||
$shop = Shop::findOrFail($id);
|
||||
return new ProductCollection(Product::where('user_id', $shop->user_id)->where('published',1)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function topSellingProducts($id)
|
||||
{
|
||||
$shop = Shop::findOrFail($id);
|
||||
|
||||
return Cache::remember("app.top_selling_products-$id", 86400, function () use ($shop){
|
||||
return new ProductMiniCollection(Product::where('user_id', $shop->user_id)->where('published',1)->orderBy('num_of_sale', 'desc')->limit(10)->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function featuredProducts($id)
|
||||
{
|
||||
$shop = Shop::findOrFail($id);
|
||||
|
||||
return Cache::remember("app.featured_products-$id", 86400, function () use ($shop){
|
||||
return new ProductMiniCollection(Product::where(['user_id' => $shop->user_id, 'seller_featured' => 1])->where('published',1)->latest()->limit(10)->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function newProducts($id)
|
||||
{
|
||||
$shop = Shop::findOrFail($id);
|
||||
|
||||
return Cache::remember("app.new_products-$id", 86400, function () use ($shop){
|
||||
return new ProductMiniCollection(Product::where('user_id', $shop->user_id)->where('published',1)->orderBy('created_at', 'desc')->limit(10)->get());
|
||||
});
|
||||
}
|
||||
|
||||
public function brands($id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
29
desarrollo2/app/Http/Controllers/Api/V2/SliderController.php
Normal file
29
desarrollo2/app/Http/Controllers/Api/V2/SliderController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\SliderCollection;
|
||||
use Cache;
|
||||
|
||||
class SliderController extends Controller
|
||||
{
|
||||
public function sliders()
|
||||
{
|
||||
return new SliderCollection(get_setting('home_slider_images') != null ? json_decode(get_setting('home_slider_images'), true) : []);
|
||||
}
|
||||
|
||||
public function bannerOne()
|
||||
{
|
||||
return new SliderCollection(get_setting('home_banner1_images') != null ? json_decode(get_setting('home_banner1_images'), true) : []);
|
||||
}
|
||||
|
||||
public function bannerTwo()
|
||||
{
|
||||
return new SliderCollection(get_setting('home_banner2_images') != null ? json_decode(get_setting('home_banner2_images'), true) : []);
|
||||
}
|
||||
|
||||
public function bannerThree()
|
||||
{
|
||||
return new SliderCollection(get_setting('home_banner3_images') != null ? json_decode(get_setting('home_banner3_images'), true) : []);
|
||||
}
|
||||
}
|
||||
449
desarrollo2/app/Http/Controllers/Api/V2/SslCommerzController.php
Normal file
449
desarrollo2/app/Http/Controllers/Api/V2/SslCommerzController.php
Normal file
@@ -0,0 +1,449 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Http\Controllers\SSLCommerz;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
# IF BROWSE FROM LOCAL HOST, KEEP true
|
||||
if (!defined("SSLCZ_IS_LOCAL_HOST")) {
|
||||
define("SSLCZ_IS_LOCAL_HOST", true);
|
||||
}
|
||||
|
||||
class SslCommerzController extends Controller
|
||||
{
|
||||
public $sslc_submit_url;
|
||||
public $sslc_validation_url;
|
||||
public $sslc_mode;
|
||||
public $sslc_data;
|
||||
public $store_id;
|
||||
public $store_pass;
|
||||
public $error = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
# IF SANDBOX TRUE, THEN IT WILL CONNECT WITH SSLCOMMERZ SANDBOX (TEST) SYSTEM
|
||||
if (BusinessSetting::where('type', 'sslcommerz_sandbox')->first()->value == 1) {
|
||||
$this->setSSLCommerzMode(true);
|
||||
} else {
|
||||
$this->setSSLCommerzMode(false);
|
||||
}
|
||||
|
||||
$this->store_id = env('SSLCZ_STORE_ID');
|
||||
$this->store_pass = env('SSLCZ_STORE_PASSWD');
|
||||
|
||||
$this->sslc_submit_url = "https://" . $this->sslc_mode . ".sslcommerz.com/gwprocess/v3/api.php";
|
||||
$this->sslc_validation_url = "https://" . $this->sslc_mode . ".sslcommerz.com/validator/api/validationserverAPI.php";
|
||||
}
|
||||
|
||||
public function begin(Request $request)
|
||||
{
|
||||
|
||||
$payment_type = $request->payment_type;
|
||||
$combined_order_id = $request->combined_order_id;
|
||||
$amount = $request->amount;
|
||||
$user_id = $request->user_id;
|
||||
|
||||
$post_data = array();
|
||||
$post_data['total_amount'] = $request->amount; # You cant not pay less than 10
|
||||
$post_data['currency'] = "BDT";
|
||||
|
||||
if ($request->payment_type == "cart_payment") {
|
||||
$post_data['tran_id'] = 'AIZ-' . $request->combined_order_id . '-' . date('Ymd'); // tran_id must be unique
|
||||
|
||||
} else if (
|
||||
$request->payment_type == "wallet_payment" ||
|
||||
$request->payment_type == "seller_package_payment" ||
|
||||
$request->payment_type == "customer_package_payment"
|
||||
|
||||
) {
|
||||
$post_data['tran_id'] = 'AIZ-' . $request->user_id . '-' . date('Ymd');
|
||||
}
|
||||
|
||||
$post_data['value_a'] = $request->user_id;
|
||||
$post_data['value_b'] = $request->combined_order_id;
|
||||
$post_data['value_c'] = $request->payment_type;
|
||||
$post_data['value_d'] = $request->amount;
|
||||
|
||||
if ($request->payment_type == "cart_payment") {
|
||||
$combined_order = CombinedOrder::find($combined_order_id);
|
||||
$post_data['value_d'] = $combined_order->grand_total;
|
||||
} else if ($request->payment_type == "wallet_payment") {
|
||||
$post_data['value_b'] = 'sslcommerz';
|
||||
} else if ($request->payment_type == "seller_package_payment" || $request->payment_type == "customer_package_payment") {
|
||||
$post_data['value_b'] = $request->package_id;
|
||||
}
|
||||
|
||||
|
||||
# CUSTOMER INFORMATION
|
||||
$post_data['cus_name'] = "Customer Name";
|
||||
$post_data['cus_add1'] = "Customer Address";
|
||||
$post_data['cus_city'] = "Customer City";
|
||||
$post_data['cus_postcode'] = "1234";
|
||||
$post_data['cus_country'] = "Bangladesh";
|
||||
$post_data['cus_phone'] = "123456123";
|
||||
$post_data['cus_email'] = "some@mail.com";
|
||||
|
||||
|
||||
$post_data['success_url'] = url("api/v2/sslcommerz/success");
|
||||
$post_data['fail_url'] = url("api/v2/sslcommerz/fail");
|
||||
$post_data['cancel_url'] = url("api/v2/sslcommerz/cancel");
|
||||
|
||||
return $this->initiate($post_data);
|
||||
}
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
$sslc = new SSLCommerz();
|
||||
#Start to received these value from session. which was saved in index function.
|
||||
$tran_id = $request->value_a;
|
||||
#End to received these value from session. which was saved in index function.
|
||||
$payment = json_encode($request->all());
|
||||
|
||||
if (isset($request->value_c)) {
|
||||
|
||||
try {
|
||||
if ($request->value_c == 'cart_payment') {
|
||||
|
||||
checkout_done($request->value_b, $payment);
|
||||
} elseif ($request->value_c == 'wallet_payment') {
|
||||
|
||||
wallet_payment_done($request->value_a, $request->value_d, 'SslCommerz', $payment);
|
||||
} elseif ($request->value_c == 'seller_package_payment') {
|
||||
|
||||
seller_purchase_payment_done($request->value_a, $request->value_b, $request->value_d, 'SslCommerz', $payment);
|
||||
} else if ($request->value_c == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($request->value_a, $request->value_b);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Payment Failed')
|
||||
]);
|
||||
|
||||
/*return response()->json([
|
||||
'result' => false,
|
||||
'payment_type'=> $payment_type,
|
||||
'message' => 'Payment Successful'
|
||||
]);*/
|
||||
}
|
||||
|
||||
public function payment_process(Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
public function payment_fail(Request $request)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Payment Failed')
|
||||
]);
|
||||
}
|
||||
|
||||
public function payment_cancel(Request $request)
|
||||
{
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'message' => translate('Payment Cancelled')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function initiate($post_data)
|
||||
{
|
||||
/*return response()->json([
|
||||
'post_data' => json_encode($post_data),
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => "gg",
|
||||
]);*/
|
||||
|
||||
if ($post_data != '' && is_array($post_data)) {
|
||||
|
||||
$post_data['store_id'] = $this->store_id;
|
||||
$post_data['store_passwd'] = $this->store_pass;
|
||||
|
||||
$load_sslc = $this->sendRequest($post_data);
|
||||
|
||||
if ($load_sslc) {
|
||||
if (isset($this->sslc_data['status']) && $this->sslc_data['status'] == 'SUCCESS') {
|
||||
if (isset($this->sslc_data['GatewayPageURL']) && $this->sslc_data['GatewayPageURL'] != '') {
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'url' => $this->sslc_data['GatewayPageURL'],
|
||||
'message' => 'Redirect Url is found'
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => 'No redirect URL found!'
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => "Invalid Credential!",
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => "Connectivity Issue. Please contact your sslcommerz manager",
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'url' => '',
|
||||
'message' => "Please provide a valid information list about transaction with transaction id, amount, success url, fail url, cancel url, store id and pass at least",
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# SEND CURL REQUEST
|
||||
public function sendRequest($data)
|
||||
{
|
||||
|
||||
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, $this->sslc_submit_url);
|
||||
curl_setopt($handle, CURLOPT_POST, 1);
|
||||
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
if (SSLCZ_IS_LOCAL_HOST) {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
|
||||
} else {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2); // Its default value is now 2
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, true);
|
||||
}
|
||||
|
||||
|
||||
$content = curl_exec($handle);
|
||||
|
||||
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code == 200 && !(curl_errno($handle))) {
|
||||
curl_close($handle);
|
||||
$sslcommerzResponse = $content;
|
||||
|
||||
# PARSE THE JSON RESPONSE
|
||||
$this->sslc_data = json_decode($sslcommerzResponse, true);
|
||||
|
||||
return $this;
|
||||
} else {
|
||||
curl_close($handle);
|
||||
$msg = "FAILED TO CONNECT WITH SSLCOMMERZ API";
|
||||
$this->error = $msg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# SET SSLCOMMERZ PAYMENT MODE - LIVE OR TEST
|
||||
public function setSSLCommerzMode($test)
|
||||
{
|
||||
if ($test) {
|
||||
$this->sslc_mode = "sandbox";
|
||||
} else {
|
||||
$this->sslc_mode = "securepay";
|
||||
}
|
||||
}
|
||||
|
||||
# VALIDATE SSLCOMMERZ TRANSACTION
|
||||
public function sslcommerz_validate($merchant_trans_id, $merchant_trans_amount, $merchant_trans_currency, $post_data)
|
||||
{
|
||||
# MERCHANT SYSTEM INFO
|
||||
if ($merchant_trans_id != "" && $merchant_trans_amount != 0) {
|
||||
|
||||
# CALL THE FUNCTION TO CHECK THE RESUKT
|
||||
$post_data['store_id'] = $this->store_id;
|
||||
$post_data['store_pass'] = $this->store_pass;
|
||||
|
||||
if ($this->SSLCOMMERZ_hash_varify($this->store_pass, $post_data)) {
|
||||
|
||||
$val_id = urlencode($post_data['val_id']);
|
||||
$store_id = urlencode($this->store_id);
|
||||
$store_passwd = urlencode($this->store_pass);
|
||||
$requested_url = ($this->sslc_validation_url . "?val_id=" . $val_id . "&store_id=" . $store_id . "&store_passwd=" . $store_passwd . "&v=1&format=json");
|
||||
|
||||
$handle = curl_init();
|
||||
curl_setopt($handle, CURLOPT_URL, $requested_url);
|
||||
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
if (SSLCZ_IS_LOCAL_HOST) {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
|
||||
} else {
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2); // Its default value is now 2
|
||||
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, true);
|
||||
}
|
||||
|
||||
|
||||
$result = curl_exec($handle);
|
||||
|
||||
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
|
||||
|
||||
if ($code == 200 && !(curl_errno($handle))) {
|
||||
|
||||
# TO CONVERT AS ARRAY
|
||||
# $result = json_decode($result, true);
|
||||
# $status = $result['status'];
|
||||
|
||||
# TO CONVERT AS OBJECT
|
||||
$result = json_decode($result);
|
||||
$this->sslc_data = $result;
|
||||
|
||||
# TRANSACTION INFO
|
||||
$status = $result->status;
|
||||
$tran_date = $result->tran_date;
|
||||
$tran_id = $result->tran_id;
|
||||
$val_id = $result->val_id;
|
||||
$amount = $result->amount;
|
||||
$store_amount = $result->store_amount;
|
||||
$bank_tran_id = $result->bank_tran_id;
|
||||
$card_type = $result->card_type;
|
||||
$currency_type = $result->currency_type;
|
||||
$currency_amount = $result->currency_amount;
|
||||
|
||||
# ISSUER INFO
|
||||
$card_no = $result->card_no;
|
||||
$card_issuer = $result->card_issuer;
|
||||
$card_brand = $result->card_brand;
|
||||
$card_issuer_country = $result->card_issuer_country;
|
||||
$card_issuer_country_code = $result->card_issuer_country_code;
|
||||
|
||||
# API AUTHENTICATION
|
||||
$APIConnect = $result->APIConnect;
|
||||
$validated_on = $result->validated_on;
|
||||
$gw_version = $result->gw_version;
|
||||
|
||||
# GIVE SERVICE
|
||||
if ($status == "VALID" || $status == "VALIDATED") {
|
||||
if ($merchant_trans_currency == "BDT") {
|
||||
if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $amount) < 1) && trim($merchant_trans_currency) == trim('BDT')) {
|
||||
return true;
|
||||
} else {
|
||||
# DATA TEMPERED
|
||||
$this->error = "Data has been tempered";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//echo "trim($merchant_trans_id) == trim($tran_id) && ( abs($merchant_trans_amount-$currency_amount) < 1 ) && trim($merchant_trans_currency)==trim($currency_type)";
|
||||
if (trim($merchant_trans_id) == trim($tran_id) && (abs($merchant_trans_amount - $currency_amount) < 1) && trim($merchant_trans_currency) == trim($currency_type)) {
|
||||
return true;
|
||||
} else {
|
||||
# DATA TEMPERED
|
||||
$this->error = "Data has been tempered";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
# FAILED TRANSACTION
|
||||
$this->error = "Failed Transaction";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
# Failed to connect with SSLCOMMERZ
|
||||
$this->error = "Faile to connect with SSLCOMMERZ";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
# Hash validation failed
|
||||
$this->error = "Hash validation failed";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
# INVALID DATA
|
||||
$this->error = "Invalid data";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# FUNCTION TO CHECK HASH VALUE
|
||||
public function SSLCOMMERZ_hash_varify($store_passwd = "", $post_data)
|
||||
{
|
||||
|
||||
if (isset($post_data) && isset($post_data['verify_sign']) && isset($post_data['verify_key'])) {
|
||||
# NEW ARRAY DECLARED TO TAKE VALUE OF ALL POST
|
||||
$pre_define_key = explode(',', $post_data['verify_key']);
|
||||
|
||||
$new_data = array();
|
||||
if (!empty($pre_define_key)) {
|
||||
foreach ($pre_define_key as $value) {
|
||||
if (isset($post_data[$value])) {
|
||||
$new_data[$value] = ($post_data[$value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
# ADD MD5 OF STORE PASSWORD
|
||||
$new_data['store_passwd'] = md5($store_passwd);
|
||||
|
||||
# SORT THE KEY AS BEFORE
|
||||
ksort($new_data);
|
||||
|
||||
$hash_string = "";
|
||||
foreach ($new_data as $key => $value) {
|
||||
$hash_string .= $key . '=' . ($value) . '&';
|
||||
}
|
||||
$hash_string = rtrim($hash_string, '&');
|
||||
|
||||
if (md5($hash_string) == $post_data['verify_sign']) {
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$this->error = "Verification signature not matched";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->error = 'Required data mission. ex: verify_key, verify_sign';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# FUNCTION TO GET IMAGES FROM WEB
|
||||
public function _get_image($gw = "", $source = array())
|
||||
{
|
||||
$logo = "";
|
||||
if (!empty($source) && isset($source['desc'])) {
|
||||
|
||||
foreach ($source['desc'] as $key => $volume) {
|
||||
|
||||
if (isset($volume['gw']) && $volume['gw'] == $gw) {
|
||||
|
||||
if (isset($volume['logo'])) {
|
||||
$logo = str_replace("/gw/", "/gw1/", $volume['logo']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $logo;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public function getResultData()
|
||||
{
|
||||
return $this->sslc_data;
|
||||
}
|
||||
}
|
||||
122
desarrollo2/app/Http/Controllers/Api/V2/StripeController.php
Normal file
122
desarrollo2/app/Http/Controllers/Api/V2/StripeController.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Models\CustomerPackage;
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CustomerPackageController;
|
||||
use App\Http\Controllers\WalletController;
|
||||
use App\Models\CombinedOrder;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Http\Request;
|
||||
use Stripe\Exception\CardException;
|
||||
use Stripe\PaymentIntent;
|
||||
use Stripe\Stripe;
|
||||
|
||||
class StripeController extends Controller
|
||||
{
|
||||
public function stripe(Request $request)
|
||||
{
|
||||
$data['payment_type'] = $request->payment_type;
|
||||
$data['combined_order_id'] = $request->combined_order_id;
|
||||
$data['amount'] = $request->amount;
|
||||
$data['user_id'] = $request->user_id;
|
||||
$data['package_id'] = 0;
|
||||
|
||||
|
||||
if(isset($request->package_id)) {
|
||||
$data['package_id'] = $request->package_id;
|
||||
}
|
||||
|
||||
return view('frontend.payment.stripe_app', $data);
|
||||
}
|
||||
|
||||
public function create_checkout_session(Request $request)
|
||||
{
|
||||
$amount = 0;
|
||||
|
||||
if ($request->payment_type == 'cart_payment') {
|
||||
$combined_order = CombinedOrder::find($request->combined_order_id);
|
||||
$amount = round($combined_order->grand_total * 100);
|
||||
} elseif ($request->payment_type == 'wallet_payment') {
|
||||
$amount = round($request->amount * 100);
|
||||
} elseif ($request->payment_type == 'customer_package_payment') {
|
||||
$amount = round($request->amount * 100);
|
||||
} elseif ($request->payment_type == 'seller_package_payment') {
|
||||
$amount = round($request->amount * 100);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['payment_type'] = $request->payment_type;
|
||||
$data['combined_order_id'] = $request->combined_order_id;
|
||||
$data['amount'] = $request->amount;
|
||||
$data['user_id'] = $request->user_id;
|
||||
$data['package_id'] = $request->package_id;
|
||||
|
||||
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
|
||||
|
||||
$session = \Stripe\Checkout\Session::create([
|
||||
'payment_method_types' => ['card'],
|
||||
'line_items' => [
|
||||
[
|
||||
'price_data' => [
|
||||
'currency' => Currency::findOrFail(get_setting('system_default_currency'))->code,
|
||||
'product_data' => [
|
||||
'name' => "Payment"
|
||||
],
|
||||
'unit_amount' => $amount,
|
||||
],
|
||||
'quantity' => 1,
|
||||
]
|
||||
],
|
||||
'mode' => 'payment',
|
||||
'client_reference_id' => json_encode($data),
|
||||
// 'success_url' => route('api.stripe.success', $data),
|
||||
'success_url' => env('APP_URL') . "/api/v2/stripe/success?session_id={CHECKOUT_SESSION_ID}",
|
||||
'cancel_url' => route('api.stripe.cancel'),
|
||||
]);
|
||||
|
||||
return response()->json(['id' => $session->id, 'status' => 200]);
|
||||
}
|
||||
|
||||
public function payment_success(Request $request)
|
||||
{
|
||||
$stripe = new \Stripe\StripeClient(env('STRIPE_SECRET'));
|
||||
|
||||
try {
|
||||
$session = $stripe->checkout->sessions->retrieve($request->session_id);
|
||||
|
||||
$decoded_reference_data = json_decode($session->client_reference_id);
|
||||
|
||||
$payment = ["status" => "Success"];
|
||||
|
||||
$payment_type = $decoded_reference_data->payment_type;
|
||||
|
||||
if ($payment_type == 'cart_payment') {
|
||||
checkout_done($decoded_reference_data->combined_order_id, json_encode($payment));
|
||||
}
|
||||
|
||||
if ($payment_type == 'wallet_payment') {
|
||||
wallet_payment_done($decoded_reference_data->user_id, $decoded_reference_data->amount, 'Stripe', json_encode($payment));
|
||||
}
|
||||
|
||||
if ($payment_type == 'seller_package_payment') {
|
||||
seller_purchase_payment_done($decoded_reference_data->user_id, $decoded_reference_data->package_id, $decoded_reference_data->amount, 'Stripe', json_encode($payment));
|
||||
}
|
||||
if ($payment_type == 'customer_package_payment') {
|
||||
customer_purchase_payment_done($decoded_reference_data->user_id, $decoded_reference_data->package_id);
|
||||
}
|
||||
|
||||
return response()->json(['result' => true, 'message' => translate("Payment is successful")]);
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => translate("Payment is failed")]);
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
return response()->json(['result' => false, 'message' => translate("Payment is cancelled")]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\CategoryCollection;
|
||||
use App\Models\Category;
|
||||
|
||||
class SubCategoryController extends Controller
|
||||
{
|
||||
public function index($id)
|
||||
{
|
||||
return new CategoryCollection(Category::where('parent_id', $id)->get());
|
||||
}
|
||||
}
|
||||
68
desarrollo2/app/Http/Controllers/Api/V2/UserController.php
Normal file
68
desarrollo2/app/Http/Controllers/Api/V2/UserController.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\UserCollection;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Laravel\Sanctum\PersonalAccessToken;
|
||||
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function info($id)
|
||||
{
|
||||
return new UserCollection(User::where('id', auth()->user()->id)->get());
|
||||
}
|
||||
|
||||
public function updateName(Request $request)
|
||||
{
|
||||
$user = User::findOrFail($request->user_id);
|
||||
$user->update([
|
||||
'name' => $request->name
|
||||
]);
|
||||
return response()->json([
|
||||
'message' => translate('Profile information has been updated successfully')
|
||||
]);
|
||||
}
|
||||
|
||||
public function getUserInfoByAccessToken(Request $request)
|
||||
{
|
||||
|
||||
$false_response = [
|
||||
'result' => false,
|
||||
'id' => 0,
|
||||
'name' => "",
|
||||
'email' => "",
|
||||
'avatar' => "",
|
||||
'avatar_original' => "",
|
||||
'phone' => ""
|
||||
];
|
||||
|
||||
|
||||
|
||||
$token = PersonalAccessToken::findToken($request->access_token);
|
||||
if (!$token) {
|
||||
return response()->json($false_response);
|
||||
}
|
||||
|
||||
$user = $token->tokenable;
|
||||
|
||||
|
||||
|
||||
if ($user == null) {
|
||||
return response()->json($false_response);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'avatar' => $user->avatar,
|
||||
'avatar_original' => uploaded_asset($user->avatar_original),
|
||||
'phone' => $user->phone
|
||||
]);
|
||||
}
|
||||
}
|
||||
71
desarrollo2/app/Http/Controllers/Api/V2/WalletController.php
Normal file
71
desarrollo2/app/Http/Controllers/Api/V2/WalletController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\WalletCollection;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WalletController extends Controller
|
||||
{
|
||||
public function balance()
|
||||
{
|
||||
$user = User::find(auth()->user()->id);
|
||||
$latest = Wallet::where('user_id', auth()->user()->id)->latest()->first();
|
||||
return response()->json([
|
||||
'balance' => format_price($user->balance),
|
||||
'last_recharged' => $latest == null ? "Not Available" : $latest->created_at->diffForHumans(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function walletRechargeHistory()
|
||||
{
|
||||
return new WalletCollection(Wallet::where('user_id', auth()->user()->id)->latest()->paginate(10));
|
||||
}
|
||||
|
||||
public function processPayment(Request $request)
|
||||
{
|
||||
$order = new OrderController;
|
||||
$user = User::find($request->user_id);
|
||||
|
||||
if ($user->balance >= $request->amount) {
|
||||
|
||||
$response = $order->store($request, true);
|
||||
$decoded_response = $response->original;
|
||||
if ($decoded_response['result'] == true) { // only decrease user balance with a success
|
||||
$user->balance -= $request->amount;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
} else {
|
||||
return response()->json([
|
||||
'result' => false,
|
||||
'combined_order_id' => 0,
|
||||
'message' => translate('Insufficient wallet balance')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function offline_recharge(Request $request)
|
||||
{
|
||||
$wallet = new Wallet;
|
||||
$wallet->user_id = auth()->user()->id;
|
||||
$wallet->amount = $request->amount;
|
||||
$wallet->payment_method = $request->payment_option;
|
||||
$wallet->payment_details = $request->trx_id;
|
||||
$wallet->approval = 0;
|
||||
$wallet->offline_payment = 1;
|
||||
$wallet->reciept = $request->photo;
|
||||
$wallet->save();
|
||||
// flash(translate('Offline Recharge has been done. Please wait for response.'))->success();
|
||||
//return redirect()->route('wallet.index');
|
||||
return response()->json([
|
||||
'result' => true,
|
||||
'message' => translate('Offline Recharge has been done. Please wait for response.')
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
108
desarrollo2/app/Http/Controllers/Api/V2/WishlistController.php
Normal file
108
desarrollo2/app/Http/Controllers/Api/V2/WishlistController.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V2;
|
||||
|
||||
use App\Http\Resources\V2\WishlistCollection;
|
||||
use App\Models\Wishlist;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WishlistController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$product_ids = Wishlist::where('user_id', auth()->user()->id)->pluck("product_id")->toArray();
|
||||
$existing_product_ids = Product::whereIn('id', $product_ids)->pluck("id")->toArray();
|
||||
|
||||
$query = Wishlist::query();
|
||||
$query->where('user_id', auth()->user()->id)->whereIn("product_id", $existing_product_ids);
|
||||
|
||||
return new WishlistCollection($query->latest()->get());
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
Wishlist::updateOrCreate(
|
||||
['user_id' => $request->user_id, 'product_id' => $request->product_id]
|
||||
);
|
||||
return response()->json(['message' => translate('Product is successfully added to your wishlist')], 201);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
Wishlist::destroy($id);
|
||||
return response()->json(['result' => true, 'message' => translate('Product is successfully removed from your wishlist')], 200);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['result' => false, 'message' => $e->getMessage()], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
$product = Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->count();
|
||||
if ($product > 0) {
|
||||
return response()->json([
|
||||
'message' => translate('Product present in wishlist'),
|
||||
'is_in_wishlist' => true,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => (integer)Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->first()->id
|
||||
], 200);
|
||||
} else {
|
||||
Wishlist::create(
|
||||
['user_id' =>auth()->user()->id, 'product_id' => $request->product_id]
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => translate('Product added to wishlist'),
|
||||
'is_in_wishlist' => true,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => (integer)Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->first()->id
|
||||
], 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function remove(Request $request)
|
||||
{
|
||||
$product = Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->count();
|
||||
if ($product == 0) {
|
||||
return response()->json([
|
||||
'message' => translate('Product in not in wishlist'),
|
||||
'is_in_wishlist' => false,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => 0
|
||||
], 200);
|
||||
} else {
|
||||
Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->delete();
|
||||
|
||||
return response()->json([
|
||||
'message' => translate('Product is removed from wishlist'),
|
||||
'is_in_wishlist' => false,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => 0
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
||||
public function isProductInWishlist(Request $request)
|
||||
{
|
||||
$product = Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->count();
|
||||
if ($product > 0)
|
||||
return response()->json([
|
||||
'message' => translate('Product present in wishlist'),
|
||||
'is_in_wishlist' => true,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => (integer)Wishlist::where(['product_id' => $request->product_id, 'user_id' => auth()->user()->id])->first()->id
|
||||
], 200);
|
||||
|
||||
return response()->json([
|
||||
'message' => translate('Product is not present in wishlist'),
|
||||
'is_in_wishlist' => false,
|
||||
'product_id' => (integer)$request->product_id,
|
||||
'wishlist_id' => 0
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
251
desarrollo2/app/Http/Controllers/AttributeController.php
Normal file
251
desarrollo2/app/Http/Controllers/AttributeController.php
Normal file
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Attribute;
|
||||
use App\Models\Color;
|
||||
use App\Models\AttributeTranslation;
|
||||
use App\Models\AttributeValue;
|
||||
use CoreComponentRepository;
|
||||
use Str;
|
||||
|
||||
class AttributeController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_product_attributes'])->only('index');
|
||||
$this->middleware(['permission:edit_product_attribute'])->only('edit');
|
||||
$this->middleware(['permission:delete_product_attribute'])->only('destroy');
|
||||
|
||||
$this->middleware(['permission:view_product_attribute_values'])->only('show');
|
||||
$this->middleware(['permission:edit_product_attribute_value'])->only('edit_attribute_value');
|
||||
$this->middleware(['permission:delete_product_attribute_value'])->only('destroy_attribute_value');
|
||||
|
||||
$this->middleware(['permission:view_colors'])->only('colors');
|
||||
$this->middleware(['permission:edit_color'])->only('edit_color');
|
||||
$this->middleware(['permission:delete_color'])->only('destroy_color');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
$attributes = Attribute::with('attribute_values')->orderBy('created_at', 'desc')->paginate(15);
|
||||
return view('backend.product.attribute.index', compact('attributes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
$attribute->name = $request->name;
|
||||
$attribute->save();
|
||||
|
||||
$attribute_translation = AttributeTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'attribute_id' => $attribute->id]);
|
||||
$attribute_translation->name = $request->name;
|
||||
$attribute_translation->save();
|
||||
|
||||
flash(translate('Attribute has been inserted successfully'))->success();
|
||||
return redirect()->route('attributes.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['attribute'] = Attribute::findOrFail($id);
|
||||
$data['all_attribute_values'] = AttributeValue::with('attribute')->where('attribute_id', $id)->get();
|
||||
|
||||
// echo '<pre>';print_r($data['all_attribute_values']);die;
|
||||
|
||||
return view("backend.product.attribute.attribute_value.index", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$lang = $request->lang;
|
||||
$attribute = Attribute::findOrFail($id);
|
||||
return view('backend.product.attribute.edit', compact('attribute','lang'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$attribute = Attribute::findOrFail($id);
|
||||
if($request->lang == env("DEFAULT_LANGUAGE")){
|
||||
$attribute->name = $request->name;
|
||||
}
|
||||
$attribute->save();
|
||||
|
||||
$attribute_translation = AttributeTranslation::firstOrNew(['lang' => $request->lang, 'attribute_id' => $attribute->id]);
|
||||
$attribute_translation->name = $request->name;
|
||||
$attribute_translation->save();
|
||||
|
||||
flash(translate('Attribute has been updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$attribute = Attribute::findOrFail($id);
|
||||
|
||||
foreach ($attribute->attribute_translations as $key => $attribute_translation) {
|
||||
$attribute_translation->delete();
|
||||
}
|
||||
|
||||
Attribute::destroy($id);
|
||||
flash(translate('Attribute has been deleted successfully'))->success();
|
||||
return redirect()->route('attributes.index');
|
||||
|
||||
}
|
||||
|
||||
public function store_attribute_value(Request $request)
|
||||
{
|
||||
$attribute_value = new AttributeValue;
|
||||
$attribute_value->attribute_id = $request->attribute_id;
|
||||
$attribute_value->value = ucfirst($request->value);
|
||||
$attribute_value->save();
|
||||
|
||||
flash(translate('Attribute value has been inserted successfully'))->success();
|
||||
return redirect()->route('attributes.show', $request->attribute_id);
|
||||
}
|
||||
|
||||
public function edit_attribute_value(Request $request, $id)
|
||||
{
|
||||
$attribute_value = AttributeValue::findOrFail($id);
|
||||
return view("backend.product.attribute.attribute_value.edit", compact('attribute_value'));
|
||||
}
|
||||
|
||||
public function update_attribute_value(Request $request, $id)
|
||||
{
|
||||
$attribute_value = AttributeValue::findOrFail($id);
|
||||
|
||||
$attribute_value->attribute_id = $request->attribute_id;
|
||||
$attribute_value->value = ucfirst($request->value);
|
||||
|
||||
$attribute_value->save();
|
||||
|
||||
flash(translate('Attribute value has been updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy_attribute_value($id)
|
||||
{
|
||||
$attribute_values = AttributeValue::findOrFail($id);
|
||||
AttributeValue::destroy($id);
|
||||
|
||||
flash(translate('Attribute value has been deleted successfully'))->success();
|
||||
return redirect()->route('attributes.show', $attribute_values->attribute_id);
|
||||
|
||||
}
|
||||
|
||||
public function colors(Request $request) {
|
||||
$sort_search = null;
|
||||
$colors = Color::orderBy('created_at', 'desc');
|
||||
|
||||
if ($request->search != null){
|
||||
$colors = $colors->where('name', 'like', '%'.$request->search.'%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
$colors = $colors->paginate(10);
|
||||
|
||||
return view('backend.product.color.index', compact('colors', 'sort_search'));
|
||||
}
|
||||
|
||||
public function store_color(Request $request) {
|
||||
$request->validate([
|
||||
'name' => 'required',
|
||||
'code' => 'required|unique:colors|max:255',
|
||||
]);
|
||||
$color = new Color;
|
||||
$color->name = Str::replace(' ', '', $request->name);
|
||||
$color->code = $request->code;
|
||||
|
||||
$color->save();
|
||||
|
||||
flash(translate('Color has been inserted successfully'))->success();
|
||||
return redirect()->route('colors');
|
||||
}
|
||||
|
||||
public function edit_color(Request $request, $id)
|
||||
{
|
||||
$color = Color::findOrFail($id);
|
||||
return view('backend.product.color.edit', compact('color'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the color.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update_color(Request $request, $id)
|
||||
{
|
||||
$color = Color::findOrFail($id);
|
||||
|
||||
$request->validate([
|
||||
'code' => 'required|unique:colors,code,'.$color->id,
|
||||
]);
|
||||
|
||||
$color->name = Str::replace(' ', '', $request->name);
|
||||
$color->code = $request->code;
|
||||
|
||||
$color->save();
|
||||
|
||||
flash(translate('Color has been updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function destroy_color($id)
|
||||
{
|
||||
Color::destroy($id);
|
||||
|
||||
flash(translate('Color has been deleted successfully'))->success();
|
||||
return redirect()->route('colors');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\AttributeValueRequest;
|
||||
use App\Models\AttributeValue;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AttributeValueController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(AttributeValueRequest $request, AttributeValue $attribute_value)
|
||||
{
|
||||
$attribute_value->update($request->validated());
|
||||
|
||||
flash(translate('Attribute value has been updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(AttributeValue $attribute_value)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
146
desarrollo2/app/Http/Controllers/AuctionProductBidController.php
Normal file
146
desarrollo2/app/Http/Controllers/AuctionProductBidController.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\AuctionProductBid;
|
||||
use App\Models\Product;
|
||||
use Auth;
|
||||
use Mail;
|
||||
use DB;
|
||||
use App\Mail\AuctionBidMailManager;
|
||||
|
||||
|
||||
class AuctionProductBidController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_auction_product_bids'])->only('product_bids_admin');
|
||||
$this->middleware(['permission:delete_auction_product_bids'])->only('bid_destroy_admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$bids = DB::table('auction_product_bids')
|
||||
->orderBy('id', 'desc')
|
||||
->join('products', 'auction_product_bids.product_id', '=', 'products.id')
|
||||
->where('auction_product_bids.user_id', Auth::user()->id)
|
||||
->select('auction_product_bids.id')
|
||||
->distinct()
|
||||
->paginate(10);
|
||||
return view('auction.frontend.my_bidded_products', compact('bids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$bid = AuctionProductBid::where('product_id', $request->product_id)->where('user_id', Auth::user()->id)->first();
|
||||
if ($bid == null) {
|
||||
$bid = new AuctionProductBid;
|
||||
$bid->user_id = Auth::user()->id;
|
||||
}
|
||||
$bid->product_id = $request->product_id;
|
||||
$bid->amount = $request->amount;
|
||||
if ($bid->save()) {
|
||||
$secound_max_bid = AuctionProductBid::where('product_id', $request->product_id)->orderBy('amount','desc')->skip(1)->first();
|
||||
if($secound_max_bid != null){
|
||||
if($secound_max_bid->user->email != null){
|
||||
$product = Product::where('id',$request->product_id)->first();
|
||||
$array['view'] = 'emails.auction_bid';
|
||||
$array['subject'] = translate('Auction Bid');
|
||||
$array['from'] = env('MAIL_FROM_ADDRESS');
|
||||
$array['content'] = 'Hi! A new user bidded more then you for the product, '.$product->name.'. '.'Highest bid amount: '.$bid->amount;
|
||||
$array['link'] = route('auction-product', $product->slug);
|
||||
try {
|
||||
Mail::to($secound_max_bid->user->email)->queue(new AuctionBidMailManager($array));
|
||||
} catch (\Exception $e) {
|
||||
//dd($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flash(translate('Bid Placed Successfully'))->success();
|
||||
} else {
|
||||
flash(translate('Something went wrong!'))->error();
|
||||
}
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
public function product_bids_admin($id)
|
||||
{
|
||||
$product = Product::where('id', $id)->first();
|
||||
$bids = AuctionProductBid::latest()->where('product_id', $id)->paginate(15);
|
||||
return view('auction.auction_products.bids', compact('bids', 'product'));
|
||||
}
|
||||
|
||||
public function product_bids_seller($id)
|
||||
{
|
||||
$product = Product::where('id', $id)->first();
|
||||
$bids = AuctionProductBid::latest()->where('product_id', $id)->paginate(15);
|
||||
return view('auction.frontend.seller.auction_products_bids', compact('bids', 'product'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function bid_destroy_admin($id)
|
||||
{
|
||||
AuctionProductBid::destroy($id);
|
||||
flash(translate('Bid deleted successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function bid_destroy_seller($id)
|
||||
{
|
||||
AuctionProductBid::destroy($id);
|
||||
flash(translate('Bid deleted successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
408
desarrollo2/app/Http/Controllers/AuctionProductController.php
Normal file
408
desarrollo2/app/Http/Controllers/AuctionProductController.php
Normal file
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Category;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderDetail;
|
||||
use App\Models\User;
|
||||
use App\Services\AuctionService;
|
||||
use App\Models\ProductQuery;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
|
||||
class AuctionProductController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_all_auction_products'])->only('all_auction_product_list');
|
||||
$this->middleware(['permission:view_inhouse_auction_products'])->only('inhouse_auction_products');
|
||||
$this->middleware(['permission:view_seller_auction_products'])->only('seller_auction_products');
|
||||
$this->middleware(['permission:add_auction_product'])->only('product_create_admin');
|
||||
$this->middleware(['permission:edit_auction_product'])->only('product_edit_admin');
|
||||
$this->middleware(['permission:delete_auction_product'])->only('product_destroy_admin');
|
||||
$this->middleware(['permission:view_auction_product_orders'])->only('admin_auction_product_orders');
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
// Auction products list admin panel
|
||||
public function all_auction_product_list(Request $request)
|
||||
{
|
||||
$sort_search = null;
|
||||
$seller_id = null;
|
||||
$type = 'all';
|
||||
$products = Product::orderBy('created_at', 'desc')->where('auction_product', 1);
|
||||
|
||||
if ($request->has('user_id') && $request->user_id != null) {
|
||||
$products = $products->where('user_id', $request->user_id);
|
||||
$seller_id = $request->user_id;
|
||||
}
|
||||
if ($request->search != null) {
|
||||
$products = $products->where('name', 'like', '%' . $request->search . '%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
|
||||
$products = $products->paginate(15);
|
||||
|
||||
return view('auction.auction_products.index', compact('products', 'sort_search', 'type', 'seller_id'));
|
||||
}
|
||||
|
||||
public function inhouse_auction_products(Request $request)
|
||||
{
|
||||
$sort_search = null;
|
||||
$seller_id = null;
|
||||
$type = 'in_house';
|
||||
$products = Product::where('added_by', 'admin')->orderBy('created_at', 'desc')->where('auction_product', 1);
|
||||
if ($request->search != null) {
|
||||
$products = $products->where('name', 'like', '%' . $request->search . '%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
|
||||
$products = $products->paginate(15);
|
||||
|
||||
return view('auction.auction_products.index', compact('products', 'sort_search', 'type', 'seller_id'));
|
||||
}
|
||||
|
||||
public function seller_auction_products(Request $request)
|
||||
{
|
||||
$sort_search = null;
|
||||
$seller_id = null;
|
||||
$type = 'seller';
|
||||
$products = Product::where('added_by', 'seller')->orderBy('created_at', 'desc')->where('auction_product', 1);
|
||||
|
||||
if ($request->has('user_id') && $request->user_id != null) {
|
||||
$products = $products->where('user_id', $request->user_id);
|
||||
$seller_id = $request->user_id;
|
||||
}
|
||||
|
||||
if ($request->search != null) {
|
||||
$products = $products
|
||||
->where('name', 'like', '%' . $request->search . '%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
|
||||
$products = $products->paginate(15);
|
||||
|
||||
return view('auction.auction_products.index', compact('products', 'sort_search', 'type', 'seller_id'));
|
||||
}
|
||||
// Auction products list admin panel end
|
||||
|
||||
// Auction Products list in Seller panel
|
||||
public function auction_product_list_seller(Request $request)
|
||||
{
|
||||
if (get_setting('seller_auction_product') == 0) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
$sort_search = null;
|
||||
$products = Product::where('auction_product', 1)->where('user_id', Auth::user()->id)->orderBy('created_at', 'desc');
|
||||
if ($request->search != null) {
|
||||
$products = $products
|
||||
->where('name', 'like', '%' . $request->search . '%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
|
||||
$products = $products->paginate(15);
|
||||
|
||||
return view('auction.frontend.seller.auction_product_list', compact('products', 'sort_search'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function product_create_admin()
|
||||
{
|
||||
$categories = Category::where('parent_id', 0)
|
||||
->where('digital', 0)
|
||||
->with('childrenCategories')
|
||||
->get();
|
||||
|
||||
return view('auction.auction_products.create', compact('categories'));
|
||||
}
|
||||
|
||||
public function product_create_seller()
|
||||
{
|
||||
$categories = Category::where('parent_id', 0)
|
||||
->where('digital', 0)
|
||||
->with('childrenCategories')
|
||||
->get();
|
||||
|
||||
if (get_setting('seller_auction_product') == 1) {
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (Auth::user()->shop->seller_package != null && Auth::user()->shop->seller_package->product_upload_limit > Auth::user()->products()->count()) {
|
||||
return view('auction.frontend.seller.auction_product_upload', compact('categories'));
|
||||
} else {
|
||||
flash(translate('Upload limit has been reached. Please upgrade your package.'))->warning();
|
||||
return back();
|
||||
}
|
||||
} else {
|
||||
return view('auction.frontend.seller.auction_product_upload', compact('categories'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function product_store_admin(Request $request)
|
||||
{
|
||||
(new AuctionService)->store($request);
|
||||
return redirect()->route('auction.inhouse_products');
|
||||
}
|
||||
|
||||
public function product_store_seller(Request $request)
|
||||
{
|
||||
if (addon_is_activated('seller_subscription')) {
|
||||
if (
|
||||
Auth::user()->shop->seller_package == null ||
|
||||
Auth::user()->shop->seller_package->product_upload_limit <= Auth::user()->products()->count()
|
||||
) {
|
||||
flash(translate('Upload limit has been reached. Please upgrade your package.'))->warning();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
(new AuctionService)->store($request);
|
||||
return redirect()->route('auction_products.seller.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function product_destroy_admin($id)
|
||||
{
|
||||
(new AuctionService)->destroy($id);
|
||||
return redirect()->route('auction.inhouse_products');
|
||||
}
|
||||
|
||||
public function product_destroy_seller($id)
|
||||
{
|
||||
(new AuctionService)->destroy($id);
|
||||
return redirect()->route('auction_products.seller.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function product_edit_admin(Request $request, $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
$lang = $request->lang;
|
||||
$tags = json_decode($product->tags);
|
||||
$categories = Category::where('parent_id', 0)
|
||||
->where('digital', 0)
|
||||
->with('childrenCategories')
|
||||
->get();
|
||||
return view('auction.auction_products.edit', compact('product', 'categories', 'tags', 'lang'));
|
||||
}
|
||||
|
||||
public function product_edit_seller(Request $request, $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
$lang = $request->lang;
|
||||
$tags = json_decode($product->tags);
|
||||
$categories = Category::where('parent_id', 0)
|
||||
->where('digital', 0)
|
||||
->with('childrenCategories')
|
||||
->get();
|
||||
|
||||
return view('auction.frontend.seller.auction_product_edit', compact('product', 'categories', 'tags', 'lang'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function product_update_admin(Request $request, $id)
|
||||
{
|
||||
(new AuctionService)->update($request, $id);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function product_update_seller(Request $request, $id)
|
||||
{
|
||||
(new AuctionService)->update($request, $id);
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
(new AuctionService)->destroy($id);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function get_products_by_brand(Request $request)
|
||||
{
|
||||
$products = Product::where('brand_id', $request->brand_id)->get();
|
||||
return view('partials.product_select', compact('products'));
|
||||
}
|
||||
|
||||
|
||||
public function updatePublished(Request $request)
|
||||
{
|
||||
$product = Product::findOrFail($request->id);
|
||||
$product->published = $request->status;
|
||||
|
||||
if ($product->added_by == 'seller' && addon_is_activated('seller_subscription')) {
|
||||
$seller = $product->user->shop;
|
||||
if ($seller->package_invalid_at != null && Carbon::now()->diffInDays(Carbon::parse($seller->package_invalid_at), false) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
$product->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function all_auction_products()
|
||||
{
|
||||
$products = Product::latest()->where('published', 1)->where('auction_product', 1);
|
||||
if (get_setting('seller_auction_product') == 0) {
|
||||
$products = $products->where('added_by', 'admin');
|
||||
}
|
||||
$products = $products->where('auction_start_date', '<=', strtotime("now"))->where('auction_end_date', '>=', strtotime("now"))->paginate(15);
|
||||
return view('auction.frontend.all_auction_products', compact('products'));
|
||||
}
|
||||
|
||||
public function auction_product_details(Request $request, $slug)
|
||||
{
|
||||
$detailedProduct = Product::where('slug', $slug)->first();
|
||||
$product_queries = ProductQuery::where('product_id', $detailedProduct->id)->where('customer_id', '!=', Auth::id())->latest('id')->paginate(3);
|
||||
$total_query = ProductQuery::where('product_id', $detailedProduct->id)->count();
|
||||
$reviews = $detailedProduct->reviews()->paginate(3);
|
||||
|
||||
// review status
|
||||
$review_status = 0;
|
||||
if (Auth::check()) {
|
||||
$OrderDetail = OrderDetail::with(['order' => function ($q) {
|
||||
$q->where('user_id', Auth::id());
|
||||
}])->where('product_id', $detailedProduct->id)->where('delivery_status', 'delivered')->first();
|
||||
$review_status = $OrderDetail ? 1 : 0;
|
||||
}
|
||||
|
||||
if ($detailedProduct != null) {
|
||||
return view('frontend.product_details', compact('detailedProduct', 'product_queries', 'total_query', 'reviews', 'review_status'));
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function purchase_history_user()
|
||||
{
|
||||
$orders = DB::table('orders')
|
||||
->orderBy('code', 'desc')
|
||||
->join('order_details', 'orders.id', '=', 'order_details.order_id')
|
||||
->join('products', 'order_details.product_id', '=', 'products.id')
|
||||
->where('orders.user_id', Auth::user()->id)
|
||||
->where('products.auction_product', '1')
|
||||
->select('order_details.order_id as id')
|
||||
->paginate(15);
|
||||
return view('auction.frontend.purchase_history', compact('orders'));
|
||||
}
|
||||
|
||||
public function admin_auction_product_orders(Request $request)
|
||||
{
|
||||
$payment_status = null;
|
||||
$delivery_status = null;
|
||||
$sort_search = null;
|
||||
$date = $request->date;
|
||||
$orders = DB::table('orders')
|
||||
->orderBy('code', 'desc')
|
||||
->join('order_details', 'orders.id', '=', 'order_details.order_id')
|
||||
->join('products', 'order_details.product_id', '=', 'products.id')
|
||||
->where('products.auction_product', '1')
|
||||
->select('orders.id');
|
||||
|
||||
if ($request->payment_status != null) {
|
||||
$orders = $orders->where('payment_status', $request->payment_status);
|
||||
$payment_status = $request->payment_status;
|
||||
}
|
||||
if ($request->delivery_status != null) {
|
||||
$orders = $orders->where('delivery_status', $request->delivery_status);
|
||||
$delivery_status = $request->delivery_status;
|
||||
}
|
||||
if ($request->has('search')) {
|
||||
$sort_search = $request->search;
|
||||
$orders = $orders->where('code', 'like', '%' . $sort_search . '%');
|
||||
}
|
||||
if ($date != null) {
|
||||
$orders = $orders->whereDate('orders.created_at', '>=', date('Y-m-d', strtotime(explode(" to ", $date)[0])))->whereDate('orders.created_at', '<=', date('Y-m-d', strtotime(explode(" to ", $date)[1])));
|
||||
}
|
||||
|
||||
$orders = $orders->paginate(15);
|
||||
|
||||
return view('auction.auction_product_orders', compact('orders', 'payment_status', 'delivery_status', 'sort_search', 'date'));
|
||||
}
|
||||
|
||||
public function auction_orders_show($id)
|
||||
{
|
||||
$order = Order::findOrFail(decrypt($id));
|
||||
$order_shipping_address = json_decode($order->shipping_address);
|
||||
$delivery_boys = User::where('city', $order_shipping_address->city)
|
||||
->where('user_type', 'delivery_boy')
|
||||
->get();
|
||||
|
||||
$order->viewed = 1;
|
||||
$order->save();
|
||||
|
||||
return view('auction.auction_product_order_details', compact('order', 'delivery_boys'));
|
||||
}
|
||||
|
||||
public function seller_auction_product_orders(Request $request)
|
||||
{
|
||||
if (get_setting('seller_auction_product') == 0) {
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
||||
$payment_status = null;
|
||||
$delivery_status = null;
|
||||
$sort_search = null;
|
||||
$orders = DB::table('orders')
|
||||
->orderBy('code', 'desc')
|
||||
->where('orders.seller_id', Auth::user()->id)
|
||||
->join('order_details', 'orders.id', '=', 'order_details.order_id')
|
||||
->join('products', 'order_details.product_id', '=', 'products.id')
|
||||
->where('products.auction_product', '1')
|
||||
->select('orders.id');
|
||||
|
||||
|
||||
if ($request->payment_status != null) {
|
||||
$orders = $orders->where('payment_status', $request->payment_status);
|
||||
$payment_status = $request->payment_status;
|
||||
}
|
||||
if ($request->delivery_status != null) {
|
||||
$orders = $orders->where('delivery_status', $request->delivery_status);
|
||||
$delivery_status = $request->delivery_status;
|
||||
}
|
||||
if ($request->has('search')) {
|
||||
$sort_search = $request->search;
|
||||
$orders = $orders->where('code', 'like', '%' . $sort_search . '%');
|
||||
}
|
||||
|
||||
$orders = $orders->paginate(15);
|
||||
return view('auction.frontend.seller.auction_product_orders', compact('orders', 'payment_status', 'delivery_status', 'sort_search'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use App\Models\User;
|
||||
use App\Mail\SecondEmailVerifyMailManager;
|
||||
use App\Utility\SmsUtility;
|
||||
use Mail;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reset link to the given user.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function sendResetLinkEmail(Request $request)
|
||||
{
|
||||
$phone = "+{$request['country_code']}{$request['phone']}";
|
||||
if (filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
||||
$user = User::where('email', $request->email)->first();
|
||||
if ($user != null) {
|
||||
$user->verification_code = rand(100000,999999);
|
||||
$user->save();
|
||||
|
||||
$array['view'] = 'emails.verification';
|
||||
$array['from'] = env('MAIL_FROM_ADDRESS');
|
||||
$array['subject'] = translate('Password Reset');
|
||||
$array['content'] = translate('Verification Code is').': '. $user->verification_code;
|
||||
|
||||
Mail::to($user->email)->queue(new SecondEmailVerifyMailManager($array));
|
||||
|
||||
return view('auth.passwords.reset');
|
||||
}
|
||||
else {
|
||||
flash(translate('No account exists with this email'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
else{
|
||||
$user = User::where('phone', $phone)->first();
|
||||
if ($user != null) {
|
||||
$user->verification_code = rand(100000,999999);
|
||||
$user->save();
|
||||
SmsUtility::password_reset($user);
|
||||
return view('otp_systems.frontend.auth.passwords.reset_with_phone');
|
||||
}
|
||||
else {
|
||||
flash(translate('No account exists with this phone number'))->error();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
377
desarrollo2/app/Http/Controllers/Auth/LoginController.php
Normal file
377
desarrollo2/app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use GeneaLabs\LaravelSocialiter\Facades\Socialiter;
|
||||
use Socialite;
|
||||
use App\Models\User;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Cart;
|
||||
use App\Services\SocialRevoke;
|
||||
use Session;
|
||||
use Illuminate\Http\Request;
|
||||
use CoreComponentRepository;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use GuzzleHttp\Client;
|
||||
use Auth;
|
||||
use Storage;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
/*protected $redirectTo = '/';*/
|
||||
|
||||
|
||||
/**
|
||||
* Redirect the user to the Google authentication page.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function redirectToProvider($provider)
|
||||
{
|
||||
if (request()->get('query') == 'mobile_app') {
|
||||
request()->session()->put('login_from', 'mobile_app');
|
||||
}
|
||||
if ($provider == 'apple') {
|
||||
return Socialite::driver("sign-in-with-apple")
|
||||
->scopes(["name", "email"])
|
||||
->redirect();
|
||||
}
|
||||
return Socialite::driver($provider)->redirect();
|
||||
}
|
||||
|
||||
public function handleAppleCallback(Request $request)
|
||||
{
|
||||
try {
|
||||
$user = Socialite::driver("sign-in-with-apple")->user();
|
||||
} catch (\Exception $e) {
|
||||
flash(translate("Something Went wrong. Please try again."))->error();
|
||||
return redirect()->route('user.login');
|
||||
}
|
||||
//check if provider_id exist
|
||||
$existingUserByProviderId = User::where('provider_id', $user->id)->first();
|
||||
|
||||
if ($existingUserByProviderId) {
|
||||
$existingUserByProviderId->access_token = $user->token;
|
||||
$existingUserByProviderId->refresh_token = $user->refreshToken;
|
||||
if (!isset($user->user['is_private_email'])) {
|
||||
$existingUserByProviderId->email = $user->email;
|
||||
}
|
||||
$existingUserByProviderId->save();
|
||||
//proceed to login
|
||||
auth()->login($existingUserByProviderId, true);
|
||||
} else {
|
||||
//check if email exist
|
||||
$existing_or_new_user = User::firstOrNew([
|
||||
'email' => $user->email
|
||||
]);
|
||||
$existing_or_new_user->provider_id = $user->id;
|
||||
$existing_or_new_user->access_token = $user->token;
|
||||
$existing_or_new_user->refresh_token = $user->refreshToken;
|
||||
$existing_or_new_user->provider = 'apple';
|
||||
if (!$existing_or_new_user->exists) {
|
||||
$existing_or_new_user->name = 'Apple User';
|
||||
if ($user->name) {
|
||||
$existing_or_new_user->name = $user->name;
|
||||
}
|
||||
$existing_or_new_user->email = $user->email;
|
||||
$existing_or_new_user->email_verified_at = date('Y-m-d H:m:s');
|
||||
}
|
||||
$existing_or_new_user->save();
|
||||
|
||||
auth()->login($existing_or_new_user, true);
|
||||
}
|
||||
|
||||
if (session('temp_user_id') != null) {
|
||||
Cart::where('temp_user_id', session('temp_user_id'))
|
||||
->update([
|
||||
'user_id' => auth()->user()->id,
|
||||
'temp_user_id' => null
|
||||
]);
|
||||
|
||||
Session::forget('temp_user_id');
|
||||
}
|
||||
|
||||
if (session('link') != null) {
|
||||
return redirect(session('link'));
|
||||
} else {
|
||||
if (auth()->user()->user_type == 'seller') {
|
||||
return redirect()->route('seller.dashboard');
|
||||
}
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Obtain the user information from Google.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function handleProviderCallback(Request $request, $provider)
|
||||
{
|
||||
if (session('login_from') == 'mobile_app') {
|
||||
return $this->mobileHandleProviderCallback($request, $provider);
|
||||
}
|
||||
try {
|
||||
if ($provider == 'twitter') {
|
||||
$user = Socialite::driver('twitter')->user();
|
||||
} else {
|
||||
$user = Socialite::driver($provider)->stateless()->user();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
flash(translate("Something Went wrong. Please try again."))->error();
|
||||
return redirect()->route('user.login');
|
||||
}
|
||||
|
||||
//check if provider_id exist
|
||||
$existingUserByProviderId = User::where('provider_id', $user->id)->first();
|
||||
|
||||
if ($existingUserByProviderId) {
|
||||
$existingUserByProviderId->access_token = $user->token;
|
||||
$existingUserByProviderId->save();
|
||||
//proceed to login
|
||||
auth()->login($existingUserByProviderId, true);
|
||||
} else {
|
||||
//check if email exist
|
||||
$existingUser = User::where('email', '!=', null)->where('email', $user->email)->first();
|
||||
|
||||
if ($existingUser) {
|
||||
//update provider_id
|
||||
$existing_User = $existingUser;
|
||||
$existing_User->provider_id = $user->id;
|
||||
$existing_User->provider = $provider;
|
||||
$existing_User->access_token = $user->token;
|
||||
$existing_User->save();
|
||||
|
||||
//proceed to login
|
||||
auth()->login($existing_User, true);
|
||||
} else {
|
||||
//create a new user
|
||||
$newUser = new User;
|
||||
$newUser->name = $user->name;
|
||||
$newUser->email = $user->email;
|
||||
$newUser->email_verified_at = date('Y-m-d Hms');
|
||||
$newUser->provider_id = $user->id;
|
||||
$newUser->provider = $provider;
|
||||
$newUser->access_token = $user->token;
|
||||
$newUser->save();
|
||||
//proceed to login
|
||||
auth()->login($newUser, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (session('temp_user_id') != null) {
|
||||
Cart::where('temp_user_id', session('temp_user_id'))
|
||||
->update([
|
||||
'user_id' => auth()->user()->id,
|
||||
'temp_user_id' => null
|
||||
]);
|
||||
|
||||
Session::forget('temp_user_id');
|
||||
}
|
||||
|
||||
if (session('link') != null) {
|
||||
return redirect(session('link'));
|
||||
} else {
|
||||
if (auth()->user()->user_type == 'seller') {
|
||||
return redirect()->route('seller.dashboard');
|
||||
}
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
public function mobileHandleProviderCallback($request, $provider)
|
||||
{
|
||||
$return_provider = '';
|
||||
$result = false;
|
||||
if ($provider) {
|
||||
$return_provider = $provider;
|
||||
$result = true;
|
||||
}
|
||||
return response()->json([
|
||||
'result' => $result,
|
||||
'provider' => $return_provider
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the user login request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
protected function validateLogin(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required_without:phone',
|
||||
'phone' => 'required_without:email',
|
||||
'password' => 'required|string',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the needed authorization credentials from the request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
protected function credentials(Request $request)
|
||||
{
|
||||
if ($request->get('phone') != null) {
|
||||
return ['phone' => "+{$request['country_code']}{$request['phone']}", 'password' => $request->get('password')];
|
||||
} elseif ($request->get('email') != null) {
|
||||
return $request->only($this->username(), 'password');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user's role and redirect user based on their role
|
||||
* @return
|
||||
*/
|
||||
public function authenticated()
|
||||
{
|
||||
if (session('temp_user_id') != null) {
|
||||
Cart::where('temp_user_id', session('temp_user_id'))
|
||||
->update(
|
||||
[
|
||||
'user_id' => auth()->user()->id,
|
||||
'temp_user_id' => null
|
||||
]
|
||||
);
|
||||
|
||||
Session::forget('temp_user_id');
|
||||
}
|
||||
|
||||
if (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff') {
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
return redirect()->route('admin.dashboard');
|
||||
} elseif (auth()->user()->user_type == 'seller') {
|
||||
return redirect()->route('seller.dashboard');
|
||||
} else {
|
||||
|
||||
if (session('link') != null) {
|
||||
return redirect(session('link'));
|
||||
} else {
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the failed login response instance.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
protected function sendFailedLoginResponse(Request $request)
|
||||
{
|
||||
flash(translate('Invalid login credentials'))->error();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the user out of the application.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
{
|
||||
if (auth()->user() != null && (auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff')) {
|
||||
$redirect_route = 'login';
|
||||
} else {
|
||||
$redirect_route = 'home';
|
||||
}
|
||||
|
||||
//User's Cart Delete
|
||||
// if (auth()->user()) {
|
||||
// Cart::where('user_id', auth()->user()->id)->delete();
|
||||
// }
|
||||
|
||||
$this->guard()->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
return $this->loggedOut($request) ?: redirect()->route($redirect_route);
|
||||
}
|
||||
|
||||
public function account_deletion(Request $request)
|
||||
{
|
||||
|
||||
$redirect_route = 'home';
|
||||
|
||||
if (auth()->user()) {
|
||||
Cart::where('user_id', auth()->user()->id)->delete();
|
||||
}
|
||||
|
||||
// if (auth()->user()->provider) {
|
||||
// $social_revoke = new SocialRevoke;
|
||||
// $revoke_output = $social_revoke->apply(auth()->user()->provider);
|
||||
|
||||
// if ($revoke_output) {
|
||||
// }
|
||||
// }
|
||||
|
||||
$auth_user = auth()->user();
|
||||
|
||||
// user images delete from database and file storage
|
||||
$uploads = $auth_user->uploads;
|
||||
if ($uploads) {
|
||||
foreach ($uploads as $upload) {
|
||||
if (env('FILESYSTEM_DRIVER') == 's3') {
|
||||
Storage::disk('s3')->delete($upload->file_name);
|
||||
if (file_exists(public_path() . '/' . $upload->file_name)) {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
$upload->delete();
|
||||
}
|
||||
} else {
|
||||
unlink(public_path() . '/' . $upload->file_name);
|
||||
$upload->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$auth_user->customer_products()->delete();
|
||||
|
||||
User::destroy(auth()->user()->id);
|
||||
|
||||
auth()->guard()->logout();
|
||||
$request->session()->invalidate();
|
||||
|
||||
flash(translate("Your account deletion successfully done."))->success();
|
||||
return redirect()->route($redirect_route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest')->except(['logout', 'account_deletion']);
|
||||
}
|
||||
}
|
||||
177
desarrollo2/app/Http/Controllers/Auth/RegisterController.php
Normal file
177
desarrollo2/app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use Nexmo;
|
||||
use Cookie;
|
||||
use Session;
|
||||
use App\Models\Cart;
|
||||
use App\Models\User;
|
||||
use Twilio\Rest\Client;
|
||||
|
||||
use App\Rules\Recaptcha;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\OtpConfiguration;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\BusinessSetting;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use App\Http\Controllers\OTPVerificationController;
|
||||
use App\Notifications\EmailVerificationNotification;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
// protected $redirectTo = '/';
|
||||
|
||||
// /**
|
||||
// * Create a new controller instance.
|
||||
// *
|
||||
// * @return void
|
||||
// */
|
||||
// public function __construct()
|
||||
// {
|
||||
// $this->middleware('guest');
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Get a validator for an incoming registration request.
|
||||
// *
|
||||
// * @param array $data
|
||||
// * @return \Illuminate\Contracts\Validation\Validator
|
||||
// */
|
||||
// protected function validator(array $data)
|
||||
// {
|
||||
// return Validator::make($data, [
|
||||
// 'name' => 'required|string|max:255',
|
||||
// 'password' => 'required|string|min:6|confirmed',
|
||||
// 'g-recaptcha-response' => [
|
||||
// Rule::when(get_setting('google_recaptcha') == 1, ['required', new Recaptcha()], ['sometimes'])
|
||||
// ]
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Create a new user instance after a valid registration.
|
||||
// *
|
||||
// * @param array $data
|
||||
// * @return \App\Models\User
|
||||
// */
|
||||
// protected function create(array $data)
|
||||
// {
|
||||
// if (filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
|
||||
// $user = User::create([
|
||||
// 'name' => $data['name'],
|
||||
// 'email' => $data['email'],
|
||||
// 'password' => Hash::make($data['password']),
|
||||
// ]);
|
||||
// }
|
||||
// else {
|
||||
// if (addon_is_activated('otp_system')){
|
||||
// $user = User::create([
|
||||
// 'name' => $data['name'],
|
||||
// 'phone' => '+'.$data['country_code'].$data['phone'],
|
||||
// 'password' => Hash::make($data['password']),
|
||||
// 'verification_code' => rand(100000, 999999)
|
||||
// ]);
|
||||
|
||||
// $otpController = new OTPVerificationController;
|
||||
// $otpController->send_code($user);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(session('temp_user_id') != null){
|
||||
// Cart::where('temp_user_id', session('temp_user_id'))
|
||||
// ->update([
|
||||
// 'user_id' => $user->id,
|
||||
// 'temp_user_id' => null
|
||||
// ]);
|
||||
|
||||
// Session::forget('temp_user_id');
|
||||
// }
|
||||
|
||||
// if(Cookie::has('referral_code')){
|
||||
// $referral_code = Cookie::get('referral_code');
|
||||
// $referred_by_user = User::where('referral_code', $referral_code)->first();
|
||||
// if($referred_by_user != null){
|
||||
// $user->referred_by = $referred_by_user->id;
|
||||
// $user->save();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return $user;
|
||||
// }
|
||||
|
||||
// public function register(Request $request)
|
||||
// {
|
||||
// if (filter_var($request->email, FILTER_VALIDATE_EMAIL)) {
|
||||
// if(User::where('email', $request->email)->first() != null){
|
||||
// flash(translate('Email or Phone already exists.'));
|
||||
// return back();
|
||||
// }
|
||||
// }
|
||||
// elseif (User::where('phone', '+'.$request->country_code.$request->phone)->first() != null) {
|
||||
// flash(translate('Phone already exists.'));
|
||||
// return back();
|
||||
// }
|
||||
|
||||
// $this->validator($request->all())->validate();
|
||||
|
||||
// $user = $this->create($request->all());
|
||||
|
||||
// $this->guard()->login($user);
|
||||
|
||||
// if($user->email != null){
|
||||
// if(BusinessSetting::where('type', 'email_verification')->first()->value != 1){
|
||||
// $user->email_verified_at = date('Y-m-d H:m:s');
|
||||
// $user->save();
|
||||
// flash(translate('Registration successful.'))->success();
|
||||
// }
|
||||
// else {
|
||||
// try {
|
||||
// $user->sendEmailVerificationNotification();
|
||||
// flash(translate('Registration successful. Please verify your email.'))->success();
|
||||
// } catch (\Throwable $th) {
|
||||
// $user->delete();
|
||||
// flash(translate('Registration failed. Please try again later.'))->error();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return $this->registered($request, $user)
|
||||
// ?: redirect($this->redirectPath());
|
||||
// }
|
||||
|
||||
// protected function registered(Request $request, $user)
|
||||
// {
|
||||
// if ($user->email == null) {
|
||||
// return redirect()->route('verification');
|
||||
// }elseif(session('link') != null){
|
||||
// return redirect(session('link'));
|
||||
// }else {
|
||||
// return redirect()->route('home');
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
//protected $redirectTo = '/';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the response for a successful password reset.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param string $response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
protected function sendResetResponse(Request $request, $response)
|
||||
{
|
||||
if(auth()->user()->user_type == 'admin' || auth()->user()->user_type == 'staff')
|
||||
{
|
||||
return redirect()->route('admin.dashboard')
|
||||
->with('status', trans($response));
|
||||
}
|
||||
|
||||
return redirect()->route('home')
|
||||
->with('status', trans($response));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\VerifiesEmails;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\OTPVerificationController;
|
||||
class VerificationController extends Controller
|
||||
{
|
||||
|
||||
public function verify(Request $request, $id, $hash)
|
||||
{
|
||||
// Aquí debes implementar la lógica para verificar el token y marcar el correo electrónico como verificado
|
||||
// Puedes usar el $id y $hash para buscar el usuario en la base de datos y realizar la verificación
|
||||
|
||||
// Ejemplo de implementación:
|
||||
$user = User::find($id);
|
||||
|
||||
if ($user && hash_equals($hash, $user->confirmation_code)) {
|
||||
$user->email_verified_at = now();
|
||||
$user->save();
|
||||
|
||||
// Inicia sesión al usuario si lo deseas
|
||||
auth()->login($user);
|
||||
|
||||
// Redirige al usuario a la página de éxito o a donde desees
|
||||
return redirect()->route('shop.view.signup.complete');
|
||||
}
|
||||
|
||||
// Si la verificación falla, puedes redirigir al usuario a una página de error o mostrar un mensaje de error
|
||||
return redirect()->route('shop.view.email.verification');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
84
desarrollo2/app/Http/Controllers/BidController.php
Normal file
84
desarrollo2/app/Http/Controllers/BidController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BidController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
136
desarrollo2/app/Http/Controllers/BlogCategoryController.php
Normal file
136
desarrollo2/app/Http/Controllers/BlogCategoryController.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\BlogCategory;
|
||||
|
||||
class BlogCategoryController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_blog_categories'])->only('index');
|
||||
$this->middleware(['permission:add_blog_category'])->only('create');
|
||||
$this->middleware(['permission:edit_blog_category'])->only('edit');
|
||||
$this->middleware(['permission:delete_blog_category'])->only('destroy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$sort_search =null;
|
||||
$categories = BlogCategory::orderBy('category_name', 'asc');
|
||||
|
||||
if ($request->has('search')){
|
||||
$sort_search = $request->search;
|
||||
$categories = $categories->where('category_name', 'like', '%'.$sort_search.'%');
|
||||
}
|
||||
|
||||
$categories = $categories->paginate(15);
|
||||
return view('backend.blog_system.category.index', compact('categories', 'sort_search'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$all_categories = BlogCategory::all();
|
||||
return view('backend.blog_system.category.create', compact('all_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$request->validate([
|
||||
'category_name' => 'required|max:255',
|
||||
]);
|
||||
|
||||
$category = new BlogCategory;
|
||||
|
||||
$category->category_name = $request->category_name;
|
||||
$category->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->category_name));
|
||||
|
||||
$category->save();
|
||||
|
||||
|
||||
flash(translate('Blog category has been created successfully'))->success();
|
||||
return redirect()->route('blog-category.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$cateogry = BlogCategory::find($id);
|
||||
$all_categories = BlogCategory::all();
|
||||
|
||||
return view('backend.blog_system.category.edit', compact('cateogry','all_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'category_name' => 'required|max:255',
|
||||
]);
|
||||
|
||||
$category = BlogCategory::find($id);
|
||||
|
||||
$category->category_name = $request->category_name;
|
||||
$category->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->category_name));
|
||||
|
||||
$category->save();
|
||||
|
||||
|
||||
flash(translate('Blog category has been updated successfully'))->success();
|
||||
return redirect()->route('blog-category.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
BlogCategory::find($id)->delete();
|
||||
|
||||
return redirect('admin/blog-category');
|
||||
}
|
||||
}
|
||||
210
desarrollo2/app/Http/Controllers/BlogController.php
Normal file
210
desarrollo2/app/Http/Controllers/BlogController.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\BlogCategory;
|
||||
use App\Models\Blog;
|
||||
|
||||
class BlogController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_blogs'])->only('index');
|
||||
$this->middleware(['permission:add_blog'])->only('create');
|
||||
$this->middleware(['permission:edit_blog'])->only('edit');
|
||||
$this->middleware(['permission:delete_blog'])->only('destroy');
|
||||
$this->middleware(['permission:publish_blog'])->only('change_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$sort_search = null;
|
||||
$blogs = Blog::orderBy('created_at', 'desc');
|
||||
|
||||
if ($request->search != null){
|
||||
$blogs = $blogs->where('title', 'like', '%'.$request->search.'%');
|
||||
$sort_search = $request->search;
|
||||
}
|
||||
|
||||
$blogs = $blogs->paginate(15);
|
||||
|
||||
return view('backend.blog_system.blog.index', compact('blogs','sort_search'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$blog_categories = BlogCategory::all();
|
||||
return view('backend.blog_system.blog.create', compact('blog_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$request->validate([
|
||||
'category_id' => 'required',
|
||||
'title' => 'required|max:255',
|
||||
]);
|
||||
|
||||
$blog = new Blog;
|
||||
|
||||
$blog->category_id = $request->category_id;
|
||||
$blog->title = $request->title;
|
||||
$blog->banner = $request->banner;
|
||||
$blog->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug));
|
||||
$blog->short_description = $request->short_description;
|
||||
$blog->description = $request->description;
|
||||
|
||||
$blog->meta_title = $request->meta_title;
|
||||
$blog->meta_img = $request->meta_img;
|
||||
$blog->meta_description = $request->meta_description;
|
||||
$blog->meta_keywords = $request->meta_keywords;
|
||||
|
||||
$blog->save();
|
||||
|
||||
flash(translate('Blog post has been created successfully'))->success();
|
||||
return redirect()->route('blog.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$blog = Blog::find($id);
|
||||
$blog_categories = BlogCategory::all();
|
||||
|
||||
return view('backend.blog_system.blog.edit', compact('blog','blog_categories'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate([
|
||||
'category_id' => 'required',
|
||||
'title' => 'required|max:255',
|
||||
]);
|
||||
|
||||
$blog = Blog::find($id);
|
||||
|
||||
$blog->category_id = $request->category_id;
|
||||
$blog->title = $request->title;
|
||||
$blog->banner = $request->banner;
|
||||
$blog->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->slug));
|
||||
$blog->short_description = $request->short_description;
|
||||
$blog->description = $request->description;
|
||||
|
||||
$blog->meta_title = $request->meta_title;
|
||||
$blog->meta_img = $request->meta_img;
|
||||
$blog->meta_description = $request->meta_description;
|
||||
$blog->meta_keywords = $request->meta_keywords;
|
||||
|
||||
$blog->save();
|
||||
|
||||
flash(translate('Blog post has been updated successfully'))->success();
|
||||
return redirect()->route('blog.index');
|
||||
}
|
||||
|
||||
public function change_status(Request $request) {
|
||||
$blog = Blog::find($request->id);
|
||||
$blog->status = $request->status;
|
||||
|
||||
$blog->save();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
Blog::find($id)->delete();
|
||||
|
||||
return redirect('admin/blogs');
|
||||
}
|
||||
|
||||
|
||||
public function all_blog(Request $request) {
|
||||
$selected_categories = array();
|
||||
$search = null;
|
||||
$blogs = Blog::query();
|
||||
|
||||
if ($request->has('search')) {
|
||||
$search = $request->search;;
|
||||
$blogs->where(function ($q) use ($search) {
|
||||
foreach (explode(' ', trim($search)) as $word) {
|
||||
$q->where('title', 'like', '%' . $word . '%')
|
||||
->orWhere('short_description', 'like', '%' . $word . '%');
|
||||
}
|
||||
});
|
||||
|
||||
$case1 = $search . '%';
|
||||
$case2 = '%' . $search . '%';
|
||||
|
||||
$blogs->orderByRaw("CASE
|
||||
WHEN title LIKE '$case1' THEN 1
|
||||
WHEN title LIKE '$case2' THEN 2
|
||||
ELSE 3
|
||||
END");
|
||||
}
|
||||
|
||||
if ($request->has('selected_categories')) {
|
||||
$selected_categories = $request->selected_categories;
|
||||
$blog_categories = BlogCategory::whereIn('slug', $selected_categories)->pluck('id')->toArray();
|
||||
|
||||
$blogs->whereIn('category_id', $blog_categories);
|
||||
}
|
||||
|
||||
$blogs = $blogs->where('status', 1)->orderBy('created_at', 'desc')->paginate(12);
|
||||
|
||||
$recent_blogs = Blog::where('status', 1)->orderBy('created_at', 'desc')->limit(9)->get();
|
||||
|
||||
return view("frontend.blog.listing", compact('blogs', 'selected_categories', 'search', 'recent_blogs'));
|
||||
}
|
||||
|
||||
public function blog_details($slug) {
|
||||
$blog = Blog::where('slug', $slug)->first();
|
||||
$recent_blogs = Blog::where('status', 1)->orderBy('created_at', 'desc')->limit(9)->get();
|
||||
return view("frontend.blog.details", compact('blog', 'recent_blogs'));
|
||||
}
|
||||
}
|
||||
153
desarrollo2/app/Http/Controllers/BrandController.php
Normal file
153
desarrollo2/app/Http/Controllers/BrandController.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Brand;
|
||||
use App\Models\BrandTranslation;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BrandController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:view_all_brands'])->only('index');
|
||||
$this->middleware(['permission:add_brand'])->only('create');
|
||||
$this->middleware(['permission:edit_brand'])->only('edit');
|
||||
$this->middleware(['permission:delete_brand'])->only('destroy');
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$sort_search =null;
|
||||
$brands = Brand::orderBy('name', 'asc');
|
||||
if ($request->has('search')){
|
||||
$sort_search = $request->search;
|
||||
$brands = $brands->where('name', 'like', '%'.$sort_search.'%');
|
||||
}
|
||||
$brands = $brands->paginate(15);
|
||||
return view('backend.product.brands.index', compact('brands', 'sort_search'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$brand = new Brand;
|
||||
$brand->name = $request->name;
|
||||
$brand->meta_title = $request->meta_title;
|
||||
$brand->meta_description = $request->meta_description;
|
||||
if ($request->slug != null) {
|
||||
$brand->slug = str_replace(' ', '-', $request->slug);
|
||||
}
|
||||
else {
|
||||
$brand->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->name)).'-'.Str::random(5);
|
||||
}
|
||||
|
||||
$brand->logo = $request->logo;
|
||||
$brand->save();
|
||||
|
||||
$brand_translation = BrandTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'brand_id' => $brand->id]);
|
||||
$brand_translation->name = $request->name;
|
||||
$brand_translation->save();
|
||||
|
||||
flash(translate('Brand has been inserted successfully'))->success();
|
||||
return redirect()->route('brands.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Request $request, $id)
|
||||
{
|
||||
$lang = $request->lang;
|
||||
$brand = Brand::findOrFail($id);
|
||||
return view('backend.product.brands.edit', compact('brand','lang'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$brand = Brand::findOrFail($id);
|
||||
if($request->lang == env("DEFAULT_LANGUAGE")){
|
||||
$brand->name = $request->name;
|
||||
}
|
||||
$brand->meta_title = $request->meta_title;
|
||||
$brand->meta_description = $request->meta_description;
|
||||
if ($request->slug != null) {
|
||||
$brand->slug = strtolower($request->slug);
|
||||
}
|
||||
else {
|
||||
$brand->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $request->name)).'-'.Str::random(5);
|
||||
}
|
||||
$brand->logo = $request->logo;
|
||||
$brand->save();
|
||||
|
||||
$brand_translation = BrandTranslation::firstOrNew(['lang' => $request->lang, 'brand_id' => $brand->id]);
|
||||
$brand_translation->name = $request->name;
|
||||
$brand_translation->save();
|
||||
|
||||
flash(translate('Brand has been updated successfully'))->success();
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$brand = Brand::findOrFail($id);
|
||||
Product::where('brand_id', $brand->id)->delete();
|
||||
foreach ($brand->brand_translations as $key => $brand_translation) {
|
||||
$brand_translation->delete();
|
||||
}
|
||||
Brand::destroy($id);
|
||||
|
||||
flash(translate('Brand has been deleted successfully'))->success();
|
||||
return redirect()->route('brands.index');
|
||||
|
||||
}
|
||||
}
|
||||
546
desarrollo2/app/Http/Controllers/BusinessSettingsController.php
Normal file
546
desarrollo2/app/Http/Controllers/BusinessSettingsController.php
Normal file
@@ -0,0 +1,546 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\BusinessSetting;
|
||||
use Artisan;
|
||||
use CoreComponentRepository;
|
||||
|
||||
class BusinessSettingsController extends Controller
|
||||
{
|
||||
public function __construct() {
|
||||
// Staff Permission Check
|
||||
$this->middleware(['permission:seller_commission_configuration'])->only('vendor_commission');
|
||||
$this->middleware(['permission:seller_verification_form_configuration'])->only('seller_verification_form');
|
||||
$this->middleware(['permission:general_settings'])->only('general_setting');
|
||||
$this->middleware(['permission:features_activation'])->only('activation');
|
||||
$this->middleware(['permission:smtp_settings'])->only('smtp_settings');
|
||||
$this->middleware(['permission:payment_methods_configurations'])->only('payment_method');
|
||||
$this->middleware(['permission:order_configuration'])->only('order_configuration');
|
||||
$this->middleware(['permission:file_system_&_cache_configuration'])->only('file_system');
|
||||
$this->middleware(['permission:social_media_logins'])->only('social_login');
|
||||
$this->middleware(['permission:facebook_chat'])->only('facebook_chat');
|
||||
$this->middleware(['permission:facebook_comment'])->only('facebook_comment');
|
||||
$this->middleware(['permission:analytics_tools_configuration'])->only('google_analytics');
|
||||
$this->middleware(['permission:google_recaptcha_configuration'])->only('google_recaptcha');
|
||||
$this->middleware(['permission:google_map_setting'])->only('google_map');
|
||||
$this->middleware(['permission:google_firebase_setting'])->only('google_firebase');
|
||||
$this->middleware(['permission:shipping_configuration'])->only('shipping_configuration');
|
||||
}
|
||||
|
||||
public function general_setting(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.general_settings');
|
||||
}
|
||||
|
||||
public function activation(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.activation');
|
||||
}
|
||||
|
||||
public function social_login(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.social_login');
|
||||
}
|
||||
|
||||
public function smtp_settings(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.smtp_settings');
|
||||
}
|
||||
|
||||
public function google_analytics(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.google_configuration.google_analytics');
|
||||
}
|
||||
|
||||
public function google_recaptcha(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.google_configuration.google_recaptcha');
|
||||
}
|
||||
|
||||
public function google_map(Request $request) {
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.google_configuration.google_map');
|
||||
}
|
||||
|
||||
public function google_firebase(Request $request) {
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.google_configuration.google_firebase');
|
||||
}
|
||||
|
||||
public function facebook_chat(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.facebook_chat');
|
||||
}
|
||||
|
||||
public function facebook_comment(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.facebook_configuration.facebook_comment');
|
||||
}
|
||||
|
||||
public function payment_method(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.payment_method');
|
||||
}
|
||||
|
||||
public function file_system(Request $request)
|
||||
{
|
||||
CoreComponentRepository::instantiateShopRepository();
|
||||
CoreComponentRepository::initializeCache();
|
||||
return view('backend.setup_configurations.file_system');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the API key's for payment methods.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function payment_method_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', $request->payment_method.'_sandbox')->first();
|
||||
if($business_settings != null){
|
||||
if ($request->has($request->payment_method.'_sandbox')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the API key's for GOOGLE analytics.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function google_analytics_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'google_analytics')->first();
|
||||
|
||||
if ($request->has('google_analytics')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function google_recaptcha_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'google_recaptcha')->first();
|
||||
|
||||
if ($request->has('google_recaptcha')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function google_map_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'google_map')->first();
|
||||
|
||||
if ($request->has('google_map')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function google_firebase_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'google_firebase')->first();
|
||||
|
||||
if ($request->has('google_firebase')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the API key's for GOOGLE analytics.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function facebook_chat_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'facebook_chat')->first();
|
||||
|
||||
if ($request->has('facebook_chat')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function facebook_comment_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'facebook_comment')->first();
|
||||
if(!$business_settings) {
|
||||
$business_settings = new BusinessSetting;
|
||||
$business_settings->type = 'facebook_comment';
|
||||
}
|
||||
|
||||
$business_settings->value = 0;
|
||||
if ($request->facebook_comment) {
|
||||
$business_settings->value = 1;
|
||||
}
|
||||
|
||||
$business_settings->save();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function facebook_pixel_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', 'facebook_pixel')->first();
|
||||
|
||||
if ($request->has('facebook_pixel')) {
|
||||
$business_settings->value = 1;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings->value = 0;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the API key's for other methods.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function env_key_update(Request $request)
|
||||
{
|
||||
foreach ($request->types as $key => $type) {
|
||||
$this->overWriteEnvFile($type, $request[$type]);
|
||||
}
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* overWrite the Env File values.
|
||||
* @param String type
|
||||
* @param String value
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function overWriteEnvFile($type, $val)
|
||||
{
|
||||
if(env('DEMO_MODE') != 'On'){
|
||||
$path = base_path('.env');
|
||||
if (file_exists($path)) {
|
||||
$val = '"'.trim($val).'"';
|
||||
if(is_numeric(strpos(file_get_contents($path), $type)) && strpos(file_get_contents($path), $type) >= 0){
|
||||
file_put_contents($path, str_replace(
|
||||
$type.'="'.env($type).'"', $type.'='.$val, file_get_contents($path)
|
||||
));
|
||||
}
|
||||
else{
|
||||
file_put_contents($path, file_get_contents($path)."\r\n".$type.'='.$val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function seller_verification_form(Request $request)
|
||||
{
|
||||
return view('backend.sellers.seller_verification_form.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update sell verification form.
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function seller_verification_form_update(Request $request)
|
||||
{
|
||||
$form = array();
|
||||
$select_types = ['select', 'multi_select', 'radio'];
|
||||
$j = 0;
|
||||
for ($i=0; $i < count($request->type); $i++) {
|
||||
$item['type'] = $request->type[$i];
|
||||
$item['label'] = $request->label[$i];
|
||||
if(in_array($request->type[$i], $select_types)){
|
||||
$item['options'] = json_encode($request['options_'.$request->option[$j]]);
|
||||
$j++;
|
||||
}
|
||||
array_push($form, $item);
|
||||
}
|
||||
$business_settings = BusinessSetting::where('type', 'verification_form')->first();
|
||||
$business_settings->value = json_encode($form);
|
||||
if($business_settings->save()){
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Verification form updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
|
||||
foreach ($request->types as $key => $type) {
|
||||
if($type == 'site_name'){
|
||||
$this->overWriteEnvFile('APP_NAME', $request[$type]);
|
||||
}
|
||||
if($type == 'timezone'){
|
||||
$this->overWriteEnvFile('APP_TIMEZONE', $request[$type]);
|
||||
}
|
||||
else {
|
||||
$lang = null;
|
||||
if(gettype($type) == 'array'){
|
||||
$lang = array_key_first($type);
|
||||
$type = $type[$lang];
|
||||
$business_settings = BusinessSetting::where('type', $type)->where('lang',$lang)->first();
|
||||
}else{
|
||||
$business_settings = BusinessSetting::where('type', $type)->first();
|
||||
}
|
||||
|
||||
if($business_settings!=null){
|
||||
if(gettype($request[$type]) == 'array'){
|
||||
$business_settings->value = json_encode($request[$type]);
|
||||
}
|
||||
else {
|
||||
$business_settings->value = $request[$type];
|
||||
}
|
||||
$business_settings->lang = $lang;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings = new BusinessSetting;
|
||||
$business_settings->type = $type;
|
||||
if(gettype($request[$type]) == 'array'){
|
||||
$business_settings->value = json_encode($request[$type]);
|
||||
}
|
||||
else {
|
||||
$business_settings->value = $request[$type];
|
||||
}
|
||||
$business_settings->lang = $lang;
|
||||
$business_settings->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate("Settings updated successfully"))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function updateActivationSettings(Request $request)
|
||||
{
|
||||
$env_changes = ['FORCE_HTTPS', 'FILESYSTEM_DRIVER'];
|
||||
if (in_array($request->type, $env_changes)) {
|
||||
|
||||
return $this->updateActivationSettingsInEnv($request);
|
||||
}
|
||||
|
||||
$business_settings = BusinessSetting::where('type', $request->type)->first();
|
||||
if($business_settings!=null){
|
||||
if ($request->type == 'maintenance_mode' && $request->value == '1') {
|
||||
if(env('DEMO_MODE') != 'On'){
|
||||
Artisan::call('down');
|
||||
}
|
||||
}
|
||||
elseif ($request->type == 'maintenance_mode' && $request->value == '0') {
|
||||
if(env('DEMO_MODE') != 'On') {
|
||||
Artisan::call('up');
|
||||
}
|
||||
}
|
||||
$business_settings->value = $request->value;
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings = new BusinessSetting;
|
||||
$business_settings->type = $request->type;
|
||||
$business_settings->value = $request->value;
|
||||
$business_settings->save();
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
return '1';
|
||||
}
|
||||
|
||||
public function updateActivationSettingsInEnv($request)
|
||||
{
|
||||
if ($request->type == 'FORCE_HTTPS' && $request->value == '1') {
|
||||
$this->overWriteEnvFile($request->type, 'On');
|
||||
|
||||
if(strpos(env('APP_URL'), 'http:') !== FALSE) {
|
||||
$this->overWriteEnvFile('APP_URL', str_replace("http:", "https:", env('APP_URL')));
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($request->type == 'FORCE_HTTPS' && $request->value == '0') {
|
||||
$this->overWriteEnvFile($request->type, 'Off');
|
||||
if(strpos(env('APP_URL'), 'https:') !== FALSE) {
|
||||
$this->overWriteEnvFile('APP_URL', str_replace("https:", "http:", env('APP_URL')));
|
||||
}
|
||||
|
||||
}
|
||||
elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '1') {
|
||||
$this->overWriteEnvFile($request->type, 's3');
|
||||
}
|
||||
elseif ($request->type == 'FILESYSTEM_DRIVER' && $request->value == '0') {
|
||||
$this->overWriteEnvFile($request->type, 'local');
|
||||
}
|
||||
|
||||
return '1';
|
||||
}
|
||||
|
||||
public function vendor_commission(Request $request)
|
||||
{
|
||||
return view('backend.sellers.seller_commission.index');
|
||||
}
|
||||
|
||||
public function vendor_commission_update(Request $request){
|
||||
foreach ($request->types as $key => $type) {
|
||||
$business_settings = BusinessSetting::where('type', $type)->first();
|
||||
if($business_settings!=null){
|
||||
$business_settings->value = $request[$type];
|
||||
$business_settings->save();
|
||||
}
|
||||
else{
|
||||
$business_settings = new BusinessSetting;
|
||||
$business_settings->type = $type;
|
||||
$business_settings->value = $request[$type];
|
||||
$business_settings->save();
|
||||
}
|
||||
}
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
flash(translate('Seller Commission updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function shipping_configuration(Request $request){
|
||||
return view('backend.setup_configurations.shipping_configuration.index');
|
||||
}
|
||||
|
||||
public function shipping_configuration_update(Request $request){
|
||||
$business_settings = BusinessSetting::where('type', $request->type)->first();
|
||||
$business_settings->value = $request[$request->type];
|
||||
$business_settings->save();
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
flash(translate('Shipping Method updated successfully'))->success();
|
||||
return back();
|
||||
}
|
||||
|
||||
public function order_configuration(){
|
||||
return view('backend.setup_configurations.order_configuration.index');
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user