| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Repositories;
- use App\Models\Thirdlogin;
- use Prettus\Repository\Eloquent\BaseRepository;
- /**
- * Class ThirdloginRepository.
- *
- * @package namespace App\Repositories;
- */
- class ThirdloginRepository extends BaseRepository
- {
- public function model()
- {
- return Thirdlogin::class;
- }
- public function checkWechat($openid, $unionid, $type)
- {
- $thirdlogin=$this->model->where('openid', $openid)->first();
- if (!$thirdlogin && $unionid) {
- $thirdlogin=$this->model->where('unionid', $unionid)->first();
- if ($thirdlogin) {
- $newThirdlogin=$thirdlogin->toArray();
- unset($newThirdlogin['id']);
- unset($newThirdlogin['created_at']);
- unset($newThirdlogin['updated_at']);
- $newThirdlogin['type']=$type;
- $newThirdlogin['openid']=$openid;
- $newThirdlogin['unionid']=$unionid;
- $this->model->create($newThirdlogin);
- }
- }
- if (!$thirdlogin) {
- return false;
- }
- return $this->getUser($thirdlogin);
- }
- public function checkQQ($openid)
- {
- $thirdlogin=$this->model->where('openid', $openid)->first();
- if (!$thirdlogin) {
- return false;
- }
- return $this->getUser($thirdlogin);
- }
- /**
- * @param Thirdlogin $thirdlogin
- * @return
- */
- protected function getUser($thirdlogin)
- {
- if ($thirdlogin->utype == 1) {
- return $thirdlogin->company()->withTrashed()->first();
- } else {
- return $thirdlogin->member()->withTrashed()->first();
- }
- }
- public function checkBind($user, $type)
- {
- return $this->model->where(['uid'=>$user->id,'utype'=>$user->utype])->whereIn('type', $type)->first();
- }
- public function unBind($type, $user)
- {
- return $this->model->where(['uid'=>$user->id,'utype'=>$user->utype])->whereIn('type', $type)->delete();
- }
- }
|