初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model\app\agent;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 分销关系
|
||||
*/
|
||||
class Relation extends Model
|
||||
{
|
||||
|
||||
// 表名,不含前缀
|
||||
protected $name = 'app_agent_relation';
|
||||
// 自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = false;
|
||||
// 定义时间戳字段名
|
||||
protected $createTime = false;
|
||||
protected $updateTime = false;
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('app\common\model\User', 'user_id', 'id')->setEagerlyType(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取统计数据
|
||||
* @param $userId
|
||||
* @return int[]
|
||||
*/
|
||||
public function getUserTotal($userId,$status='',$time=[]){
|
||||
|
||||
$data = [
|
||||
];
|
||||
|
||||
$where = [
|
||||
'parent_id'=>$userId
|
||||
];
|
||||
if($status){
|
||||
$where['status'] = $status;
|
||||
}
|
||||
|
||||
if($time){
|
||||
$where['createtime'] = ['BETWEEN',[$time['start'], $time['end']]];
|
||||
}
|
||||
|
||||
$data['count'] = self::where($where)->count(); //下级数量
|
||||
$data['normal'] = self::where($where)->where(['status'=>1])->count(); //正常数量
|
||||
$data['hidden'] = self::where($where)->where(['status'=>0])->count(); //解绑数量
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user