李帅

1.todo facebook

...@@ -5,6 +5,7 @@ namespace App\Http\Controllers\V1; ...@@ -5,6 +5,7 @@ namespace App\Http\Controllers\V1;
5 use App\Http\Controllers\Controller; 5 use App\Http\Controllers\Controller;
6 use App\Jobs\SendVerificationMessage; 6 use App\Jobs\SendVerificationMessage;
7 use App\Models\User; 7 use App\Models\User;
8 +use App\Models\UserProfile;
8 use Illuminate\Http\Request; 9 use Illuminate\Http\Request;
9 use Illuminate\Support\Facades\Auth; 10 use Illuminate\Support\Facades\Auth;
10 use Illuminate\Support\Facades\File; 11 use Illuminate\Support\Facades\File;
...@@ -70,6 +71,7 @@ class UserController extends Controller ...@@ -70,6 +71,7 @@ class UserController extends Controller
70 $data['password'] = bcrypt($data['password']); 71 $data['password'] = bcrypt($data['password']);
71 72
72 $user = User::query()->create($data); 73 $user = User::query()->create($data);
74 + UserProfile::query()->create(['user_id' => $user->id]);
73 75
74 $token = $user->createToken($user->email)->plainTextToken; 76 $token = $user->createToken($user->email)->plainTextToken;
75 77
...@@ -124,7 +126,7 @@ class UserController extends Controller ...@@ -124,7 +126,7 @@ class UserController extends Controller
124 public function user() 126 public function user()
125 { 127 {
126 $user = Auth::user(); 128 $user = Auth::user();
127 - 129 + $user->profile;
128 return Response::success($user); 130 return Response::success($user);
129 } 131 }
130 } 132 }
......
...@@ -52,4 +52,8 @@ class User extends Authenticatable ...@@ -52,4 +52,8 @@ class User extends Authenticatable
52 return Storage::disk('public')->url($avatar); 52 return Storage::disk('public')->url($avatar);
53 } 53 }
54 54
55 + public function profile()
56 + {
57 + return $this->hasOne('App\Models\UserProfile','user_id','id');
58 + }
55 } 59 }
......
...@@ -12,4 +12,10 @@ class UserProfile extends Model ...@@ -12,4 +12,10 @@ class UserProfile extends Model
12 12
13 protected $table = 'user_profiles'; 13 protected $table = 'user_profiles';
14 14
15 + protected $fillable = ['user_id'];
16 +
17 + public function user()
18 + {
19 + return $this->belongsTo('App\Models\User', 'id', 'user_id');
20 + }
15 } 21 }
......
...@@ -8,7 +8,11 @@ ...@@ -8,7 +8,11 @@
8 8
9 namespace App\Payment; 9 namespace App\Payment;
10 10
11 +use App\Models\MembershipGood;
11 use App\Models\Order; 12 use App\Models\Order;
13 +use App\Models\User;
14 +use App\Models\UserProfile;
15 +use Carbon\Carbon;
12 use GuzzleHttp\Client; 16 use GuzzleHttp\Client;
13 use Illuminate\Support\Facades\Redis; 17 use Illuminate\Support\Facades\Redis;
14 18
...@@ -111,6 +115,11 @@ class PaypalPayment implements PaymentInterface ...@@ -111,6 +115,11 @@ class PaypalPayment implements PaymentInterface
111 $body = $response->getBody(); 115 $body = $response->getBody();
112 $content = json_decode($body->getContents(),true); 116 $content = json_decode($body->getContents(),true);
113 117
118 + /** 更新订单交易号 */
119 + $order->pay_number = $content['id'];
120 + $order->pay_type = 'paypal';
121 + $order->save();
122 +
114 return $content; 123 return $content;
115 } 124 }
116 125
...@@ -131,12 +140,46 @@ class PaypalPayment implements PaymentInterface ...@@ -131,12 +140,46 @@ class PaypalPayment implements PaymentInterface
131 140
132 141
133 // todo 应该使用队列,异步执行回调程序 142 // todo 应该使用队列,异步执行回调程序
143 + if (!$this->notify($orderId)) return false;
134 144
135 return $content; 145 return $content;
136 } 146 }
137 147
138 - public function notify() 148 + public function notify($orderId)
139 { 149 {
150 + $order = Order::query()->where('pay_number',$orderId)->first();
151 + if (!$order) return false;
152 +
153 + /** 修改订单状态*/
154 + $order->pay_time = Carbon::now();
155 + $order->status = Order::PAID;
156 + $order->save();
157 +
158 + /** 给用户加会员*/
159 + $goods = MembershipGood::query()->find($order->order_goods->goods_id);
160 + $days = $goods->limit_days;// 计算天数
161 + $user = UserProfile::query()->find($order->user_id);
162 + if ($user->is_vip == 0){
163 + $user->is_vip = 1;
164 + $user->create_vip_time = Carbon::now();
165 + $user->expire_vip_time = Carbon::now()->addDays($days);
166 + }else{
167 + if (Carbon::now()->gte($user->expire_vip_time)){ // 已经过期了
168 + $user->expire_vip_time = Carbon::now()->addDays($days);
169 + }else{
170 + $user->expire_vip_time = Carbon::parse($user->expire_vip_time)->addDays($days);
171 + }
172 + }
173 +
174 + $user->buy_number += 1;
175 + $user->buy_amount += $order->pay_amount;
176 + $user->last_buy_time = Carbon::now();
177 + $user->save();
178 +
179 + /** 修改订单状态*/
180 + $order->status = Order::DONE;
181 + $order->save();
140 182
183 + return true;
141 } 184 }
142 } 185 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -23,6 +23,8 @@ class EventServiceProvider extends ServiceProvider ...@@ -23,6 +23,8 @@ class EventServiceProvider extends ServiceProvider
23 // ... other providers 23 // ... other providers
24 \SocialiteProviders\Weixin\WeixinExtendSocialite::class.'@handle', 24 \SocialiteProviders\Weixin\WeixinExtendSocialite::class.'@handle',
25 \SocialiteProviders\Apple\AppleExtendSocialite::class.'@handle', 25 \SocialiteProviders\Apple\AppleExtendSocialite::class.'@handle',
26 + \SocialiteProviders\Facebook\FacebookExtendSocialite::class.'@handle',
27 + \SocialiteProviders\Twitter\TwitterExtendSocialite::class.'@handle',
26 28
27 ], 29 ],
28 ]; 30 ];
......
...@@ -47,4 +47,15 @@ return [ ...@@ -47,4 +47,15 @@ return [
47 'redirect' => env('APPLE_REDIRECT_URI') 47 'redirect' => env('APPLE_REDIRECT_URI')
48 ], 48 ],
49 49
50 + 'facebook' => [
51 + 'client_id' => env('FACEBOOK_CLIENT_ID'),
52 + 'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
53 + 'redirect' => env('FACEBOOK_REDIRECT_URI')
54 + ],
55 +
56 + 'twitter' => [
57 + 'client_id' => env('TWITTER_CLIENT_ID'),
58 + 'client_secret' => env('TWITTER_CLIENT_SECRET'),
59 + 'redirect' => env('TWITTER_REDIRECT_URI')
60 + ],
50 ]; 61 ];
......
1 +<?php
2 +
3 +use Illuminate\Database\Migrations\Migration;
4 +use Illuminate\Database\Schema\Blueprint;
5 +use Illuminate\Support\Facades\Schema;
6 +
7 +class AlterUserProfilesTable extends Migration
8 +{
9 + /**
10 + * Run the migrations.
11 + *
12 + * @return void
13 + */
14 + public function up()
15 + {
16 + Schema::table('user_profiles', function (Blueprint $table) {
17 +
18 + $table->unsignedInteger('user_id')->after('id')->comment('用户id');
19 +
20 + $table->unsignedTinyInteger('is_vip')->after('unionid')->default('0')->comment('是否会员');
21 +
22 + $table->timestamp('create_vip_time')->after('is_vip')->nullable()->comment('会员创建时间');
23 +
24 + $table->timestamp('expire_vip_time')->after('create_vip_time')->nullable()->comment('会员失效时间');
25 +
26 + $table->unsignedInteger('buy_number')->default(0)->comment('购买次数')->change();
27 + $table->decimal('buy_amount')->default(0.00)->comment('消费金额')->change();
28 + });
29 + }
30 +
31 + /**
32 + * Reverse the migrations.
33 + *
34 + * @return void
35 + */
36 + public function down()
37 + {
38 + Schema::dropColumns('user_profiles', ['is_vip','create_vip_time','expire_vip_time']);
39 + }
40 +}