[WIP] Order process

This commit is contained in:
Ludovic CANDELLIER
2022-07-03 22:38:08 +02:00
parent bcb3e15f33
commit 06cfb92757
60 changed files with 1146 additions and 295 deletions

View File

@@ -3,18 +3,56 @@
namespace App\Repositories\Shop;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravolt\Avatar\Avatar;
use App\Repositories\Core\File;
use App\Models\Shop\Customer;
class Customers
{
public static function getAvatar()
public static function getAvatar($id = false)
{
$customer = $id ? self::get($id) : self::getAuth();
$file = self::makeAvatarFilename($customer);
if (!File::checkFile($file)) {
self::createAvatar($customer);
}
return self::getPublic(self::getAvatarFilename($customer));
}
public static function createAvatar($customer)
{
$filename = self::makeAvatarFilename($customer);
$name = $customer->first_name . ' ' . $customer->last_name;
$avatar = new Avatar();
$ret = $avatar->create($name)
->setBackground($bgColor)
->setBorder(1, '#29292e')
->setFontFamily('Roboto Condensed')
->setDimension(40)
->setFontSize(16)
->save($filename);
return $ret;
}
public static function makeAvatarFilename($customer)
{
$path = storage_path(self::getStorage());
if (File::checkDirOrCreate($path)) {
$filename = $path . 'user-' . $customer->uuid . '.png';
}
return $filename ?? false;
}
public static function getAvatarFilename($customer)
{
return 'user-' . $customer->uuid . '.png';
}
public static function getName()
{
$user = self::getAuth();
@@ -85,16 +123,15 @@ class Customers
public static function storeDeliveries($customer, $deliveries)
{
if ($deliveries) {
$deliveries = collect($deliveries)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray();
return $customer->deliveries()->sync($deliveries);
} else {
if (!$deliveries) {
return false;
}
$deliveries = collect($deliveries)->transform(
function ($item, $key) {
return (int) $item;
}
)->toArray();
return $customer->deliveries()->sync($deliveries);
}
public static function storeAddresses($customer, $addresses)
@@ -107,6 +144,7 @@ class Customers
public static function create($data)
{
$data['uuid'] = Str::uuid()->toString();
return Customer::create($data);
}
@@ -122,4 +160,16 @@ class Customers
{
return Customer::destroy($id);
}
public static function getStorage($filename = false)
{
$path = '/app/public/Customers/';
return $filename ? $path . $filename : $path;
}
public static function getPublic($filename = false)
{
$path = '/storage/Customers/';
return $filename ? $path . $filename : $path;
}
}