quanwei
7 days ago 30563323a53b0d0260c97d08a9e8bd4cc8227a95
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
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
 
namespace app\api\controller\user;
 
use app\api\controller\Controller;
use app\api\model\plus\shareholder\Referee;
use app\api\model\plus\shareholder\Setting;
use app\api\model\plus\shareholder\User as ShareholderUserModel;
use app\api\model\plus\shareholder\Apply as ShareholderApplyModel;
use app\api\model\plus\team\Order as TeamOrder;
use app\api\model\settings\Message as MessageModel;
use app\api\model\plus\agent\User as AgentUserModel;
use app\common\model\product\Product as ProductModel;
/**
 * 分销中心
 */
class Shareholder extends Controller
{
    // 用户
    private $user;
    // 股东
    private $shareholder;
    // 分销设置
    private $setting;
 
    /**
     * 构造方法
     */
    public function initialize()
    {
        // 用户信息
        $this->user = $this->getUser();
        // 股东信息
        $this->shareholder = ShareholderUserModel::detail($this->user['user_id'],['user','grade']);
        // 股东设置
        $this->setting = Setting::getAll();
        // 分销商用户信息
        $this->agent = AgentUserModel::detail($this->user['user_id']);
    }
 
    /**
     * 股东中心
     */
    public function center()
    {
        //如果不是股东,列出条件 by lyzflash
        $is_shareholder = $this->isShareholderUser();
        if (!$is_shareholder){
            if ( (new ShareholderApplyModel)->becomeShareholderByTeam($this->user['user_id'],110,$this->user['app_id'])){
                // 股东信息
                $this->shareholder = ShareholderUserModel::detail($this->user['user_id'],['user','grade']);
                //如果不是股东,列出条件 by lyzflash
                $is_shareholder = $this->isShareholderUser();
            }
        }
        $setting = $this->setting['basic']['values'];
        $agent_total = $agent_money = $team_money = 0;
        //统计下级分销商总数
        if ($setting['become'] == '40' && $this->agent) {
            $agent_total = $this->agent['first_num'] + $this->agent['second_num']+ $this->agent['third_num'];
        }
        // 累计佣金
        if ($setting['become'] == '50' && $this->agent) {
            $agent_money = $this->agent['total_money'];
        }
        // 累计团队业绩
        if ($setting['become'] == '70') {
            $team_money = TeamOrder::getOrderAllPrice($this->user['user_id']);
            // 如果计算自己的业绩
            if ($setting['self_buy_money'] == '1') {
                $team_money += $this->user['expend_money'];
                //log_write($team_money);
            }
        }
        // 购买商品
        $productList = [];
        if ($setting['become'] == '100') {
            if ($setting['become__buy_product_ids']) {
                $productList = (new ProductModel)->getListByIds($setting['become__buy_product_ids']);
            }
        }
        return $this->renderSuccess('', [
            // 当前是否为分销商
            'is_agent' => $this->isAgentUser(),
            // 当前是否为股东
            'is_shareholder' => $is_shareholder,
            // 当前是否在申请中
            'is_applying' => ShareholderApplyModel::isApplying($this->user['user_id']),
            // 当前用户信息
            'user' => $this->user,
            // 股东用户信息
            'shareholder' => $this->shareholder,
            // 背景图
            'background' => $this->setting['background']['values']['index'],
            //权益说明
            'description_pic' => $this->setting['background']['values']['description'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            //'shareholdernum'=>count($user_ids),
            // 下级分销商总数
            'agent_total' => $agent_total,
            // 累计佣金
            'agent_money' => $agent_money,
            // 累计团队业绩
            'team_money' => $team_money,
            'setting' => $setting,
            'productList' => $productList
        ]);
    }
 
    /**
     * 股东申请状态
     */
    public function apply($platform= '')
    {
        return $this->renderSuccess('', [
            // 当前是否为股东
            'is_shareholder' => $this->isShareholderUser(),
            // 当前是否在申请中
            'is_applying' => ShareholderApplyModel::isApplying($this->user['user_id']),
            // 背景图
            'background' => $this->setting['background']['values']['apply'],
            //权益说明
            'description' => $this->setting['background']['values']['description'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            // 申请协议
            'license' => $this->setting['license']['values']['license'],
            // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
            'template_arr' => MessageModel::getMessageByNameArr($platform, ['shareholder_apply_user']),
        ]);
    }
 
    /**
     * 股东提现信息
     */
    public function cash($platform = '')
    {
        // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
        $template_arr = MessageModel::getMessageByNameArr($platform, ['shareholder_cash_user']);
        return $this->renderSuccess('', [
            // 股东用户信息
            'shareholder' => $this->shareholder,
            // 结算设置
            'settlement' => $this->setting['settlement']['values'],
            // 背景图
            'background' => $this->setting['background']['values']['cash_apply'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            // 小程序消息
            'template_arr' => $template_arr
        ]);
    }
 
    /**
     * 当前用户是否为股东
     */
    private function isShareholderUser()
    {
        return !!$this->shareholder && !$this->shareholder['is_delete'];
    }
    
    /**
     * 当前用户是否为分销商
     */
    private function isAgentUser()
    {
        return !!$this->agent && !$this->agent['is_delete'];
    }
}