fix pictures

This commit is contained in:
2026-06-29 19:58:06 +03:30
parent 8fc71a1281
commit c177bdbb22
6 changed files with 72 additions and 31 deletions
+15 -12
View File
@@ -30,27 +30,30 @@ class FileController extends Controller
public function store(Request $request)
{
// Store FIle in Public Storage By Date
// Date Sample is : <Year>/<Month>/<Day> of today
$data = $request->all();
$path = $this->createDir();
$uploaded = $request->file('file');
if (! $uploaded || ! $uploaded->isValid()) {
return response()->json(['message' => 'فایل بارگذاری نشد یا خالی است'], 422);
}
$path = $this->createDir();
$data = $request->all();
$data['original_name'] = $uploaded->getClientOriginalName();
$data['ext'] = $uploaded->getClientOriginalExtension();
if (!isset($data['title']) || is_null($data['title'])) {
$data['ext'] = $uploaded->getClientOriginalExtension()
?: $uploaded->extension()
?: 'jpg';
if (! isset($data['title']) || is_null($data['title'])) {
$data['title'] = $data['original_name'];
}
$file_name_src = md5(time() . $data['original_name']);
$file_name = $file_name_src . '.' . $data['ext'];
$file_name_src = md5(time().$data['original_name']);
$file_name = $file_name_src.'.'.$data['ext'];
$data['has_thumb'] = false;
$data['size'] = $uploaded->getSize();
Storage::disk('public')->putFileAs($path, $uploaded, $file_name);
$data['src'] = 'storage/' . $path . '/' . $file_name;
// $data['size'] = $file->getSize();
$data['src'] = 'storage/'.$path.'/'.$file_name;
$data['user_id'] = auth()->id();
$data['sts'] = 1;
$file_create = File::create($data);
return response()->json($file_create);
return response()->json($file_create->fresh());
}
}
@@ -295,7 +295,7 @@ class GiftCardController extends Controller
]);
}
private function applyDiscount(string $code, $customerId): array
public function applyDiscount(string $code, $customerId): array
{
$giftcode = $this->verifyDiscount($code);
if (! empty($giftcode['message'])) {
@@ -276,12 +276,15 @@ class CartController extends Controller
$data['total_price'] = $total_price;
//مقدار قابل پرداخت
$data['payment_amount'] = $data['total_price'];
if(!empty($data[0]['discount_code'])){
$discount = new GiftCardController();
$discount = $discount->useDiscount($data[0]['discount_code'], $data['customer_id']);
if (!empty($data[0]['discount_code'])) {
$discountCtrl = app(GiftCardController::class);
$discountResult = $discountCtrl->applyDiscount((string) $data[0]['discount_code'], $data['customer_id']);
if (!empty($discountResult['message'])) {
throw new UnprocessableEntityHttpException($discountResult['message']);
}
$data['discount'] = true;
if(!empty($discount['amount'])){
$data['payment_amount'] = $data['total_price'] = $data['total_price'] - ($data['total_price'] * (float)$discount['amount']);
if (!empty($discountResult['amount'])) {
$data['payment_amount'] = $data['total_price'] = $data['total_price'] - ($data['total_price'] * (float) $discountResult['amount']);
}
}
$data['cart_id'] = (int)$cart->id;
@@ -407,11 +410,14 @@ class CartController extends Controller
];
if (!empty($payload[0]['discount_code'])) {
$discount = new GiftCardController();
$discount = $discount->useDiscount($payload[0]['discount_code'], $customerId);
if (!empty($discount['amount'])) {
$discountCtrl = app(GiftCardController::class);
$discountResult = $discountCtrl->applyDiscount((string) $payload[0]['discount_code'], $customerId);
if (!empty($discountResult['message'])) {
throw new UnprocessableEntityHttpException($discountResult['message']);
}
if (!empty($discountResult['amount'])) {
$orderData['payment_amount'] = $orderData['total_price'] =
$orderData['total_price'] - ($orderData['total_price'] * (float) $discount['amount']);
$orderData['total_price'] - ($orderData['total_price'] * (float) $discountResult['amount']);
}
}
@@ -78,7 +78,7 @@ class ProductController extends SuperController
]);
if ($product->relationLoaded('file') && $product->file) {
$product->file->setAttribute('full_src', $product->file->src);
$product->file->setAttribute('full_src', File::publicUrl($product->file->getAttributes()['src'] ?? null));
}
if ($representativeId !== null && (int) $product->id === $representativeId) {