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
<?php
 
namespace app\shop\controller\plus\bonus;
 
use app\shop\controller\Controller;
use app\shop\model\plus\bonus\User as UserModel;
use app\shop\model\plus\bonus\Setting as SettingModel;
use app\shop\model\plus\bonus\Referee as RefereeModel;
/**
 * 分销控制器
 */
class User extends Controller
{
    /**
     * 队长列表
     */
    public function index($keyword = '', $search_type = 'user_id')
    {
        $model = new UserModel;
        $list = $model->getList($keyword, $search_type, $this->postData());
        
        foreach ($list as $key => $val) {
            $list[$key]['cash_total'] = sprintf('%.2f', $val['moeny'] + $val['freeze_money'] + $val['total_money']);
        }
        $basicSetting = SettingModel::getItem('basic');
        $total_money_wait = (new UserModel)->getTotalMoney('money');
        $total_money_freeze = (new UserModel)->getTotalMoney('freeze_money_second');
        return $this->renderSuccess('', compact('list', 'basicSetting', 'total_money_wait', 'total_money_freeze'));
    }
 
    /**
     * 编辑队长
     */
    public function edit()
    {
        if ($this->request->isGet()) {
            return $this->renderSuccess('');
        }
        //判断是否更换用户并且是不是分红用户
        $new_user_id = $this->postData('new_user_id');
        if($new_user_id) {
            $model = UserModel::detail($new_user_id);
            if($model) {
                return $this->renderError($model->getError() ?: '更换的会员已经是分红用户,请重新选择');
            }
        }
        $user_id = $this->postData('user_id');
        $model = UserModel::detail($user_id);
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 队长用户列表
     */
    public function fans($user_id, $level = -1)
    {
        $model = new RefereeModel;
        $list = $model->getList($user_id, $level);
        $basicSetting = SettingModel::getItem('basic');
        return $this->renderSuccess('', compact('list', 'basicSetting'));
    }
 
    /**
     * 软删除队长用户
     */
    public function delete($user_id)
    {
        $model = UserModel::detail($user_id);
        if (!$model->setDelete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
    public function architecture($keyword = '', $type = 0)
    {
        $model = new UserModel;
        $list = $model->getArchitecture($keyword, $type);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 分红用户导出
     */
    public function export($keyword = '', $search_type = 'user_id')
    {
        $model = new UserModel;
        return $model->exportList($keyword, $search_type, $this->postData());
    }
 
}