diff --git a/beike/Admin/Http/Controllers/FileManagerController.php b/beike/Admin/Http/Controllers/FileManagerController.php index c117ba84..c824b369 100644 --- a/beike/Admin/Http/Controllers/FileManagerController.php +++ b/beike/Admin/Http/Controllers/FileManagerController.php @@ -126,7 +126,7 @@ class FileManagerController extends Controller $savePath = $request->get('path'); $originName = $file->getClientOriginalName(); - $filePath = $file->storeAs($savePath, $originName, 'catalog'); + $filePath = (new FileManagerService)->uploadFile($file, $savePath, $originName); return [ 'name' => $originName, diff --git a/beike/Admin/Services/FileManagerService.php b/beike/Admin/Services/FileManagerService.php index 65bfa5d1..cc673f98 100644 --- a/beike/Admin/Services/FileManagerService.php +++ b/beike/Admin/Services/FileManagerService.php @@ -13,11 +13,12 @@ namespace Beike\Admin\Services; class FileManagerService { - private $fileBasePath = ''; + protected $fileBasePath = ''; + protected $basePath = ''; public function __construct() { - $this->fileBasePath = public_path('catalog'); + $this->fileBasePath = public_path('catalog') . $this->basePath; } /** @@ -26,6 +27,7 @@ class FileManagerService public function getDirectories($baseFolder = '/'): array { $currentBasePath = rtrim($this->fileBasePath . $baseFolder, '/'); + $directories = glob("{$currentBasePath}/*", GLOB_ONLYDIR); $result = []; @@ -114,7 +116,7 @@ class FileManagerService */ public function createDirectory($folderName) { - $catalogFolderPath = "catalog/{$folderName}"; + $catalogFolderPath = "catalog{$this->basePath}/{$folderName}"; $folderPath = public_path($catalogFolderPath); if (is_dir($folderPath)) { throw new \Exception(trans('admin/file_manager.directory_already_exist')); @@ -130,7 +132,7 @@ class FileManagerService */ public function deleteDirectoryOrFile($filePath) { - $filePath = public_path("catalog/{$filePath}"); + $filePath = public_path("catalog{$this->basePath}/{$filePath}"); if (is_dir($filePath)) { $files = glob($filePath . '/*'); if ($files) { @@ -154,7 +156,7 @@ class FileManagerService return; } foreach ($files as $file) { - $filePath = public_path("catalog/{$basePath}/$file"); + $filePath = public_path("catalog{$this->basePath}/{$basePath}/$file"); if (file_exists($filePath)) { @unlink($filePath); } @@ -170,7 +172,7 @@ class FileManagerService */ public function updateName($originPath, $newPath) { - $originPath = public_path("catalog/{$originPath}"); + $originPath = public_path("catalog{$this->basePath}/{$originPath}"); if (! is_dir($originPath) && ! file_exists($originPath)) { throw new \Exception(trans('admin/file_manager.target_not_exist')); } @@ -182,6 +184,12 @@ class FileManagerService @rename($originPath, $newPath); } + public function uploadFile($file, $savePath, $originName) + { + $savePath = $this->basePath . $savePath; + return $file->storeAs($savePath, $originName, 'catalog'); + } + /** * 处理文件夹 * @@ -205,7 +213,7 @@ class FileManagerService */ private function hasSubFolders($folderPath): bool { - $path = public_path("catalog/{$folderPath}"); + $path = public_path("catalog{$this->basePath}/{$folderPath}"); $subFiles = glob($path . '/*'); foreach ($subFiles as $subFile) { if (is_dir($subFile)) { diff --git a/beike/Repositories/OrderRepo.php b/beike/Repositories/OrderRepo.php index e23f9498..307f21c8 100644 --- a/beike/Repositories/OrderRepo.php +++ b/beike/Repositories/OrderRepo.php @@ -31,7 +31,7 @@ class OrderRepo */ public static function filterAll(array $filters = []) { - $builder = self::getListBuilder($filters)->orderByDesc('created_at'); + $builder = static::getListBuilder($filters)->orderByDesc('created_at'); return $builder->get(); } @@ -44,7 +44,7 @@ class OrderRepo */ public static function getListByCustomer($customer): LengthAwarePaginator { - $builder = self::getListBuilder(['customer' => $customer])->orderByDesc('created_at'); + $builder = static::getListBuilder(['customer' => $customer])->orderByDesc('created_at'); return $builder->paginate(perPage()); } @@ -56,7 +56,7 @@ class OrderRepo */ public static function getLatestOrders($customer, $limit) { - return self::getListBuilder(['customer' => $customer]) + return static::getListBuilder(['customer' => $customer]) ->orderByDesc('created_at') ->take($limit) ->get(); @@ -68,7 +68,7 @@ class OrderRepo */ public static function filterOrders(array $filters = []): LengthAwarePaginator { - $builder = self::getListBuilder($filters)->orderByDesc('created_at'); + $builder = static::getListBuilder($filters)->orderByDesc('created_at'); return $builder->paginate(perPage()); } @@ -266,6 +266,7 @@ class OrderRepo OrderProductRepo::createOrderProducts($order, $carts['carts']); OrderTotalRepo::createTotals($order, $totals); + hook_filter('repository.order.create.after', ['order' => $order, 'data' => $data]); return $order; } diff --git a/beike/Repositories/ProductRepo.php b/beike/Repositories/ProductRepo.php index ebc044fb..7ab39b80 100644 --- a/beike/Repositories/ProductRepo.php +++ b/beike/Repositories/ProductRepo.php @@ -55,7 +55,7 @@ class ProductRepo */ public static function getProductsByCategory($categoryId, $filterData) { - $builder = self::getBuilder(array_merge(['category_id' => $categoryId, 'active' => 1], $filterData)); + $builder = static::getBuilder(array_merge(['category_id' => $categoryId, 'active' => 1], $filterData)); return $builder->with('inCurrentWishlist') ->paginate($filterData['per_page'] ?? perPage()) @@ -72,7 +72,7 @@ class ProductRepo if (! $productIds) { return ProductSimple::collection(new Collection()); } - $builder = self::getBuilder(['product_ids' => $productIds])->whereHas('masterSku'); + $builder = static::getBuilder(['product_ids' => $productIds])->whereHas('masterSku'); $products = $builder->with('inCurrentWishlist')->get(); return ProductSimple::collection($products); @@ -220,7 +220,7 @@ class ProductRepo public static function getFilterAttribute($data): array { - $builder = self::getBuilder(array_diff_key($data, ['attr' => '', 'price' => ''])) + $builder = static::getBuilder(array_diff_key($data, ['attr' => '', 'price' => ''])) ->select(['pa.attribute_id', 'pa.attribute_value_id']) ->with(['attributes.attribute.description', 'attributes.attribute_value.description']) ->leftJoin('product_attributes as pa', 'pa.product_id', 'products.id') @@ -274,7 +274,7 @@ class ProductRepo { $selectPrice = $data['price'] ?? '-'; // unset($data['price']); - $builder = self::getBuilder(['category_id' => $data['category_id']])->leftJoin('product_skus as ps', 'products.id', 'ps.product_id') + $builder = static::getBuilder(['category_id' => $data['category_id']])->leftJoin('product_skus as ps', 'products.id', 'ps.product_id') ->where('ps.is_default', 1); $min = $builder->min('ps.price'); $max = $builder->max('ps.price'); @@ -293,7 +293,7 @@ class ProductRepo public static function list($data = []) { - return self::getBuilder($data)->paginate($data['per_page'] ?? 20); + return static::getBuilder($data)->paginate($data['per_page'] ?? 20); } public static function autocomplete($name) @@ -353,7 +353,7 @@ class ProductRepo } $items = []; - $products = self::getBuilder()->select('id')->get(); + $products = static::getBuilder()->select('id')->get(); foreach ($products as $product) { $items[$product->id] = [ 'id' => $product->id, diff --git a/beike/Services/StateMachineService.php b/beike/Services/StateMachineService.php index 425bad89..dc771fc6 100644 --- a/beike/Services/StateMachineService.php +++ b/beike/Services/StateMachineService.php @@ -152,7 +152,7 @@ class StateMachineService ]; } - return $result; + return hook_filter('service.state_machine.all_statuses', $result); } /** @@ -232,6 +232,8 @@ class StateMachineService } $this->{$function}($oldStatusCode, $status); } + + hook_filter('service.state_machine.change_status.after', ['order' => $order, 'status' => $status, 'comment' => $comment, 'notify' => $notify]); } /** @@ -242,11 +244,6 @@ class StateMachineService */ private function validStatusCode($statusCode) { - if (! in_array($statusCode, self::ORDER_STATUS)) { - $statusCodeString = implode(', ', self::ORDER_STATUS); - - throw new \Exception("Invalid order status, must be one of the '{$statusCodeString}'"); - } $orderId = $this->orderId; $orderNumber = $this->order->number; $currentStatusCode = $this->order->status; diff --git a/beike/Shop/Services/CartService.php b/beike/Shop/Services/CartService.php index dfa6aea4..7645b4ed 100644 --- a/beike/Shop/Services/CartService.php +++ b/beike/Shop/Services/CartService.php @@ -50,7 +50,9 @@ class CartService return $description && $product; }); - return CartDetail::collection($cartItems)->jsonSerialize(); + $cartList = CartDetail::collection($cartItems)->jsonSerialize(); + + return hook_filter('service.cart.list', $cartList); } /** @@ -183,6 +185,6 @@ class CartService 'amount_format' => currency_format($amount), ]; - return hook_filter('cart.data', $data); + return hook_filter('service.cart.data', $data); } } diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index 6c0403b6..22a866e7 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -232,7 +232,8 @@ class CheckoutService $cartList = CartService::list($customer, true); $carts = CartService::reloadData($cartList); - $totalService = (new TotalService($currentCart, $cartList)); + $totalClass = hook_filter('service.checkout.total_service', 'Beike\Shop\Services\TotalService'); + $totalService = (new $totalClass($currentCart, $cartList)); $this->totalService = $totalService; $addresses = AddressRepo::listByCustomer($customer); @@ -268,7 +269,7 @@ class CheckoutService 'totals' => $totalService->getTotals($this), ]; - return hook_filter('checkout.data', $data); + return hook_filter('service.checkout.data', $data); } public static function formatAddress($address) diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index 39726843..0ae10206 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -17,16 +17,16 @@ use Illuminate\Support\Str; class TotalService { - private const TOTAL_CODES = [ + protected const TOTAL_CODES = [ 'subtotal', 'tax', 'shipping', 'customer_discount', ]; - public Cart $currentCart; + protected Cart $currentCart; - public array $cartProducts; + protected array $cartProducts; public array $taxes = []; @@ -34,7 +34,7 @@ class TotalService public float $amount = 0; - public string $shippingMethod = ''; + protected string|array $shippingMethod = ''; public function __construct($currentCart, $cartProducts) { @@ -54,6 +54,11 @@ class TotalService return $this; } + public function getShippingMethod(): string + { + return $this->shippingMethod; + } + /** * 获取税费数据 * @@ -132,4 +137,14 @@ class TotalService return collect($carts)->sum('subtotal'); } + + public function getCartProducts() + { + return $this->cartProducts; + } + + public function getCurrentCart() + { + return $this->currentCart; + } } diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 92c9745c..ead0dbc9 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -25,7 +25,7 @@ class ShippingService public static function getTotal(CheckoutService $checkout): ?array { $totalService = $checkout->totalService; - $shippingMethod = $totalService->shippingMethod; + $shippingMethod = $totalService->getShippingMethod(); if (empty($shippingMethod)) { return null; } diff --git a/resources/js/http.js b/resources/js/http.js index 099bfe67..c92c4dae 100644 --- a/resources/js/http.js +++ b/resources/js/http.js @@ -3,7 +3,7 @@ * @link https://beikeshop.com * @Author pu shuo * @Date 2022-08-02 19:19:52 - * @LastEditTime 2022-09-16 20:58:16 + * @LastEditTime 2023-05-29 18:56:35 */ window.axios = require('axios'); @@ -25,8 +25,8 @@ export default { * @param url 接口路由 * @returns {AxiosPromise} */ - get (url, params, {hmsg, hload}={}) { - return this.request('get', url, params = params, {hmsg, hload}); + get (url, params, {hmsg, hload, base}={}) { + return this.request('get', url, params = params, {hmsg, hload, base}); }, /** @@ -37,8 +37,8 @@ export default { * @returns {AxiosPromise} */ - post (url, params, {hmsg, hload}={}) { - return this.request('post', url, params, {hmsg, hload}); + post (url, params, {hmsg, hload, base}={}) { + return this.request('post', url, params, {hmsg, hload, base}); }, /** @@ -48,8 +48,8 @@ export default { * @returns {Promise} */ - delete (url, params, {hmsg, hload}={}) { - return this.request('delete', url, params, {hmsg, hload}); + delete (url, params, {hmsg, hload, base}={}) { + return this.request('delete', url, params, {hmsg, hload, base}); }, /** @@ -59,8 +59,8 @@ export default { * @returns {Promise} */ - put (url, params, {hmsg, hload}={}) { - return this.request('put', url, params, {hmsg, hload}); + put (url, params, {hmsg, hload, base}={}) { + return this.request('put', url, params, {hmsg, hload, base}); }, @@ -73,11 +73,15 @@ export default { * @returns {Promise} */ // 错误和失败信息都在这里进行处理,界面中调用的时候只处理正确数据即可 - request(method, url, params = {}, {hmsg, hload} = {}) { + request(method, url, params = {}, {hmsg, hload, base} = {}) { if (!hload) { layer.load(2, {shade: [0.3,'#fff'] }) } + if (base) { + axios.defaults.baseURL = base; + } + return new Promise((resolve, reject) => { axios({method: method, url: url, [method == 'get' ? 'params' : 'data']: params}).then((res) => { if (res) { diff --git a/themes/default/checkout.blade.php b/themes/default/checkout.blade.php index c47bbab4..05023c44 100644 --- a/themes/default/checkout.blade.php +++ b/themes/default/checkout.blade.php @@ -88,8 +88,7 @@ {{ $carts['quantity'] }}
- @hook('checkout.total.header') - + @hookwrapper('checkout.products')
@foreach ($carts['carts'] as $cart)
@@ -111,6 +110,7 @@
@endforeach
+ @endhookwrapper
    @foreach ($totals as $total)
  • {{ $total['title'] }}{{ $total['amount_format'] }}