更新内核
增加自定义表单(未完成)
This commit is contained in:
@@ -12,13 +12,20 @@ use app\common\controller\Admin;
|
||||
|
||||
class Form extends Admin {
|
||||
|
||||
public function _initialize(){
|
||||
parent::_initialize();
|
||||
$this->model = model('Form');
|
||||
}
|
||||
|
||||
//自定义表单
|
||||
public function index(){
|
||||
$list = array();
|
||||
$map = array();
|
||||
$order = "id desc";
|
||||
$list = $this->model->where($map)->order($order)->paginate(25);
|
||||
|
||||
$data = array(
|
||||
'list' => $list,
|
||||
//'page' => $list->render()
|
||||
'page' => $list->render()
|
||||
);
|
||||
$this->setMeta('自定义表单');
|
||||
$this->assign($data);
|
||||
@@ -59,4 +66,15 @@ class Form extends Admin {
|
||||
return $this->error('删除失败!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 表单数据
|
||||
* @description 表单数据
|
||||
* @Author molong
|
||||
* @DateTime 2017-06-30
|
||||
* @return html 页面
|
||||
*/
|
||||
public function lists(){
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
25
application/api/controller/Wechat.php
Normal file
25
application/api/controller/Wechat.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\api\controller;
|
||||
use app\common\controller\Api;
|
||||
|
||||
class Wechat extends Api {
|
||||
|
||||
public function config(){
|
||||
$js = new \Wechat\WechatScript(config('wxapp'));
|
||||
$this->data['data'] = $js->getJsSign('http://test.tensent.cn:81/home');
|
||||
// dump($this->data);
|
||||
// $this->data['data'] = array(
|
||||
// 'appid' => 'dddd',
|
||||
// 'timestamp' => time()
|
||||
// );
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class Api {
|
||||
protected $data;
|
||||
|
||||
public function __construct() {
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
$this->data = array('code' => 0, 'msg' => '', 'time' => time(), 'data' => '');
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,64 @@ namespace app\common\model;
|
||||
*/
|
||||
class Form extends Base{
|
||||
|
||||
protected $auto = ['update_time'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid'=>"id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
);
|
||||
|
||||
|
||||
protected static function init(){
|
||||
self::beforeInsert(function($event){
|
||||
$data = $event->toArray();
|
||||
$tablename = strtolower($data['name']);
|
||||
//实例化一个数据库操作类
|
||||
$db = new \com\Datatable();
|
||||
//检查表是否存在并创建
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
self::afterInsert(function($event){
|
||||
$data = $event->toArray();
|
||||
|
||||
$fields = include(APP_PATH.'admin/fields.php');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $key => $value) {
|
||||
if ($data['is_doc']) {
|
||||
$fields[$key]['form_id'] = $data['id'];
|
||||
}else{
|
||||
if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
$fields[$key]['form_id'] = $data['id'];
|
||||
}else{
|
||||
unset($fields[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
model('FormAttr')->saveAll($fields);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
self::beforeUpdate(function($event){
|
||||
$data = $event->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
if (!empty($attribute_sort)) {
|
||||
foreach ($attribute_sort as $key => $value) {
|
||||
db('FormAttr')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||
foreach ($value as $k => $v) {
|
||||
db('FormAttr')->where('id', $v)->setField('sort', $k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -107,5 +107,9 @@ return array(
|
||||
'view_replace_str' => array(
|
||||
'__ADDONS__' => BASE_PATH . '/addons',
|
||||
'__PUBLIC__' => BASE_PATH . '/public',
|
||||
),
|
||||
'wxapp' => array(
|
||||
'appid'=>'wx4924a63b43e2fc1a',
|
||||
'appsecret'=>'0821fc43d2305d4b4722a591361df438'
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user