<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2024 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace Modules\Wechat\Listeners;

use Modules\Member\Events\LoginEvent;
use Modules\Wechat\Models\MemberSocial;

class LoginBind {

	/**
	 * @title 会员登录后更新用户信息
	 *
	 * @param LoginEvent $event
	 * @return void
	 */
	public function handle(LoginEvent $event) {
		$member = $event->member;
		$openid = $event->openid;
		$type = $event->type;

		$social = MemberSocial::where('openid', $openid)->where('type', $type)->first();
		if ($social && $social->member_id == 0) {
			$social->member_id = $member->uid;
			$social->save();
		}
	}
}