add offers count, & minor fixes code standards
This commit is contained in:
@@ -10,9 +10,15 @@ use App\Repositories\Languages;
|
||||
|
||||
class Applications
|
||||
{
|
||||
public static function select_all()
|
||||
|
||||
public static function getFullBySlug($slug)
|
||||
{
|
||||
return Application::all()->toArray();
|
||||
return Application::with('clients')->active()->bySlug($slug)->first();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Application::all();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
@@ -39,7 +45,9 @@ class Applications
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
return self::get($id)->update($data);
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
@@ -97,4 +105,12 @@ class Applications
|
||||
{
|
||||
return Application::active()->bySlug($slug)->first();
|
||||
}
|
||||
|
||||
public static function toggleActive($id, $active) {
|
||||
return self::update(['active' => $active], $id);
|
||||
}
|
||||
|
||||
public static function toggleVisible($id, $visible) {
|
||||
return self::update(['visible' => $visible], $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class NewUser extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
$currentUser = \Auth::user();
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.newuser.subject', ['name' => config('app.name')]))
|
||||
->line(
|
||||
__(
|
||||
'notifications.newuser.intro', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->action(
|
||||
__('notifications.newuser.button'),
|
||||
route('users.firstlogin', $notifiable->remember_token)
|
||||
)
|
||||
->salutation(
|
||||
__(
|
||||
'notifications.salutation', [
|
||||
'name' => $currentUser->first_name.' '.$currentUser->last_name,
|
||||
]
|
||||
)
|
||||
)
|
||||
->line(__('notifications.newuser.outro'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,19 @@ class PasswordSecurities
|
||||
{
|
||||
public static function create($user_id, $delay = 90)
|
||||
{
|
||||
return PasswordSecurity::create(
|
||||
[
|
||||
return PasswordSecurity::create([
|
||||
'user_id' => $user_id,
|
||||
'password_expiry_days' => $delay,
|
||||
'password_updated_at' => Carbon::now(),
|
||||
]
|
||||
);
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getUserName($id) {
|
||||
return self::getUser($id)->username;
|
||||
}
|
||||
|
||||
public static function getUser($id) {
|
||||
return PasswordSecurity::with('user')->find($id)->user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User\Notifications;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
|
||||
class ResetPassword extends \Illuminate\Auth\Notifications\ResetPassword
|
||||
{
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||
*/
|
||||
/*
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('notifications.email')
|
||||
->greeting(__('notifications.greeting', ['firstname' => $notifiable->first_name]))
|
||||
->subject(__('notifications.resetpassword.subject'))
|
||||
->line(__('notifications.resetpassword.intro'))
|
||||
->action(
|
||||
__('notifications.resetpassword.button'),
|
||||
route('password.reset', $this->token)
|
||||
)
|
||||
->line(__('notifications.resetpassword.outro'));
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -2,11 +2,6 @@
|
||||
|
||||
namespace App\Repositories\Core\Auth;
|
||||
|
||||
use Hyn\Tenancy\Environment;
|
||||
use Hyn\Tenancy\Database\Connection;
|
||||
use App\Models\Admin\Website;
|
||||
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
|
||||
|
||||
use App\Models\Core\Auth\UserClient;
|
||||
use App\Models\Core\Auth\User;
|
||||
|
||||
@@ -48,7 +43,7 @@ class UserClients
|
||||
{
|
||||
$history = "";
|
||||
foreach ($clients as $key => $client_id) {
|
||||
$client = Clients::select_by_id($client_id);
|
||||
$client = Clients::get($client_id);
|
||||
if ($client) {
|
||||
self::associate_client($user_id, $client_id);
|
||||
$history .= $client['name'] . "| ";
|
||||
|
||||
@@ -15,7 +15,9 @@ use App\Models\Core\Auth\RoleUser;
|
||||
|
||||
use App\Repositories\Clients;
|
||||
use App\Repositories\Partners;
|
||||
use App\Repositories\Core\Upload;
|
||||
|
||||
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
|
||||
class Users
|
||||
{
|
||||
use LaratrustUserTrait;
|
||||
@@ -35,16 +37,18 @@ class Users
|
||||
$data = $user->toArray();
|
||||
$data['name'] = $user->name;
|
||||
$data['avatar'] = self::getAvatar($id);
|
||||
$data['last_login'] = $user->previousLoginAt();
|
||||
// $data['last_login'] = $user->previousLoginAt();
|
||||
// $data['roles'] = self::getRoles();
|
||||
// $data['permissions'] = self::getPermissions();
|
||||
$data['roles'] = $user->roles->pluck('id')->toArray();
|
||||
$data['permissions'] = $user->allPermissions()->pluck('id')->toArray();
|
||||
$data['clients'] = $user->clients->pluck('id')->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
|
||||
if (!empty($data['password'])) {
|
||||
@@ -60,19 +64,20 @@ class Users
|
||||
$data['active'] = true;
|
||||
|
||||
$user = $id ? self::update($data, $id) : self::create($data);
|
||||
$user->roles()->sync(array_keys($data['roles'] ?? []));
|
||||
|
||||
if (isset($data['roles'])) {
|
||||
$user->roles()->sync(array_keys($data['roles']));
|
||||
}
|
||||
UserClients::associate($user->id, $data['clients'] ?? false );
|
||||
// $user->sendNewUserNotification($data['remember_token'], Auth::user());
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
public static function create($data, $copy_password = false)
|
||||
{
|
||||
$data['password'] = $data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8));
|
||||
return User::create($data);
|
||||
$data['password'] = $copy_password ? $data['password'] : ($data['password'] ? Hash::make($data['password']) : Hash::make(Str::random(8)));
|
||||
$user = User::create($data);
|
||||
PasswordSecurities::create($user->id);
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
@@ -95,12 +100,17 @@ class Users
|
||||
return $user ? $user->id : false;
|
||||
}
|
||||
|
||||
public static function getName()
|
||||
public static function getName($id = false)
|
||||
{
|
||||
$user = self::getUser();
|
||||
$user = $id ? self::get($id) : self::getUser();
|
||||
return $user->first_name . ' ' . $user->last_name;
|
||||
}
|
||||
|
||||
public static function getUsername($id = false)
|
||||
{
|
||||
return $id ? self::get($id)->username : self::getUser()->username;
|
||||
}
|
||||
|
||||
public static function getUser()
|
||||
{
|
||||
return Auth::user();
|
||||
@@ -113,7 +123,7 @@ class Users
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return User::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
return User::orderBy('name')->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function delete($id)
|
||||
@@ -124,7 +134,7 @@ class Users
|
||||
|
||||
public static function getListByRole($role)
|
||||
{
|
||||
return self::selectOptions()->orderBy('name', 'asc')->whereRoleIs($role)->get();
|
||||
return self::selectOptions()->orderBy('name')->whereRoleIs($role)->get();
|
||||
}
|
||||
|
||||
public static function hasRole($role, $user = false)
|
||||
@@ -211,37 +221,36 @@ class Users
|
||||
return User::count();
|
||||
}
|
||||
|
||||
// récupère tous les utilisateurs pour un statut donné
|
||||
public static function select_all_by_status_id($status_id)
|
||||
{
|
||||
return User::byStatus($status_id);
|
||||
}
|
||||
|
||||
// récupère toutes les informations d'un utilisateur pour un id donné
|
||||
public static function select_by_id($user_id)
|
||||
{
|
||||
return User::with('status')->find($user_id)->toArray();
|
||||
}
|
||||
|
||||
// récupère toutes les informations d'un utilisateur pour un nom donné
|
||||
public static function select_by_name($name)
|
||||
{
|
||||
return User::byName($name)->first()->toArray();
|
||||
return self::getByName($name)->toArray();
|
||||
}
|
||||
|
||||
public static function getByUsername($username)
|
||||
{
|
||||
return User::byUsername($username)->withTrashed()->first();
|
||||
}
|
||||
|
||||
// récupère les utilisateurs actifs d'un statut, d'une équipe et d'une entité donnés
|
||||
public static function select_by_status_and_team_and_entity($status_id, $team_id, $third_party_id)
|
||||
{
|
||||
return User::active()->byStatus($status_id)->byTeam($team_id)->byThirdParty($third_party_id)->get()->toArray();
|
||||
}
|
||||
|
||||
// récupère toutes les informations nécessaires d'un utilisateur pour un id donné
|
||||
public static function select_datas_by_id($user_id)
|
||||
{
|
||||
return User::with('status')->find($user_id)->toArray();
|
||||
}
|
||||
|
||||
// met à jour le statut actif/inactif d'un utilisateur
|
||||
public static function toggle_active($id, $active)
|
||||
{
|
||||
return self::get($id)->update(['active' => $active]);
|
||||
@@ -251,26 +260,29 @@ class Users
|
||||
{
|
||||
$targetDir = 'uploads';
|
||||
$file = $request->file('avatar_file');
|
||||
$data = \App\Repositories\Core\Upload::getData($file);
|
||||
$file_uploaded = \App\Repositories\Core\Upload::store($file, $targetDir);
|
||||
$data = Upload::getData($file);
|
||||
$file_uploaded = Upload::store($file, $targetDir);
|
||||
$tab = pathinfo($file_uploaded);
|
||||
$response['name'] = $tab['basename'];
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
// met à jour l'avatar d'un utilisateur
|
||||
public static function update_avatar($id, $avatar)
|
||||
{
|
||||
return User::find($id)->update(['avatar' => $avatar]);
|
||||
}
|
||||
|
||||
// met à jour le mot de passe d'un utilisateur
|
||||
public static function update_password($id, $password)
|
||||
{
|
||||
$password = Hash::make($password);
|
||||
UserClients::changePasswordsByUser($id, $password);
|
||||
$connection = app(Connection::class);
|
||||
return User::on($connection->systemName())->find($id)->update(['password' => $password]);
|
||||
return User::find($id)->update(['password' => $password]);
|
||||
// $connection = app(Connection::class);
|
||||
// return User::on($connection->systemName())->find($id)->update(['password' => $password]);
|
||||
}
|
||||
|
||||
public static function validate($username, $field = 'current_password')
|
||||
{
|
||||
return PasswordRules::changePassword($username, $field);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Comments
|
||||
|
||||
public static function getClass($model)
|
||||
{
|
||||
return 'App\Models\\' . str_replace('.','\\', $model);
|
||||
return 'App\Models\\' . str_replace('.', '\\', $model);
|
||||
}
|
||||
|
||||
public static function getByModel($model)
|
||||
@@ -66,7 +66,7 @@ class Comments
|
||||
unset($data['_token']);
|
||||
$data['commentable_type'] = Comments::getClass($data['commentable_type']);
|
||||
$data['commentable_id'] = (int) $data['commentable_id'];
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
return $id ? self::update($data, $id) : self::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
@@ -83,7 +83,7 @@ class Comments
|
||||
$model = self::get($id);
|
||||
$model->update($data);
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteComments($model)
|
||||
{
|
||||
@@ -94,5 +94,4 @@ class Comments
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Collective\Html\Eloquent\FormAccessible;
|
||||
use Collective\Html\Eloquent\Form;
|
||||
|
||||
class Database
|
||||
{
|
||||
|
||||
@@ -6,8 +6,6 @@ use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
use Jenssegers\Date\Date;
|
||||
|
||||
use App\Repositories\Languages;
|
||||
|
||||
class DateCalculation
|
||||
{
|
||||
public static function isPast($date, $format = false)
|
||||
@@ -20,12 +18,12 @@ class DateCalculation
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date)->greaterThan(Carbon::now());
|
||||
}
|
||||
|
||||
public static function isAfter($date1, $date2)
|
||||
public static function isAfter($date1, $date2, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date1)->greaterThan(Carbon::createFromFormat(self::getFormat($format), $date2));
|
||||
}
|
||||
|
||||
public static function isBefore($date1, $date2)
|
||||
public static function isBefore($date1, $date2, $format = false)
|
||||
{
|
||||
return Carbon::createFromFormat(self::getFormat($format), $date1)->lessThan(Carbon::createFromFormat(self::getFormat($format), $date2));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,14 @@ namespace App\Repositories\Core;
|
||||
|
||||
class Export
|
||||
{
|
||||
public $xls;
|
||||
public $sheet;
|
||||
public $filename;
|
||||
public $stockage;
|
||||
public $lig;
|
||||
public $nb;
|
||||
public $debug;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
set_time_limit(0);
|
||||
@@ -68,7 +76,7 @@ class Export
|
||||
$txt = $options[$key][$txt];
|
||||
}
|
||||
if (isset($multioptions[$key])) {
|
||||
$tabs = BaseController::getReverseMultiOptions($txt);
|
||||
$tabs = self::getReverseMultiOptions($txt);
|
||||
foreach ($tabs as $key2 => $value) {
|
||||
$txt .= $multioptions[$key][$key2] . '\n';
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Repositories\Core;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class Stat
|
||||
{
|
||||
public static $is_debug = false;
|
||||
@@ -17,48 +19,38 @@ class Stat
|
||||
return $model->where('created_at', '<', $end)->count();
|
||||
}
|
||||
|
||||
/*
|
||||
fonctions de rendus
|
||||
*/
|
||||
|
||||
public static function renderStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyMultiVar($var, $var_option));
|
||||
self::renderStatsJson(self::getStatsbyMultiVar($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsbyVar($var)
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyVar($var));
|
||||
self::renderStatsJson(self::getStatsbyVar($var));
|
||||
}
|
||||
|
||||
public static function renderStatsbyOptions($var, $var_option = '')
|
||||
{
|
||||
static::renderStatsJson(static::getStatsbyOptions($var, $var_option));
|
||||
self::renderStatsJson(self::getStatsbyOptions($var, $var_option));
|
||||
}
|
||||
|
||||
public static function renderStatsJson($data)
|
||||
{
|
||||
Response::headers()->set('Content-Type', 'application/json');
|
||||
Response::setBody(json_encode($data, JSON_NUMERIC_CHECK));
|
||||
return json_encode($data, JSON_NUMERIC_CHECK);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Fonctions internes
|
||||
*/
|
||||
|
||||
public static function getStatsbyMultiVar($var, $var_option = '')
|
||||
{
|
||||
if (empty($var_option)) {
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
return self::getInstance()->getStatsbyMultiOptions($var, $options);
|
||||
$options = self::getOption($var_option);
|
||||
return self::getStatsbyMultiOptions($var, $options);
|
||||
}
|
||||
|
||||
public static function getCountByPeriod($var, $begin, $end)
|
||||
{
|
||||
$count = static::getModel()
|
||||
$count = self::getModel()
|
||||
->whereBetween($var, $begin, $end)
|
||||
->count();
|
||||
return $count;
|
||||
@@ -67,7 +59,7 @@ class Stat
|
||||
public static function getCountbyVar($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
$data = self::getModel()
|
||||
->select($db::raw("count(id) as y, $var as name"))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
@@ -82,7 +74,7 @@ class Stat
|
||||
$var_option = $var;
|
||||
}
|
||||
$options = self::getInstance()->controller->getOption($var_option);
|
||||
$nb = static::getCountbyOption($var);
|
||||
$nb = self::getCountbyOption($var);
|
||||
// var_Debug::message($nb);
|
||||
foreach ($options as $key => $value) {
|
||||
$y = (int) $nb[$key];
|
||||
@@ -95,7 +87,7 @@ class Stat
|
||||
public static function getCountbyOption($var)
|
||||
{
|
||||
$db = self::getInstance()->app->db;
|
||||
$data = static::getModel()
|
||||
$data = self::getModel()
|
||||
->select($db::raw('count(id) as nb'))
|
||||
->groupBy($var)
|
||||
->get();
|
||||
@@ -112,7 +104,7 @@ class Stat
|
||||
public static function getStatsbyMultiOptions($var, $options)
|
||||
{
|
||||
foreach ($options as $key => $value) {
|
||||
$nb = static::getCountbyBin($var, $key);
|
||||
$nb = self::getCountbyBin($var, $key);
|
||||
$data[] = ['y' => $nb, 'name' => $value];
|
||||
}
|
||||
return ($data);
|
||||
@@ -121,7 +113,7 @@ class Stat
|
||||
public static function getCountbyBin($var, $value)
|
||||
{
|
||||
$bit = pow(2, $value);
|
||||
$count = static::getModel()
|
||||
$count = self::getModel()
|
||||
->where($var, '&', $bit)
|
||||
->count();
|
||||
return $count;
|
||||
@@ -149,7 +141,7 @@ class Stat
|
||||
|
||||
public static function serializeValues($tab)
|
||||
{
|
||||
return static::serializeByVar($tab, 'count');
|
||||
return self::serializeByVar($tab, 'count');
|
||||
}
|
||||
|
||||
public static function serializeByVar($tab, $var, $n = 0)
|
||||
|
||||
@@ -21,10 +21,8 @@ class Upload
|
||||
{
|
||||
$data = (is_array($data)) ? (object) $data : $data;
|
||||
$pos = strrpos($file, '/');
|
||||
$uuid = substr($file, $pos+1);
|
||||
$uuid = substr($file, $pos + 1);
|
||||
$uuid = pathinfo($uuid, PATHINFO_FILENAME);
|
||||
// $uuid = str_replace('.' . strtolower($data->filetype), '', $uuid);
|
||||
// $uuid = str_replace('.' . $data->filetype, '', $uuid);
|
||||
return $uuid;
|
||||
}
|
||||
|
||||
@@ -36,6 +34,7 @@ class Upload
|
||||
// $path = Storage::putFile('avatars', $request->file('avatar'));
|
||||
// $path = $request->file('avatar')->storeAs('avatars',$request->user()->id,'s3');
|
||||
// $path = $request->file('avatar')->storePublicly('avatars', 's3');
|
||||
$request = Request();
|
||||
return $request->has($var) ? basename($request->file($var)->store($path)) : false;
|
||||
}
|
||||
|
||||
@@ -128,27 +127,17 @@ class Upload
|
||||
if (Storage::exists($dest)) {
|
||||
self::delete($dest);
|
||||
}
|
||||
return Storage::move($source, $dest); // transfère et renomme le fichier du dossier temporaire au dossier du client
|
||||
return Storage::move($source, $dest);
|
||||
}
|
||||
|
||||
public static function delete($file)
|
||||
{
|
||||
// Storage::delete($file);
|
||||
// return unlink($file);
|
||||
return Storage::delete($file);
|
||||
}
|
||||
|
||||
public static function deleteFile($path)
|
||||
{
|
||||
if (!Storage::exists($path)) {
|
||||
return false;
|
||||
}
|
||||
return Storage::delete($path);
|
||||
return Storage::exists($file) ? Storage::delete($file) : false;
|
||||
}
|
||||
|
||||
public static function deleteRecursive($path)
|
||||
{
|
||||
rmdir_recursive($targetDir);
|
||||
return rmdir_recursive($path);
|
||||
}
|
||||
|
||||
public function make_dir($path, $permissions = 0777)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
use \Cart;
|
||||
|
||||
class ShopCart
|
||||
{
|
||||
@@ -11,8 +12,40 @@ class ShopCart
|
||||
return self::get()->add($data);
|
||||
}
|
||||
|
||||
public static function remove($id)
|
||||
{
|
||||
return self::get()->remove($id);
|
||||
}
|
||||
|
||||
public static function clear()
|
||||
{
|
||||
Cart::session(1)->clear();
|
||||
return Cart::clear();
|
||||
// return self::get()->clear();
|
||||
}
|
||||
|
||||
public static function has($id)
|
||||
{
|
||||
return array_key_exists($id, self::getContent()->toArray());
|
||||
}
|
||||
|
||||
public static function keys()
|
||||
{
|
||||
return array_keys(self::getContent()->toArray());
|
||||
}
|
||||
|
||||
public static function count()
|
||||
{
|
||||
return self::getContent()->count();
|
||||
}
|
||||
|
||||
public static function getContent()
|
||||
{
|
||||
return self::get()->getContent();
|
||||
}
|
||||
|
||||
public static function get()
|
||||
{
|
||||
return \Cart::session(Users::getId());
|
||||
return Cart::session(Users::getId());
|
||||
}
|
||||
}
|
||||
|
||||
38
app/Repositories/Core/User/ShopCartStorage.php
Normal file
38
app/Repositories/Core/User/ShopCartStorage.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\User;
|
||||
|
||||
use Darryldecode\Cart\CartCollection;
|
||||
|
||||
use App\Models\Core\CartStorage;
|
||||
use App\Repositories\Core\Auth\Users;
|
||||
|
||||
class ShopCartStorage
|
||||
{
|
||||
public function has($key)
|
||||
{
|
||||
return CartStorage::find($key);
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ($this->has($key)) {
|
||||
return new CartCollection(CartStorage::find($key)->cart_data);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function put($key, $value)
|
||||
{
|
||||
if ($row = CartStorage::find($key)) {
|
||||
$row->cart_data = $value;
|
||||
$row->save();
|
||||
} else {
|
||||
CartStorage::create([
|
||||
'id' => $key,
|
||||
'cart_data' => $value
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\ArticleComponent;
|
||||
|
||||
class ArticleComponents
|
||||
{
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticleComponent::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticleComponent::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticleComponent::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticleComponent::create($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return ArticleComponent::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticleComponent::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\ArticlePrice;
|
||||
|
||||
class ArticlePrices
|
||||
{
|
||||
public static function getByArticle($id)
|
||||
{
|
||||
return ArticlePrice::byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getByArticleWithAttribute($id)
|
||||
{
|
||||
return ArticlePrice::with('article_attribute.attribute_value')->byArticle($id)->get();
|
||||
}
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
$model = ArticlePrice::orderBy('name');
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return ArticlePrice::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return ArticlePrice::find($id);
|
||||
}
|
||||
|
||||
public static function storePrices($article_id, $prices)
|
||||
{
|
||||
// dump($article_id);
|
||||
// dump($prices);
|
||||
// exit;
|
||||
if ($prices) {
|
||||
foreach ($prices as $key => $price) {
|
||||
$price['article_attribute']['article_attribute_value_id'] = $price['attribute']['attribute_value_id'];
|
||||
$prices[$key]['article_attribute_id'] = ArticleAttributes::storeAttribute($article_id, $price['article_attribute']);
|
||||
|
||||
unset($prices[$key]['article_attribute']);
|
||||
unset($prices[$key]['attribute']);
|
||||
self::store($prices[$key]);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$attributes = isset($data['attributes']) ? $data['attributes'] : false;
|
||||
unset($data['attributes']);
|
||||
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$price = $id ? self::update($data) : self::create($data);
|
||||
|
||||
$ret = $attributes ? self::storeAttributes($price->id, $attributes) : false;
|
||||
|
||||
return $price->id;
|
||||
}
|
||||
|
||||
public static function storeAttributes($article_price_id, $attributes)
|
||||
{
|
||||
return ArticleAttributes::storeAttribute($article_price_id, $attributes);
|
||||
}
|
||||
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return ArticlePrice::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$article = ArticlePrice::find($id);
|
||||
$article->update($data);
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return ArticlePrice::destroy($id);
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,7 @@ class Articles
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->with(['prices','product','image'])->get();
|
||||
return Article::byCategory($category_id)->with(['prices', 'product', 'image'])->get();
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
@@ -223,7 +223,6 @@ class Articles
|
||||
self::storeImages($article, $images);
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
@@ -270,11 +269,6 @@ class Articles
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
public static function storePrices($article, $prices)
|
||||
{
|
||||
return ArticlePrices::storePrices($article->id, $prices);
|
||||
}
|
||||
|
||||
public static function storeImages($article, $files)
|
||||
{
|
||||
return Medias::storeImages($article, $files);
|
||||
|
||||
@@ -118,7 +118,7 @@ class Categories
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$category = Category::find($id);
|
||||
$category = self::get($id);
|
||||
$ret = $category->update($data);
|
||||
CategoryTrees::update($data, $category->category_id);
|
||||
return $category;
|
||||
@@ -127,7 +127,7 @@ class Categories
|
||||
public static function destroy($id)
|
||||
{
|
||||
$category = self::get($id);
|
||||
self::deleteNode($category->category_id);
|
||||
CategoryTrees::destroy($category->category_id);
|
||||
return Category::destroy($id);
|
||||
}
|
||||
|
||||
|
||||
73
app/Repositories/Shop/Merchandises.php
Normal file
73
app/Repositories/Shop/Merchandises.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
class Merchandises
|
||||
{
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Merchandise::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
$export = [];
|
||||
foreach ($data as $key => $name) {
|
||||
$export[] = ['value' => $key, 'text' => $name];
|
||||
}
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getPrices($id)
|
||||
{
|
||||
return Merchandise::with(['price_lists.price_list_values', 'price_lists.sale_channel'])->find($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getStatus($status_id)
|
||||
{
|
||||
return self::getStatuses()[$status_id];
|
||||
}
|
||||
|
||||
public static function getStatuses()
|
||||
{
|
||||
return ['Actif','Suspendu','Invisible','Obsolete'];
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Merchandise::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Merchandise::find($id);
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data, $id) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Merchandise::create($data);
|
||||
}
|
||||
|
||||
public static function update($data, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$item = self::get($id);
|
||||
$item->update($data);
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Merchandise::destroy($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user