RewardController.php
6.7 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\model\BankModel;
use app\portal\model\BrandModel;
use app\portal\model\CooperationModel;
use app\portal\model\ProcessModel;
use app\portal\model\RewardModel;
use cmf\controller\AdminBaseController;
use app\portal\model\PortalTagModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
class RewardController extends AdminBaseController
{
/**
* 列表(暂无用)
* @adminMenu(
* 'name' => '文章管理',
* 'parent' => 'portal/AdminIndex/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '文章列表',
* 'param' => ''
* )
*/
public function index(Request $request)
{
$where_coo['status'] = 1;
$where_coo['type'] = array('lt',5);
// $where_coo = array();
if($request->post()){
$search = $request->post();
if($search['start_time']){
$start = strtotime($search['start_time']);
if($search['end_time']){
$end = strtotime($search['end_time']);
}else{
$end = time();
}
$where_coo['update_time'] = array('between',"$start,$end");
$this->assign('start_time',date('Y-m-d H:i',$start));
$this->assign('end_time',date('Y-m-d H:i',$end));
}
if($search['keyword']){
$where_coo['name'] = array('like',"%".$search['keyword']."%");
$this->assign('keyword',$search['keyword']);
}
}
$coo_list = Db::name('Reward')->where($where_coo)->order(' create_time desc')->paginate();
$page = $coo_list->render();
$this->assign('page',$page);
$this->assign('list',$coo_list);
return $this->fetch();
}
/**
* 添加、修改
* @adminMenu(
* 'name' => '添加文章',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加文章',
* 'param' => ''
* )
*/
public function add(Request $request)
{
if($request->post()){
// 添加数据
$data = $request->param();
if($request->Post('id')){
// 修改
$add = $data;
$validate = Loader::validate('Reward');
if(!$validate->scene('edit')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$add['id'] = $request->param('id');
$model = new RewardModel();
$final = $model->isUpdate(true)->allowField(true)->save($add);
}else{
// 添加
$add = $data;
$validate = Loader::validate('Reward');
if(!$validate->scene('add')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$model = new RewardModel();
$final = $model->save($add);
}
if($final){
$this->success('成功',url('index'));
}else{
$this->error('失败');
}
}else{
$where_find['id'] = $request->param('id');
$list = Db::name('Reward')->where($where_find)->find();
$this->assign('list',$list);
return $this->fetch('add');
}
}
// 删除
public function del(Request $request){
$ids = $this->request->post();
$id = $request->param('id');
if($ids){
$add_del['id'] = array('in',$ids['ids']);
}else if($id){
$add_del['id'] = $request->param('id');
}else{
$this->error('删除失败');
}
$add_del['status'] = 9;
$model = new BankModel();
$del = $model->isUpdate(true)->allowField(true)->save($add_del);
if($del){
$this->success('删除成功',url('index'));
}else{
$this->error('删除失败');
}
}
//Earnest
/**
* 诚意金添加、修改
* @adminMenu(
* 'name' => '添加文章',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加文章',
* 'param' => ''
* )
*/
public function earnest(Request $request)
{
$where_reward['type'] = 5;
$where_reward['status'] = 1;
$reward_id = Db::name('Reward')->where($where_reward)->find();
if($request->post()){
// 添加数据
$data = $request->param();
if($reward_id){
// 修改
$add = $data;
$add['type'] = 5;
$validate = Loader::validate('Reward');
if(!$validate->scene('edit')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$add['id'] = $request->param('id');
$model = new RewardModel();
$final = $model->isUpdate(true)->allowField(true)->save($add);
}else{
// 添加
$add = $data;
$add['type'] = 5;
$validate = Loader::validate('Reward');
if(!$validate->scene('add')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$model = new RewardModel();
$final = $model->save($add);
}
if($final){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$where_find['id'] = $reward_id['id'];
$list = Db::name('Reward')->where($where_find)->find();
$this->assign('list',$list);
return $this->fetch();
}
}
}