197 lines
4.8 KiB
PHP
197 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Live;
|
|
|
|
use App\Models\CommunityGroupAdmin;
|
|
use App\Models\CommunityStar;
|
|
use App\Models\ShareFundLog;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Models\Wechat;
|
|
use App\Models\User;
|
|
use App\Http\Response\ResponseJson;
|
|
class Viewer extends Model
|
|
{
|
|
use ResponseJson;
|
|
protected $fillable = [];
|
|
protected $guarded = [];
|
|
public function live()
|
|
{
|
|
return $this->belongsToMany(Live::class);
|
|
}
|
|
|
|
public function reglive()
|
|
{
|
|
return $this->belongsTo(Live::class);
|
|
}
|
|
|
|
public function fromViewer()
|
|
{
|
|
return $this->hasOne(Viewer::class,'id','viewer_id');
|
|
}
|
|
|
|
public function share()
|
|
{
|
|
return $this->hasMany(Viewer::class, 'viewer_id');
|
|
}
|
|
|
|
//推荐人
|
|
public function referrer(){
|
|
return $this->belongsTo(Viewer::class, 'viewer_id');
|
|
}
|
|
|
|
//分享给我的
|
|
public function viewershare(){
|
|
return $this->hasMany(ViewerShare::class, 'viewer_id');
|
|
}
|
|
|
|
//我分享出去的
|
|
public function shareviewer(){
|
|
return $this->hasMany(ViewerShare::class, 'sharer_id');
|
|
}
|
|
public function anchor(){
|
|
return $this->hasOne(Anchor::class, 'viewer_id');
|
|
}
|
|
|
|
public function focus(){
|
|
return $this->belongsToMany(Anchor::class);
|
|
}
|
|
|
|
public function asset(){
|
|
return $this->hasOne(Asset::class);
|
|
}
|
|
|
|
public function record(){
|
|
return $this->hasOne(Record::class);
|
|
}
|
|
|
|
public function feedbak(){
|
|
return $this->hasMany(Feedback::class);
|
|
}
|
|
|
|
public function assetlog(){
|
|
return $this->hasMany(AssetLog::class);
|
|
}
|
|
|
|
public function platfrom(){
|
|
return $this->belongsTo(Platfrom::class, 'source', 'code');
|
|
}
|
|
|
|
public function shareRoles()
|
|
{
|
|
return $this->belongsToMany(ShareRole::class, 'live_share_role_viewers');
|
|
}
|
|
|
|
public function giftorder(){
|
|
return $this->hasMany(GiftOrder::class);
|
|
}
|
|
|
|
public function liveorder(){
|
|
return $this->hasMany(LiveOrder::class);
|
|
}
|
|
public function messenger(){
|
|
return $this->hasOne(Messenger::class);
|
|
}
|
|
|
|
public function question(){
|
|
return $this->hasMany(Question::class);
|
|
}
|
|
public function liveViewer(){
|
|
return $this->hasMany(LiveViewer::class);
|
|
}
|
|
public function groupAdmin(){
|
|
return $this->hasMany(CommunityGroupAdmin::class);
|
|
}
|
|
public function star(){
|
|
return $this->hasMany(CommunityStar::class, 'from_id');
|
|
}
|
|
public function shareFundLog(){
|
|
return $this->hasMany(ShareFundLog::class);
|
|
}
|
|
public function otherShareFundLog(){
|
|
return $this->hasMany(ShareFundLog::class, 'other_viewer_id');
|
|
}
|
|
|
|
public function viewerShareAudit(){
|
|
return $this->hasMany(ViewerShareAudit::class, 'viewer_id');
|
|
}
|
|
|
|
public function otherViewerShareAudit(){
|
|
return $this->hasMany(ViewerShareAudit::class, 'other_viewer_id');
|
|
}
|
|
|
|
public function taskViewer(){
|
|
return $this->hasMany(TaskViewer::class);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'user_id');
|
|
}
|
|
|
|
public function activityUser()
|
|
{
|
|
return $this->hasOne(ActivityUser::class, 'id', 'user_id');
|
|
}
|
|
|
|
public function shareRole()
|
|
{
|
|
$share_role = null;
|
|
$share_roles = $this->shareRoles;
|
|
if (count($share_roles)) {
|
|
$share_role = $share_roles[0];
|
|
}
|
|
return $share_role;
|
|
}
|
|
|
|
|
|
public function getUserId()
|
|
{
|
|
//根据unionid
|
|
$unionid = $this->unionid;
|
|
if (empty($unionid)) {
|
|
//根据手机号
|
|
$mobile = $this->mobile;
|
|
if (empty($mobile)) {
|
|
return '未查询到相应信息';
|
|
}
|
|
$user_id = User::where('mobile', $mobile)->value('id');
|
|
if (empty($user_id)) {
|
|
return '未查询到相应信息'; //没有同手机号账号
|
|
}
|
|
return $user_id;
|
|
}
|
|
|
|
//查询user unionid
|
|
$user_id = Wechat::where('unionid', $unionid)->value('user_id');
|
|
if (empty($user_id)) {
|
|
return '未查询到相应信息'; //没有同unionid账号
|
|
}
|
|
return $user_id;
|
|
}
|
|
|
|
public function opus(){
|
|
return $this->hasMany(Opus::class);
|
|
}
|
|
|
|
public function ballot(){
|
|
return $this->hasMany(Ballot::class);
|
|
}
|
|
/**
|
|
* 是否是可提现福币者
|
|
* @return boolean [description]
|
|
*/
|
|
public function isWithdrawer()
|
|
{
|
|
try {
|
|
$user = $this->user;
|
|
//是否是置顶推广人
|
|
$is_withdrawer = empty($user) || empty($user->withdrawer)?0:1;
|
|
return $is_withdrawer;
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
}
|