AdminServiceController.php
4.3 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use app\portal\model\ServiceModel;
use app\portal\model\ServiceRuleModel;
use app\portal\model\CompanyModel;
use think\Db;
use think\db\Query;
class AdminServiceController extends AdminBaseController
{
//列表页
public function index(){
$list = Db::name('service')
->where(function (Query $query) {
$data = $this->request->param();
if (!empty($data['name'])) {
$keyword = $data['name'];
$query->where('name', 'like', "%$keyword%");
}
})
->order("id desc")
->paginate(10,false,['query'=>request()->param()]);
// 获取分页显示
$page = $list->render();
$this->assign('list', $list);
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();
}
//新增页面
public function add(){
return $this->fetch();
}
//新增提交
public function addPost(){
$data = $this->request->param();
$result = $this->validate($data, 'Service');
if ($result !== true) {
$this->error($result);
}
// $companyModel = new CompanyModel();
// if(strpos($companyModel::HOST,$data['icon']) === false){
// $data['icon'] = $companyModel::HOST.$data['icon'];
// }
$serviceModel = new ServiceModel();
$data['create_time'] = time();
$serviceModel->allowField(true)->save($data);
$this->success("添加成功!", url("AdminService/index"));
}
//设置服务页面
public function edit(){
$id = $this->request->param('id', 0, 'intval');
$serviceModel = new ServiceModel();
$service = $serviceModel->get($id);
$this->assign('post', $service);
//查询企业名称
$resCompany = $this->getCompany();
$this->assign('company_list',$resCompany);
//查询该服务权限的企业
$rule = $this->getRule($id);
$this->assign('rule',$rule);
return $this->fetch();
}
//获取企业名称
private function getCompany(){
$res = Db::name('company')
->field('id,company_name')
->select()
->toArray();
return $res;
}
//获取服务权限
private function getRule($id){
$res = Db::name('service_rule')
->where('s_id',$id)
->field('id,c_id')
->find();
$arr['c_id'] = explode(',',trim($res['c_id'],','));
$arr['id'] = $res['id'];
return $arr;
}
//设置保存页面
public function editPost(){
$data = $this->request->param();
// $companyModel = new CompanyModel();
// if(strpos($data['icon'],$companyModel::HOST) === false){
// $data['icon'] = $companyModel::HOST.$data['icon'];
// }
$res['s_id'] = $data['id'];
if(isset($data['c_id']) && !empty($data['c_id'])){
$res['c_id'] = ','.implode($data['c_id'],',').',';
}else{
$res['c_id'] = '';
}
$res['create_time'] = time();
$ruleModel = new ServiceRuleModel();
if(isset($data['rule_id']) && !empty($data['rule_id'])){
$ruleModel->where('id',$data['rule_id'])->update($res);
}else{
$ruleModel->allowField(true)->save($res);
}
$serviceModel = new ServiceModel();
$serviceModel->where('id',$data['id'])->update(['english_name'=>$data['english_name'],'icon'=>$data['icon']]);
$this->success("设置成功!", url("AdminService/index"));
}
}