liyaozhi
2025-10-28 1320688354fd168c51cf2e05f29a2253f4ed9c00
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
<?php
 
namespace app\shop\controller\user;
 
use app\common\library\helper;
use app\common\model\user\Tag as TagModel;
use app\common\model\user\UserTag as UserTagModel;
use app\shop\controller\Controller;
use app\shop\model\user\User as UserModel;
use app\shop\model\user\Grade;
use app\shop\service\order\ExportService;
 
/**
 * 用户管理
 */
class User extends Controller
{
    /**
     * 商户列表
     */
    public function index($nickName = '', $gender = null, $reg_date = '', $grade_id = null)
    {
        $list = UserModel::getList($nickName, $grade_id, $reg_date, $gender = -1, $this->postData());
        $GradeModel = new Grade();
        $grade = $GradeModel->getLists();
        // 所有标签
        $allTag = TagModel::getAll();
        return $this->renderSuccess('', compact('list', 'grade', 'allTag'));
    }
 
    /**
     * 其他用户详情
     */
    public function getDetail($user_id = '')
    {
        $detail = UserModel::detail($user_id);
        return $this->renderSuccess('', compact('detail'));
    }
 
 
    /**
     * 删除用户
     */
    public function delete($user_id)
    {
        // 用户详情
        $model = UserModel::detail($user_id);
        if ($model && $model->setDelete()) {
            return $this->renderSuccess('删除成功');
        }
        return $this->renderError($model->getError() ?: '删除失败');
    }
 
 
    /**
     * 添加用户
     */
    public function add()
    {
        $model = new UserModel;
        // 新增记录
        if ($model->add($this->request->param())) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     * 用户充值
     */
    public function recharge($user_id, $source)
    {
        // 用户详情
        $model = UserModel::detail($user_id);
 
        if ($model->recharge($this->store['user']['user_name'], $source, $this->postData('params'))) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 等级改用户
     */
    public function edit($user_id)
    {
        // 用户详情
        $model = UserModel::detail($user_id);
        if ($this->request->isGet()) {
            return $this->renderSuccess('', compact('model'));
        }
        // 修改记录
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    public function tag($user_id){
        if($this->request->isGet()){
            // 用户详情
            $user = UserModel::detail($user_id);
            // 标签
            $userTag = UserTagModel::getListByUser($user_id);
            $userTag = helper::getArrayColumn($userTag, 'tag_id');
            // 所有标签
            $allTag = TagModel::getAll();
            return $this->renderSuccess('', compact('user', 'userTag' , 'allTag'));
        }
        $model = UserModel::detail($user_id);
        if($model->editTag($this->postData())){
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    /**
     * 等级改用户
     */
    public function grade($user_id)
    {
        // 用户详情
        $model = UserModel::detail($user_id);
        // 修改记录
        if ($model->updateGrade($this->postData())) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    /**
     * 导出
     */
    public function export()
    {
        ini_set('memory_limit','-1');
        set_time_limit(0);
        $postData = $this->postData();
        $data = UserModel::getList($postData["nick_name"], $postData["grade_id"], $postData["reg_date"], $gender = -1, $this->postData(),false);
        $list = $data->toArray();
        return (new Exportservice)->userList($list);
    }
 
}