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
ab5dd96d
authored
Nov 07, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
用户模型修改
parent
b35f33bd
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
101 additions
and
36 deletions
.idea/workspace.xml
app/Http/Controllers/Api/AuthApiController.php
app/Http/Controllers/Api/InquiryApiController.php
app/Http/Controllers/Auth/RegisterController.php
app/Http/Services/InquiryService.php
app/Models/InquiryItems.php → app/Models/InquiryItemsModel.php
app/Models/Inquiry.php → app/Models/InquiryModel.php
app/Models/UserAddress.php → app/Models/UserAddressModel.php
app/Models/User.php → app/Models/UserModel.php
config/auth.php
config/field.php
database/factories/UserAddressFactory.php
database/factories/UserFactory.php
database/seeds/UserAddressSeeder.php
routes/api.php
.idea/workspace.xml
View file @
ab5dd96d
...
...
@@ -3,9 +3,20 @@
<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/Http/Controllers/Api/InquiryApiController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Api/InquiryApiController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Controllers/Auth/RegisterController.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Http/Services/InquiryService.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Http/Services/InquiryService.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/Inquiry.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/Inquiry.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/Inquiry.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/InquiryModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/InquiryItems.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/InquiryItemsModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/User.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/UserModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/app/Models/UserAddress.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/app/Models/UserAddressModel.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/config/auth.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/config/auth.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/config/field.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/config/field.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/database/factories/UserAddressFactory.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/database/factories/UserAddressFactory.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/database/factories/UserFactory.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/database/factories/UserFactory.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/database/seeds/UserAddressSeeder.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/database/seeds/UserAddressSeeder.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/routes/api.php"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/routes/api.php"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/app/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/app/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/app/public/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/app/public/.gitignore"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/storage/framework/.gitignore"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/storage/framework/.gitignore"
afterDir=
"false"
/>
...
...
@@ -184,7 +195,7 @@
<updated>
1666170258203
</updated>
<workItem
from=
"1666170260162"
duration=
"17108000"
/>
<workItem
from=
"1666835076791"
duration=
"693000"
/>
<workItem
from=
"1667266026118"
duration=
"2
2846
000"
/>
<workItem
from=
"1667266026118"
duration=
"2
5211
000"
/>
</task>
<servers
/>
</component>
...
...
app/Http/Controllers/Api/AuthApiController.php
View file @
ab5dd96d
...
...
@@ -3,7 +3,7 @@
namespace
App\Http\Controllers\Api
;
use
App\Http\Requests\UserRegister
;
use
App\Models\User
;
use
App\Models\User
Model
;
use
Illuminate\Foundation\Auth\RegistersUsers
;
use
Illuminate\Foundation\Auth\ThrottlesLogins
;
use
Illuminate\Http\Request
;
...
...
@@ -21,7 +21,7 @@ class AuthApiController extends Controller
public
function
register
(
UserRegister
$request
)
{
$email
=
$request
->
input
(
'email'
);
if
(
User
::
where
(
'email'
,
$email
)
->
exists
())
{
if
(
User
Model
::
where
(
'email'
,
$email
)
->
exists
())
{
return
$this
->
setError
(
'Email has been taken'
);
}
...
...
@@ -31,7 +31,7 @@ class AuthApiController extends Controller
if
(
$cachedEmailCode
!=
$request
->
input
(
'email_code'
))
{
return
$this
->
setError
(
'Email code invalid'
);
}
$user
=
User
::
createUser
(
$request
->
all
());
$user
=
User
Model
::
createUser
(
$request
->
all
());
\Auth
::
login
(
$user
);
return
$this
->
setSuccess
(
'Register success'
);
...
...
@@ -51,7 +51,7 @@ class AuthApiController extends Controller
return
$this
->
setError
(
$validator
->
errors
()
->
first
());
}
$userExists
=
User
::
where
(
'email'
,
$request
->
email
)
->
exists
();
$userExists
=
User
Model
::
where
(
'email'
,
$request
->
email
)
->
exists
();
if
(
!
$userExists
)
{
return
$this
->
setError
(
'User dose not exist'
);
}
...
...
@@ -90,12 +90,12 @@ class AuthApiController extends Controller
$password
=
$request
->
get
(
'password'
);
$oldPassword
=
$request
->
get
(
'old_password'
);
$userId
=
Auth
::
user
()
->
id
;
$hashedPassword
=
User
::
where
(
'id'
,
$userId
)
->
value
(
'password'
);
$hashedPassword
=
User
Model
::
where
(
'id'
,
$userId
)
->
value
(
'password'
);
if
(
!
Hash
::
check
(
$oldPassword
,
$hashedPassword
))
{
return
$this
->
setError
(
'Wrong Password!'
);
}
$user
=
User
::
find
(
$userId
);
$user
=
User
Model
::
find
(
$userId
);
$user
->
password
=
Hash
::
make
(
$password
);
$user
->
update_time
=
time
();
$result
=
$user
->
save
();
...
...
@@ -114,7 +114,7 @@ class AuthApiController extends Controller
if
(
!
$email
)
{
return
$this
->
setError
(
'Email address required'
);
}
$info
=
User
::
where
(
'email'
,
$email
)
->
first
();
$info
=
User
Model
::
where
(
'email'
,
$email
)
->
first
();
if
(
$info
&&
$type
==
'register'
)
{
return
$this
->
setError
(
'This email had been registered'
);
}
...
...
app/Http/Controllers/Api/InquiryApiController.php
View file @
ab5dd96d
...
...
@@ -27,12 +27,19 @@ class InquiryApiController extends Controller
return
$this
->
setSuccess
(
'Add inquiry success'
);
}
public
function
list
s
(
Request
$request
)
public
function
list
(
Request
$request
)
{
$searchKeyWord
=
$request
->
input
(
'keyword'
);
$status
=
$request
->
input
(
'status'
);
$userId
=
$request
->
user
->
id
;
$result
=
InquiryService
::
getInquiryList
(
$userId
,
$searchKeyWord
,
$status
);
return
$this
->
setSuccessData
(
$result
);
return
$this
->
setSuccessData
(
$result
[
'data'
],
$result
[
'total'
]);
}
public
function
detail
(
Request
$request
)
{
$inquiryId
=
$request
->
input
(
'inquiry_id'
);
$inquiry
=
InquiryService
::
getInquiryDetail
(
$inquiryId
);
return
$this
->
setSuccessData
(
$inquiry
);
}
}
app/Http/Controllers/Auth/RegisterController.php
View file @
ab5dd96d
...
...
@@ -3,7 +3,7 @@
namespace
App\Http\Controllers\Auth
;
use
App\Http\Controllers\Controller
;
use
App\Models\User
;
use
App\Models\User
Model
;
use
App\Providers\RouteServiceProvider
;
use
Illuminate\Foundation\Auth\RegistersUsers
;
use
Illuminate\Support\Facades\Hash
;
...
...
@@ -60,11 +60,11 @@ class RegisterController extends Controller
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
* @return \App\Models\User
Model
*/
protected
function
create
(
array
$data
)
{
return
User
::
create
([
return
User
Model
::
create
([
'name'
=>
$data
[
'name'
],
'email'
=>
$data
[
'email'
],
'password'
=>
Hash
::
make
(
$data
[
'password'
]),
...
...
app/Http/Services/InquiryService.php
View file @
ab5dd96d
...
...
@@ -2,8 +2,8 @@
namespace
App\Http\Services
;
use
App\Models\Inquiry
;
use
App\Models\InquiryItems
;
use
App\Models\Inquiry
Model
;
use
App\Models\InquiryItems
Model
;
use
Illuminate\Support\Facades\DB
;
class
InquiryService
...
...
@@ -19,7 +19,7 @@ class InquiryService
'remark'
=>
$remark
,
'create_time'
=>
time
(),
];
$inquiryId
=
Inquiry
::
addInquiry
(
$inquiry
);
$inquiryId
=
Inquiry
Model
::
addInquiry
(
$inquiry
);
$inquiryItems
=
[];
foreach
(
$items
as
$item
)
{
$inquiryItems
[]
=
[
...
...
@@ -31,16 +31,44 @@ class InquiryService
'create_time'
=>
$item
[
'create_time'
],
];
}
return
InquiryItems
::
addInquiryItems
(
$inquiryItems
);
return
InquiryItems
Model
::
addInquiryItems
(
$inquiryItems
);
});
}
public
function
getInquiryList
(
$userId
,
$searchKeyWord
,
$status
)
public
static
function
getInquiryDetail
(
$inquiryId
)
{
$query
=
Inquiry
::
where
(
'user_id'
,
$userId
)
->
orderBy
(
'inquiry_id'
,
'desc'
);
$inquiry
=
InquiryModel
::
where
(
'inquiry_id'
,
$inquiryId
)
->
first
()
->
toArray
();
$inquiryItems
=
InquiryItemsModel
::
where
(
'inquiry_id'
,
$inquiryId
)
->
get
()
->
toArray
();
$inquiry
[
'items'
]
=
$inquiryItems
;
return
$inquiry
;
}
public
static
function
getInquiryList
(
$userId
,
$searchKeyWord
,
$status
)
{
$query
=
InquiryModel
::
with
(
'inquiry_items'
)
->
select
([
'inquiry_id'
,
'inquiry_sn'
,
'create_time'
,
'remark'
,
'status'
])
->
where
(
'user_id'
,
$userId
)
->
orderBy
(
'inquiry_id'
,
'desc'
);
if
(
!
empty
(
$searchKeyWord
))
{
// $query->where('goods_name')
$query
->
whereHas
(
'inquiry_items'
,
function
(
$q
)
use
(
$searchKeyWord
)
{
$q
->
where
(
'goods_name'
,
$searchKeyWord
);
});
}
if
(
!
empty
(
$status
))
{
$query
->
where
(
'status'
,
$status
);
}
$result
=
$query
->
paginate
(
10
)
->
toArray
();
foreach
(
$result
[
'data'
]
as
&
$item
)
{
$item
[
'create_time'
]
=
date
(
'Y-m-d H:i:s'
,
$item
[
'create_time'
]);
$item
[
'status_name'
]
=
\Arr
::
get
(
config
(
'field.inquiry_status'
),
$item
[
'status'
]);
$item
[
'goods_name'
]
=
\Arr
::
get
(
\Arr
::
get
(
$item
[
'inquiry_items'
],
0
),
'goods_name'
,
''
);
unset
(
$item
[
'inquiry_items'
]);
}
unset
(
$item
);
return
$result
;
}
}
app/Models/InquiryItems.php
→
app/Models/InquiryItems
Model
.php
View file @
ab5dd96d
...
...
@@ -4,8 +4,11 @@ namespace App\Models;
use
Illuminate\Database\Eloquent\Model
;
class
InquiryItems
extends
Model
class
InquiryItems
Model
extends
Model
{
protected
$table
=
'inquiry_items'
;
public
$timestamps
=
false
;
public
static
function
addInquiryItems
(
$inquiryItems
=
[])
...
...
app/Models/Inquiry.php
→
app/Models/Inquiry
Model
.php
View file @
ab5dd96d
...
...
@@ -4,14 +4,16 @@ namespace App\Models;
use
Illuminate\Database\Eloquent\Model
;
class
Inquiry
extends
Model
class
Inquiry
Model
extends
Model
{
//
protected
$table
=
'inquiry'
;
public
$timestamps
=
false
;
public
function
inquiry_items
()
{
return
$this
->
hasMany
(
InquiryItems
::
class
,
'inquiry_id'
,
'inquiry_id'
);
return
$this
->
hasMany
(
InquiryItems
Model
::
class
,
'inquiry_id'
,
'inquiry_id'
);
}
public
static
function
addInquiry
(
$inquiry
)
...
...
app/Models/UserAddress.php
→
app/Models/UserAddress
Model
.php
View file @
ab5dd96d
...
...
@@ -4,15 +4,17 @@ namespace App\Models;
use
Illuminate\Database\Eloquent\Model
;
class
UserAddress
extends
Model
class
UserAddress
Model
extends
Model
{
protected
$table
=
'user_address'
;
//
protected
$fillable
=
[
];
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
);
return
$this
->
belongsTo
(
User
Model
::
class
);
}
}
app/Models/User.php
→
app/Models/User
Model
.php
View file @
ab5dd96d
...
...
@@ -7,10 +7,12 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Support\Facades\Hash
;
class
User
extends
Authenticatable
implements
MustVerifyEmail
class
User
Model
extends
Authenticatable
implements
MustVerifyEmail
{
use
Notifiable
;
protected
$table
=
'users'
;
/**
* The attributes that are mass assignable.
*
...
...
@@ -45,7 +47,7 @@ class User extends Authenticatable implements MustVerifyEmail
public
static
function
createUser
(
$data
)
{
return
User
::
create
([
return
User
Model
::
create
([
'first_name'
=>
$data
[
'first_name'
],
'last_name'
=>
$data
[
'last_name'
],
'phone'
=>
$data
[
'phone'
],
...
...
config/auth.php
View file @
ab5dd96d
...
...
@@ -68,7 +68,7 @@ return [
'providers'
=>
[
'users'
=>
[
'driver'
=>
'eloquent'
,
'model'
=>
App\Models\User
::
class
,
'model'
=>
App\Models\User
Model
::
class
,
],
// 'users' => [
...
...
config/field.php
View file @
ab5dd96d
...
...
@@ -2,4 +2,10 @@
return
[
'public_url'
=>
env
(
'PUBLIC_URL'
),
'inquiry_status'
=>
[
-
1
=>
'Closed'
,
0
=>
'Pending'
,
1
=>
'Replied'
,
]
];
database/factories/UserAddressFactory.php
View file @
ab5dd96d
...
...
@@ -2,10 +2,10 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use
App\Models\UserAddress
;
use
App\Models\UserAddress
Model
;
use
Faker\Generator
as
Faker
;
$factory
->
define
(
UserAddress
::
class
,
function
(
Faker
$faker
)
{
$factory
->
define
(
UserAddress
Model
::
class
,
function
(
Faker
$faker
)
{
return
[
'user_id'
=>
$faker
->
numberBetween
(
10000
,
20000
),
'country'
=>
$faker
->
country
,
...
...
database/factories/UserFactory.php
View file @
ab5dd96d
...
...
@@ -2,7 +2,7 @@
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use
App\Models\User
;
use
App\Models\User
Model
;
use
Faker\Generator
as
Faker
;
use
Illuminate\Support\Str
;
...
...
@@ -17,7 +17,7 @@ use Illuminate\Support\Str;
|
*/
$factory
->
define
(
User
::
class
,
function
(
Faker
$faker
)
{
$factory
->
define
(
User
Model
::
class
,
function
(
Faker
$faker
)
{
return
[
'name'
=>
$faker
->
name
,
'email'
=>
$faker
->
unique
()
->
safeEmail
,
...
...
database/seeds/UserAddressSeeder.php
View file @
ab5dd96d
...
...
@@ -11,8 +11,8 @@ class UserAddressSeeder extends Seeder
*/
public
function
run
()
{
factory
(
\App\Models\UserAddress
::
class
,
50
)
->
create
([
'user_id'
=>
1
])
->
each
(
function
(
$userAddress
)
{
$userAddress
->
save
(
factory
(
\App\Models\UserAddress
::
class
)
->
make
()
->
toArray
());
factory
(
\App\Models\UserAddress
Model
::
class
,
50
)
->
create
([
'user_id'
=>
1
])
->
each
(
function
(
$userAddress
)
{
$userAddress
->
save
(
factory
(
\App\Models\UserAddress
Model
::
class
)
->
make
()
->
toArray
());
});
}
}
routes/api.php
View file @
ab5dd96d
...
...
@@ -21,9 +21,13 @@ Route::middleware(['api'])->namespace('Api')->group(function () {
Route
::
middleware
([
'api'
,
'api.check'
])
->
namespace
(
'Api'
)
->
group
(
function
()
{
Route
::
GET
(
'/auth/logout'
,
'AuthApiController@logout'
);
Route
::
POST
(
'auth/reset_password'
,
'AuthApiController@resetPassword'
);
Route
::
POST
(
'auth/send_email_code'
,
'AuthApiController@sendEmailCode'
);
Route
::
ANY
(
'inquiry/add'
,
'InquiryApiController@add'
);
Route
::
ANY
(
'inquiry/list'
,
'InquiryApiController@list'
);
Route
::
ANY
(
'inquiry/detail'
,
'InquiryApiController@detail'
);
});
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