Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8908a842
authored
Nov 10, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
地址补充接口完善
parent
4e77187f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
8 deletions
.idea/workspace.xml
app/Http/Controllers/Api/UserAddressApiController.php
app/Http/Requests/UserAddressSave.php
app/Http/Services/UserAddressService.php
.idea/workspace.xml
View file @
8908a842
...
...
@@ -3,8 +3,9 @@
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"fb90add0-1393-48c2-9f26-72365d42cd03"
name=
"变更"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Api/AuthApiController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/UserModel.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/UserModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Api/UserAddressApiController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Requests/UserAddressSave.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Requests/UserAddressSave.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Services/UserAddressService.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Services/UserAddressService.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/bootstrap/app.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/bootstrap/app.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/bootstrap/cache/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/bootstrap/cache/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/app/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/app/.gitignore"
afterDir=
"false"
/>
...
...
@@ -188,7 +189,7 @@
<workItem
from=
"1666835076791"
duration=
"693000"
/>
<workItem
from=
"1667266026118"
duration=
"40321000"
/>
<workItem
from=
"1667959054458"
duration=
"183000"
/>
<workItem
from=
"1667986756173"
duration=
"
3812
000"
/>
<workItem
from=
"1667986756173"
duration=
"
5340
000"
/>
</task>
<servers
/>
</component>
...
...
app/Http/Controllers/Api/UserAddressApiController.php
View file @
8908a842
...
...
@@ -40,7 +40,8 @@ class UserAddressApiController extends Controller
'detail_address'
,
'city'
,
'province'
,
'post_code'
'post_code'
,
'is_default'
]);
$user
=
$request
->
user
;
$result
=
UserAddressService
::
addUserAddress
(
$address
,
$user
);
...
...
@@ -65,7 +66,8 @@ class UserAddressApiController extends Controller
'detail_address'
,
'city'
,
'province'
,
'post_code'
'post_code'
,
'is_default'
,
]);
$user
=
$request
->
user
;
$result
=
UserAddressService
::
updateUserAddress
(
$address
,
$user
);
...
...
app/Http/Requests/UserAddressSave.php
View file @
8908a842
...
...
@@ -24,8 +24,6 @@ class UserAddressSave extends BaseRequest
public
function
rules
()
{
$rules
=
[
'email'
=>
'required|email'
,
'phone'
=>
'required|max:20'
,
'country'
=>
'required|max:64'
,
'province'
=>
'required|max:64'
,
'city'
=>
'required|max:64'
,
...
...
@@ -35,6 +33,12 @@ class UserAddressSave extends BaseRequest
'detail_address'
=>
'required|max:255'
,
'post_code'
=>
'required|max:10'
,
];
$isRegister
=
request
()
->
input
(
'is_register'
);
if
(
!
$isRegister
)
{
$rules
[
'email'
]
=
'required|email'
;
$rules
[
'phone'
]
=
'required|max:20'
;
}
if
(
request
()
->
routeIs
(
'user_address.update'
))
{
$rules
[
'address_id'
]
=
'required'
;
}
...
...
app/Http/Services/UserAddressService.php
View file @
8908a842
...
...
@@ -10,6 +10,11 @@ class UserAddressService
public
static
function
addUserAddress
(
$address
,
$user
)
{
return
DB
::
transaction
(
function
()
use
(
$address
,
$user
)
{
//如果没有邮箱和电话,就代表是注册的时候去新建的地址
if
(
empty
(
$address
[
'email'
])
&&
empty
(
$address
[
'phone'
]))
{
$address
[
'email'
]
=
$user
->
email
;
$address
[
'phone'
]
=
$user
->
phone
;
}
$address
[
'user_id'
]
=
$user
->
id
;
$address
[
'create_time'
]
=
time
();
return
UserAddressModel
::
insert
(
$address
);
...
...
@@ -19,9 +24,12 @@ class UserAddressService
public
static
function
updateUserAddress
(
$address
,
$user
)
{
return
DB
::
transaction
(
function
()
use
(
$address
,
$user
)
{
if
(
$address
[
'is_default'
])
{
UserAddressModel
::
where
(
'user_id'
,
$user
->
id
)
->
update
([
'is_default'
=>
0
]);
}
$address
[
'user_id'
]
=
$user
->
id
;
$address
[
'create_time'
]
=
time
();
return
UserAddressModel
::
where
(
'address_id'
,
$address
[
'address_id'
])
->
update
(
$address
);
return
UserAddressModel
::
where
(
'address_id'
,
$address
[
'address_id'
])
->
update
(
$address
);
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment