quanwei
2025-11-15 6f12eadd25c8f5335fd9eccf373bf9835bf3e4c6
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
<?php
 
namespace app\api\controller\user;
 
use app\api\controller\Controller;
use app\api\model\plus\agent\Referee;
use app\api\model\plus\agent\Setting;
use app\api\model\plus\agent\User as AgentUserModel;
use app\api\model\plus\agent\Apply as AgentApplyModel;
use app\api\model\settings\Message as MessageModel;
use app\common\model\product\Product as ProductModel;
 
/**
 * 分销中心
 */
class Agent extends Controller
{
    // 用户
    private $user;
    // 分销商
    private $agent;
    // 分销设置
    private $setting;
 
    /**
     * 构造方法
     */
    public function initialize()
    {
        // 用户信息
        $this->user = $this->getUser();
        // 分销商用户信息
        $this->agent = AgentUserModel::detail($this->user['user_id']);
        // 分销商设置
        $this->setting = Setting::getAll();
    }
 
    /**
     * 分销商中心
     */
    public function center()
    {
        //如果不是分销商,列出条件 by lyzflash
        $is_agent = $this->isAgentUser();
        $is_applying = AgentApplyModel::isApplying($this->user['user_id']);
        $setting = $this->setting['condition']['values'];
        $productList = [];
        if (!$is_agent && !$is_applying && $setting['become'] == '50' && $setting['become__buy_product_ids']) {
            $productList = (new ProductModel)->getListByIds($setting['become__buy_product_ids']);
        }
        return $this->renderSuccess('', [
            // 当前是否为分销商
            'is_agent' => $this->isAgentUser(),
            // 当前是否在申请中
            'is_applying' => AgentApplyModel::isApplying($this->user['user_id']),
            // 当前用户信息
            'user' => $this->user,
            // 分销商用户信息
            'agent' => $this->agent,
            // 背景图
            'background' => $this->setting['background']['values']['index'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            'setting' => $setting,
            'productList' => $productList
        ]);
    }
 
    /**
     * 分销商申请状态
     */
    public function apply($referee_id = null, $platform= '')
    {
        // 推荐人昵称
        $referee_name = '平台';
        // 如果之前有关联分销商,则继续关联之前的分销商
        $has_referee_id = Referee::getRefereeUserId($this->user['user_id'], 1);
        if($has_referee_id > 0){
            $referee_id = $has_referee_id;
        }
        if ($referee_id > 0 && ($referee = AgentUserModel::detail($referee_id))) {
            $referee_name = $referee['user']['nickName'];
        }
 
        return $this->renderSuccess('', [
            // 当前是否为分销商
            'is_agent' => $this->isAgentUser(),
            // 当前是否在申请中
            'is_applying' => AgentApplyModel::isApplying($this->user['user_id']),
            // 推荐人昵称
            'referee_name' => $referee_name,
            // 背景图
            'background' => $this->setting['background']['values']['apply'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            // 申请协议
            'license' => $this->setting['license']['values']['license'],
            // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
            'template_arr' => MessageModel::getMessageByNameArr($platform, ['agent_apply_user']),
        ]);
    }
 
    /**
     * 分销商提现信息
     */
    public function cash($platform = '')
    {
        // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
        $template_arr = MessageModel::getMessageByNameArr($platform, ['agent_cash_user']);
        return $this->renderSuccess('', [
            // 分销商用户信息
            'agent' => $this->agent,
            // 结算设置
            'settlement' => $this->setting['settlement']['values'],
            // 背景图
            'background' => $this->setting['background']['values']['cash_apply'],
            // 页面文字
            'words' => $this->setting['words']['values'],
            // 小程序消息
            'template_arr' => $template_arr
        ]);
    }
 
    /**
     * 当前用户是否为分销商
     */
    private function isAgentUser()
    {
        return !!$this->agent && !$this->agent['is_delete'];
    }
 
}