Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-Server
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
李帅
2022-03-28 18:29:26 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
55d0e4e9642acf0a6680f5f12f85040e947f4850
55d0e4e9
1 parent
34d36047
1.todo facebook
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
110 additions
and
2 deletions
app/Http/Controllers/V1/UserController.php
app/Models/User.php
app/Models/UserProfile.php
app/Payment/PaypalPayment.php
app/Providers/EventServiceProvider.php
config/services.php
database/migrations/2022_03_28_122608_alter_user_profiles_table.php
app/Http/Controllers/V1/UserController.php
View file @
55d0e4e
...
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\V1;
use
App\Http\Controllers\Controller
;
use
App\Jobs\SendVerificationMessage
;
use
App\Models\User
;
use
App\Models\UserProfile
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\File
;
...
...
@@ -70,6 +71,7 @@ class UserController extends Controller
$data
[
'password'
]
=
bcrypt
(
$data
[
'password'
]);
$user
=
User
::
query
()
->
create
(
$data
);
UserProfile
::
query
()
->
create
([
'user_id'
=>
$user
->
id
]);
$token
=
$user
->
createToken
(
$user
->
email
)
->
plainTextToken
;
...
...
@@ -124,7 +126,7 @@ class UserController extends Controller
public
function
user
()
{
$user
=
Auth
::
user
();
$user
->
profile
;
return
Response
::
success
(
$user
);
}
}
...
...
app/Models/User.php
View file @
55d0e4e
...
...
@@ -52,4 +52,8 @@ class User extends Authenticatable
return
Storage
::
disk
(
'public'
)
->
url
(
$avatar
);
}
public
function
profile
()
{
return
$this
->
hasOne
(
'App\Models\UserProfile'
,
'user_id'
,
'id'
);
}
}
...
...
app/Models/UserProfile.php
View file @
55d0e4e
...
...
@@ -12,4 +12,10 @@ class UserProfile extends Model
protected
$table
=
'user_profiles'
;
protected
$fillable
=
[
'user_id'
];
public
function
user
()
{
return
$this
->
belongsTo
(
'App\Models\User'
,
'id'
,
'user_id'
);
}
}
...
...
app/Payment/PaypalPayment.php
View file @
55d0e4e
...
...
@@ -8,7 +8,11 @@
namespace
App\Payment
;
use
App\Models\MembershipGood
;
use
App\Models\Order
;
use
App\Models\User
;
use
App\Models\UserProfile
;
use
Carbon\Carbon
;
use
GuzzleHttp\Client
;
use
Illuminate\Support\Facades\Redis
;
...
...
@@ -111,6 +115,11 @@ class PaypalPayment implements PaymentInterface
$body
=
$response
->
getBody
();
$content
=
json_decode
(
$body
->
getContents
(),
true
);
/** 更新订单交易号 */
$order
->
pay_number
=
$content
[
'id'
];
$order
->
pay_type
=
'paypal'
;
$order
->
save
();
return
$content
;
}
...
...
@@ -131,12 +140,46 @@ class PaypalPayment implements PaymentInterface
// todo 应该使用队列,异步执行回调程序
if
(
!
$this
->
notify
(
$orderId
))
return
false
;
return
$content
;
}
public
function
notify
()
public
function
notify
(
$orderId
)
{
$order
=
Order
::
query
()
->
where
(
'pay_number'
,
$orderId
)
->
first
();
if
(
!
$order
)
return
false
;
/** 修改订单状态*/
$order
->
pay_time
=
Carbon
::
now
();
$order
->
status
=
Order
::
PAID
;
$order
->
save
();
/** 给用户加会员*/
$goods
=
MembershipGood
::
query
()
->
find
(
$order
->
order_goods
->
goods_id
);
$days
=
$goods
->
limit_days
;
// 计算天数
$user
=
UserProfile
::
query
()
->
find
(
$order
->
user_id
);
if
(
$user
->
is_vip
==
0
){
$user
->
is_vip
=
1
;
$user
->
create_vip_time
=
Carbon
::
now
();
$user
->
expire_vip_time
=
Carbon
::
now
()
->
addDays
(
$days
);
}
else
{
if
(
Carbon
::
now
()
->
gte
(
$user
->
expire_vip_time
)){
// 已经过期了
$user
->
expire_vip_time
=
Carbon
::
now
()
->
addDays
(
$days
);
}
else
{
$user
->
expire_vip_time
=
Carbon
::
parse
(
$user
->
expire_vip_time
)
->
addDays
(
$days
);
}
}
$user
->
buy_number
+=
1
;
$user
->
buy_amount
+=
$order
->
pay_amount
;
$user
->
last_buy_time
=
Carbon
::
now
();
$user
->
save
();
/** 修改订单状态*/
$order
->
status
=
Order
::
DONE
;
$order
->
save
();
return
true
;
}
}
\ No newline at end of file
...
...
app/Providers/EventServiceProvider.php
View file @
55d0e4e
...
...
@@ -23,6 +23,8 @@ class EventServiceProvider extends ServiceProvider
// ... other providers
\SocialiteProviders\Weixin\WeixinExtendSocialite
::
class
.
'@handle'
,
\SocialiteProviders\Apple\AppleExtendSocialite
::
class
.
'@handle'
,
\SocialiteProviders\Facebook\FacebookExtendSocialite
::
class
.
'@handle'
,
\SocialiteProviders\Twitter\TwitterExtendSocialite
::
class
.
'@handle'
,
],
];
...
...
config/services.php
View file @
55d0e4e
...
...
@@ -47,4 +47,15 @@ return [
'redirect'
=>
env
(
'APPLE_REDIRECT_URI'
)
],
'facebook'
=>
[
'client_id'
=>
env
(
'FACEBOOK_CLIENT_ID'
),
'client_secret'
=>
env
(
'FACEBOOK_CLIENT_SECRET'
),
'redirect'
=>
env
(
'FACEBOOK_REDIRECT_URI'
)
],
'twitter'
=>
[
'client_id'
=>
env
(
'TWITTER_CLIENT_ID'
),
'client_secret'
=>
env
(
'TWITTER_CLIENT_SECRET'
),
'redirect'
=>
env
(
'TWITTER_REDIRECT_URI'
)
],
];
...
...
database/migrations/2022_03_28_122608_alter_user_profiles_table.php
0 → 100644
View file @
55d0e4e
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AlterUserProfilesTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'user_profiles'
,
function
(
Blueprint
$table
)
{
$table
->
unsignedInteger
(
'user_id'
)
->
after
(
'id'
)
->
comment
(
'用户id'
);
$table
->
unsignedTinyInteger
(
'is_vip'
)
->
after
(
'unionid'
)
->
default
(
'0'
)
->
comment
(
'是否会员'
);
$table
->
timestamp
(
'create_vip_time'
)
->
after
(
'is_vip'
)
->
nullable
()
->
comment
(
'会员创建时间'
);
$table
->
timestamp
(
'expire_vip_time'
)
->
after
(
'create_vip_time'
)
->
nullable
()
->
comment
(
'会员失效时间'
);
$table
->
unsignedInteger
(
'buy_number'
)
->
default
(
0
)
->
comment
(
'购买次数'
)
->
change
();
$table
->
decimal
(
'buy_amount'
)
->
default
(
0.00
)
->
comment
(
'消费金额'
)
->
change
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropColumns
(
'user_profiles'
,
[
'is_vip'
,
'create_vip_time'
,
'expire_vip_time'
]);
}
}
Please
register
or
login
to post a comment