<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\admin\controller\setting;
use app\admin\model\special\SpecialSubject;
use app\admin\model\special\RecommendBanner;
use app\admin\model\special\Special;
use app\admin\model\special\Lecturer;
use app\admin\model\system\Recommend;
use app\admin\model\system\RecommendRelation;
use app\admin\model\system\WebRecommend;
use app\admin\model\system\WebRecommendRelation;
use app\admin\model\user\Group;
use service\FormBuilder as Form;
use service\JsonService as Json;
use service\UploadService as Upload;
use think\Request;
use think\Url;
use app\admin\model\system\SystemGroup as GroupModel;
use app\admin\model\system\SystemGroupData as GroupDataModel;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAttachment;
use service\SystemConfigService;
use app\admin\model\system\SystemConfig;
use app\admin\model\download\DataDownload;
/**
* 数据列表控制器 在组合数据中
* Class SystemGroupData
* @package app\admin\controller\setting
*/
class SystemGroupData extends AuthController
{
/**
* 显示资源列表
* @return \think\Response
*/
public function index($gid)
{
$where = parent::getMore([
['status', '']
], $this->request);
$this->assign('where', $where);
$this->assign(compact("gid"));
$this->assign(GroupModel::getField($gid));
$where['gid'] = $gid;
$this->assign(GroupDataModel::getList($where));
return $this->fetch();
}
/**
* 显示创建资源表单页.
* @return \think\Response
*/
public function create($gid)
{
$Fields = GroupModel::getField($gid);
$f = array();
foreach ($Fields["fields"] as $key => $value) {
$info = [];
if (!empty($value["param"])) {
$value["param"] = str_replace("\r\n", "\n", $value["param"]);//防止不兼容
$params = explode("\n", $value["param"]);
if (is_array($params) && !empty($params)) {
foreach ($params as $index => $v) {
if (strstr($v, '=>') !== false) {
list($left, $right) = explode('=>', $v);
} else if (strstr($v, '=') !== false) {
list($left, $right) = explode('=', $v);
}
$val["value"] = $left;
$val["label"] = $right;
$info[] = $val;
}
}
}
switch ($value["type"]) {
case 'input':
$f[] = Form::input($value["title"], $value["name"])->maxlength(90);
break;
case 'textarea':
$f[] = Form::input($value["title"], $value["name"])->type('textarea')->placeholder($value['param']);
break;
case 'radio':
$f[] = Form::radio($value["title"], $value["name"], isset($info[0]["value"]) ? $info[0]["value"] : '')->options($info);
break;
case 'checkbox':
$f[] = Form::checkbox($value["title"], $value["name"], isset($info[0]) ? $info[0] : '')->options($info);
break;
case 'select':
$f[] = Form::select($value["title"], $value["name"], isset($info[0]) ? $info[0] : '')->options($info)->multiple(false);
break;
case 'upload':
$f[] = Form::frameImageOne($value["title"], $value["name"], Url::build('admin/widget.images/index', array('fodder' => $value["title"])))->icon('image')->width('100%')->height('500px');
break;
case 'uploads':
$f[] = Form::frameImages($value["title"], $value["name"], Url::build('admin/widget.images/index', array('fodder' => $value["title"])))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0);
break;
default:
$f[] = Form::input($value["title"], $value["name"]);
break;
}
}
$f[] = Form::number('sort', '排序', 1)->min(0);
$f[] = Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
$form = Form::make_post_form('添加数据', $f, Url::build('save', compact('gid')), 2);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request, $gid)
{
$Fields = GroupModel::getField($gid);
$params = $request->post();
$value = array();
foreach ($params as $key => $param) {
foreach ($Fields['fields'] as $index => $field) {
if ($key == $field["title"]) {
if ($param == "" || preg_replace("#(^( |\s)+|( |\s)+$)#", "", $param) == '')
return Json::fail($field["name"] . "不能为空!");
else {
$value[$key]["type"] = $field["type"];
$value[$key]["value"] = $param;
}
}
}
}
$data = array("gid" => $gid, "add_time" => time(), "value" => json_encode($value), "sort" => $params["sort"], "status" => $params["status"]);
GroupDataModel::set($data);
return Json::successful('添加数据成功!');
}
/**
* 显示编辑资源表单页.
* @param int $id
* @return \think\Response
*/
public function edit($gid, $id)
{
$GroupData = GroupDataModel::get($id);
$GroupDataValue = json_decode($GroupData["value"], true);
$Fields = GroupModel::getField($gid);
$f = array();
foreach ($Fields['fields'] as $key => $value) {
$info = [];
if (!empty($value["param"])) {
$value["param"] = str_replace("\r\n", "\n", $value["param"]);//防止不兼容
$params = explode("\n", $value["param"]);
if (is_array($params) && !empty($params)) {
foreach ($params as $index => $v) {
if (strstr($v, '=>') !== false) {
list($left, $right) = explode('=>', $v);
} else if (strstr($v, '=') !== false) {
list($left, $right) = explode('=', $v);
}
$val["value"] = $left;
$val["label"] = $right;
$info[] = $val;
}
}
}
switch ($value['type']) {
case 'input':
$f[] = Form::input($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->maxlength(90);
break;
case 'textarea':
$f[] = Form::input($value['title'], $value['name'], $GroupDataValue[$value['title']]['value'])->type('textarea');
break;
case 'radio':
$f[] = Form::radio($value['title'], $valu
评论0