Agent.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace addons\shopro\model\commission;
use think\Model;
use addons\shopro\library\commission\Agent as AgentLibrary;
class Agent extends Model
{
protected $pk = 'user_id';
// 表名
protected $name = 'shopro_commission_agent';
// 自动写入时间戳字段
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
public static function getRanking($params) {
extract($params);
$goods = self::with(['user' => function ($query) {
$query->field('id,avatar,nickname');
}])
->field('user_id,level,parent_agent_id,total_income,createtime,status')
->normal()
->order('total_income', 'desc')->order('createtime', 'desc')
->paginate($per_page ?? 10);
return $goods;
}
/**
* 正常的分销商
*/
public function scopeNormal($query) {
return $query->where('status', AgentLibrary::AGENT_STATUS_NORMAL);
}
/**
* 可参与的分销商
*/
public function scopeAvaliable($query) {
return $query->where('status', 'in', [AgentLibrary::AGENT_STATUS_NORMAL, AgentLibrary::AGENT_STATUS_FREEZE]);
}
/**
* 禁用的分销商
*/
public function scopeForbidden($query) {
return $query->where('status', AgentLibrary::AGENT_STATUS_FORBIDDEN);
}
/**
* 审核中的分销商
*/
public function scopePending($query) {
return $query->where('status', AgentLibrary::AGENT_STATUS_PENDING);
}
public function user(){
return $this->belongsTo(\addons\shopro\model\User::class, 'user_id');
}
public function level(){
return $this->belongsTo(\addons\shopro\model\commission\Level::class, 'level', 'level');
}
public function getChildAgentLevelAttr($value, $data){
if(!empty($value)) {
return json_decode($value, true);
}
return [];
}
public function setChildAgentLevelAttr($value, $data){
return json_encode($value);
}
public function getChildAgentLevel_1Attr($value, $data){
if(!empty($value)) {
return json_decode($value, true);
}
return [];
}
public function setChildAgentLevel_1Attr($value, $data){
return json_encode($value);
}
}