This commit is contained in:
pushuo 2022-08-16 18:57:37 +08:00
parent 0405a9a855
commit b0f1472d2b
10 changed files with 95 additions and 39 deletions

View File

@ -469,12 +469,13 @@ if (!function_exists('sub_string')) {
*/
function sub_string($string, int $length = 16, string $dot = '...'): string
{
$strLength = strlen($string);
$strLength = mb_strlen($string);
if ($length <= 0) {
return $string;
} elseif ($strLength <= $length) {
return $string;
}
return mb_substr($string, 0, $length) . $dot;
}
}

View File

@ -33,10 +33,16 @@ class ProductController extends Controller
* @param Request $request
* @return AnonymousResourceCollection
*/
public function search(Request $request): AnonymousResourceCollection
public function search(Request $request)
{
$keyword = $request->get('keyword');
$products = ProductRepo::getBuilder(['name' => $keyword])->where('active', true)->paginate();
return ProductSimple::collection($products);
$data = [
'products' => $products,
'items' => ProductSimple::collection($products)->jsonSerialize(),
];
return view('search', $data);
}
}

View File

@ -30,10 +30,13 @@ class ProductSimple extends JsonResource
throw new \Exception("invalid master sku for product {$this->id}");
}
$name = $this->description->name ?? '';
return [
'id' => $this->id,
'sku_id' => $masterSku->id,
'name' => $this->description->name ?? '',
'name' => $name,
'name_format' => sub_string($name, 50),
'url' => shop_route('products.show', ['product' => $this]),
'price' => $masterSku->price,
'origin_price' => $masterSku->origin_price,

View File

@ -140,6 +140,7 @@ class CartService
if (empty($carts)) {
$carts = CartService::list(current_customer());
}
$selected = collect($carts)->where('selected', 1);
$quantity = $selected->sum('quantity');
$amount = $selected->sum('subtotal');

View File

@ -2213,9 +2213,8 @@ $(function () {
$('#offcanvas-search-top input').keydown(function (e) {
if (e.keyCode == 13) {
if ($(this).val() != '') {
location.href = 'products/keyword?name=' + $(this).val();
} // $('#offcanvas-search-top .btn-search').click();
location.href = 'products/search?keyword=' + $(this).val();
}
}
});
});

View File

@ -43,8 +43,8 @@
@close="closeCustomersDialog('form')" :close-on-click-modal="false">
<el-form ref="form" :rules="rules" :model="dialog.form" label-width="100px">
<el-form-item label="code" prop="name">
<el-input v-model="dialog.form.name" placeholder="code"></el-input>
<el-form-item label="名称" prop="name">
<el-input v-model="dialog.form.name" placeholder="名称"></el-input>
</el-form-item>
<el-form-item label="编码" prop="code">

View File

@ -8,7 +8,6 @@ $(function() {
if ($(this).val() != '') {
location.href = 'products/search?keyword=' + $(this).val();
}
// $('#offcanvas-search-top .btn-search').click();
}
})
})

View File

@ -12,12 +12,23 @@
</nav>
<div class="row">
<x-shop-sidebar />
<x-shop-sidebar/>
<div class="col-12 col-md-9">
<div class="card mb-4 order-head">
<div class="card-header"><h5 class="card-title">订单详情</h5></div>
<div class="card-header d-flex align-items-center justify-content-between">
<h6 class="card-title">订单详情</h6>
<div>
@if ($order->status == 'unpaid')
<a href="{{ shop_route('orders.pay', $order->number) }}" class="btn btn-primary btn-sm nowrap">去支付</a>
@endif
@if ($order->status == 'shipped')
<button class="btn btn-primary btn-sm shipped-ed" type="button">确认收货</button>
@endif
</div>
</div>
<div class="card-body">
<div class="bg-light p-2 table-responsive">
<table class="table table-borderless mb-0">
<thead>
@ -34,9 +45,6 @@
<td>{{ $order->created_at }}</td>
<td>
{{ $order->status }}
@if ($order->status == 'unpaid')
<a href="{{ shop_route('orders.pay', $order->number) }}" class="btn btn-primary btn-sm nowrap">去支付</a>
@endif
</td>
<td>{{ $order->total }}</td>
</tr>
@ -47,37 +55,42 @@
</div>
<div class="card mb-4">
<div class="card-header"><h5 class="card-title">订购商品</h5></div>
<div class="card-header">
<h6 class="card-title">订购商品</h6>
</div>
<div class="card-body">
@foreach ($order->orderProducts as $product)
<div class="product-list">
<div class="d-flex">
<div class="left"><img src="{{ $product->image }}" class="img-fluid"></div>
<div class="right">
<div class="name">{{ $product->name }} x {{ $product->quantity }}</div>
<div class="price">{{ $product->price }}</div>
<div class="product-list">
<div class="d-flex">
<div class="left"><img src="{{ $product->image }}" class="img-fluid"></div>
<div class="right">
<div class="name">{{ $product->name }} x {{ $product->quantity }}</div>
<div class="price">{{ $product->price }}</div>
</div>
</div>
@if ($order->status == 'completed')
<a href="{{ shop_route('account.rma.create', [$product->id]) }}"
class="btn btn-outline-primary btn-sm">申请售后</a>
@endif
</div>
@if ($order->status == 'completed')
<a href="{{ shop_route('account.rma.create', [$product->id]) }}" class="btn btn-outline-primary btn-sm">申请售后</a>
@endif
</div>
@endforeach
</div>
</div>
<div class="card mb-4">
<div class="card-header"><h5 class="card-title">Order Total</h5></div>
<div class="card-header">
<h6 class="card-title">Order Total</h6>
</div>
<div class="card-body">
<table class="table table-bordered border">
<tbody>
@foreach (array_chunk($order->orderTotals->all(), 2) as $totals)
<tr>
@foreach ($totals as $total)
<td class="bg-light wp-200">{{ $total->title }}</td>
<td><strong>{{ $total->value }}</strong></td>
@endforeach
</tr>
<tr>
@foreach ($totals as $total)
<td class="bg-light wp-200">{{ $total->title }}</td>
<td><strong>{{ $total->value }}</strong></td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
@ -85,17 +98,21 @@
</div>
@if (0)
<div class="card mb-4">
<div class="card-header"><h5 class="card-title">物流状态</h5></div>
<div class="card-body">
<div class="card mb-4">
<div class="card-header">
<h6 class="card-title">物流状态</h6>
</div>
<div class="card-body">
</div>
</div>
</div>
@endif
@if ($order->orderHistories->count())
<div class="card mb-4">
<div class="card-header"><h5 class="card-title">订单状态</h5></div>
<div class="card-header">
<h6 class="card-title">订单状态</h6>
</div>
<div class="card-body">
<table class="table ">
<thead class="">
@ -122,3 +139,15 @@
</div>
</div>
@endsection
@push('add-scripts')
<script>
$('.shipped-ed').click(function(event) {
$http.post('orders/{{ $order->id }}/complete').then((res) => {
layer.msg(res.message)
window.location.reload()
})
});
</script>
@endpush

View File

@ -0,0 +1,18 @@
@extends('layout.master')
@section('body-class', 'page-categories')
@section('content')
<div class="container">
{{-- {{ Diglactic\Breadcrumbs\Breadcrumbs::render('category', $category) }} --}}
<div class="row">
@foreach ($items as $product)
<div class="col-6 col-md-3">@include('shared.product')</div>
@endforeach
</div>
{{ $products->links('shared/pagination/bootstrap-4') }}
</div>
@endsection

View File

@ -28,7 +28,7 @@
</button>
</div>
</div>
<div class="product-name">{{ $product['name'] }}</div>
<div class="product-name">{{ $product['name_format'] }}</div>
<div class="product-price">
<span class="price-new">{{ $product['price_format'] }}</span>
<span class="price-lod">{{ $product['origin_price_format'] }}</span>