自定义表单优化
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\common\controller\Front;
|
||||
use app\common\model\Form as FormM;
|
||||
|
||||
class Form extends Front {
|
||||
|
||||
@@ -23,6 +25,33 @@ class Form extends Front {
|
||||
* 表单首页
|
||||
*/
|
||||
public function index(){
|
||||
$id = $this->request->param('id');
|
||||
$map = [];
|
||||
|
||||
$map['id'] = $id;
|
||||
|
||||
$info = FormM::where($map)->find();
|
||||
|
||||
$info['logo_url'] = get_cover($info['logo'], 'path');
|
||||
$info['cover_url'] = get_cover($info['cover'], 'path');
|
||||
|
||||
$info['attr'] = $info->attr()->where('is_show', 1)->order('sort asc, id asc')->select();
|
||||
|
||||
if ($info['relation']) {
|
||||
$relation = explode(",", $info['relation']);
|
||||
if (is_array($relation)) {
|
||||
$rmap['id'] = ['IN', $relation];
|
||||
}elseif (is_string($relation)) {
|
||||
$rmap['id'] = $relation;
|
||||
}
|
||||
$info['relation_list'] = M('Article')->where($rmap)->order('sort desc, id asc')->select();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'info' => $info
|
||||
];
|
||||
|
||||
$this->assign($data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
@@ -47,9 +76,23 @@ class Form extends Front {
|
||||
public function add(\think\Request $request){
|
||||
if ($request->isPost()) {
|
||||
$data = $request->param();
|
||||
|
||||
$form = FormM::where('id', $data['form_id'])->find();
|
||||
|
||||
$data['is_mobile'] = $this->isMobile();
|
||||
$result = $this->model->save($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('提交成功!');
|
||||
$data = ['code' => 0, 'data' => '', 'msg' => '', 'url' => ''];
|
||||
if ($form['sub_action'] == 0) {
|
||||
$data['code'] = 1;
|
||||
}elseif ($form['sub_action'] == 1) {
|
||||
$data['code'] = 2;
|
||||
}elseif ($form['sub_action'] == 2) {
|
||||
$data['code'] = 3;
|
||||
}
|
||||
$data['msg'] = $form['sub_content'];
|
||||
// $data['data'] = $form['sub_tips'] ? get_cover($form['sub_tips'], 'path') : '';
|
||||
return $data;
|
||||
}else{
|
||||
return $this->error('提交失败!');
|
||||
}
|
||||
@@ -64,4 +107,13 @@ class Form extends Front {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function msg(){
|
||||
$param = $this->request->param();
|
||||
|
||||
$form = FormM::where('id', $param['id'])->find();
|
||||
$form['sub_tips_url'] = $form['sub_tips'] ? get_cover($form['sub_tips'], 'path') : '';
|
||||
$this->assign(['form' => $form]);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user