Skip to content

Commit d48f145

Browse files
committed
Личный кабинет пользователя
1 parent 6bf094d commit d48f145

25 files changed

Lines changed: 743 additions & 57 deletions

File tree

‎core/routes.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static function (RouteCollectorProxy $group) {
2424
static function (RouteCollectorProxy $group) {
2525
$group->any('/profile', App\Controllers\User\Profile::class);
2626
$group->any('/addresses', App\Controllers\User\Addresses::class);
27+
$group->any('/orders[/{uuid}]', App\Controllers\User\Orders::class);
2728
}
2829
);
2930

‎core/src/Controllers/Admin/Orders.php‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected function beforeGet(Builder $c): Builder
1919
{
2020
$c->with('orderProducts', 'orderProducts.product');
2121
$c->with('address');
22+
$c->with('payment');
2223

2324
return $c;
2425
}
@@ -42,6 +43,21 @@ protected function afterCount(Builder $c): Builder
4243
{
4344
$c->withCount('orderProducts');
4445
$c->with('user:id,fullname,username');
46+
$c->with('payment:order_id,paid');
47+
48+
return $c;
49+
}
50+
51+
protected function addSorting(Builder $c): Builder
52+
{
53+
if ($sort = $this->getProperty('sort')) {
54+
if ($sort === 'num') {
55+
$dir = strtolower($this->getProperty('dir', '')) === 'desc' ? 'desc' : 'asc';
56+
$c->orderBy('created_at', $dir);
57+
} else {
58+
$c = parent::addSorting($c);
59+
}
60+
}
4561

4662
return $c;
4763
}
@@ -85,6 +101,11 @@ protected function afterSave(Model $record): Model
85101
}
86102
}
87103

104+
if ($record->payment && $payment = $this->getProperty('payment')) {
105+
$record->payment->paid = $payment['paid'] ?? null;
106+
$record->payment->save();
107+
}
108+
88109
$record->calculate();
89110

90111
return $record;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace App\Controllers\User;
4+
5+
use App\Models\Order;
6+
use Illuminate\Database\Eloquent\Builder;
7+
use Vesp\Controllers\ModelGetController;
8+
9+
class Orders extends ModelGetController
10+
{
11+
protected $scope = 'profile';
12+
protected $model = Order::class;
13+
14+
protected function beforeGet(Builder $c): Builder
15+
{
16+
$c->where('user_id', $this->user->id);
17+
$c->with('address');
18+
$c->with('payment');
19+
$c->with('orderProducts', 'orderProducts.product');
20+
21+
return $c;
22+
}
23+
24+
protected function beforeCount(Builder $c): Builder
25+
{
26+
$c->where('user_id', $this->user->id);
27+
if ($query = trim($this->getProperty('query', ''))) {
28+
$c->where('num', 'LIKE', "$query%");
29+
}
30+
31+
return $c;
32+
}
33+
34+
protected function afterCount(Builder $c): Builder
35+
{
36+
$c->withCount('orderProducts');
37+
$c->with('payment:order_id,paid');
38+
39+
return $c;
40+
}
41+
42+
protected function addSorting(Builder $c): Builder
43+
{
44+
if ($sort = $this->getProperty('sort')) {
45+
if ($sort === 'num') {
46+
$dir = strtolower($this->getProperty('dir', '')) === 'desc' ? 'desc' : 'asc';
47+
$c->orderBy('created_at', $dir);
48+
} else {
49+
$c = parent::addSorting($c);
50+
}
51+
}
52+
53+
return $c;
54+
}
55+
56+
protected function getPrimaryKey(): ?array
57+
{
58+
if ($uuid = $this->getProperty('uuid')) {
59+
return ['uuid' => $uuid];
60+
}
61+
62+
return null;
63+
}
64+
}

‎core/src/Models/Payment.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ class Payment extends Model
3131
];
3232
protected $guarded = ['paid', 'paid_at'];
3333

34+
protected static function booted(): void
35+
{
36+
static::saving(static function (self $model) {
37+
if (!$model->paid && $model->paid_at) {
38+
$model->paid_at = null;
39+
} elseif ($model->paid && !$model->paid_at) {
40+
$model->paid_at = Carbon::now();
41+
}
42+
});
43+
}
44+
3445
public function order(): BelongsTo
3546
{
3647
return $this->belongsTo(Order::class);

‎frontend/src/admin/components/forms/order.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<b-row>
4545
<b-col md="6">
4646
<b-form-group :label="$t('models.order.cart')">
47-
<b-form-input :value="$price(record.cart, null)" disabled />
47+
<b-form-input :value="$price(record.cart)" disabled />
4848
</b-form-group>
4949
</b-col>
5050
<b-col md="6">
@@ -72,7 +72,7 @@
7272
</b-row>
7373

7474
<b-form-group :label="$t('models.order.comment')">
75-
<b-form-textarea v-model.trim="record.comment" rows="5" autofocus />
75+
<b-form-textarea v-model.trim="record.comment" rows="5" />
7676
</b-form-group>
7777
</div>
7878
</template>

‎frontend/src/admin/components/order/address.vue‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
</div>
2525
</b-form-group>
2626

27-
<b-form-group :label="$t('models.user_address.company')">
28-
<b-form-input v-model.trim="myValue.address.company" :disabled="myValue.address_id > 0" />
29-
</b-form-group>
30-
3127
<b-form-group :label="$t('models.user_address.receiver')">
3228
<b-form-input v-model.trim="myValue.address.receiver" :disabled="myValue.address_id > 0" />
3329
</b-form-group>
3430

31+
<b-form-group :label="$t('models.user_address.company')">
32+
<b-form-input v-model.trim="myValue.address.company" :disabled="myValue.address_id > 0" />
33+
</b-form-group>
34+
3535
<b-form-group :label="$t('models.user_address.address')">
3636
<b-form-input v-model.trim="myValue.address.address" :disabled="myValue.address_id > 0" />
3737
</b-form-group>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<template>
2+
<div>
3+
<b-form-group :label="$t('models.payment.service')">
4+
<b-form-input :value="record.service" disabled />
5+
</b-form-group>
6+
7+
<b-row>
8+
<b-col md="6">
9+
<b-form-group :label="$t('models.payment.amount')">
10+
<b-form-input :value="record.amount" disabled />
11+
</b-form-group>
12+
</b-col>
13+
<b-col md="6">
14+
<b-form-group :label="$t('models.payment.paid')">
15+
<b-form-select v-model="record.paid" :options="paidOptions" />
16+
</b-form-group>
17+
</b-col>
18+
</b-row>
19+
20+
<b-form-group :label="$t('models.payment.link')">
21+
<b-form-textarea :value="record.link" rows="2" disabled />
22+
</b-form-group>
23+
<b-form-group :label="$t('models.payment.remote_id')" disabled>
24+
<b-form-input :value="record.remote_id" />
25+
</b-form-group>
26+
27+
<b-row>
28+
<b-col md="6">
29+
<b-form-group :label="$t('models.payment.created_at')">
30+
<b-form-input :value="$options.filters.datetime(record.created_at)" disabled />
31+
</b-form-group>
32+
</b-col>
33+
<b-col md="6">
34+
<b-form-group :label="$t('models.payment.paid_at')">
35+
<vesp-input-date-picker v-model="record.paid_at" type="datetime" />
36+
</b-form-group>
37+
</b-col>
38+
</b-row>
39+
</div>
40+
</template>
41+
42+
<script>
43+
export default {
44+
name: 'OrderPayment',
45+
props: {
46+
value: {
47+
type: Object,
48+
required: true,
49+
},
50+
},
51+
computed: {
52+
record: {
53+
get() {
54+
return this.value
55+
},
56+
set(newValue) {
57+
this.$emit('input', newValue)
58+
},
59+
},
60+
paidOptions() {
61+
return [
62+
{text: this.$t('models.payment.paid_null'), value: null},
63+
{text: this.$t('models.payment.paid_true'), value: true},
64+
{text: this.$t('models.payment.paid_false'), value: false},
65+
]
66+
},
67+
},
68+
}
69+
</script>

‎frontend/src/admin/components/product/options.vue‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export default {
4040
type: String,
4141
default: 'primary',
4242
},
43+
disabled: {
44+
type: Boolean,
45+
default: false,
46+
},
4347
},
4448
data() {
4549
return {
@@ -79,7 +83,7 @@ export default {
7983
return this.isActive(option, variant) ? this.variantActive : this.variantInactive
8084
},
8185
onSelect(option, variant) {
82-
if (option === 'discount') {
86+
if (this.disabled) {
8387
return
8488
}
8589
const record = {...this.record}

‎frontend/src/admin/lexicons/en.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default {
9898
tab_main: 'Main',
9999
tab_products: 'Products',
100100
tab_address: 'Address',
101+
tab_payment: 'Payment',
101102
num: 'Number',
102103
address: 'Address',
103104
cart: 'Cart',
@@ -128,6 +129,21 @@ export default {
128129
email: 'Email',
129130
phone: 'Phone',
130131
},
132+
payment: {
133+
title_one: 'Payment',
134+
title_many: 'Payments',
135+
service: 'Service',
136+
amount: 'Amount',
137+
paid: 'Status',
138+
paid_null: 'Waiting',
139+
paid_true: 'Paid',
140+
paid_false: 'Cancelled',
141+
link: 'Payment Link',
142+
remote_id: 'Remote Id',
143+
created_at: 'Created At',
144+
updated_at: 'Updated At',
145+
paid_at: 'Paid At',
146+
},
131147
},
132148
errors: {
133149
user: {

‎frontend/src/admin/lexicons/ru.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default {
9898
tab_main: 'Основное',
9999
tab_products: 'Товары',
100100
tab_address: 'Адрес',
101+
tab_payment: 'Оплата',
101102
num: 'Номер',
102103
address: 'Адрес',
103104
cart: 'Корзина',
@@ -128,6 +129,21 @@ export default {
128129
email: 'Email',
129130
phone: 'Телефон',
130131
},
132+
payment: {
133+
title_one: 'Оплата',
134+
title_many: 'Платежи',
135+
service: 'Сервис',
136+
amount: 'Сумма',
137+
paid: 'Статус',
138+
paid_null: 'Ожидание',
139+
paid_true: 'Оплачено',
140+
paid_false: 'Отменено',
141+
link: 'Ссылка на оплату',
142+
remote_id: 'Идентификатор на сервисе',
143+
created_at: 'Дата создания',
144+
updated_at: 'Дата изменения',
145+
paid_at: 'Дата оплаты',
146+
},
131147
},
132148
errors: {
133149
user: {

0 commit comments

Comments
 (0)