李帅

1.todo facebook

......@@ -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);
}
}
......
......@@ -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');
}
}
......
......@@ -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');
}
}
......
......@@ -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
......
......@@ -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',
],
];
......
......@@ -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')
],
];
......
<?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']);
}
}