You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
3.3 KiB
117 lines
3.3 KiB
<?php
|
|
|
|
namespace app\distribution\model;
|
|
|
|
use app\base\model\user\User;
|
|
use app\base\model\user\UserInfo;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
class DistributionUserRelation extends Base
|
|
{
|
|
use SoftDelete;
|
|
|
|
protected $type = [
|
|
'create_time' => 'timestamp:Y.m.d H:i',
|
|
];
|
|
|
|
|
|
public function getRelationList($where, $where_u, $next_income, $page, $field = '*', $order = '', $per_page_number = 10)
|
|
{
|
|
$primary_key_name = $this->getPk();
|
|
|
|
|
|
if (empty($order)) {
|
|
$order = (empty($data[$primary_key_name]) ? 'id' : $data[$primary_key_name]) . ' desc';
|
|
}
|
|
if (!empty($where_u)) {
|
|
$dataList = $this->hasWhere('userInfo', $where_u, $field)->with(['userInfo'])->where($where)->order($order)
|
|
->paginate(['list_rows' => $per_page_number, 'page' => $page], false)->each(function ($item, $key) use ($next_income) {
|
|
$item['next_income'] = empty($next_income[$item['user_id']]) ? 0 : $next_income[$item['user_id']];
|
|
return $item;
|
|
});
|
|
} else {
|
|
$dataList = $this->with(['userInfo'])->field($field)->where($where)->order($order)
|
|
->paginate(['list_rows' => $per_page_number, 'page' => $page], false)->each(function ($item, $key) use ($next_income) {
|
|
$item['next_income'] = empty($next_income[$item['user_id']]) ? 0 : $next_income[$item['user_id']];
|
|
return $item;
|
|
});
|
|
}
|
|
|
|
return $dataList;
|
|
}
|
|
|
|
/*
|
|
* 获取用户 - 一对一
|
|
* @date 2021-03-01
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->hasOne(User::class, 'id', 'user_id');
|
|
}
|
|
|
|
/*
|
|
* 获取用户信息 - 一对一
|
|
* @date 2021-03-01
|
|
*/
|
|
public function userInfo()
|
|
{
|
|
return $this->hasOne(UserInfo::class, 'user_id', 'user_id')->bind([
|
|
'head_img',
|
|
'nick_name'
|
|
]);
|
|
}
|
|
|
|
/*
|
|
* 获取用户佣金 - 一对一
|
|
* @date 2021-03-01
|
|
*/
|
|
public function distributionCommission()
|
|
{
|
|
return $this->hasOne('DistributionCommissionMy', 'user_id', 'user_id')->bind(['commission','total_commission']);
|
|
}
|
|
|
|
/**
|
|
* 关联上一级
|
|
* @return \think\model\relation\HasOne
|
|
*/
|
|
public function getUpperLevel()
|
|
{
|
|
return $this->hasOne(UserInfo::class, 'user_id', 'first_user_id')->bind(['upper_nick_name'=>'nick_name']);
|
|
}
|
|
|
|
/**
|
|
* 关联下一级
|
|
* @return \think\model\relation\HasMany
|
|
*/
|
|
public function getFirstLevel()
|
|
{
|
|
return $this->hasMany('DistributionUserRelation', 'first_user_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* 关联下二级
|
|
* @return \think\model\relation\HasMany
|
|
*/
|
|
public function getSecondLevel()
|
|
{
|
|
return $this->hasMany('DistributionUserRelation', 'second_user_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* 关联下三级
|
|
* @return \think\model\relation\HasMany
|
|
*/
|
|
public function getThirdLevel()
|
|
{
|
|
return $this->hasMany('DistributionUserRelation', 'third_user_id', 'user_id');
|
|
}
|
|
|
|
/**
|
|
* 关联分销佣金
|
|
* @return \think\model\relation\HasMany
|
|
*/
|
|
public function getIncome()
|
|
{
|
|
return $this->hasMany('DistributionCommissionIncome', 'user_id', 'user_id');
|
|
}
|
|
} |