show orders for account home page
This commit is contained in:
parent
9fb56b1e4b
commit
f95af926c1
|
|
@ -44,6 +44,20 @@ class OrderRepo
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $customer
|
||||
* @param $limit
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getLatestOrders($customer, $limit)
|
||||
{
|
||||
return self::getListBuilder(['customer' => $customer])
|
||||
->orderByDesc('created_at')
|
||||
->take($limit)
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $filters
|
||||
* @return LengthAwarePaginator
|
||||
|
|
|
|||
|
|
@ -11,34 +11,38 @@
|
|||
|
||||
namespace Beike\Shop\Http\Controllers\Account;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Beike\Repositories\CustomerRepo;
|
||||
use Beike\Repositories\OrderRepo;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Beike\Shop\Http\Requests\EditRequest;
|
||||
use Beike\Repositories\CustomerRepo;
|
||||
use Beike\Shop\Http\Controllers\Controller;
|
||||
use Beike\Shop\Http\Requests\ForgottenRequest;
|
||||
use Beike\Shop\Http\Resources\CustomerResource;
|
||||
use Beike\Shop\Http\Resources\Account\OrderList;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
* 个人中心首页
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = current_customer()->toArray();
|
||||
$data['avatar'] = image_resize($data['avatar']);
|
||||
$customer = current_customer();
|
||||
$data = [
|
||||
'customer' => new CustomerResource($customer),
|
||||
'latest_orders' => OrderList::collection(OrderRepo::getLatestOrders($customer, 10)),
|
||||
];
|
||||
return view('account/account', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码,提交"origin_password"、"password", "password_confirmation", 验证新密码和确认密码相等,且原密码正确则修改密码
|
||||
* 修改密码,提交 "origin_password"、"password", "password_confirmation", 验证新密码和确认密码相等,且原密码正确则修改密码
|
||||
* @param ForgottenRequest $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updatePassword(ForgottenRequest $request)
|
||||
public function updatePassword(ForgottenRequest $request): array
|
||||
{
|
||||
if (Hash::make($request->get('origin_password')) != current_customer()->getAuthPassword()) {
|
||||
throw new \Exception("原密码错误");
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Beike\Shop\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CustomerResource extends JsonResource
|
||||
|
|
@ -9,12 +10,13 @@ class CustomerResource extends JsonResource
|
|||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function toArray($request)
|
||||
public function toArray($request): array
|
||||
{
|
||||
$data = [
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
|
|
@ -23,7 +25,5 @@ class CustomerResource extends JsonResource
|
|||
'from' => $this->from,
|
||||
'customer_group_name' => $this->customer_group_name,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
namespace Beike\Shop\View\Components;
|
||||
|
||||
use Beike\Models\Customer;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class AccountSidebar extends Component
|
||||
{
|
||||
|
|
@ -27,6 +26,9 @@ class AccountSidebar extends Component
|
|||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.account.sidebar', ['customer' => $this->customer]);
|
||||
$data = [
|
||||
'customer' => $this->customer,
|
||||
];
|
||||
return view('components.account.sidebar', $data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,39 @@
|
|||
<div class="text mb-3 text-muted">您还没有订单!<a href="">去下单</a></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@foreach ($latest_orders as $order)
|
||||
<tbody>
|
||||
<tr class="sep-row"><td colspan="4"></td></tr>
|
||||
<tr class="head-tr">
|
||||
<td colspan="4">
|
||||
<span class="order-created me-4">{{ $order->created_at }}</span>
|
||||
<span class="order-number">订单号:{{ $order->number }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
@foreach ($order->orderProducts as $product)
|
||||
<tr class="{{ $loop->first ? 'first-tr' : '' }}">
|
||||
<td>
|
||||
<div class="product-info">
|
||||
<div class="img"><img src="{{ $product->image }}" class="img-fluid"></div>
|
||||
<div class="name">
|
||||
<span>{{ $product->name }}</span>
|
||||
</div>
|
||||
<div class="quantity">{{ $product->quantity }}</div>
|
||||
</div>
|
||||
</td>
|
||||
@if ($loop->first)
|
||||
<td rowspan="{{ $loop->count }}">{{ $order->total }}</td>
|
||||
<td rowspan="{{ $loop->count }}">{{ $order->status }}</td>
|
||||
<td rowspan="{{ $loop->count }}" class="text-end">
|
||||
<a href="{{ shop_route('account.order.show', ['number' => $order->number]) }}" class="btn btn-outline-secondary btn-sm">查看</a>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.edit.index') }}">
|
||||
<span>修改个人信息</span></a>
|
||||
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.order.index') }}">
|
||||
<span>我的订单</span><span class="px-3 badge rounded-pill bg-dark">5</span></a>
|
||||
<span>我的订单</span></a>
|
||||
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('addresses.index') }}">
|
||||
<span>我的地址</span><span class="px-3 badge rounded-pill bg-dark">5</span></a>
|
||||
<span>我的地址</span></a>
|
||||
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('account.wishlist.index') }}">
|
||||
<span>我的收藏</span></a>
|
||||
<a class="list-group-item d-flex justify-content-between align-items-center" href="{{ shop_route('logout') }}">
|
||||
<span>退出登录</span></a>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue