quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
<?php
 
namespace app\operations\controller\takeout;
 
use app\operations\controller\Controller;
use app\operations\model\takeout\Commander as CommanderModel;
use app\operations\model\takeout\School as SchoolModel;
use app\operations\model\takeout\CommanderCash as CommanderCashModel;
 
/**
 * 控制器
 */
class Commander extends Controller
{
    /**
     * 列表
     */
    public function index()
    {
        $model = new CommanderModel;
        $list = $model->getList($this->postData());
        $school = (new SchoolModel())->getAll();
        return $this->renderSuccess('', compact('list','school'));
    }
 
    /**
     * 添加
     */
    public function add()
    {
        $postData = $this->postData();
        if(empty($postData["user_id"])){
            return $this->renderError('请选择会员');
        }
        if(empty($postData["school_id"])){
            return $this->renderError('请选择学校');
        }
        if(empty($postData["real_name"]) || empty($postData["mobile"])){
            return $this->renderError('请填写姓名和手机号');
        }
        $is_exsit = CommanderModel::isCommander($postData["user_id"]);
        if($is_exsit){
            return $this->renderError('该会员已成为团长');
        }
        $model = new CommanderModel;
        // 新增记录
        if ($model->add($postData["user_id"],$this->postData())) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }
 
    /**
     * 编辑
     */
    public function edit()
    {
        $postData = $this->postData();
        if(empty($postData["school_id"])){
            return $this->renderError('请选择学校');
        }
        if(empty($postData["real_name"]) || empty($postData["mobile"])){
            return $this->renderError('请填写姓名和手机号');
        }
        $model = CommanderModel::detail($postData["commander_id"]);
        //换了团长,判断
        if($model["user_id"] != $postData["user_id"]){
            $is_exsit = CommanderModel::isCommander($postData["user_id"]);
            if($is_exsit){
                return $this->renderError('该会员已成为团长');
            }
        }
 
        if ($model->edit($postData)) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }
 
    /**
     * 软删除
     */
    public function delete($commander_id)
    {
        $model = CommanderModel::detail($commander_id);
        if (!$model->setDelete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
    /**
     * 提现列表
     */
    public function cash()
    {
        $model = new CommanderCashModel;
        $postData = $this->postData();
        $list = $model->getList($postData);
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 提现审核
     */
    public function cashSubmit($id)
    {
        $model = CommanderCashModel::detail($id);
        if ($model->submit($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 确认打款
     */
    public function cashMoney($id)
    {
        $model = CommanderCashModel::detail($id);
 
        if ($model->money()) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
}