- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
343 行
11 KiB
PHP
可执行文件
343 行
11 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace app\admin\controller\general;
|
||
|
||
use app\common\controller\Backend;
|
||
use app\common\library\Email;
|
||
use app\common\library\FcConfig;
|
||
use app\common\model\Config as ConfigModel;
|
||
use think\Cache;
|
||
use think\Db;
|
||
use think\Exception;
|
||
use think\Validate;
|
||
|
||
/**
|
||
* 系统配置
|
||
*
|
||
* @icon fa fa-cogs
|
||
* @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
|
||
*/
|
||
class Config extends Backend
|
||
{
|
||
|
||
/**
|
||
* @var \app\common\model\Config
|
||
*/
|
||
protected $model = null;
|
||
protected $noNeedRight = ['check', 'rulelist', 'selectpage', 'get_fields_list'];
|
||
|
||
public function _initialize()
|
||
{
|
||
parent::_initialize();
|
||
// $this->model = model('Config');
|
||
$this->model = new ConfigModel;
|
||
ConfigModel::event('before_write', function ($row) {
|
||
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) {
|
||
throw new Exception(__("Site name incorrect"));
|
||
}
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 查看
|
||
*/
|
||
public function index()
|
||
{
|
||
$siteList = [];
|
||
$groupList = ConfigModel::getGroupList();
|
||
foreach ($groupList as $k => $v) {
|
||
$siteList[$k]['name'] = $k;
|
||
$siteList[$k]['title'] = $v;
|
||
$siteList[$k]['list'] = [];
|
||
}
|
||
|
||
foreach ($this->model->all() as $k => $v) {
|
||
if (!isset($siteList[$v['group']])) {
|
||
continue;
|
||
}
|
||
$value = $v->toArray();
|
||
$value['title'] = __($value['title']);
|
||
if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) {
|
||
$value['value'] = explode(',', $value['value']);
|
||
}
|
||
$value['content'] = json_decode($value['content'], true);
|
||
if (in_array($value['name'], ['categorytype', 'configgroup', 'attachmentcategory'])) {
|
||
$dictValue = (array)json_decode($value['value'], true);
|
||
foreach ($dictValue as $index => &$item) {
|
||
$item = __($item);
|
||
}
|
||
unset($item);
|
||
$value['value'] = json_encode($dictValue, JSON_UNESCAPED_UNICODE);
|
||
}
|
||
$value['tip'] = htmlspecialchars($value['tip']);
|
||
if ($value['name'] == 'cdnurl') {
|
||
//cdnurl不支持在线修改
|
||
continue;
|
||
}
|
||
$siteList[$v['group']]['list'][] = $value;
|
||
}
|
||
// 把小程序 / 发布 / 分销三组业务配置并入系统配置页(值真源仍是 fa_fc_config)
|
||
$fcGroups = FcConfig::groups();
|
||
$merged = [];
|
||
foreach ($siteList as $k => $v) {
|
||
$merged[$k] = $v;
|
||
if ($k === 'basic') {
|
||
foreach ($fcGroups as $gk => $gv) {
|
||
$merged[$gk] = $gv;
|
||
}
|
||
}
|
||
}
|
||
if (!isset($merged['fc_miniapp'])) {
|
||
foreach ($fcGroups as $gk => $gv) {
|
||
$merged[$gk] = $gv;
|
||
}
|
||
}
|
||
$siteList = $merged;
|
||
|
||
$index = 0;
|
||
foreach ($siteList as $k => &$v) {
|
||
$v['active'] = !$index ? true : false;
|
||
$index++;
|
||
}
|
||
unset($v);
|
||
$this->view->assign('siteList', $siteList);
|
||
$this->view->assign('typeList', ConfigModel::getTypeList());
|
||
$this->view->assign('ruleList', ConfigModel::getRegexList());
|
||
$this->view->assign('groupList', ConfigModel::getGroupList());
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 添加
|
||
*/
|
||
public function add()
|
||
{
|
||
if (!config('app_debug')) {
|
||
$this->error(__('Only work at development environment'));
|
||
}
|
||
if ($this->request->isPost()) {
|
||
$this->token();
|
||
$params = $this->request->post("row/a", [], 'trim');
|
||
if ($params) {
|
||
foreach ($params as $k => &$v) {
|
||
$v = is_array($v) && $k !== 'setting' ? implode(',', $v) : $v;
|
||
}
|
||
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) {
|
||
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE);
|
||
} else {
|
||
$params['content'] = '';
|
||
}
|
||
try {
|
||
$result = $this->model->create($params);
|
||
} catch (Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($result !== false) {
|
||
try {
|
||
ConfigModel::refreshFile();
|
||
} catch (Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success();
|
||
} else {
|
||
$this->error($this->model->getError());
|
||
}
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
return $this->view->fetch();
|
||
}
|
||
|
||
/**
|
||
* 编辑
|
||
* @param null $ids
|
||
*/
|
||
public function edit($ids = null)
|
||
{
|
||
if ($this->request->isPost()) {
|
||
$this->token();
|
||
$row = $this->request->post("row/a", [], 'trim');
|
||
if ($row) {
|
||
// 小程序 / 发布 / 分销:写入 fc_config(系统配置页的业务分组)
|
||
try {
|
||
FcConfig::save($row);
|
||
} catch (\Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
|
||
$configList = [];
|
||
foreach ($this->model->all() as $v) {
|
||
if (isset($row[$v['name']])) {
|
||
$value = $row[$v['name']];
|
||
if (is_array($value) && isset($value['field'])) {
|
||
$value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE);
|
||
} else {
|
||
$value = is_array($value) ? implode(',', $value) : $value;
|
||
}
|
||
$v['value'] = $value;
|
||
$configList[] = $v->toArray();
|
||
}
|
||
}
|
||
try {
|
||
if ($configList) {
|
||
$this->model->allowField(true)->saveAll($configList);
|
||
}
|
||
} catch (Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
if ($configList) {
|
||
try {
|
||
ConfigModel::refreshFile();
|
||
} catch (Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
}
|
||
$this->success();
|
||
}
|
||
$this->error(__('Parameter %s can not be empty', ''));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
* @param string $ids
|
||
*/
|
||
public function del($ids = "")
|
||
{
|
||
if (!config('app_debug')) {
|
||
$this->error(__('Only work at development environment'));
|
||
}
|
||
$name = $this->request->post('name');
|
||
$config = ConfigModel::getByName($name);
|
||
if ($name && $config) {
|
||
try {
|
||
$config->delete();
|
||
ConfigModel::refreshFile();
|
||
} catch (Exception $e) {
|
||
$this->error($e->getMessage());
|
||
}
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 检测配置项是否存在
|
||
* @internal
|
||
*/
|
||
public function check()
|
||
{
|
||
$params = $this->request->post("row/a");
|
||
if ($params) {
|
||
$config = $this->model->get($params);
|
||
if (!$config) {
|
||
$this->success();
|
||
} else {
|
||
$this->error(__('Name already exist'));
|
||
}
|
||
} else {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 规则列表
|
||
* @internal
|
||
*/
|
||
public function rulelist()
|
||
{
|
||
//主键
|
||
$primarykey = $this->request->request("keyField");
|
||
//主键值
|
||
$keyValue = $this->request->request("keyValue", "");
|
||
|
||
$keyValueArr = array_filter(explode(',', $keyValue));
|
||
$regexList = \app\common\model\Config::getRegexList();
|
||
$list = [];
|
||
foreach ($regexList as $k => $v) {
|
||
if ($keyValueArr) {
|
||
if (in_array($k, $keyValueArr)) {
|
||
$list[] = ['id' => $k, 'name' => $v];
|
||
}
|
||
} else {
|
||
$list[] = ['id' => $k, 'name' => $v];
|
||
}
|
||
}
|
||
return json(['list' => $list]);
|
||
}
|
||
|
||
/**
|
||
* 发送测试邮件
|
||
* @internal
|
||
*/
|
||
public function emailtest()
|
||
{
|
||
$row = $this->request->post('row/a');
|
||
$receiver = $this->request->post("receiver");
|
||
if ($receiver) {
|
||
if (!Validate::is($receiver, "email")) {
|
||
$this->error(__('Please input correct email'));
|
||
}
|
||
\think\Config::set('site', array_merge(\think\Config::get('site'), $row));
|
||
$email = new Email;
|
||
$result = $email
|
||
->to($receiver)
|
||
->subject(__("This is a test mail", config('site.name')))
|
||
->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . __('This is a test mail content', config('site.name')) . '</div>')
|
||
->send();
|
||
if ($result) {
|
||
$this->success();
|
||
} else {
|
||
$this->error($email->getError());
|
||
}
|
||
} else {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
}
|
||
|
||
public function selectpage()
|
||
{
|
||
$id = $this->request->get("id/d");
|
||
$config = \app\common\model\Config::get($id);
|
||
if (!$config) {
|
||
$this->error(__('Invalid parameters'));
|
||
}
|
||
$setting = $config['setting'];
|
||
//自定义条件
|
||
$custom = isset($setting['conditions']) ? (array)json_decode($setting['conditions'], true) : [];
|
||
$custom = array_filter($custom);
|
||
|
||
$this->request->request(['showField' => $setting['field'], 'keyField' => $setting['primarykey'], 'custom' => $custom, 'searchField' => [$setting['field'], $setting['primarykey']]]);
|
||
$this->model = \think\Db::connect()->setTable($setting['table']);
|
||
return parent::selectpage();
|
||
}
|
||
|
||
/**
|
||
* 获取表列表
|
||
* @internal
|
||
*/
|
||
public function get_table_list()
|
||
{
|
||
$tableList = [];
|
||
$dbname = \think\Config::get('database.database');
|
||
$tableList = \think\Db::query("SELECT `TABLE_NAME` AS `name`,`TABLE_COMMENT` AS `title` FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` = '{$dbname}';");
|
||
$this->success('', null, ['tableList' => $tableList]);
|
||
}
|
||
|
||
/**
|
||
* 获取表字段列表
|
||
* @internal
|
||
*/
|
||
public function get_fields_list()
|
||
{
|
||
$table = $this->request->request('table');
|
||
$dbname = \think\Config::get('database.database');
|
||
//从数据库中获取表字段信息
|
||
$sql = "SELECT `COLUMN_NAME` AS `name`,`COLUMN_COMMENT` AS `title`,`DATA_TYPE` AS `type` FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION";
|
||
//加载主表的列
|
||
$fieldList = Db::query($sql, [$dbname, $table]);
|
||
$this->success("", null, ['fieldList' => $fieldList]);
|
||
}
|
||
}
|