初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 自动任务配置
|
||||
*/
|
||||
class Crontab extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* AttachmentGroup模型对象
|
||||
* @var \app\admin\model\attachment\AttachmentGroup
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $configName = 'crontab';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
\app\common\model\fill\Handle::check('app_config',$this->configName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig(){
|
||||
$data = \app\common\model\app\Config::getConfig($this->configName);
|
||||
|
||||
if($data['token'] == '123456'){
|
||||
$this->resetToken();
|
||||
$data = \app\common\model\app\Config::getConfig($this->configName);
|
||||
}
|
||||
|
||||
$data['request_url'] = $this->getRequestUrl();
|
||||
|
||||
return $this->success("获取成功",$data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取请求地址
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestUrl(){
|
||||
global $_W;
|
||||
if(\app\common\library\Platform::getSystemType() == 'single'){
|
||||
return $_W['siteroot'].'/index.php?i='.$_W['uniacid'].'&route=callback/auto/handle';
|
||||
}else{
|
||||
return $_W['siteroot'].'/app/index.php?i='.$_W['uniacid'].'&c=entry&m=tuzi_v1&do=index&route=callback/auto/handle';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新 Token
|
||||
* @return void
|
||||
*/
|
||||
public function refreshToken(){
|
||||
$this->resetToken();
|
||||
return $this->success("刷新成功");
|
||||
}
|
||||
|
||||
public function resetToken(){
|
||||
$data = \app\common\model\app\Config::getConfig($this->configName);
|
||||
//随机获取 10 位的随机数
|
||||
$data['token'] = \fast\Random::alnum(10);
|
||||
\app\common\model\app\Config::setConfig($this->configName,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function setConfig(){
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
$data = \app\common\model\app\Config::setConfig($this->configName,$row);
|
||||
return $this->success("保存成功",$data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 跑马灯配置
|
||||
*/
|
||||
class Marquee extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* AttachmentGroup模型对象
|
||||
* @var \app\admin\model\attachment\AttachmentGroup
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
|
||||
protected $configName = 'marquee';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig(){
|
||||
|
||||
\app\common\model\fill\Handle::check('app_config',$this->configName);
|
||||
|
||||
$data = \app\common\model\app\Config::getConfig($this->configName);
|
||||
|
||||
return $this->success("获取成功",$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function setConfig(){
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
$type = $this->request->post("type", [], 'trim');
|
||||
|
||||
\app\common\model\fill\Handle::check('app_config',$this->configName);
|
||||
|
||||
$data = \app\common\model\app\Config::setConfig($this->configName,$row);
|
||||
return $this->success("保存成功",$data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
/**
|
||||
* 支付配置
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Pay extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Column模型对象
|
||||
* @var \app\admin\model\course\Column
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $AddonContro = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\config\Pay;
|
||||
$this->AddonContro = new \app\admin\controller\Addon;
|
||||
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
return $this->success("获取成功",$this->model->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig(){
|
||||
$name = $this->request->post("name");
|
||||
|
||||
$config = $this->AddonContro->getConfig('epay',false);
|
||||
|
||||
if(!$config['config']){
|
||||
return $this->error("获取失败");
|
||||
}
|
||||
|
||||
foreach ($config['config'] as $item){
|
||||
if($item['name'] == $name){
|
||||
$config['config'] = [$item];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $this->success("获取成功",$config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function setConfig(){
|
||||
$name = $this->request->post("name");
|
||||
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
|
||||
$config = $this->AddonContro->getConfig('epay',false)['config'];
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($config as $k => &$v) {
|
||||
|
||||
if($v['name'] == $name){
|
||||
$data[$v['name']] = $params[$name];
|
||||
}else{
|
||||
if($v['type'] == 'array'){
|
||||
$arr = [];
|
||||
foreach ($v['value'] as $option){
|
||||
$arr[$option['key']] = $option['value'];
|
||||
}
|
||||
$data[$v['name']] = $arr;
|
||||
}else{
|
||||
$data[$v['name']] = $v['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->AddonContro->setConfig('epay',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus(){
|
||||
$name = $this->request->post("name");
|
||||
$status = $this->request->post("status",false);
|
||||
|
||||
if(!$name){
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
|
||||
$this->model->setStatus($name,$status);
|
||||
|
||||
return $this->success("操作成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
/**
|
||||
* 短信
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Sms extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Column模型对象
|
||||
* @var \app\admin\model\course\Column
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\config\Sms;
|
||||
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
return $this->success("获取成功",$this->model->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus(){
|
||||
$name = $this->request->post("name");
|
||||
$status = $this->request->post("status",false);
|
||||
|
||||
if(!$name){
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
|
||||
$this->model->setStatus($name,$status);
|
||||
|
||||
return $this->success("操作成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\Config;
|
||||
use think\Cache;
|
||||
use app\common\model\config\System as ConfigModel;
|
||||
/**
|
||||
* 系统配置
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class System extends Backend
|
||||
{
|
||||
|
||||
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['check', 'rulelist'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
//填充默认配置
|
||||
\app\common\model\fill\Handle::check('config_system');
|
||||
|
||||
$this->model = new \app\admin\model\config\System();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$siteList = [];
|
||||
|
||||
$group = input('group','basic');
|
||||
$name = input('name');
|
||||
|
||||
$where = [
|
||||
'group'=>$group,
|
||||
'uniacid'=>UNIACID,
|
||||
'status'=>1
|
||||
];
|
||||
|
||||
|
||||
|
||||
if($name){
|
||||
$where['name'] = $name;
|
||||
}
|
||||
|
||||
if($group == 'payment'){
|
||||
$where['name'] = ['not in',['virtual_pay','douyinpay']];
|
||||
}
|
||||
|
||||
|
||||
// 检查并补齐分组内新增的配置项(兼容版本升级后新增配置组的场景)
|
||||
\app\common\model\fill\Handle::checkByGroup($group);
|
||||
$list = $this->model->where($where)->order('sort','asc')->select();
|
||||
|
||||
foreach ($list as $k => $v) {
|
||||
|
||||
$value = $v->toArray();
|
||||
|
||||
$value['title'] = __($value['title']);
|
||||
$value['value'] = json_decode($value['value'],true);
|
||||
|
||||
$value['value'] = array_values(array_filter($value['value'], function($item){
|
||||
return isset($item['name']) && isset($item['type']);
|
||||
}));
|
||||
|
||||
|
||||
//从默认配置里获取已有配置项中缺失的配置,并按默认定义顺序展示
|
||||
$systemDefaultConfig = \app\common\model\fill\Handle::getSystemDefaultConfig($value['name']);
|
||||
if($systemDefaultConfig){
|
||||
$value['value'] = $this->syncConfigWithDefault($value['value'], $systemDefaultConfig);
|
||||
}
|
||||
|
||||
if($value['name'] == 'aliyun_message'){
|
||||
$value['value'] = $this->buildAliyunMessageRuntimeConfig($value['value']);
|
||||
}
|
||||
|
||||
$siteList[] = $value;
|
||||
}
|
||||
$data = [
|
||||
'siteList'=>$siteList,
|
||||
'typeList'=>ConfigModel::getTypeList(),
|
||||
'ruleList'=>ConfigModel::getRegexList(),
|
||||
'groupList'=>ConfigModel::getGroupList(),
|
||||
];
|
||||
|
||||
|
||||
return $this->success("获取成功",$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用默认配置补齐元信息和顺序,保留已保存的 value。
|
||||
* @param array $currentConfig
|
||||
* @param array $defaultConfig
|
||||
* @return array
|
||||
*/
|
||||
protected function syncConfigWithDefault($currentConfig, $defaultConfig)
|
||||
{
|
||||
$currentMap = [];
|
||||
foreach ($currentConfig as $item) {
|
||||
if (isset($item['name'])) {
|
||||
$currentMap[$item['name']] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($defaultConfig as $defaultItem) {
|
||||
if (!isset($defaultItem['name'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = isset($currentMap[$defaultItem['name']]) ? $currentMap[$defaultItem['name']] : $defaultItem;
|
||||
foreach (['content', 'tip', 'title', 'type'] as $field) {
|
||||
if (isset($defaultItem[$field])) {
|
||||
$item[$field] = $defaultItem[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if ($defaultItem['name'] == 'data_center' && (!isset($item['value']) || $item['value'] === '')) {
|
||||
$item['value'] = 'cn-shanghai';
|
||||
}
|
||||
|
||||
if (isset($defaultItem['type']) && $defaultItem['type'] == 'array' && isset($item['value'], $defaultItem['value'])) {
|
||||
$item['value'] = $this->contrastConfigArrayValue($item['value'], $defaultItem['value']);
|
||||
}
|
||||
|
||||
$result[] = $item;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断数组类型的配置的成员差异
|
||||
* @param $nowConfig
|
||||
* @param $defaultConfig
|
||||
* @return void
|
||||
*/
|
||||
public function contrastConfigArrayValue($nowConfig,$defaultConfig){
|
||||
// 获取数组一中的所有 key
|
||||
$array1Keys = array_column($nowConfig, 'key');
|
||||
|
||||
// 获取数组二中的所有 key
|
||||
$array2Keys = array_column($defaultConfig, 'key');
|
||||
|
||||
// 计算数组一和数组二的差集,即数组一中没有但数组二中有的 key
|
||||
$keysToAdd = array_diff($array2Keys, $array1Keys);
|
||||
|
||||
// 遍历差集,将缺失的 key 补全到数组一中
|
||||
foreach ($keysToAdd as $keyToAdd) {
|
||||
foreach ($defaultConfig as $item) {
|
||||
if ($item['key'] === $keyToAdd) {
|
||||
$nowConfig[] = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 计算数组一和数组二的差集,即数组一中有但数组二中没有的 key
|
||||
$keysToRemove = array_diff($array1Keys, $array2Keys);
|
||||
// 遍历差集,从数组一中移除这些 key
|
||||
foreach ($keysToRemove as $keyToRemove) {
|
||||
foreach ($nowConfig as $key => $item) {
|
||||
if ($item['key'] === $keyToRemove) {
|
||||
unset($nowConfig[$key]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($nowConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建阿里云互动消息运行时配置。
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function buildAliyunMessageRuntimeConfig($config)
|
||||
{
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 持久化阿里云互动消息配置。
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
protected function saveAliyunMessageConfig($config)
|
||||
{
|
||||
$this->model->where(['name' => 'aliyun_message', 'uniacid' => UNIACID])->update([
|
||||
'value' => json_encode(array_values($config), JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
Cache::rm(\app\common\constant\cache\Keys::SYSTEM_CONFIG('aliyun_message'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) ? implode(',', $v) : $v;
|
||||
}
|
||||
try {
|
||||
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) {
|
||||
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$params['content'] = '';
|
||||
}
|
||||
$result = $this->model->create($params);
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param null $ids
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$group = $this->request->post("group",'basic');
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if ($row) {
|
||||
$configList = [];
|
||||
$list = $this->model->where([
|
||||
'group'=>$group
|
||||
])->select();
|
||||
|
||||
|
||||
foreach ($list as $v) {
|
||||
$v = $v->toArray();
|
||||
if (isset($v['name']) && isset($row[$v['name']])) {
|
||||
|
||||
$value = $row[$v['name']];
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $this->buildConfigValue($v['name'], $v['value'], $value);
|
||||
} else {
|
||||
$value = is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
|
||||
|
||||
$v['value'] = $value;
|
||||
|
||||
$configId = $v['id'];
|
||||
unset($v['id']);
|
||||
|
||||
$this->model->where(['id'=>$configId])->update($v);
|
||||
|
||||
Cache::rm(\app\common\constant\cache\Keys::SYSTEM_CONFIG($v['name']));
|
||||
// $configList[] = $v;
|
||||
}
|
||||
}
|
||||
// dump($configList);
|
||||
// die();
|
||||
|
||||
$this->model->allowField(true)->saveAll($configList);
|
||||
|
||||
if($group=='sms'){
|
||||
// (new \app\admin\model\config\Sms())->setAddonStatus();
|
||||
}
|
||||
|
||||
if($group=='oss'){
|
||||
$config = \app\common\model\config\System::getConfig('alivod');
|
||||
if($config && $config['status'] == 'open'){
|
||||
\app\admin\controller\Addon::selfstate('alivod','enable');
|
||||
}else{
|
||||
// \app\admin\controller\Addon::selfstate('alivod','disable');
|
||||
}
|
||||
}
|
||||
|
||||
$this->success("操作成功");
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置时保留原配置项顺序,只更新各项 value。
|
||||
* @param string $configName
|
||||
* @param string $currentValue
|
||||
* @param array $postValue
|
||||
* @return string
|
||||
*/
|
||||
protected function buildConfigValue($configName, $currentValue, $postValue)
|
||||
{
|
||||
$currentConfig = json_decode($currentValue, true);
|
||||
if (!is_array($currentConfig) || !$this->isConfigItemList($currentConfig)) {
|
||||
return json_encode(ConfigModel::getArrayData($postValue), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
$defaultConfig = \app\common\model\fill\Handle::getSystemDefaultConfig($configName);
|
||||
if ($defaultConfig) {
|
||||
$currentConfig = $this->syncConfigWithDefault($currentConfig, $defaultConfig);
|
||||
}
|
||||
|
||||
$postMap = [];
|
||||
if ($this->isConfigItemList($postValue)) {
|
||||
foreach ($postValue as $item) {
|
||||
if (isset($item['name'])) {
|
||||
$postMap[$item['name']] = isset($item['value']) ? $item['value'] : '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$postMap = $postValue;
|
||||
}
|
||||
|
||||
foreach ($currentConfig as &$item) {
|
||||
if (isset($item['name']) && array_key_exists($item['name'], $postMap)) {
|
||||
$item['value'] = $postMap[$item['name']];
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode(array_values($currentConfig), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为系统配置项列表。
|
||||
* @param array $config
|
||||
* @return bool
|
||||
*/
|
||||
protected function isConfigItemList($config)
|
||||
{
|
||||
foreach ($config as $item) {
|
||||
if (!is_array($item) || !isset($item['name'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !empty($config);
|
||||
}
|
||||
|
||||
public function platform($type)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if ($row) {
|
||||
try {
|
||||
$config = $this->model->get(['name' => $type]);
|
||||
$config->value = json_encode($row);
|
||||
$config->save();
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$config = $this->model->where(['name' => $type])->value('value');
|
||||
$config = json_decode($config, true);
|
||||
if ($type === 'wxOfficialAccount') {
|
||||
//动态解析微信公众号服务端Api Url地址域名
|
||||
$config['url'] = request()->domain();
|
||||
}
|
||||
$this->assign('row', $config);
|
||||
return $this->view->fetch();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param string $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
$name = $this->request->post('name');
|
||||
$config = ConfigModel::getByName($name);
|
||||
if ($name && $config) {
|
||||
try {
|
||||
$config->delete();
|
||||
$this->refreshFile();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新配置文件
|
||||
*/
|
||||
protected function refreshFile()
|
||||
{
|
||||
$config = [];
|
||||
foreach ($this->model->all() as $k => $v) {
|
||||
$value = $v->toArray();
|
||||
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) {
|
||||
$value['value'] = explode(',', $value['value']);
|
||||
}
|
||||
if ($value['type'] == 'array') {
|
||||
$value['value'] = (array)json_decode($value['value'], true);
|
||||
}
|
||||
$config[$value['name']] = $value['value'];
|
||||
}
|
||||
file_put_contents(
|
||||
APP_PATH . 'extra' . DS . 'site.php',
|
||||
'<?php' . "\n\nreturn " . var_export($config, true) . ";"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测配置项是否存在
|
||||
* @internal
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$config = $this->model->get($params);
|
||||
if (!$config) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error(__('Name already exist'));
|
||||
}
|
||||
} else {
|
||||
return $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]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 登录终端限制配置
|
||||
*/
|
||||
class Terminal extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型对象
|
||||
* @var null
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $configName = 'terminal';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
\app\common\model\fill\Handle::check('app_config', $this->configName);
|
||||
|
||||
$data = \app\common\model\app\Config::getConfig($this->configName);
|
||||
|
||||
return $this->success("获取成功", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function setConfig()
|
||||
{
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
|
||||
// 登录终端限制数:范围 1-50,非数字回退默认值 3
|
||||
if (isset($row['login_terminal_limit'])) {
|
||||
$limit = trim((string)$row['login_terminal_limit']);
|
||||
if ($limit === '' || !is_numeric($limit)) {
|
||||
$row['login_terminal_limit'] = '3';
|
||||
} else {
|
||||
$limit = intval($limit);
|
||||
if ($limit < 1) {
|
||||
$limit = 1;
|
||||
}
|
||||
if ($limit > 50) {
|
||||
$limit = 50;
|
||||
}
|
||||
$row['login_terminal_limit'] = (string)$limit;
|
||||
}
|
||||
}
|
||||
|
||||
\app\common\model\fill\Handle::check('app_config', $this->configName);
|
||||
|
||||
$data = \app\common\model\app\Config::setConfig($this->configName, $row);
|
||||
return $this->success("保存成功", $data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\pay\VirtualPayService;
|
||||
use think\Cache;
|
||||
|
||||
/**
|
||||
* 虚拟支付管理
|
||||
*
|
||||
* @icon fa fa-credit-card
|
||||
*/
|
||||
class VirtualPay extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var VirtualPayService
|
||||
*/
|
||||
protected $virtualPayService = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
try {
|
||||
$this->virtualPayService = new VirtualPayService();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商家账户可提现余额
|
||||
* @return mixed
|
||||
*/
|
||||
public function queryBizBalance()
|
||||
{
|
||||
if (!$this->virtualPayService) {
|
||||
return $this->error('虚拟支付未配置,请先完成虚拟支付配置');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->virtualPayService->queryBizBalance();
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('查询余额失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (isset($result['errcode']) && $result['errcode'] !== 0) {
|
||||
return $this->error('查询失败:' . ($result['errmsg'] ?? '未知错误'));
|
||||
}
|
||||
|
||||
return $this->success('查询成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建提现单
|
||||
* @return mixed
|
||||
*/
|
||||
public function createWithdraw()
|
||||
{
|
||||
if (!$this->virtualPayService) {
|
||||
return $this->error('虚拟支付未配置,请先完成虚拟支付配置');
|
||||
}
|
||||
|
||||
$virtualPayConfig = \app\common\model\config\System::getConfig('virtual_pay');
|
||||
if (isset($virtualPayConfig['balance_withdraw_switch']) && $virtualPayConfig['balance_withdraw_switch'] === 'close') {
|
||||
return $this->error('余额提现功能已关闭');
|
||||
}
|
||||
|
||||
$amount = $this->request->post('amount', '');
|
||||
$withdrawId = $this->request->post('withdraw_no', '');
|
||||
|
||||
if (empty($withdrawId)) {
|
||||
$withdrawId = $this->virtualPayService->generateWithdrawNo();
|
||||
}
|
||||
|
||||
if (strlen($withdrawId) < 8 || strlen($withdrawId) > 32) {
|
||||
return $this->error('提现单号长度必须在8-32个字符之间');
|
||||
}
|
||||
|
||||
if ($amount !== '' && (!is_numeric($amount) || $amount <= 0)) {
|
||||
return $this->error('提现金额必须大于0');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->virtualPayService->createWithdrawOrder($withdrawId, $amount);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('创建提现单失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (isset($result['errcode']) && $result['errcode'] !== 0) {
|
||||
return $this->error('提现失败:' . ($result['errmsg'] ?? '未知错误'));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'withdraw_no' => $result['withdraw_no'] ?? $withdrawId,
|
||||
'wx_withdraw_no' => $result['wx_withdraw_no'] ?? '',
|
||||
];
|
||||
|
||||
return $this->success('提现单创建成功', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询提现单
|
||||
* @return mixed
|
||||
*/
|
||||
public function queryWithdraw()
|
||||
{
|
||||
if (!$this->virtualPayService) {
|
||||
return $this->error('虚拟支付未配置,请先完成虚拟支付配置');
|
||||
}
|
||||
|
||||
$withdrawId = $this->request->post('withdraw_no', '');
|
||||
if (empty($withdrawId)) {
|
||||
return $this->error('提现单号不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->virtualPayService->queryWithdrawOrder($withdrawId);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('查询提现单失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (isset($result['errcode']) && $result['errcode'] !== 0) {
|
||||
return $this->error('查询失败:' . ($result['errmsg'] ?? '未知错误'));
|
||||
}
|
||||
|
||||
$statusMap = [1 => '提现中', 2 => '提现成功', 3 => '提现失败'];
|
||||
if (isset($result['status'])) {
|
||||
$result['status_text'] = $statusMap[$result['status']] ?? '未知';
|
||||
}
|
||||
|
||||
return $this->success('查询成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取虚拟支付配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$config = \app\common\model\config\System::getConfig('virtual_pay');
|
||||
if (!$config) {
|
||||
return $this->error('配置不存在');
|
||||
}
|
||||
|
||||
$config['exchange_rate'] = $config['exchange_rate'] ?? '1';
|
||||
|
||||
return $this->success('获取成功', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存虚拟支付配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function setConfig()
|
||||
{
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if (!$row) {
|
||||
return $this->error('参数不能为空');
|
||||
}
|
||||
|
||||
$configName = 'virtual_pay';
|
||||
$config = \app\common\model\config\System::load($configName);
|
||||
if (!$config) {
|
||||
return $this->error('配置不存在');
|
||||
}
|
||||
$config = $this->syncConfigWithDefault($configName, $config);
|
||||
|
||||
foreach ($config as &$item) {
|
||||
if (isset($row[$item['name']])) {
|
||||
$value = $row[$item['name']];
|
||||
if ($item['name'] === 'virtual_goods_types') {
|
||||
$value = $this->normalizeVirtualGoodsTypes($value);
|
||||
}
|
||||
if ($item['name'] === 'exchange_rate') {
|
||||
$value = in_array(intval($value), [1, 10, 100], true) ? (string)intval($value) : '1';
|
||||
}
|
||||
$item['value'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$model = new \app\admin\model\config\System();
|
||||
$dbRow = $model->where(['name' => $configName])->find();
|
||||
if ($dbRow) {
|
||||
$dbRow->value = json_encode(array_values($config), JSON_UNESCAPED_UNICODE);
|
||||
$dbRow->save();
|
||||
}
|
||||
|
||||
Cache::rm(\app\common\constant\cache\Keys::SYSTEM_CONFIG($configName));
|
||||
|
||||
\think\Log::info('[VirtualPay] 配置已更新,缓存已清除');
|
||||
|
||||
return $this->success('保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 补齐新增的默认配置项,保留已有值。
|
||||
* @param string $configName
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
private function syncConfigWithDefault($configName, $config)
|
||||
{
|
||||
$defaultConfig = \app\common\model\fill\Handle::getSystemDefaultConfig($configName);
|
||||
if (!$defaultConfig) {
|
||||
return $config;
|
||||
}
|
||||
|
||||
$configMap = [];
|
||||
foreach ($config as $item) {
|
||||
if (isset($item['name'])) {
|
||||
$configMap[$item['name']] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [];
|
||||
foreach ($defaultConfig as $defaultItem) {
|
||||
if (!isset($defaultItem['name'])) {
|
||||
continue;
|
||||
}
|
||||
$result[] = isset($configMap[$defaultItem['name']]) ? array_merge($defaultItem, ['value' => $configMap[$defaultItem['name']]['value']]) : $defaultItem;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容前端用数组、JSON字符串或逗号字符串提交复选框值。
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
private function normalizeVirtualGoodsTypes($value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = trim($value);
|
||||
$decoded = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
$value = $decoded;
|
||||
} elseif ($value === '') {
|
||||
$value = [];
|
||||
} else {
|
||||
$value = explode(',', $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
foreach ($value as $item) {
|
||||
$item = trim((string)$item);
|
||||
if ($item !== '') {
|
||||
$list[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($list));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
/**
|
||||
* 云点播
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Vod extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Column模型对象
|
||||
* @var \app\admin\model\course\Column
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\config\Vod;
|
||||
|
||||
}
|
||||
|
||||
public function getList(){
|
||||
return $this->success("获取成功",$this->model->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus(){
|
||||
$name = $this->request->post("name");
|
||||
$status = $this->request->post("status",false);
|
||||
|
||||
if(!$name){
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
|
||||
$this->model->setStatus($name,$status);
|
||||
|
||||
return $this->success("操作成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\config;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Cache;
|
||||
|
||||
/**
|
||||
* 微信小程序配置管理
|
||||
*/
|
||||
class WxMiniProgram extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
protected $configName = 'wxMiniProgram';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
\app\common\model\fill\Handle::check('config_system', $this->configName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$data = \app\common\model\config\System::getConfig($this->configName);
|
||||
return $this->success("获取成功", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
* @return mixed
|
||||
*/
|
||||
public function refreshToken()
|
||||
{
|
||||
$token = $this->generateRandomString(32);
|
||||
$this->saveConfig('msg_push_token', $token);
|
||||
return $this->success("刷新成功", ['msg_push_token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新EncodingAESKey
|
||||
* @return mixed
|
||||
*/
|
||||
public function refreshAESKey()
|
||||
{
|
||||
$aesKey = $this->generateRandomString(43);
|
||||
$this->saveConfig('msg_push_aes_key', $aesKey);
|
||||
return $this->success("刷新成功", ['msg_push_aes_key' => $aesKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置字段
|
||||
* @param string $fieldName 字段名
|
||||
* @param string $value 值
|
||||
*/
|
||||
private function saveConfig($fieldName, $value)
|
||||
{
|
||||
$config = \app\common\model\config\System::load($this->configName);
|
||||
if (!$config) {
|
||||
$this->error("配置不存在");
|
||||
}
|
||||
|
||||
foreach ($config as &$item) {
|
||||
if ($item['name'] === $fieldName) {
|
||||
$item['value'] = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$model = new \app\admin\model\config\System();
|
||||
$row = $model->where(['name' => $this->configName])->find();
|
||||
if ($row) {
|
||||
$row->value = json_encode(array_values($config), JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
Cache::rm(\app\common\constant\cache\Keys::SYSTEM_CONFIG($this->configName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成随机字符串
|
||||
* @param int $length 长度
|
||||
* @return string
|
||||
*/
|
||||
private function generateRandomString($length)
|
||||
{
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
$result = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$result .= $chars[random_int(0, strlen($chars) - 1)];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user