Files
sentcms/application/index/controller/Form.php
2020-03-25 10:40:32 +08:00

119 lines
3.0 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\index\controller;
use app\common\controller\Front;
use app\common\model\Form as FormM;
class Form extends Front {
public function _initialize() {
parent::_initialize();
$model_name = $this->request->param('model');
$this->form = db('Form')->where('name', $model_name)->find();
$this->model = M($model_name, 'form');
}
/**
* 表单首页
*/
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();
}
/**
* 表单列表
*/
public function lists(){
$list = $this->model->order('id desc')->paginate('20');
$data = array(
'list' => $list,
'page' => $list->render()
);
$this->assign($data);
return $this->fetch();
}
/**
* 表单数据提交
*/
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) {
$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('提交失败!');
}
}else{
$map['form_id'] = $this->form['id'];
$attr = model('FormAttr')->getFieldlist($map);
$data = array(
'attr' => $attr
);
$this->assign($data);
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();
}
}