diff --git a/beike/Admin/Providers/AdminServiceProvider.php b/beike/Admin/Providers/AdminServiceProvider.php index 3934ce12..968109a5 100644 --- a/beike/Admin/Providers/AdminServiceProvider.php +++ b/beike/Admin/Providers/AdminServiceProvider.php @@ -133,5 +133,6 @@ class AdminServiceProvider extends ServiceProvider { View::share('languages', languages()); View::share('admin_base_url', admin_route('home.index')); + View::share('shop_base_url', shop_route('home.index')); } } diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index f6eaa141..7cb7c23c 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -162,6 +162,14 @@ class Plugin implements Arrayable, \ArrayAccess return $this->enabled; } + public function getSetting($name = '') + { + if ($name) { + return plugin_setting("{$this->code}.{$name}"); + } + return plugin_setting($this->code); + } + /** * 获取插件对应的设置字段, 并获取已存储在DB的字段值 diff --git a/beike/Repositories/CustomerRepo.php b/beike/Repositories/CustomerRepo.php index 28c664e1..3be6d43d 100644 --- a/beike/Repositories/CustomerRepo.php +++ b/beike/Repositories/CustomerRepo.php @@ -29,7 +29,7 @@ class CustomerRepo */ public static function create($customerData) { - $customerData['password'] = Hash::make($customerData['password']); + $customerData['password'] = Hash::make($customerData['password'] ?? ''); return Customer::query()->create($customerData); } diff --git a/beike/Shop/Http/Controllers/Account/LoginController.php b/beike/Shop/Http/Controllers/Account/LoginController.php index 52d45cda..d374ed84 100644 --- a/beike/Shop/Http/Controllers/Account/LoginController.php +++ b/beike/Shop/Http/Controllers/Account/LoginController.php @@ -27,7 +27,10 @@ class LoginController extends Controller if (current_customer()) { return redirect(shop_route('account.index')); } - return view('account/login'); + $loginData = [ + 'social_buttons' => hook_filter('login.social.buttons', []), + ]; + return view('account/login', $loginData); } public function store(LoginRequest $request) diff --git a/beike/Shop/Http/Controllers/LoginController.php b/beike/Shop/Http/Controllers/LoginController.php deleted file mode 100644 index 958fa6c5..00000000 --- a/beike/Shop/Http/Controllers/LoginController.php +++ /dev/null @@ -1,39 +0,0 @@ - - * @created 2022-06-22 20:22:54 - * @modified 2022-06-22 20:22:54 - */ - -namespace Beike\Shop\Http\Controllers; - -use Beike\Models\Customer; -use Illuminate\Http\Request; - -class LoginController extends Controller -{ - public function index() - { - return view('login'); - } - - public function store(Request $request) - { - $credentials = $request->validate([ - 'email' => ['required', 'email'], - 'password' => ['required'], - ]); - - if (auth(Customer::AUTH_GUARD)->attempt($credentials)) { - return redirect(route('home')); - } - - return back()->withErrors([ - 'email' => 'The provided credentials do not match our records.', - ]); - } -} diff --git a/beike/Shop/Providers/PluginServiceProvider.php b/beike/Shop/Providers/PluginServiceProvider.php index 45a79b08..1abf8b12 100644 --- a/beike/Shop/Providers/PluginServiceProvider.php +++ b/beike/Shop/Providers/PluginServiceProvider.php @@ -38,7 +38,7 @@ class PluginServiceProvider extends ServiceProvider */ public function boot() { - if(!installed()) { + if (!installed()) { return; } $manager = app('plugin'); @@ -48,6 +48,7 @@ class PluginServiceProvider extends ServiceProvider foreach ($plugins as $plugin) { $pluginCode = $plugin->getDirname(); $this->bootPlugin($plugin); + $this->loadMigrations($pluginCode); $this->loadRoutes($pluginCode); $this->loadTranslations($pluginCode); } @@ -78,6 +79,20 @@ class PluginServiceProvider extends ServiceProvider } + /** + * 加载插件数据库迁移脚本 + * + * @param $pluginCode + */ + private function loadMigrations($pluginCode) + { + $migrationPath = "{$this->pluginBasePath}/{$pluginCode}/Migrations"; + if (is_dir($migrationPath)) { + $this->loadMigrationsFrom("{$migrationPath}"); + } + } + + /** * 加载插件路由 * diff --git a/beike/Shop/Services/AccountService.php b/beike/Shop/Services/AccountService.php index 602931b4..3d9cf18a 100644 --- a/beike/Shop/Services/AccountService.php +++ b/beike/Shop/Services/AccountService.php @@ -26,9 +26,9 @@ class AccountService * 注册用户 * * @param array $data // ['email', 'password'] - * @return Customer + * @return mixed */ - public static function register(array $data): Customer + public static function register(array $data) { $data['customer_group_id'] = system_setting('base.default_customer_group_id', 0); // default_customer_group_id为默认客户组名称 $data['status'] = !system_setting('base.approve_customer'); // approve_customer为是否需要审核客户 @@ -38,7 +38,7 @@ class AccountService if ($data['email'] ?? 0) { $data['name'] = substr($data['email'], 0, strrpos($data['email'], '@'));; } - $data['avatar'] = ''; + $data['avatar'] = $data['avatar'] ?? ''; return CustomerRepo::create($data); } @@ -49,7 +49,8 @@ class AccountService * @param $type * @return void */ - public static function sendVerifyCodeForForgotten($email, $type) { + public static function sendVerifyCodeForForgotten($email, $type) + { $code = str_pad(mt_rand(10, 999999), 6, '0', STR_PAD_LEFT); VerifyCodeRepo::deleteByAccount($email); @@ -68,7 +69,7 @@ class AccountService * @param $code * @param $account * @param $password - * @param $type $account类型,email代表$account为邮箱地址,telephone代表$account为手机号码 + * @param $type $account类型,email代表$account为邮箱地址,telephone代表$account为手机号码 * @return void */ public static function verifyAndChangePassword($code, $account, $password, $type = 'email') diff --git a/composer.json b/composer.json index efecc777..ec2fe19e 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "jenssegers/agent": "^2.6", "laravel/framework": "^9.0", "laravel/tinker": "^2.7", + "overtrue/socialite": "^4.5", "spatie/laravel-permission": "^5.5", "srmklive/paypal": "^3.0", "stripe/stripe-php": "^8.8", diff --git a/package.json b/package.json index bbb90abc..1d81b15e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "axios": "^0.21", - "bootstrap": "^4.6.1", + "bootstrap": "^5.2.1", "bootstrap-5.1.3": "npm:bootstrap@5.1.3", "browser-sync": "^2.27.10", "browser-sync-webpack-plugin": "^2.3.0", diff --git a/plugins/.gitignore b/plugins/.gitignore deleted file mode 100644 index dfc932a2..00000000 --- a/plugins/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -* -!FlatShipping -!LatestProducts -!Paypal -!Stripe diff --git a/plugins/FlatShipping/Static/css/demo.css b/plugins/FlatShipping/Static/css/demo.css new file mode 100644 index 00000000..30fdbc42 --- /dev/null +++ b/plugins/FlatShipping/Static/css/demo.css @@ -0,0 +1,8 @@ +/** +这里是插件css, 请在blade里面使用以下代码引入 + + */ + +#bk-stripe-app .form-wrap { + max-width: 400px; +} \ No newline at end of file diff --git a/plugins/FlatShipping/Static/image/logo.png b/plugins/FlatShipping/Static/image/logo.png new file mode 100644 index 00000000..9d97eb43 Binary files /dev/null and b/plugins/FlatShipping/Static/image/logo.png differ diff --git a/plugins/FlatShipping/Static/js/demo.js b/plugins/FlatShipping/Static/js/demo.js new file mode 100644 index 00000000..5bfe05d3 --- /dev/null +++ b/plugins/FlatShipping/Static/js/demo.js @@ -0,0 +1,4 @@ +/** + * 这里是插件js, 请在blade里面使用以下代码引入 + * + */ diff --git a/plugins/FlatShipping/config.json b/plugins/FlatShipping/config.json index e5fae213..ba4d0db1 100644 --- a/plugins/FlatShipping/config.json +++ b/plugins/FlatShipping/config.json @@ -4,7 +4,7 @@ "description": "按订单总额收取固定运费", "type": "shipping", "version": "v1.0.0", - "icon": "", + "icon": "/image/logo.png", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com" diff --git a/plugins/LatestProducts/Static/css/demo.css b/plugins/LatestProducts/Static/css/demo.css new file mode 100644 index 00000000..30fdbc42 --- /dev/null +++ b/plugins/LatestProducts/Static/css/demo.css @@ -0,0 +1,8 @@ +/** +这里是插件css, 请在blade里面使用以下代码引入 + + */ + +#bk-stripe-app .form-wrap { + max-width: 400px; +} \ No newline at end of file diff --git a/plugins/LatestProducts/Static/image/logo.png b/plugins/LatestProducts/Static/image/logo.png new file mode 100644 index 00000000..37ff0126 Binary files /dev/null and b/plugins/LatestProducts/Static/image/logo.png differ diff --git a/plugins/LatestProducts/Static/js/demo.js b/plugins/LatestProducts/Static/js/demo.js new file mode 100644 index 00000000..5bfe05d3 --- /dev/null +++ b/plugins/LatestProducts/Static/js/demo.js @@ -0,0 +1,4 @@ +/** + * 这里是插件js, 请在blade里面使用以下代码引入 + * + */ diff --git a/plugins/LatestProducts/config.json b/plugins/LatestProducts/config.json index d7291fa6..bcc8fb89 100644 --- a/plugins/LatestProducts/config.json +++ b/plugins/LatestProducts/config.json @@ -4,7 +4,7 @@ "description": "首页菜单添加最新商品列表功能", "type": "view", "version": "v1.0.0", - "icon": "", + "icon": "/image/logo.png", "author": { "name": "成都光大网络科技有限公司", "email": "yangjin@beikeshop.com" diff --git a/plugins/Paypal/Static/image/logo.png b/plugins/Paypal/Static/image/logo.png index e078b425..a8ab186f 100644 Binary files a/plugins/Paypal/Static/image/logo.png and b/plugins/Paypal/Static/image/logo.png differ diff --git a/plugins/Social/Bootstrap.php b/plugins/Social/Bootstrap.php new file mode 100644 index 00000000..5fd6695c --- /dev/null +++ b/plugins/Social/Bootstrap.php @@ -0,0 +1,39 @@ + + * @created 2022-10-12 17:33:29 + * @modified 2022-10-12 17:33:29 + */ + +namespace Plugin\Social; + + +class Bootstrap +{ + public function boot() + { + $this->addSocialData(); + } + + /** + * 增加第三方登录方式 + */ + private function addSocialData() + { + add_filter('login.social.buttons', function ($buttons) { + $providers = plugin_setting('social.setting'); + if (empty($providers)) { + return $buttons; + } + + foreach ($providers as $provider) { + $buttons[] = view('Social::shop/social_button', ['provider' => $provider])->render(); + } + return $buttons; + }); + } +} diff --git a/plugins/Social/Controllers/AdminSocialController.php b/plugins/Social/Controllers/AdminSocialController.php new file mode 100644 index 00000000..86dc1b27 --- /dev/null +++ b/plugins/Social/Controllers/AdminSocialController.php @@ -0,0 +1,35 @@ + + * @created 2022-09-30 18:46:38 + * @modified 2022-09-30 18:46:38 + */ + +namespace Plugin\Social\Controllers; + +use Illuminate\Http\Request; +use Beike\Repositories\SettingRepo; +use Beike\Admin\Http\Controllers\Controller; + +class AdminSocialController extends Controller +{ + /** + * @throws \Throwable + */ + public function saveSetting(Request $request): array + { + $socialData = [ + 'type' => 'plugin', + 'space' => 'social', + 'name' => 'setting', + 'value' => json_encode($request->all()), + 'json' => 1, + ]; + SettingRepo::createOrUpdate($socialData); + return json_success('保存成功'); + } +} diff --git a/plugins/Social/Controllers/ShopSocialController.php b/plugins/Social/Controllers/ShopSocialController.php new file mode 100644 index 00000000..0f96f1f7 --- /dev/null +++ b/plugins/Social/Controllers/ShopSocialController.php @@ -0,0 +1,73 @@ + + * @created 2022-09-30 18:46:38 + * @modified 2022-09-30 18:46:38 + */ + +namespace Plugin\Social\Controllers; + +use Beike\Models\Customer; +use Illuminate\Support\Facades\Auth; +use Overtrue\Socialite\Exceptions\Exception; +use Overtrue\Socialite\SocialiteManager; +use Beike\Admin\Http\Controllers\Controller; +use Plugin\Social\Repositories\CustomerRepo; + +class ShopSocialController extends Controller +{ + private SocialiteManager $socialite; + + public function __construct() + { + $config = []; + $providerSettings = plugin_setting('social.setting'); + foreach ($providerSettings as $providerSetting) { + $provider = $providerSetting['provider']; + if (empty($provider)) { + continue; + } + $config[$provider] = [ + 'client_id' => $providerSetting['key'], + 'client_secret' => $providerSetting['secret'], + 'redirect' => plugin_route('social.callback', $provider), + ]; + } + $this->socialite = new SocialiteManager($config); + } + + /** + * @param $provider + * @return mixed + */ + public function redirect($provider) + { + $url = $this->socialite->create($provider)->redirect(); + return redirect($url); + } + + /** + * @param $provider + * @return mixed + * @throws Exception + */ + public function callback($provider) + { + $code = request('code'); + $driver = $this->socialite->create($provider); + + // For google, facebook, twitter in China. + $driver->setGuzzleOptions([ + 'proxy' => '127.0.0.1:7890' + ]); + + $userData = $driver->userFromCode($code); + $customer = CustomerRepo::createCustomer($provider, $userData); + Auth::guard(Customer::AUTH_GUARD)->login($customer); + return view('Social::shop/callback'); + } +} diff --git a/plugins/Social/Lang/en/providers.php b/plugins/Social/Lang/en/providers.php new file mode 100644 index 00000000..d16b687e --- /dev/null +++ b/plugins/Social/Lang/en/providers.php @@ -0,0 +1,35 @@ + + * @created 2022-10-13 11:30:33 + * @modified 2022-10-13 11:30:33 + */ + +return [ + 'alipay' => 'Alipay', + 'azure' => 'Azure', + 'dingtalk' => 'Dingtalk', + 'douyin' => 'Douyin', + 'douban' => 'Douban', + 'facebook' => 'Facebook', + 'feishu' => 'Feishu', + 'figma' => 'Figma', + 'github' => 'Github', + 'gitee' => 'Gitee', + 'google' => 'Google', + 'line' => 'Line', + 'linkedin' => 'Linkedin', + 'open-wework' => 'Open-wework', + 'outlook' => 'Outlook', + 'qcloud' => 'Qcloud', + 'qq' => 'QQ', + 'taobao' => 'Taobao', + 'tapd' => 'Tapd', + 'wechat' => 'Wechat', + 'wework' => 'Wework', + 'weibo' => 'Weibo', +]; diff --git a/plugins/Social/Lang/en/setting.php b/plugins/Social/Lang/en/setting.php new file mode 100644 index 00000000..a01011c3 --- /dev/null +++ b/plugins/Social/Lang/en/setting.php @@ -0,0 +1,58 @@ + + * @created 2022-08-11 15:26:18 + * @modified 2022-08-11 15:26:18 + */ + +return [ +// Text + 'text_module' => 'Modules', + 'text_success' => 'Success: You have modified module OpenCart OmniAuth!', + 'text_copyright' => 'OpenCart.cn OmniAuth © %s', + 'text_omni_explain' => 'This plugin supports WeChat scan code, WeChat Official, QQ, Weibo, Facebook, Google, Twitter and others Social Network', + 'text_omni_explain_2' => 'To use a third-party login, you need to apply to the corresponding platform, and fill in the obtained ID and key to the corresponding input box.', + 'text_wechat_title' => 'WeChat scan code login application address', + 'text_wechat_info' => 'WeChat open platform', + 'text_qq_title' => 'QQ login application address', + 'text_qq_info' => 'QQ interconnection', + 'text_weibo_title' => 'Weibo login application address', + 'text_weibo_info' => 'Weibo open platform', + 'text_facebook_title' => 'Facebook login application address', + 'text_google_title' => 'Google login application address', + 'text_Twitter_title' => 'Twitter login application address', + 'text_help_msg' => 'help information', + +// Entry + 'entry_status' => 'Status', + 'entry_bind' => 'Force Bind', + 'entry_debug' => 'Debug Mode', + + 'entry_provider' => 'Provider', + 'entry_key' => 'Client ID', + 'entry_secret' => 'Client Secret', + 'entry_scope' => 'Flags (optional)', + 'entry_callback' => 'Callback URL', + 'entry_sort_order' => 'Sort Order', + +// Button + 'button_add_row' => 'Add Provider', + +// Error + 'error_permission' => 'Warning: You do not have permission to modify module OpenCart OmniAuth!', + +// Providers + 'wechat' => 'WeChat', + 'wechatofficial' => 'WeChatOfficial', + 'qq' => 'QQ', + 'weibo' => 'Weibo', + 'facebook' => 'Facebook', + 'google' => 'Google', + 'twitter' => 'Twitter', + + 'instagram' => 'Instagram', +]; diff --git a/plugins/Social/Lang/zh_cn/providers.php b/plugins/Social/Lang/zh_cn/providers.php new file mode 100644 index 00000000..84004915 --- /dev/null +++ b/plugins/Social/Lang/zh_cn/providers.php @@ -0,0 +1,35 @@ + + * @created 2022-10-13 11:30:33 + * @modified 2022-10-13 11:30:33 + */ + +return [ + 'alipay' => '支付宝', + 'azure' => 'Azure', + 'dingtalk' => '钉钉', + 'douyin' => '抖音', + 'douban' => '豆瓣', + 'facebook' => 'Facebook', + 'feishu' => '飞书', + 'figma' => 'Figma', + 'github' => 'GitHub', + 'gitee' => 'Gitee', + 'google' => 'Google', + 'line' => 'Line', + 'linkedin' => 'Linkedin', + 'open-wework' => 'open-wework', + 'outlook' => 'Outlook', + 'qcloud' => '腾讯云', + 'qq' => 'QQ', + 'taobao' => '淘宝', + 'tapd' => 'tapd', + 'wechat' => '微信', + 'wework' => '企业微信', + 'weibo' => '微博', +]; diff --git a/plugins/Social/Lang/zh_cn/setting.php b/plugins/Social/Lang/zh_cn/setting.php new file mode 100644 index 00000000..b995632f --- /dev/null +++ b/plugins/Social/Lang/zh_cn/setting.php @@ -0,0 +1,47 @@ + + * @created 2022-08-11 15:26:18 + * @modified 2022-08-11 15:26:18 + */ + +return [ +// Text + 'text_module' => '模块', + 'text_success' => '成功: 您成功修改第三方登录配置!', + 'text_copyright' => 'OpenCart.cn 获取帮助 © %s', + 'text_omni_explain' => '本模块支持微信扫码, 微信公众号, QQ, 微博,Facebook,Google,Twitter等第三方登录', + 'text_omni_explain_2' => '要使用第三方登录, 需要到对应平台申请开通, 并把获取到的 ID 和密钥填写到上面对应的输入框', + 'text_wechat_title' => '微信扫码登录申请地址', + 'text_wechat_info' => '微信开放平台', + 'text_qq_title' => 'QQ登录申请地址', + 'text_qq_info' => 'QQ互联', + 'text_weibo_title' => '微博登录申请地址', + 'text_weibo_info' => '微博开放平台', + 'text_facebook_title' => 'Facebook登录申请地址', + 'text_google_title' => 'Google登录申请地址', + 'text_Twitter_title' => 'Twitter登录申请地址', + 'text_help_msg' => '帮助信息', + +// Entry + 'entry_status' => '状态', + 'entry_bind' => '强制绑定', + 'entry_debug' => '调试模式', + + 'entry_provider' => '类型', + 'entry_key' => 'Client ID', + 'entry_secret' => 'Client Secret', + 'entry_scope' => 'Flags (可选项)', + 'entry_callback' => '回调地址', + 'entry_sort_order' => '排序', + +// Button + 'button_add_row' => '添加类型', + +// Error + 'error_permission' => '警告: 您没有权限修改此配置!', +]; diff --git a/plugins/Social/Migrations/2022_10_13_100354_create_customer_socials.php b/plugins/Social/Migrations/2022_10_13_100354_create_customer_socials.php new file mode 100644 index 00000000..7ffcd18c --- /dev/null +++ b/plugins/Social/Migrations/2022_10_13_100354_create_customer_socials.php @@ -0,0 +1,37 @@ +id(); + $table->integer('customer_id'); + $table->string('provider'); + $table->string('user_id'); + $table->string('union_id'); + $table->string('access_token'); + $table->text('extra'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('customer_socials'); + } +}; diff --git a/plugins/Social/Models/CustomerSocial.php b/plugins/Social/Models/CustomerSocial.php new file mode 100644 index 00000000..094378aa --- /dev/null +++ b/plugins/Social/Models/CustomerSocial.php @@ -0,0 +1,30 @@ + + * @created 2022-10-13 10:35:44 + * @modified 2022-10-13 10:35:44 + */ + +namespace Plugin\Social\Models; + +use Beike\Models\Customer; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; + +class CustomerSocial extends Model +{ + public $table = 'customer_socials'; + + public $fillable = [ + 'customer_id', 'provider', 'user_id', 'union_id', 'access_token', 'extra' + ]; + + public function customer(): BelongsTo + { + return $this->belongsTo(Customer::class); + } +} diff --git a/plugins/Social/Repositories/CustomerRepo.php b/plugins/Social/Repositories/CustomerRepo.php new file mode 100644 index 00000000..f64a3233 --- /dev/null +++ b/plugins/Social/Repositories/CustomerRepo.php @@ -0,0 +1,138 @@ + + * @created 2022-10-13 09:57:13 + * @modified 2022-10-13 09:57:13 + */ + +namespace Plugin\Social\Repositories; + +use Beike\Models\Customer; +use Overtrue\Socialite\User; +use Overtrue\Socialite\Providers; +use Beike\Shop\Services\AccountService; +use Illuminate\Database\Eloquent\Model; +use Plugin\Social\Models\CustomerSocial; +use Illuminate\Database\Eloquent\Builder; +use Overtrue\Socialite\Exceptions\Exception; + +class CustomerRepo +{ + /** + * 允许的第三方服务 + */ + private const PROVIDERS = [ + Providers\Alipay::NAME, + Providers\Azure::NAME, + Providers\DingTalk::NAME, + Providers\DouYin::NAME, + Providers\Douban::NAME, + Providers\Facebook::NAME, + Providers\FeiShu::NAME, + Providers\Figma::NAME, + Providers\GitHub::NAME, + Providers\Gitee::NAME, + Providers\Google::NAME, + Providers\Line::NAME, + Providers\Linkedin::NAME, + Providers\OpenWeWork::NAME, + Providers\Outlook::NAME, + Providers\QCloud::NAME, + Providers\QQ::NAME, + Providers\Taobao::NAME, + Providers\Tapd::NAME, + Providers\WeChat::NAME, + Providers\WeWork::NAME, + Providers\Weibo::NAME, + ]; + + public static function allProviders(): array + { + $items = []; + foreach (self::PROVIDERS as $provider) { + $items[] = [ + 'code' => $provider, + 'label' => trans("Social::providers.{$provider}") + ]; + } + return $items; + } + + /** + * 创建客户, 关联第三方用户数据 + * + * @param $provider + * @param User $userData + * @return Customer + * @throws Exception + */ + public static function createCustomer($provider, User $userData): Customer + { + $social = self::getCustomerByProvider($provider, $userData->getId()); + $customer = $social->customer ?? null; + if ($customer) { + return $customer; + } + + $email = $userData->getEmail(); + $customer = Customer::query()->where('email', $email)->first(); + if (empty($customer)) { + $customerData = [ + 'from' => $provider, + 'email' => $userData->getEmail(), + 'name' => $userData->getNickname(), + 'avatar' => $userData->getAvatar(), + ]; + $customer = AccountService::register($customerData); + } + + self::createSocial($customer, $provider, $userData); + return $customer; + } + + + /** + * @param $customer + * @param $provider + * @param User $userData + * @return Model|Builder + * @throws Exception + */ + public static function createSocial($customer, $provider, User $userData): Model|Builder + { + $social = self::getCustomerByProvider($provider, $userData->getId()); + if ($social) { + return $social; + } + + $socialData = [ + 'customer_id' => $customer->id, + 'provider' => $provider, + 'user_id' => $userData->getId(), + 'union_id' => '', + 'access_token' => $userData->getAccessToken(), + 'extra' => $userData->toJSON() + ]; + return CustomerSocial::query()->create($socialData); + } + + + /** + * 通过 provider 和 user_id 获取已存在 social + * @param $provider + * @param $userId + * @return Model|Builder|null + */ + private static function getCustomerByProvider($provider, $userId): Model|Builder|null + { + return CustomerSocial::query() + ->with(['customer']) + ->where('provider', $provider) + ->where('user_id', $userId) + ->first(); + } +} diff --git a/plugins/Social/Routes/admin.php b/plugins/Social/Routes/admin.php new file mode 100644 index 00000000..0bf948a1 --- /dev/null +++ b/plugins/Social/Routes/admin.php @@ -0,0 +1,15 @@ + + * @created 2022-08-04 16:17:53 + * @modified 2022-08-04 16:17:53 + */ + +use Illuminate\Support\Facades\Route; +use Plugin\Social\Controllers\AdminSocialController; + +Route::post('/social/setting', [AdminSocialController::class, 'saveSetting'])->name('plugin.social.setting'); diff --git a/plugins/Social/Routes/shop.php b/plugins/Social/Routes/shop.php new file mode 100644 index 00000000..27bcbaca --- /dev/null +++ b/plugins/Social/Routes/shop.php @@ -0,0 +1,16 @@ + + * @created 2022-09-30 18:52:54 + * @modified 2022-09-30 18:52:54 + */ + +use Illuminate\Support\Facades\Route; +use Plugin\Social\Controllers\ShopSocialController; + +Route::get('/social/redirect/{provider}', [ShopSocialController::class, 'redirect'])->name('plugin.social.redirect'); +Route::get('/social/callbacks/{provider}', [ShopSocialController::class, 'callback'])->name('plugin.social.callback'); diff --git a/plugins/Social/Static/image/facebook.png b/plugins/Social/Static/image/facebook.png new file mode 100644 index 00000000..d5fa03b5 Binary files /dev/null and b/plugins/Social/Static/image/facebook.png differ diff --git a/plugins/Social/Static/image/google.png b/plugins/Social/Static/image/google.png new file mode 100644 index 00000000..9f0a8982 Binary files /dev/null and b/plugins/Social/Static/image/google.png differ diff --git a/plugins/Social/Static/image/logo.png b/plugins/Social/Static/image/logo.png new file mode 100644 index 00000000..6aa66561 Binary files /dev/null and b/plugins/Social/Static/image/logo.png differ diff --git a/plugins/Social/Static/image/qq.png b/plugins/Social/Static/image/qq.png new file mode 100644 index 00000000..ee614af7 Binary files /dev/null and b/plugins/Social/Static/image/qq.png differ diff --git a/plugins/Social/Views/admin/config.blade.php b/plugins/Social/Views/admin/config.blade.php index a9958ee0..e843e07d 100644 --- a/plugins/Social/Views/admin/config.blade.php +++ b/plugins/Social/Views/admin/config.blade.php @@ -2,24 +2,181 @@ @section('title', __('admin/plugin.plugins_show')) +@section('page-title-right') + +@endsection + @section('content') -
+
-
{{ $plugin->name }}
+
+
{{ $plugin->name }}
+ +
@if (session('success')) @endif -
- @csrf - {{ method_field('put') }} -这里是social配置模板 - - - - -
+ + + + + + + + + + + + + + + + + + + + + + + + + +
{{ __('Social::setting.entry_provider') }}{{ __('Social::setting.entry_status') }}{{ __('Social::setting.entry_key') }}{{ __('Social::setting.entry_secret') }}{{ __('Social::setting.entry_callback') }}{{ __('Social::setting.entry_sort_order') }}
+ + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+ + + + + +
+
+ +
+
+
{{ __('Social::setting.text_help_msg') }}
+
    +
  1. {{ __('Social::setting.text_omni_explain') }}
  2. +
  3. {{ __('Social::setting.text_omni_explain_2') }}
  4. +
  5. {{ __('Social::setting.text_wechat_title') }} + {{ __('Social::setting.text_wechat_info') }} +
  6. +
  7. {{ __('Social::setting.text_qq_title') }} + {{ __('Social::setting.text_qq_info') }} +
  8. +
  9. {{ __('Social::setting.text_weibo_title') }} + {{ __('Social::setting.text_weibo_info') }} +
  10. +
  11. {{ __('Social::setting.text_facebook_title') }} + Facebook +
  12. +
  13. {{ __('Social::setting.text_google_title') }} + Google +
  14. +
  15. {{ __('Social::setting.text_Twitter_title') }} + Twitter +
  16. + ....... +
+
+
+ + + + + @endsection diff --git a/plugins/Social/Views/shop/callback.blade.php b/plugins/Social/Views/shop/callback.blade.php new file mode 100644 index 00000000..ba9b029d --- /dev/null +++ b/plugins/Social/Views/shop/callback.blade.php @@ -0,0 +1,9 @@ + diff --git a/plugins/Social/Views/shop/social_button.blade.php b/plugins/Social/Views/shop/social_button.blade.php new file mode 100644 index 00000000..61b0c536 --- /dev/null +++ b/plugins/Social/Views/shop/social_button.blade.php @@ -0,0 +1,4 @@ + diff --git a/plugins/Stripe/Static/image/logo.png b/plugins/Stripe/Static/image/logo.png index 9cef734f..d063a121 100644 Binary files a/plugins/Stripe/Static/image/logo.png and b/plugins/Stripe/Static/image/logo.png differ diff --git a/public/vendor/clipboard/clipboard.min.js b/public/vendor/clipboard/clipboard.min.js new file mode 100644 index 00000000..54b3c463 --- /dev/null +++ b/public/vendor/clipboard/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.8 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return o}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),c=n.n(e);function a(t){try{return document.execCommand(t)}catch(t){return}}var f=function(t){t=c()(t);return a("cut"),t};var l=function(t){var e,n,o,r=1
-
+
* @Date 2022-09-09 19:16:39 - * @LastEditTime 2022-09-16 20:56:53 + * @LastEditTime 2022-09-28 17:23:48 */ export default { @@ -12,13 +12,15 @@ export default { * @return {*} */ getCarts() { - $http.get('carts/mini', null, {hload: true}).then((res) => { - $('#offcanvas-right-cart').html(res.data.html); - if (!res.data.quantity) { - $('.cart-badge-quantity').hide(); - } else { - $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); - } + $(document).ready(() => { + $http.get('carts/mini', null, {hload: true}).then((res) => { + $('#offcanvas-right-cart').html(res.data.html); + if (!res.data.quantity) { + $('.cart-badge-quantity').hide(); + } else { + $('.cart-badge-quantity').show().html(res.data.quantity > 99 ? '99+' : res.data.quantity); + } + }) }) }, @@ -118,9 +120,18 @@ export default { type: 2, title: '', shadeClose: true, + scrollbar: false, area: ['900px', '600px'], skin: 'login-pop-box', content: 'login?iframe=true' //iframe的url }); + }, + + openWin(url, name = '', iWidth = 700, iHeight = 500) { + var iTop = (window.screen.height - 30 - iHeight) / 2;; + var iLeft = (window.screen.width - 10 - iWidth) / 2;; + window.open(url, name, 'height=' + iHeight + ',innerHeight=' + iHeight +    + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft +    + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'); } } \ No newline at end of file diff --git a/themes/default/account/login.blade.php b/themes/default/account/login.blade.php index b07fc92b..e04b3f3e 100644 --- a/themes/default/account/login.blade.php +++ b/themes/default/account/login.blade.php @@ -16,69 +16,65 @@

{{ __('shop/login.index') }}

@endif -
- -
-
+