Skip to content

Commit 3699d8d

Browse files
committed
47. command for update offline user full names
1 parent 1c05ef8 commit 3699d8d

File tree

5 files changed

+193
-29
lines changed

5 files changed

+193
-29
lines changed

docs/1c-tabes.md

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,62 @@
5454
| F=SP5923 | (P)_48 | N | 13 | 0 |
5555

5656
## TABLE SC6104: Справочник ОффлайнЗаказы
57-
| Name | Descr | Type | Length | Precision |
58-
| ----------- |--------------------- | ---- | ------ | ---------- |
59-
| F=ID | ID object | C | 9 | 0 |
60-
| F=CODE | object code | C | 12 | 0 |
61-
| F=DESCR | ФИО пользователя | C | 50 | 0 |
62-
| F=ISMARK | Flag is Market | C | 1 | 0 |
63-
| F=VERSTAMP | Version stamp | C | 6 | 0 |
64-
| F=SP6089 | (P)ДисконтнаяКарта | C | 9 | 0 |
65-
| F=SP6090 | (P)КодДК | C | 13 | 0 |
66-
| F=SP6091 | (P)Товар | C | 9 | 0 |
67-
| F=SP6092 | (P)КодТовара | N | 8 | 0 |
68-
| F=SP6093 | (P)Артикул | C | 30 | 0 |
69-
| F=SP6094 | (P)НаименованиеТовар | C | 100 | 0 |
70-
| F=SP6095 | (P)Магазин | C | 9 | 0 |
71-
| F=SP6096 | (P)КодМагазина | N | 6 | 0 |
72-
| F=SP6097 | (P)ДатаПродажи | D | 8 | 0 |
73-
| F=SP6098 | (P)НомерЧека | C | 10 | 0 |
74-
| F=SP6099 | (P)Количество | N | 11 | 0 |
75-
| F=SP6100 | (P)Размер | N | 3 | 0 |
76-
| F=SP6101 | (P)Сумма | N | 19 | 2 |
77-
| F=SP6102 | (P)Телефон | C | 15 | 0 |
78-
| F=SP6107 | (P)ВремяПродаж | C | 8 | 0 |
79-
| F=SP6108 | (P)ДатаВозврата | D | 8 | 0 |
80-
| F=SP6109 | (P)ВремяВозврата | C | 8 | 0 |
81-
| F=SP6110 | (P)НомерВозврата | C | 10 | 0 |
82-
| F=SP6126 | (P)ФИО | C | 99 | 0 |
83-
| F=SP6129 | (P)Фамилия | C | 32 | 0 |
84-
| F=SP6130 | (P)Имя | C | 32 | 0 |
85-
| F=SP6131 | (P)Отчество | C | 32 | 0 |
57+
| Name | Descr | Type | Length | Precision |
58+
| ----------- |--------------------- | ---- | ------ | --------- |
59+
| F=ID | ID object | C | 9 | 0 |
60+
| F=CODE | object code | C | 12 | 0 |
61+
| F=DESCR | ФИО пользователя | C | 50 | 0 |
62+
| F=ISMARK | Flag is Market | C | 1 | 0 |
63+
| F=VERSTAMP | Version stamp | C | 6 | 0 |
64+
| F=SP6089 | (P)ДисконтнаяКарта | C | 9 | 0 |
65+
| F=SP6090 | (P)КодДК | C | 13 | 0 |
66+
| F=SP6091 | (P)Товар | C | 9 | 0 |
67+
| F=SP6092 | (P)КодТовара | N | 8 | 0 |
68+
| F=SP6093 | (P)Артикул | C | 30 | 0 |
69+
| F=SP6094 | (P)НаименованиеТовар | C | 100 | 0 |
70+
| F=SP6095 | (P)Магазин | C | 9 | 0 |
71+
| F=SP6096 | (P)КодМагазина | N | 6 | 0 |
72+
| F=SP6097 | (P)ДатаПродажи | D | 8 | 0 |
73+
| F=SP6098 | (P)НомерЧека | C | 10 | 0 |
74+
| F=SP6099 | (P)Количество | N | 11 | 0 |
75+
| F=SP6100 | (P)Размер | N | 3 | 0 |
76+
| F=SP6101 | (P)Сумма | N | 19 | 2 |
77+
| F=SP6102 | (P)Телефон | C | 15 | 0 |
78+
| F=SP6107 | (P)ВремяПродаж | C | 8 | 0 |
79+
| F=SP6108 | (P)ДатаВозврата | D | 8 | 0 |
80+
| F=SP6109 | (P)ВремяВозврата | C | 8 | 0 |
81+
| F=SP6110 | (P)НомерВозврата | C | 10 | 0 |
82+
| F=SP6126 | (P)ФИО | C | 99 | 0 |
83+
| F=SP6129 | (P)Фамилия | C | 32 | 0 |
84+
| F=SP6130 | (P)Имя | C | 32 | 0 |
85+
| F=SP6131 | (P)Отчество | C | 32 | 0 |
86+
87+
88+
## TABLE SC3964: Справочник ДисконтныеКарты
89+
| # Name | Descr | Type | Length | Precision |
90+
| ----------- | -------------------- | ---- | ------ | --------- |
91+
| F=ID | ID object | C | 9 | 0 |
92+
| F=CODE | object code | C | 13 | 0 |
93+
| F=DESCR | object description | C | 30 | 0 |
94+
| F=ISMARK | Flag is Market | C | 1 | 0 |
95+
| F=VERSTAMP | Version stamp | C | 6 | 0 |
96+
| F=SP4352 | (P)Фамилия | C | 50 | 0 |
97+
| F=SP4353 | (P)Имя | C | 18 | 0 |
98+
| F=SP4354 | (P)Отчество | C | 20 | 0 |
99+
| F=SP4355 | (P)Представление | C | 30 | 0 |
100+
| F=SP3966 | (P)ТелефонДом | C | 15 | 0 |
101+
| F=SP3967 | (P)ТелефонМоб | C | 15 | 0 |
102+
| F=SP3968 | (P)Почта | C | 30 | 0 |
103+
| F=SP3969 | (P)Адрес | C | 100 | 0 |
104+
| F=SP3970 | (P)ДеньРождения | D | 8 | 0 |
105+
| F=SP3972 | (P)Скидка | N | 3 | 0 |
106+
| F=SP3997 | (P)ДатаВыдачи | D | 8 | 0 |
107+
| F=SP4356 | (P)Пол | C | 9 | 0 |
108+
| F=SP3965 | (P)ФИО | C | 50 | 0 |
109+
| F=SP4934 | (P)ПостояннаяСкидка | N | 2 | 0 |
110+
| F=SP4935 | (P)НакопительнаяСумм | N | 16 | 2 |
111+
| F=SP5001 | (P)Дополнительно | C | 560 | 0 |
112+
| F=SP5538 | (P)НачальнаяСумма | N | 16 | 2 |
113+
| F=SP5604 | (P)СогласенНаРассылку| N | 2 | 0 |
114+
| F=SP5749 | (P)Бонусная | N | 2 | 0 |
115+
| F=SP5750 | (P)КоличествоБонусов | N | 7 | 0 |
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace App\Console\Commands\OneRun;
4+
5+
use App\Models\OneC\DiscountCard;
6+
use App\Models\User\User;
7+
use Illuminate\Console\Command;
8+
use Illuminate\Database\Eloquent\Collection;
9+
10+
class UpdateOfflineUserFullNames extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'one-run:update-offline-user-full-names';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Update full names of users who have offline orders';
25+
26+
/**
27+
* Execute the console command.
28+
*/
29+
public function handle()
30+
{
31+
/** @var Collection|User[] */
32+
$users = User::query()
33+
->has('offlineOrders')
34+
->whereNull('last_name')
35+
->get(['id', 'discount_card_number', 'first_name', 'last_name', 'patronymic_name']);
36+
37+
$this->output->progressStart($users->count());
38+
39+
foreach ($users as $user) {
40+
$this->updateFullName($user);
41+
$this->output->progressAdvance();
42+
}
43+
44+
$this->output->progressFinish();
45+
}
46+
47+
private function updateFullName(User $user): void
48+
{
49+
$id = str_pad($user->discount_card_number, 9, ' ', STR_PAD_LEFT);
50+
/** @var DiscountCard|null */
51+
$userFullNameFromDiscountCard = DiscountCard::query()
52+
->where('ID', $id)
53+
->first([
54+
'SP4353 as first_name',
55+
'SP4352 as last_name',
56+
'SP4354 as patronymic_name',
57+
]);
58+
59+
if (!$userFullNameFromDiscountCard) {
60+
return;
61+
}
62+
63+
$user->update($userFullNameFromDiscountCard->toArray());
64+
}
65+
}

src/app/Models/OneC/DiscountCard.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Models\OneC;
4+
5+
/**
6+
* @property string $ID ID object
7+
* @property string $CODE object code
8+
* @property string $DESCR object description
9+
* @property string $ISMARK Flag is Market
10+
* @property string $VERSTAMP Version stamp
11+
* @property string $SP4352 Фамилия
12+
* @property string $SP4353 Имя
13+
* @property string $SP4354 Отчество
14+
* @property string $SP4355 Представление
15+
* @property string $SP3966 ТелефонДом
16+
* @property string $SP3967 ТелефонМоб
17+
* @property string $SP3968 Почта
18+
* @property string $SP3969 Адрес
19+
* @property string $SP3970 ДеньРождения
20+
* @property string $SP3972 Скидка
21+
* @property string $SP3997 ДатаВыдачи
22+
* @property string $SP4356 Пол
23+
* @property string $SP3965 ФИО
24+
* @property string $SP4934 ПостояннаяСкидка
25+
* @property string $SP4935 НакопительнаяСумм
26+
* @property string $SP5001 Дополнительно
27+
* @property string $SP5538 НачальнаяСумма
28+
* @property string $SP5604 СогласенНаРассылку
29+
* @property string $SP5749 Бонусная
30+
* @property string $SP5750 КоличествоБонусов
31+
*/
32+
class DiscountCard extends AbstractOneCModel
33+
{
34+
/**
35+
* The table associated with the model.
36+
*
37+
* @var string
38+
*/
39+
protected $table = 'SC3964';
40+
41+
/**
42+
* The attributes that are mass assignable.
43+
*
44+
* @var array<int, string>
45+
*/
46+
protected $fillable = [];
47+
}

src/app/Models/User/User.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use App\Models\Country;
77
use App\Models\Feedback;
88
use App\Models\Logs\SmsLog;
9+
use App\Models\OneC;
10+
use App\Models\Orders\OfflineOrder;
911
use App\Models\Orders\Order;
1012
use App\Models\Payments\OnlinePayment;
1113
use Illuminate\Contracts\Auth\MustVerifyEmail;
@@ -46,6 +48,7 @@
4648
* @property-read \App\Models\User\UserPassport|null $passport
4749
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User\Address[] $addresses
4850
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Orders\Order[] $orders
51+
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Orders\OfflineOrder[] $offlineOrders
4952
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Feedback[] $reviews
5053
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Logs\SmsLog[] $mailings
5154
* @property-read \App\Models\User\UserBlacklist|null $blacklist
@@ -231,6 +234,14 @@ public function orders(): HasMany
231234
return $this->hasMany(Order::class);
232235
}
233236

237+
/**
238+
* User's offline orders
239+
*/
240+
public function offlineOrders(): HasMany
241+
{
242+
return $this->hasMany(OfflineOrder::class);
243+
}
244+
234245
/**
235246
* User's reviews
236247
*/
@@ -285,6 +296,16 @@ public function usedPromocodes(): HasMany
285296
return $this->hasMany(UserPromocode::class);
286297
}
287298

299+
/**
300+
* Get the user discount card from 1C associated with the user.
301+
*
302+
* Problem with excess spaces
303+
*/
304+
public function discountCard(): BelongsTo
305+
{
306+
return $this->belongsTo(OneC\DiscountCard::class, 'discount_card_number', 'ID');
307+
}
308+
288309
/**
289310
* Update datetime in phone_verified_at field
290311
*/

src/config/model-doc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
// Ignore models by FQCN
5151
'ignore' => [
52+
\App\Models\OneC\DiscountCard::class,
5253
\App\Models\OneC\OfflineOrder::class,
5354
\App\Models\OneC\Product::class,
5455
],

0 commit comments

Comments
 (0)