AllController.php
2.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
<?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 cmf\controller\AdminBaseController;
use app\portal\model\NeedAnswerModel;
use app\portal\model\MemberModel;
use app\portal\model\UserModel;
use app\portal\service\PostService;
use think\Db;
use think\Request;
use think\Loader;
/**
* @title 包干价接口
* @description 接口说明
* @group 接口分组
*/
class AllController extends AdminBaseController
{
public function add(Request $request)
{
if($request->post()){
// 添加数据
$data = $request->post();
if($request->Post('id')){
// 修改
$add['content'] = $data['content'];
$add['title'] = '什么是包干价';
$add['type'] = 1;
$validate = Loader::validate('NeedAnswer');
if(!$validate->scene('edit')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$add['id'] = $request->param('id');
$model = new NeedAnswerModel();
$final = $model->isUpdate(true)->allowField(true)->save($add);
}else{
// 添加
$add['content'] = $data['content'];
$add['title'] = '什么是包干价';
$add['type'] = 1;
$validate = Loader::validate('NeedAnswer');
if(!$validate->scene('add')->check($add)){
$mes = $validate->getError();
$this->error("$mes");
}
$model = new NeedAnswerModel();
$final = $model->save($add);
}
if($final){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$where_find['type'] = 1;
$list = Db::name('NeedAnswer')->where($where_find)->find();
if($list){
$list['content'] = htmlspecialchars_decode($list['content']);
}
$this->assign('list',$list);
return $this->fetch('add');
}
}
}