quanwei
17 hours ago ad8477d3ee82a3fffd5de4cd60a237c9ee6b1fb7
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
<?php
 
namespace app\shop\controller\plus\release;
 
use app\shop\controller\Controller;
use app\shop\model\plus\release\DemandProject as ProjectModel;
 
/**
 * 项目
 */
class DemandProject extends Controller
{
    /**
     * 列表
     */
    public function index()
    {
        $model = new ProjectModel;
        $list = $model->getList($this->postData());
        return $this->renderSuccess('', compact('list'));
    }
 
    /**
     * 获取默认数据(分类)
     */
    public function defaultData()
    {
        $model = new ProjectModel;
        $data = $model->getDefaultData();
        return $this->renderSuccess('', compact('data'));
    }
 
    /**
     * 后台发布需求
     */
    public function add()
    {
        $model = new ProjectModel;
        $data = $this->postData();
        // 获取表单数据
        $formData = json_decode($data['formData'], true);
        // 获取用户ID
        $user_id = isset($data['user_id']) ? intval($data['user_id']) : 0;
        if ($user_id <= 0) {
            return $this->renderError('请选择发布用户');
        }
        // 是否支付连盟币(可选)
        $pay_points = isset($data['pay_points']) ? intval($data['pay_points']) : 0;
        
        if ($model->addByAdmin($formData, $user_id, $pay_points)) {
            return $this->renderSuccess('发布成功');
        }
        return $this->renderError($model->getError() ?: '发布失败');
    }
 
    /**
     * 审核
     */
    public function submit($project_id)
    {
        $model = ProjectModel::detail($project_id);
        if ($model->submit($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
 
    /**
     * 编辑
     */
    public function edit()
    {
        $model = new ProjectModel;
        $data = $this->postData();
        // 获取表单数据
        $formData = json_decode($data['formData'], true);
        // 获取项目ID
        $project_id = isset($data['project_id']) ? intval($data['project_id']) : 0;
        if ($project_id <= 0) {
            return $this->renderError('项目ID不能为空');
        }
 
        if ($model->editByAdmin($project_id, $formData)) {
            return $this->renderSuccess('编辑成功');
        }
        return $this->renderError($model->getError() ?: '编辑失败');
    }
 
    /**
     * 删除
     */
    public function delete($project_id)
    {
        // 详情
        $model = ProjectModel::detail($project_id);
        if (!$model->setDelete()) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
 
}