This commit is contained in:
2023-03-08 09:16:04 +08:00
commit e78454540f
1318 changed files with 210569 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
<?php
namespace Modules\User\Models\Traits;
trait WechatAttribute
{
/**
* Notes : 获取微信公众号openid
*
* @Date : 2021/5/26 17:03
* @Author : Mr.wang
* @return string
*/
public function getOfficialOpenidAttribute(): string
{
return $this->official->openid ?? '';
}
/**
* Notes: description
*
* @Author: 玄尘
* @Date: 2022/8/3 16:22
*/
public function isOfficialSubscribe(): bool
{
return $this->official()->where('subscribe', 1)->exists();
}
/**
* Notes : 获取微信小程序openid
*
* @Date : 2021/5/26 17:03
* @Author : Mr.wang
* @return string
*/
public function getMiniOpenidAttribute(): string
{
return $this->mini->openid ?? '';
}
/**
* Notes: 获取用户openid
*
* @Author: 玄尘
* @Date: 2022/9/26 13:52
* @param $channel
* @return mixed
*/
public function getUserOpenid($channel)
{
$channel = strtolower($channel);
if ($channel == 'mp') {
return Arr::get($this->getOpenids(), 'official');
} else {
return Arr::get($this->getOpenids(), 'mini');
}
}
/**
* Notes: 获取openids
*
* @Author: 玄尘
* @Date: 2022/9/26 15:06
* @return array
*/
public function getOpenids(): array
{
return [
'mini' => $this->mini()->value('openid') ?? '',
'official' => $this->official()->value('openid') ?? '',
];
}
}