zm
2021-04-01 802c31297a1ae5b8c2e8fb5c62e9790dfc5d7583
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
 * Created by PhpStorm.
 * User: 风哀伤
 * Date: 2019/7/10
 * Time: 16:44
 * @copyright: ©2019 浙江禾匠信息科技
 * @link: http://www.zjhejiang.com
 */
 
namespace app\events;
 
 
use app\models\Mall;
use app\models\Share;
use app\models\User;
use yii\base\Event;
 
/**
 * Class ShareMemberEvent
 * @package app\events
 * @property Share $parent
 * @property Share $beforeParent
 * @property User $user
 * @property Mall $mall
 * @property integer $beforeParentId
 * @property integer $parentId
 * @property integer $userId
 * @property string $remark
 */
class ShareMemberEvent extends Event
{
    protected $user; // 触发事件的用户
    protected $userId; // 触发事件的用户ID
    protected $beforeParentId; // 变更前的上级ID(此为user表的id)
    protected $beforeParent; // 变更前的上级分销商(此为share表)
    protected $parent; // 变更后的上级分销商
    protected $parentId; // 变更后的上级Id
    protected $remark; //备注
    public $mall; // 商城
 
    /**
     * @param User $user
     */
    public function setUser($user)
    {
        $this->user = $user;
    }
 
    public function getUser()
    {
        if ($this->user) {
            return $this->user;
        } elseif ($this->userId) {
            $this->user = User::findOne(['id' => $this->userId]);
            return $this->user;
        } else {
            return null;
        }
    }
 
    public function setUserId($userId)
    {
        $this->userId = $userId;
    }
 
    public function getUserId()
    {
        if ($this->userId) {
            return $this->userId;
        } elseif ($this->user) {
            return $this->user->id;
        } else {
            return 0;
        }
    }
 
    public function setBeforeParentId($beforeParentId)
    {
        $this->beforeParentId = $beforeParentId;
    }
 
    public function getBeforeParentId()
    {
        if ($this->beforeParentId) {
            return $this->beforeParentId;
        } elseif ($this->beforeParent) {
            return $this->beforeParent->user_id;
        } else {
            return 0;
        }
    }
 
    public function setBeforeParent($beforeParent)
    {
        $this->beforeParent = $beforeParent;
    }
 
    public function getBeforeParent()
    {
        if ($this->beforeParent) {
            return $this->beforeParent;
        } elseif ($this->beforeParentId) {
            $this->beforeParent = Share::findOne(['user_id' => $this->beforeParentId]);
            return $this->beforeParent;
        } else {
            return null;
        }
    }
 
    public function setParent($parent)
    {
        $this->parent = $parent;
    }
 
    public function getParent()
    {
        if ($this->parent) {
            return $this->parent;
        } elseif ($this->parentId) {
            $this->parent = Share::findOne(['user_id' => $this->parentId]);
            return $this->parent;
        } else {
            return null;
        }
    }
 
    public function setParentId($parentId)
    {
        $this->parentId = $parentId;
    }
 
    public function getParentId()
    {
        if ($this->parentId) {
            return $this->parentId;
        } elseif ($this->parent) {
            return $this->parent->user_id;
        } else {
            return 0;
        }
    }
 
    public function setRemark($remark)
    {
        $this->remark = $remark;
    }
 
    public function getRemark()
    {
        if ($this->remark) {
            return $this->remark;
        } else {
            return null;
        }
    }
}