Explorar o código

新增商户贡献值配置

xialei hai 1 ano
pai
achega
2215f45648

+ 66 - 0
app/common/dao/system/config/SystemContributionDao.php

@@ -0,0 +1,66 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-24
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\dao\system\config;
12
+
13
+
14
+use app\common\dao\BaseDao;
15
+use app\common\model\BaseModel;
16
+use app\common\model\system\config\SystemContribution;
17
+use think\Collection;
18
+use think\db\exception\DataNotFoundException;
19
+use think\db\exception\DbException;
20
+use think\db\exception\ModelNotFoundException;
21
+use think\Model;
22
+
23
+/**
24
+ * Class SystemContributionDao
25
+ * @package app\common\dao\system\config
26
+ * @author xaboy
27
+ * @day 2020-03-27
28
+ */
29
+class SystemContributionDao extends BaseDao
30
+{
31
+
32
+    /**
33
+     * @return BaseModel
34
+     * @author xaboy
35
+     * @day 2020-03-30
36
+     */
37
+    protected function getModel(): string
38
+    {
39
+        return SystemContribution::class;
40
+    }
41
+
42
+
43
+    /**
44
+     * @return Collection
45
+     * @throws DataNotFoundException
46
+     * @throws DbException
47
+     * @throws ModelNotFoundException
48
+     * @author xaboy
49
+     * @day 2020-03-31
50
+     */
51
+    public function all()
52
+    {
53
+        return SystemContribution::getDB()->select();
54
+    }
55
+
56
+    /**
57
+     * @return int
58
+     * @author xaboy
59
+     * @day 2020-03-31
60
+     */
61
+    public function count()
62
+    {
63
+        return SystemContribution::getDB()->count();
64
+    }
65
+
66
+}

+ 46 - 0
app/common/model/system/config/SystemContribution.php

@@ -0,0 +1,46 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-24
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\model\system\config;
12
+
13
+
14
+use app\common\model\BaseModel;
15
+use think\model\relation\HasMany;
16
+use think\model\relation\HasOne;
17
+
18
+/**
19
+ * Class SystemContribution
20
+ * @package app\common\model\system\config
21
+ * @author xaboy
22
+ * @day 2020-03-30
23
+ */
24
+class SystemContribution extends BaseModel
25
+{
26
+    /**
27
+     * @return string
28
+     * @author xaboy
29
+     * @day 2020-03-30
30
+     */
31
+    public static function tablePk(): string
32
+    {
33
+        return 'id';
34
+    }
35
+
36
+    /**
37
+     * @return string
38
+     * @author xaboy
39
+     * @day 2020-03-30
40
+     */
41
+    public static function tableName(): string
42
+    {
43
+        return 'merchant_contribution';
44
+    }
45
+
46
+}

+ 107 - 0
app/common/repositories/system/config/ConfigContributionRepository.php

@@ -0,0 +1,107 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-26
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\common\repositories\system\config;
12
+
13
+
14
+use app\common\dao\system\config\SystemContributionDao;
15
+use app\common\repositories\BaseRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use FormBuilder\Factory\Elm;
18
+use FormBuilder\Form;
19
+use think\db\exception\DataNotFoundException;
20
+use think\db\exception\DbException;
21
+use think\db\exception\ModelNotFoundException;
22
+use think\facade\Route;
23
+
24
+/**
25
+ * Class ConfigContributionRepository
26
+ * @package crmeb\repositories\system\config
27
+ * @mixin SystemContributionDao
28
+ */
29
+class ConfigContributionRepository extends BaseRepository
30
+{
31
+
32
+    /**
33
+     * ConfigContributionRepository constructor.
34
+     * @param SystemContributionDao $dao
35
+     */
36
+    public function __construct(SystemContributionDao $dao)
37
+    {
38
+        $this->dao = $dao;
39
+    }
40
+
41
+    /**
42
+     * @return array
43
+     * @throws DataNotFoundException
44
+     * @throws DbException
45
+     * @throws ModelNotFoundException
46
+     * @author xaboy
47
+     * @day 2020-03-31
48
+     */
49
+    public function lst()
50
+    {
51
+        $list = $this->dao->all();
52
+        $count = $this->dao->count();
53
+
54
+        return compact('list', 'count');
55
+    }
56
+
57
+
58
+    /**
59
+     * @param int|null $id
60
+     * @param array $formData
61
+     * @return Form
62
+     * @throws FormBuilderException
63
+     * @author xaboy
64
+     * @day 2020-03-31
65
+     */
66
+    public function form(?int $id = null, array $formData = []): Form
67
+    {
68
+        $form = Elm::createForm(is_null($id) ? Route::buildUrl('configContributionCreate')->build() : Route::buildUrl('configContributionUpdate', ['id' => $id])->build());
69
+        $form->setRule([
70
+            Elm::input('title', '范围名称')->required(),
71
+            Elm::number('start', '范围开始')->required(),
72
+            Elm::number('end', '范围结束')->required(),
73
+            Elm::input('type', '类型')->required(),
74
+            Elm::number('jd', '京豆')->required(),
75
+            Elm::number('value', '贡献值')->required(),
76
+        ]);
77
+
78
+        return $form->setTitle(is_null($id) ? '添加' : '编辑')->formData($formData);
79
+    }
80
+
81
+    /**
82
+     * @return Form
83
+     * @throws FormBuilderException
84
+     * @author xaboy
85
+     * @day 2020-03-30
86
+     */
87
+    public function createForm()
88
+    {
89
+        return $this->form();
90
+    }
91
+
92
+
93
+    /**
94
+     * @param $id
95
+     * @return Form
96
+     * @throws DataNotFoundException
97
+     * @throws DbException
98
+     * @throws FormBuilderException
99
+     * @throws ModelNotFoundException
100
+     * @author xaboy
101
+     * @day 2020-03-31
102
+     */
103
+    public function updateForm($id)
104
+    {
105
+        return $this->form($id, $this->dao->get($id)->toArray());
106
+    }
107
+}

+ 131 - 0
app/controller/admin/system/config/Contribution.php

@@ -0,0 +1,131 @@
1
+<?php
2
+/**
3
+ * @package merchant
4
+ *
5
+ * @author xaboy
6
+ * @day 2020-03-24
7
+ *
8
+ * 
9
+ */
10
+
11
+namespace app\controller\admin\system\config;
12
+
13
+
14
+use crmeb\basic\BaseController;
15
+use app\common\repositories\system\config\ConfigContributionRepository;
16
+use FormBuilder\Exception\FormBuilderException;
17
+use think\App;
18
+use think\db\exception\DataNotFoundException;
19
+use think\db\exception\DbException;
20
+use think\db\exception\ModelNotFoundException;
21
+
22
+/**
23
+ * Class Contribution
24
+ * @package app\controller\admin\system\config
25
+ * @author xaboy
26
+ * @day 2020-03-27
27
+ */
28
+class Contribution extends BaseController
29
+{
30
+    /**
31
+     * @var ConfigContributionRepository
32
+     */
33
+    private $repository;
34
+
35
+    /**
36
+     * ConfigClassify constructor.
37
+     * @param App $app
38
+     * @param ConfigContributionRepository $repository
39
+     */
40
+    public function __construct(App $app, ConfigContributionRepository $repository)
41
+    {
42
+        parent::__construct($app);
43
+        $this->repository = $repository;
44
+    }
45
+
46
+    /**
47
+     * @return mixed 列表
48
+     * @throws DataNotFoundException
49
+     * @throws DbException
50
+     * @throws ModelNotFoundException
51
+     * @author xaboy
52
+     * @day 2020-03-31
53
+     */
54
+    public function lst()
55
+    {
56
+        $lst = $this->repository->lst();
57
+        // $lst['list'] = $lst['list']->toArray();
58
+        return app('json')->success($lst);
59
+    }
60
+
61
+
62
+    /**
63
+     * @return mixed 创建表单
64
+     * @throws FormBuilderException
65
+     * @author xaboy
66
+     * @day 2020-03-31
67
+     */
68
+    public function createTable()
69
+    {
70
+        $form = $this->repository->createForm();
71
+        return app('json')->success(formToData($form));
72
+    }
73
+
74
+    /** 修改表单
75
+     * @param int $id
76
+     * @return mixed
77
+     * @throws DataNotFoundException
78
+     * @throws DbException
79
+     * @throws ModelNotFoundException
80
+     * @throws FormBuilderException
81
+     * @author xaboy
82
+     * @day 2020-03-31
83
+     */
84
+    public function updateTable($id)
85
+    {
86
+        if (!$this->repository->exists($id)) app('json')->fail('数据不存在');
87
+        $form = $this->repository->updateForm($id);
88
+        return app('json')->success(formToData($form));
89
+    }
90
+
91
+
92
+    /** 创建
93
+     * @return mixed
94
+     * @author xaboy
95
+     * @day 2020-03-27
96
+     */
97
+    public function create()
98
+    {
99
+        $data = $this->request->params(['title', 'start', 'end', 'type', 'jd', 'value']);
100
+        $this->repository->create($data);
101
+        return app('json')->success('添加成功');
102
+    }
103
+
104
+    /**修改
105
+     * @param int $id
106
+     * @return mixed
107
+     * @throws DbException
108
+     * @author xaboy
109
+     * @day 2020-03-27
110
+     */
111
+    public function update($id)
112
+    {
113
+        $data = $this->request->params(['title', 'start', 'end', 'type', 'jd', 'value']);
114
+        $this->repository->update($id, $data);
115
+        return app('json')->success('修改成功');
116
+    }
117
+
118
+
119
+    /** 删除
120
+     * @param int $id
121
+     * @return mixed
122
+     * @throws DbException
123
+     * @author xaboy
124
+     * @day 2020-03-27
125
+     */
126
+    public function delete($id)
127
+    {
128
+        $this->repository->delete($id);
129
+        return app('json')->success('删除成功');
130
+    }
131
+}