chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
130
app/services/system/config/ConfigServices.php
Normal file
130
app/services/system/config/ConfigServices.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\system\config;
|
||||
|
||||
|
||||
use app\dao\store\StoreConfigDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\SystemConfigService;
|
||||
|
||||
/**
|
||||
* Class ConfigServices
|
||||
* @package app\services\system\config
|
||||
* @mixin StoreConfigDao
|
||||
*/
|
||||
class ConfigServices extends BaseServices
|
||||
{
|
||||
//打印机类型
|
||||
const PRINTER_NAME = [
|
||||
1 => 'yi_lian_yun',
|
||||
2 => 'fei_e_yun',
|
||||
];
|
||||
|
||||
//平台打印机配置
|
||||
const PRINTER_KEY = [
|
||||
'switch' => 'pay_success_printing_switch',
|
||||
'print_type' => 'print_type',
|
||||
'printing_client_id', 'printing_api_key', 'develop_id', 'terminal_number',
|
||||
'fey_user', 'fey_ukey', 'fey_sn',
|
||||
];
|
||||
//配置字段对应
|
||||
const PRINTER_CONFIG_KEY = [
|
||||
'yi_lian_yun' => ['printing_client_id' => 'clientId', 'printing_api_key' => 'apiKey', 'develop_id' => 'partner', 'terminal_number' => 'terminal'],
|
||||
'fei_e_yun' => ['fey_user' => 'feyUser', 'fey_ukey' => 'feyUkey', 'fey_sn' => 'feySn'],
|
||||
];
|
||||
|
||||
//门店打印机配置
|
||||
const STORE_PRINTER_KEY = [
|
||||
'switch' => 'store_pay_success_printing_switch',
|
||||
'print_type' => 'store_print_type',
|
||||
'store_printing_client_id', 'store_printing_api_key', 'store_develop_id', 'store_terminal_number',
|
||||
'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
|
||||
];
|
||||
|
||||
//门店配置字段对应
|
||||
const STORE_PRINTER_CONFIG_KEY = [
|
||||
'yi_lian_yun' => ['store_printing_client_id' => 'clientId', 'store_printing_api_key' => 'apiKey', 'store_develop_id' => 'partner', 'store_terminal_number' => 'terminal'],
|
||||
'fei_e_yun' => ['store_fey_user' => 'feyUser', 'store_fey_ukey' => 'feyUkey', 'store_fey_sn' => 'feySn'],
|
||||
];
|
||||
|
||||
//供应商打印机配置
|
||||
const SUPPLIER_PRINTER_KEY = [
|
||||
'switch' => 'store_pay_success_printing_switch',
|
||||
'print_type' => 'store_print_type',
|
||||
'store_printing_client_id', 'store_printing_api_key', 'store_develop_id', 'store_terminal_number',
|
||||
'store_fey_user', 'store_fey_ukey', 'store_fey_sn',
|
||||
];
|
||||
|
||||
//供应商配置字段对应
|
||||
const SUPPLIER_PRINTER_CONFIG_KEY = [
|
||||
'yi_lian_yun' => ['store_printing_client_id' => 'clientId', 'store_printing_api_key' => 'apiKey', 'store_develop_id' => 'partner', 'store_terminal_number' => 'terminal'],
|
||||
'fei_e_yun' => ['store_fey_user' => 'feyUser', 'store_fey_ukey' => 'feyUkey', 'store_fey_sn' => 'feySn'],
|
||||
];
|
||||
|
||||
const CONFIG_TYPE = [
|
||||
'printing_deploy' => self::PRINTER_KEY,
|
||||
'store_printing_deploy' => self::STORE_PRINTER_KEY,
|
||||
'supplier_printing_deploy' => self::SUPPLIER_PRINTER_KEY
|
||||
];
|
||||
|
||||
/**
|
||||
* StoreConfigServices constructor.
|
||||
* @param StoreConfigDao $dao
|
||||
*/
|
||||
public function __construct(StoreConfigDao $dao)
|
||||
{
|
||||
$this->dao = $dao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小票打印配置
|
||||
* @param int $type
|
||||
* @param int $relation_id
|
||||
* @return array
|
||||
*/
|
||||
public function getPrintingConfig(int $type = 0, int $relation_id = 0) : array
|
||||
{
|
||||
/** @var SystemConfigService $configService */
|
||||
$configService = app('sysConfig');
|
||||
switch ($type) {
|
||||
case 0://平台
|
||||
$keys = self::PRINTER_KEY;
|
||||
$configKey = self::PRINTER_CONFIG_KEY;
|
||||
break;
|
||||
case 2://供应商
|
||||
$keys = self::SUPPLIER_PRINTER_KEY;
|
||||
$configKey = self::SUPPLIER_PRINTER_CONFIG_KEY;
|
||||
$configService->setSupplier($relation_id);
|
||||
break;
|
||||
default:
|
||||
$keys = self::PRINTER_KEY;
|
||||
$configKey = self::PRINTER_CONFIG_KEY;
|
||||
break;
|
||||
}
|
||||
$key = array_values($keys);
|
||||
$config = $configService->more($key);
|
||||
$switch = $config[$keys['switch']] ?? 0;
|
||||
$printType = $config[$keys['print_type']] ?? 1;
|
||||
$name = self::PRINTER_NAME[$printType] ?? 'yi_lian_yun';
|
||||
$configKey = $configKey[$name];
|
||||
$configData = [];
|
||||
foreach ($config as $key => $value) {
|
||||
if (isset($configKey[$key])) {
|
||||
$configData[$configKey[$key]] = $value;
|
||||
}
|
||||
}
|
||||
return [$switch, $name, $configData];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
2867
app/services/system/config/SystemConfigServices.php
Normal file
2867
app/services/system/config/SystemConfigServices.php
Normal file
File diff suppressed because it is too large
Load Diff
140
app/services/system/config/SystemConfigTabServices.php
Normal file
140
app/services/system/config/SystemConfigTabServices.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\system\config;
|
||||
|
||||
|
||||
use app\dao\system\config\SystemConfigTabDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 系统配置分类
|
||||
* Class SystemConfigTabServices
|
||||
* @package app\services\system\config
|
||||
* @mixin SystemConfigTabDao
|
||||
*/
|
||||
class SystemConfigTabServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var SystemConfigTabDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemConfigTabDao $dao;
|
||||
|
||||
/**
|
||||
* 系统设置头部分类读取
|
||||
* @param int $pid
|
||||
* @param int $is_store
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getConfigTab(int $pid, int $is_store = 0)
|
||||
{
|
||||
$list = $this->dao->getConfigTabAll(['status' => 1, 'pid' => $pid, 'is_store' => $is_store], ['id', 'id as value', 'title as label', 'pid', 'icon', 'type'], $pid ? [] : [['type', '=', '0']]);
|
||||
return get_tree_children($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置分类列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getConfgTabList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getConfgTabList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
$menusValue = [];
|
||||
foreach ($list as $item) {
|
||||
$menusValue[] = $item->getData();
|
||||
}
|
||||
$list = get_tree_children($menusValue);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置分类选择下拉树
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSelectForm()
|
||||
{
|
||||
$menuList = $this->dao->getConfigTabAll([], ['id as value', 'pid', 'title as label']);
|
||||
$menus = [['value' => 0, 'label' => '顶级按钮']];
|
||||
$list = get_tree_children($menuList, 'children', 'value');
|
||||
$menus = array_merge($menus, $list);
|
||||
// foreach ($list as $menu) {
|
||||
// $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
|
||||
// }
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建form表单
|
||||
* @param array $formData
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function createConfigTabForm(array $formData = [])
|
||||
{
|
||||
$pid[] = isset($formData['pid']) ? $formData['pid'] : 0;
|
||||
// $form[] = Form::radio('is_store', '类型', $formData['is_store'] ?? 0)->options([['value' => 0, 'label' => '总后台'], ['value' => 1, 'label' => '门店后台']]);
|
||||
$form[] = Form::cascader('pid', '父级分类:', $pid)->data($this->getSelectForm())->changeOnSelect(true);
|
||||
$form[] = Form::input('title', '分类名称:', $formData['title'] ?? '');
|
||||
$form[] = Form::input('eng_title', '分类字段英文:', $formData['eng_title'] ?? '');
|
||||
$form[] = Form::frameInput('icon', '图标:', $this->url('admin/widget.widgets/icon', ['fodder' => 'icon'], true), $formData['icon'] ?? '')->icon('ios-ionic')->height('435px');
|
||||
$form[] = Form::radio('type', '类型:', $formData['type'] ?? 0)->options([
|
||||
['value' => 0, 'label' => '系统'],
|
||||
['value' => 3, 'label' => '其它']
|
||||
]);
|
||||
$form[] = Form::radio('status', '状态:', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
|
||||
$form[] = Form::number('sort', '排序:', (int)($formData['sort'] ?? 0))->min(0);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配置分类表单
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm()
|
||||
{
|
||||
return create_form('添加配置分类', $this->createConfigTabForm(), $this->url('/setting/config_class'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置分类表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function updateForm(int $id)
|
||||
{
|
||||
$configTabInfo = $this->dao->get($id);
|
||||
if (!$configTabInfo) {
|
||||
throw new AdminException('没有查到数据,无法修改!');
|
||||
}
|
||||
return create_form('编辑配置分类', $this->createConfigTabForm($configTabInfo->toArray()), $this->url('/setting/config_class/' . $id), 'PUT');
|
||||
}
|
||||
}
|
||||
385
app/services/system/config/SystemGroupDataServices.php
Normal file
385
app/services/system/config/SystemGroupDataServices.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\system\config;
|
||||
|
||||
use app\dao\system\config\SystemGroupDataDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 组合数据数据集
|
||||
* Class SystemGroupDataServices
|
||||
* @package app\services\system\config
|
||||
* @mixin SystemGroupDataDao
|
||||
*/
|
||||
class SystemGroupDataServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var SystemGroupDataDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemGroupDataDao $dao;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return mixed|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2022/11/3
|
||||
*/
|
||||
public function cacheInfoValue(int $id)
|
||||
{
|
||||
$groupData = $this->cacheRemember($id, function () use ($id) {
|
||||
$res = $this->dao->get($id);
|
||||
return $res ? $res->toArray() : null;
|
||||
});
|
||||
|
||||
return $groupData['value'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取某个配置下的数据从新组合成新得数据返回
|
||||
* @param string $configName
|
||||
* @param int $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getConfigNameValue(string $configName, int $limit = 0)
|
||||
{
|
||||
/** @var SystemGroupServices $systemGroupServices */
|
||||
$systemGroupServices = app()->make(SystemGroupServices::class);
|
||||
$value = $this->dao->getGroupDate((int)$systemGroupServices->getConfigNameId($configName), $limit);
|
||||
$data = [];
|
||||
foreach ($value as $key => $item) {
|
||||
$data[$key]["id"] = $item["id"];
|
||||
if (isset($item['status'])) $data[$key]["status"] = $item["status"];
|
||||
$fields = json_decode($item["value"], true) ?: [];
|
||||
foreach ($fields as $index => $field) {
|
||||
if ($field['type'] == 'upload') {
|
||||
$data[$key][$index] = set_file_url($field['value']);
|
||||
} else {
|
||||
$data[$key][$index] = $field["value"];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合数据列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGroupDataList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getGroupDataList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
$type = '';
|
||||
$gid = (int)$where['gid'];
|
||||
/** @var SystemGroupServices $services */
|
||||
$services = app()->make(SystemGroupServices::class);
|
||||
$group = $services->getOne(['id' => $gid], 'id,config_name,fields');
|
||||
|
||||
$header = json_decode($group['fields'], true) ?? [];
|
||||
$title = [];
|
||||
$param = [];
|
||||
foreach ($header as $item) {
|
||||
if ($group['config_name'] == 'order_details_images' && $item['title'] == 'order_status') {
|
||||
$status = str_replace("\r\n", "\n", $item["param"]);//防止不兼容
|
||||
$status = explode("\n", $status);
|
||||
if (is_array($status) && !empty($status)) {
|
||||
foreach ($status as $index => $v) {
|
||||
$vl = explode('=>', $v);
|
||||
if (isset($vl[0]) && isset($vl[1])) {
|
||||
$param[$vl[0]] = $vl[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($item['type'] == 'upload' || $item['type'] == 'uploads') {
|
||||
$title[$item['title']] = [];
|
||||
$type = $item['title'];
|
||||
} else {
|
||||
$title[$item['title']] = '';
|
||||
}
|
||||
}
|
||||
foreach ($list as $key => $value) {
|
||||
$list[$key] = array_merge($value, $title);
|
||||
$infos = json_decode($value['value'], true) ?: [];
|
||||
|
||||
foreach ($infos as $index => $info) {
|
||||
if ($group['config_name'] == 'user_recharge_quota' && $index == 'is_welfare') {
|
||||
$info['value'] = $info['value'] == 1 ? '是' : '否';
|
||||
}
|
||||
if ($group['config_name'] == 'order_details_images' && $index == 'order_status') {
|
||||
$list[$key][$index] = ($param[$info['value']] ?? '') . '/' . $info['value'];
|
||||
} else {
|
||||
if ($info['type'] == 'upload') {
|
||||
$list[$key][$index] = [set_file_url($info['value'])];
|
||||
} elseif ($info['type'] == 'checkbox') {
|
||||
$list[$key][$index] = implode(",", $info["value"]);
|
||||
} else {
|
||||
$list[$key][$index] = $info['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($list[$key]['value']);
|
||||
}
|
||||
return compact('list', 'count', 'type', 'gid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据gid判断出是否能再次添加组合数据
|
||||
* @param int $gid
|
||||
* @param int $count
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function isGroupGidSave(int $gid, int $count, string $key): bool
|
||||
{
|
||||
/** @var SystemGroupServices $services */
|
||||
$services = app()->make(SystemGroupServices::class);
|
||||
$configName = $services->value(['id' => $gid], 'config_name');
|
||||
if ($configName == $key) {
|
||||
return $this->dao->count(['gid' => $gid]) >= $count;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建表单
|
||||
* @param int $gid
|
||||
* @param array $groupData
|
||||
* @return mixed
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createGroupForm(int $gid, array $groupData = [])
|
||||
{
|
||||
$groupDataValue = isset($groupData["value"]) ? json_decode($groupData["value"], true) : [];
|
||||
/** @var SystemGroupServices $services */
|
||||
$services = app()->make(SystemGroupServices::class);
|
||||
$configName = $services->value(['id' => $gid], 'config_name');
|
||||
$fields = $services->getValueFields($gid);
|
||||
$f[] = Form::hidden('gid', $gid);
|
||||
foreach ($fields as $key => $value) {
|
||||
$info = [];
|
||||
if (isset($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) {
|
||||
$vl = explode('=>', $v);
|
||||
if (isset($vl[0]) && isset($vl[1])) {
|
||||
$info[$index]["value"] = $vl[0];
|
||||
$info[$index]["label"] = $vl[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$fvalue = isset($groupDataValue[$value['title']]['value']) ? $groupDataValue[$value['title']]['value'] : '';
|
||||
switch ($value["type"]) {
|
||||
case 'input':
|
||||
if (($gid == 55 && $value['title'] == 'sign_num') || in_array($configName, ['user_recharge_quota'])) {
|
||||
if ('user_recharge_quota' === $configName) {
|
||||
$f[] = Form::number($value["title"], $value["name"] . ':', $fvalue)->min(0)->max(999999)->required();
|
||||
} else {
|
||||
$f[] = Form::number($value["title"], $value["name"] . ':', (int)$fvalue)->precision(0);
|
||||
}
|
||||
} else {
|
||||
$f[] = Form::input($value["title"], $value["name"] . ':', $fvalue);
|
||||
}
|
||||
break;
|
||||
case 'textarea':
|
||||
$f[] = Form::input($value["title"], $value["name"] . ':', $fvalue)->type('textarea')->placeholder($value['param']);
|
||||
break;
|
||||
case 'radio':
|
||||
$f[] = Form::radio($value["title"], $value["name"] . ':', $fvalue ?: $info[0]["value"] ?? '')->options($info);
|
||||
break;
|
||||
case 'checkbox':
|
||||
$f[] = Form::checkbox($value["title"], $value["name"] . ':', $fvalue ?: $info[0] ?? '')->options($info);
|
||||
break;
|
||||
case 'select':
|
||||
$f[] = Form::select($value["title"], $value["name"] . ':', $fvalue !== '' ? $fvalue : $info[0] ?? '')->options($info)->multiple(false);
|
||||
break;
|
||||
case 'upload':
|
||||
if (!empty($fvalue)) {
|
||||
$image = is_string($fvalue) ? $fvalue : $fvalue[0];
|
||||
} else {
|
||||
$image = '';
|
||||
}
|
||||
$f[] = Form::frameImage($value["title"], $value["name"] . ':', $this->url('admin/widget.images/index', ['fodder' => $value["title"], 'big' => 1], true), $image)->icon('ios-image')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
break;
|
||||
case 'uploads':
|
||||
if ($fvalue) {
|
||||
if (is_string($fvalue)) $fvalue = [$fvalue];
|
||||
$images = !empty($fvalue) ? $fvalue : [];
|
||||
} else {
|
||||
$images = [];
|
||||
}
|
||||
$f[] = Form::frameImages($value["title"], $value["name"] . ':', $this->url('admin/widget.images/index', ['fodder' => $value["title"], 'big' => 1, 'type' => 'many', 'maxLength' => 5], true), $images)->maxLength(5)->icon('ios-images')->width('960px')->height('505px')->modal(['footer-hide' => true])->spin(0);
|
||||
break;
|
||||
default:
|
||||
$f[] = Form::input($value["title"], $value["name"] . ':', $fvalue);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$f[] = Form::number('sort', '排序:', (int)($groupData["sort"] ?? 1))->min(0);
|
||||
$f[] = Form::radio('status', '状态:', (int)($groupData["status"] ?? 1))->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
|
||||
return $f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取添加组合数据表单
|
||||
* @param int $gid
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm(int $gid)
|
||||
{
|
||||
return create_form('添加数据', $this->createGroupForm($gid), $this->url('/setting/group_data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取修改组合数据表单
|
||||
* @param int $gid
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function updateForm(int $gid, int $id)
|
||||
{
|
||||
$groupData = $this->dao->get($id);
|
||||
if (!$groupData) {
|
||||
throw new AdminException('修改失败未查到数据!');
|
||||
}
|
||||
return create_form('编辑数据', $this->createGroupForm($gid, $groupData->toArray()), $this->url('/setting/group_data/' . $id), 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取当前记录中的数据
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getDateValue($id)
|
||||
{
|
||||
$value = $this->dao->get($id);
|
||||
$data = [];
|
||||
if ($value) {
|
||||
$data["id"] = $value["id"];
|
||||
$data["status"] = $value["status"];
|
||||
$fields = json_decode($value["value"], true);
|
||||
foreach ($fields as $index => $field) {
|
||||
$data[$index] = $field["value"];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取数据
|
||||
* @param array $ids
|
||||
* @param string $field
|
||||
*/
|
||||
public function getGroupDataColumn(array $ids)
|
||||
{
|
||||
$systemGroup = [];
|
||||
if (!empty($ids)) {
|
||||
$systemGroupData = $this->dao->idByGroupList($ids);
|
||||
if (!empty($systemGroupData))
|
||||
$systemGroup = array_combine(array_column($systemGroupData, 'id'), $systemGroupData);
|
||||
}
|
||||
return $systemGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据配置
|
||||
* @param $data
|
||||
*/
|
||||
public function saveAll(array $data)
|
||||
{
|
||||
return $this->dao->saveAll($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据gid删除数据
|
||||
* @param int $gid
|
||||
* @return mixed
|
||||
*/
|
||||
public function delGroupDate(int $gid)
|
||||
{
|
||||
return $this->dao->delGroupDate($gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存组合数据
|
||||
* @param array $params 数据参数
|
||||
* @param string $config_name 配置名称
|
||||
* @return bool
|
||||
* @throws AdminException
|
||||
*/
|
||||
public function saveAllData(array $params, string $config_name)
|
||||
{
|
||||
/** @var SystemGroupServices $systemGroupServices */
|
||||
$systemGroupServices = app()->make(SystemGroupServices::class);
|
||||
$gid = $systemGroupServices->value(['config_name' => $config_name], 'id');
|
||||
$group = $systemGroupServices->getOne(['id' => $gid], 'id,config_name,fields');
|
||||
$fields = json_decode($group['fields'], true) ?? [];
|
||||
$this->transaction(function () use ($gid, $params, $fields) {
|
||||
$this->delGroupDate($gid);
|
||||
$data = [];
|
||||
$sort = count($params);
|
||||
foreach ($params as $k => $v) {
|
||||
$value = [];
|
||||
foreach ($v as $key => $param) {
|
||||
foreach ($fields as $index => $field) {
|
||||
if ($key == $field["title"]) {
|
||||
if ($param == "")
|
||||
throw new AdminException($field["name"] . "不能为空!");
|
||||
else {
|
||||
$value[$key]["type"] = $field["type"];
|
||||
$value[$key]["value"] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data[$k] = [
|
||||
"gid" => $gid,
|
||||
"add_time" => time(),
|
||||
"value" => json_encode($value),
|
||||
"sort" => $sort,
|
||||
"status" => $v["status"] ?? 1
|
||||
];
|
||||
$sort--;
|
||||
}
|
||||
$this->dao->saveAll($data);
|
||||
});
|
||||
\crmeb\services\GroupDataService::clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
93
app/services/system/config/SystemGroupServices.php
Normal file
93
app/services/system/config/SystemGroupServices.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\system\config;
|
||||
|
||||
use app\dao\system\config\SystemGroupDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 组合数据
|
||||
* Class SystemGroupServices
|
||||
* @package app\services\system\config
|
||||
* @mixin SystemGroupDao
|
||||
*/
|
||||
class SystemGroupServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var SystemGroupDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemGroupDao $dao;
|
||||
|
||||
/**
|
||||
* 获取组合数据列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getGroupList(array $where, array $field = ['*'])
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getGroupList($where, $field, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
foreach ($list as $key => $value) {
|
||||
if (isset($value['fields'])) {
|
||||
$list[$key]['typelist'] = $value['fields'];
|
||||
unset($list[$key]['fields']);
|
||||
}
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合数据tab下的header头部
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupDataTabHeader(int $id)
|
||||
{
|
||||
$data = $this->getValueFields($id);
|
||||
$header = [];
|
||||
foreach ($data as $key => $item) {
|
||||
if ($item['type'] == 'upload' || $item['type'] == 'uploads') {
|
||||
$header[$key]['key'] = $item['title'];
|
||||
$header[$key]['minWidth'] = 60;
|
||||
$header[$key]['type'] = 'img';
|
||||
} elseif ($item['title'] == 'url' || $item['title'] == 'wap_url' || $item['title'] == 'link' || $item['title'] == 'wap_link') {
|
||||
$header[$key]['key'] = $item['title'];
|
||||
$header[$key]['minWidth'] = 200;
|
||||
} else {
|
||||
$header[$key]['key'] = $item['title'];
|
||||
$header[$key]['minWidth'] = 100;
|
||||
}
|
||||
$header[$key]['title'] = $item['name'];
|
||||
}
|
||||
array_unshift($header, ['key' => 'id', 'title' => '编号', 'width' => 55]);
|
||||
array_push($header, ['slot' => 'status', 'title' => '是否可用', 'minWidth' => 80], ['key' => 'sort', 'title' => '排序', 'minWidth' => 80], ['slot' => 'action', 'fixed' => 'right', 'title' => '操作', 'minWidth' => 120]);
|
||||
return compact('header');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组合数据fields字段
|
||||
* @param int $id
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getValueFields(int $id)
|
||||
{
|
||||
return json_decode($this->dao->value(['id' => $id], 'fields'), true) ?: [];
|
||||
}
|
||||
|
||||
}
|
||||
597
app/services/system/config/SystemStorageServices.php
Normal file
597
app/services/system/config/SystemStorageServices.php
Normal file
@@ -0,0 +1,597 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\system\config;
|
||||
|
||||
|
||||
use app\dao\system\config\SystemStorageDao;
|
||||
use app\services\BaseServices;
|
||||
use crmeb\services\FormBuilder;
|
||||
use crmeb\services\UploadService;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class SystemStorageServices
|
||||
* @package app\services\system\config
|
||||
* @mixin SystemStorageDao
|
||||
*/
|
||||
class SystemStorageServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* @var SystemStorageDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected SystemStorageDao $dao;
|
||||
|
||||
/**
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$config = $this->getStorageConfig((int)$where['type']);
|
||||
$where['access_key'] = $config['accessKey'];
|
||||
$list = $this->dao->getStorageList($where, ['*'], $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
$item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
|
||||
$item['_update_time'] = date('Y-m-d H:i:s', $item['update_time']);
|
||||
$service = UploadService::init($item['type']);
|
||||
$region = $service->getRegion();
|
||||
foreach ($region as $value) {
|
||||
if (strstr($item['region'], $value['value'])) {
|
||||
$item['_region'] = $value['label'];
|
||||
}
|
||||
}
|
||||
if (!$item['cname']) {
|
||||
$item['cname'] = str_replace(['http://', 'https://'], '', $item['domain']);
|
||||
}
|
||||
}
|
||||
$count = $this->dao->getCount($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getFormStorage(int $type)
|
||||
{
|
||||
$upload = UploadService::init($type);
|
||||
|
||||
$config = $this->getStorageConfig($type);
|
||||
$ruleConfig = [];
|
||||
if (!$config['accessKey']) {
|
||||
$ruleConfig = [
|
||||
FormBuilder::input('accessKey', 'AccessKeyId:', $config['accessKey'] ?? '')->required(),
|
||||
FormBuilder::input('secretKey', 'AccessKeySecret:', $config['secretKey'] ?? '')->required(),
|
||||
];
|
||||
}
|
||||
|
||||
if ($type === 4 && isset($config['appid']) && !$config['appid']) {
|
||||
$ruleConfig[] = FormBuilder::input('appid', 'APPID', $config['appid'] ?? '')->required();
|
||||
}
|
||||
|
||||
$rule = [
|
||||
FormBuilder::input('name', '空间名称')->required(),
|
||||
FormBuilder::select('region', '空间区域')->options($upload->getRegion())->required(),
|
||||
FormBuilder::radio('acl', '读写权限', 'public-read')->options([
|
||||
['label' => '公共读(推荐)', 'value' => 'public-read'],
|
||||
['label' => '公共读写', 'value' => 'public-read-write'],
|
||||
])->required(),
|
||||
];
|
||||
|
||||
$rule = array_merge($ruleConfig, $rule);
|
||||
return create_form('添加云空间', $rule, '/setting/config/storage/' . $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
* @return array
|
||||
*/
|
||||
public function getStorageConfig(int $type)
|
||||
{
|
||||
$config = [
|
||||
'accessKey' => '',
|
||||
'secretKey' => ''
|
||||
];
|
||||
switch ($type) {
|
||||
case 2://七牛
|
||||
$config = [
|
||||
'accessKey' => sys_config('qiniu_accessKey', ''),
|
||||
'secretKey' => sys_config('qiniu_secretKey', ''),
|
||||
];
|
||||
break;
|
||||
case 3:// oss 阿里云
|
||||
$config = [
|
||||
'accessKey' => sys_config('accessKey', ''),
|
||||
'secretKey' => sys_config('secretKey', ''),
|
||||
];
|
||||
break;
|
||||
case 4:// cos 腾讯云
|
||||
$config = [
|
||||
'accessKey' => sys_config('tengxun_accessKey', ''),
|
||||
'secretKey' => sys_config('tengxun_secretKey', ''),
|
||||
'appid' => sys_config('tengxun_appid', ''),
|
||||
];
|
||||
break;
|
||||
case 5:// cos 京东云
|
||||
$config = [
|
||||
'accessKey' => sys_config('jd_accessKey', ''),
|
||||
'secretKey' => sys_config('jd_secretKey', ''),
|
||||
'storageRegion' => sys_config('jd_storage_region'),
|
||||
];
|
||||
break;
|
||||
case 6:// cos 华为云
|
||||
$config = [
|
||||
'accessKey' => sys_config('hw_accessKey', ''),
|
||||
'secretKey' => sys_config('hw_secretKey', ''),
|
||||
];
|
||||
break;
|
||||
case 7:// cos 天翼云
|
||||
$config = [
|
||||
'accessKey' => sys_config('ty_accessKey', ''),
|
||||
'secretKey' => sys_config('ty_secretKey', ''),
|
||||
];
|
||||
break;
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getFormStorageConfig(int $type)
|
||||
{
|
||||
$config = $this->getStorageConfig($type);
|
||||
$rule = [
|
||||
FormBuilder::hidden('type', $type),
|
||||
FormBuilder::input('accessKey', 'AccessKeyId:', $config['accessKey'] ?? '')->required(),
|
||||
FormBuilder::input('secretKey', 'AccessKeySecret:', $config['secretKey'] ?? '')->required(),
|
||||
];
|
||||
|
||||
if ($type === 4) {
|
||||
$rule[] = FormBuilder::input('appid', 'APPID', $config['appid'] ?? '')->required();
|
||||
}
|
||||
|
||||
if ($type === 5) {
|
||||
$rule[] = FormBuilder::input('storageRegion', 'Region', $config['storageRegion'] ?? '')->required();
|
||||
}
|
||||
|
||||
|
||||
return create_form('配置信息', $rule, '/setting/config/storage/config');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除空间
|
||||
* @param int $id
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function deleteStorage(int $id)
|
||||
{
|
||||
$storageInfo = $this->dao->get(['is_delete' => 0, 'id' => $id]);
|
||||
if (!$storageInfo) {
|
||||
throw new ValidateException('删除的云存储不存在');
|
||||
}
|
||||
if ($storageInfo->status) {
|
||||
throw new ValidateException('云存储正在使用中,需要启动其他空间才能删除');
|
||||
}
|
||||
|
||||
try {
|
||||
$upload = UploadService::init($storageInfo->type);
|
||||
$res = $upload->deleteBucket($storageInfo->name, $storageInfo->region);
|
||||
if (false === $res) {
|
||||
throw new ValidateException($upload->getError());
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
if ($e->getMessage() == 'The specified bucket does not exist.') {
|
||||
$storageInfo->is_delete = 1;
|
||||
$storageInfo->save();
|
||||
return true;
|
||||
}
|
||||
throw new ValidateException($e->getMessage());
|
||||
}
|
||||
$storageInfo->is_delete = 1;
|
||||
$storageInfo->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存云存储配置
|
||||
* @param int $type 存储类型(2:七牛 3:阿里云 4:腾讯云 5:京东云 6:华为云 7:天翼云)
|
||||
* @param array $data 配置数据
|
||||
* @return bool|void
|
||||
*/
|
||||
public function saveConfig(int $type, array $data)
|
||||
{
|
||||
//保存配置信息
|
||||
if (1 !== $type) {
|
||||
$accessKey = $secretKey = $appid = $storageRegion = '';
|
||||
if (isset($data['accessKey']) && isset($data['secretKey']) && $data['accessKey'] && $data['secretKey']) {
|
||||
$accessKey = $data['accessKey'];
|
||||
$secretKey = $data['secretKey'];
|
||||
unset($data['accessKey'], $data['secretKey']);
|
||||
}
|
||||
if (isset($data['appid']) && $data['appid']) {
|
||||
$appid = $data['appid'];
|
||||
unset($data['appid']);
|
||||
}
|
||||
if (isset($data['storageRegion']) && $data['storageRegion']) {
|
||||
$storageRegion = $data['storageRegion'];
|
||||
unset($data['storageRegion']);
|
||||
}
|
||||
if (!$accessKey || !$secretKey) {
|
||||
return true;
|
||||
}
|
||||
/** @var SystemConfigServices $make */
|
||||
$make = app()->make(SystemConfigServices::class);
|
||||
switch ($type) {
|
||||
case 2://七牛
|
||||
$make->update('qiniu_accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('qiniu_secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
break;
|
||||
case 3:// oss 阿里云
|
||||
$make->update('accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
break;
|
||||
case 4:// cos 腾讯云
|
||||
$make->update('tengxun_accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('tengxun_secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
$make->update('tengxun_appid', ['value' => json_encode($appid)], 'menu_name');
|
||||
break;
|
||||
case 5:// oss 京东云
|
||||
$make->update('jd_accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('jd_secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
$make->update('jd_storage_region', ['value' => json_encode($storageRegion)], 'menu_name');
|
||||
break;
|
||||
case 6:// oss 华为云
|
||||
$make->update('hw_accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('hw_secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
break;
|
||||
case 7:// oss 天翼云
|
||||
$make->update('ty_accessKey', ['value' => json_encode($accessKey)], 'menu_name');
|
||||
$make->update('ty_secretKey', ['value' => json_encode($secretKey)], 'menu_name');
|
||||
break;
|
||||
}
|
||||
\crmeb\services\SystemConfigService::clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存云存储
|
||||
* @param int $type
|
||||
* @param array $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveStorage(int $type, array $data)
|
||||
{
|
||||
//保存配置信息
|
||||
$this->saveConfig($type, $data);
|
||||
$name = $data['name'];
|
||||
|
||||
switch ($type) {
|
||||
case 3://阿里云oss
|
||||
$data['region'] = $this->getReagionHost($type, $data['region']);
|
||||
break;
|
||||
case 4://腾讯云cos
|
||||
$name = $data['name'] . '-' . sys_config('tengxun_appid');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->dao->count(['type' => $type, 'name' => $name])) {
|
||||
throw new ValidateException('云空间名称不能重复');
|
||||
}
|
||||
//保存云存储
|
||||
$data['type'] = $type;
|
||||
$upload = UploadService::init($type);
|
||||
$res = $upload->createBucket($data['name'], $data['region'], $data['acl']);
|
||||
if (false === $res) {
|
||||
throw new ValidateException($upload->getError());
|
||||
}
|
||||
|
||||
$data['domain'] = $this->getDomain($type, $data['name'], $data['region'], sys_config('tengxun_appid'));
|
||||
if (2 === $type) {
|
||||
$domianList = $upload->getDomian($data['name']);
|
||||
$data['domain'] = $domianList[count($domianList) - 1];
|
||||
} else {
|
||||
$data['cname'] = $data['domain'];
|
||||
}
|
||||
|
||||
$data['name'] = $name;
|
||||
$data['add_time'] = time();
|
||||
$data['update_time'] = time();
|
||||
$config = $this->getStorageConfig($type);
|
||||
$data['access_key'] = $config['accessKey'];
|
||||
return $this->dao->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步云储存桶
|
||||
* @param int $type
|
||||
* @return bool
|
||||
*/
|
||||
public function synchronization(int $type)
|
||||
{
|
||||
$data = [];
|
||||
switch ($type) {
|
||||
case 2://七牛
|
||||
$config = $this->getStorageConfig($type);
|
||||
$upload = UploadService::init($type);
|
||||
$list = $upload->listbuckets();
|
||||
if (false === $list) {
|
||||
throw new ValidateException('同步失败,失败原因:' . $upload->getError());
|
||||
}
|
||||
foreach ($list as $item) {
|
||||
if (!$this->dao->count(['name' => $item['id'], 'is_delete' => 0, 'access_key' => $config['accessKey']])) {
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'access_key' => $config['accessKey'],
|
||||
'name' => $item['id'],
|
||||
'region' => $item['region'],
|
||||
'acl' => $item['private'] == 0 ? 'public-read' : 'private',
|
||||
'status' => 0,
|
||||
'is_delete' => 0,
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:// oss 阿里云
|
||||
$upload = UploadService::init($type);
|
||||
$list = $upload->listbuckets();
|
||||
$config = $this->getStorageConfig($type);
|
||||
foreach ($list as $item) {
|
||||
if (!$this->dao->count(['name' => $item['name'], 'is_delete' => 0, 'access_key' => $config['accessKey']])) {
|
||||
$region = $this->getReagionHost($type, $item['location']);
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'access_key' => $config['accessKey'],
|
||||
'name' => $item['name'],
|
||||
'region' => $region,
|
||||
'acl' => 'public-read',
|
||||
'domain' => $this->getDomain($type, $item['name'], $region),
|
||||
'status' => 0,
|
||||
'is_delete' => 0,
|
||||
'add_time' => strtotime($item['createTime']),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:// cos 腾讯云
|
||||
$upload = UploadService::init($type);
|
||||
$list = $upload->listbuckets();
|
||||
if (!empty($list['Name'])) {
|
||||
$newList = $list;
|
||||
$list = [];
|
||||
$list[] = $newList;
|
||||
}
|
||||
$config = $this->getStorageConfig($type);
|
||||
foreach ($list as $item) {
|
||||
if (($id = $this->dao->value(['name' => $item['Name'], 'is_delete' => 0, 'access_key' => $config['accessKey']], 'id'))) {
|
||||
$this->dao->update($id, [
|
||||
'update_time' => time(),
|
||||
'region' => $item['Location'],
|
||||
'name' => $item['Name'],
|
||||
'domain' => sys_config('tengxun_appid') ? $this->getDomain($type, $item['Name'], $item['Location']) : '',
|
||||
'cname' => str_replace('https://','',sys_config('tengxun_appid') ? $this->getDomain($type, $item['Name'], $item['Location']) : ''),
|
||||
]);
|
||||
} else {
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'access_key' => $config['accessKey'],
|
||||
'name' => $item['Name'],
|
||||
'region' => $item['Location'],
|
||||
'acl' => 'public-read',
|
||||
'status' => 0,
|
||||
'domain' => sys_config('tengxun_appid') ? $this->getDomain($type, $item['Name'], $item['Location']) : '',
|
||||
'cname' => str_replace('https://','',sys_config('tengxun_appid') ? $this->getDomain($type, $item['Name'], $item['Location']) : ''),
|
||||
'is_delete' => 0,
|
||||
'add_time' => strtotime($item['CreationDate']),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:// cos 京东云
|
||||
$upload = UploadService::init($type);
|
||||
$list = $upload->listbuckets();
|
||||
$config = $this->getStorageConfig($type);
|
||||
$location = $config['storageRegion'] ?? 'cn-north-1';
|
||||
foreach ($list as $item) {
|
||||
if (!$this->dao->count(['name' => $item['Name'], 'access_key' => $config['accessKey']])) {
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'access_key' => $config['accessKey'],
|
||||
'name' => $item['Name'],
|
||||
'region' => $location,
|
||||
'acl' => 'public-read',
|
||||
'status' => 0,
|
||||
'domain' => $this->getDomain($type, $item['Name'], $location),
|
||||
'is_delete' => 0,
|
||||
'add_time' => time(),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:// cos 华为云
|
||||
case 7:// cos 天翼云
|
||||
$upload = UploadService::init($type);
|
||||
$list = $upload->listbuckets();
|
||||
if (!empty($list['Name'])) {
|
||||
$newList = $list;
|
||||
$list = [];
|
||||
$list[] = $newList;
|
||||
}
|
||||
$config = $this->getStorageConfig($type);
|
||||
foreach ($list as $item) {
|
||||
if (!$this->dao->count(['name' => $item['Name'], 'access_key' => $config['accessKey']])) {
|
||||
$data[] = [
|
||||
'type' => $type,
|
||||
'access_key' => $config['accessKey'],
|
||||
'name' => $item['Name'],
|
||||
'region' => $item['Location'],
|
||||
'acl' => 'public-read',
|
||||
'status' => 0,
|
||||
'domain' => $this->getDomain($type, $item['Name'], $item['Location']),
|
||||
'is_delete' => 0,
|
||||
'add_time' => strtotime($item['CreationDate']),
|
||||
'update_time' => time()
|
||||
];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ($data) {
|
||||
$this->dao->saveAll($data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
* @param string $reagion
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function getReagionHost(int $type, string $reagion)
|
||||
{
|
||||
$upload = UploadService::init($type);
|
||||
$reagionList = $upload->getRegion();
|
||||
foreach ($reagionList as $item) {
|
||||
if (strstr($item['value'], $reagion) !== false) {
|
||||
return $item['value'];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取域名
|
||||
* @param int $type
|
||||
* @param string $name
|
||||
* @param string $reagion
|
||||
* @param string $appid
|
||||
* @return string
|
||||
*/
|
||||
public function getDomain(int $type, string $name, string $reagion, string $appid = '')
|
||||
{
|
||||
$domainName = '';
|
||||
switch ($type) {
|
||||
case 3:// oss 阿里云
|
||||
$domainName = 'https://' . $name . '.' . $reagion;
|
||||
break;
|
||||
case 4:// cos 腾讯云
|
||||
$domainName = 'https://' . $name . ($appid ? '-' . $appid : '') . '.cos.' . $reagion . '.myqcloud.com';
|
||||
break;
|
||||
case 5:// cos 京东云
|
||||
$domainName = 'https://' . $name . '.s3.' . $reagion . '.jdcloud-oss.com';
|
||||
break;
|
||||
case 6:// cos 华为云
|
||||
$domainName = 'https://' . $name . '.obs.' . $reagion . '.myhuaweicloud.com';
|
||||
break;
|
||||
case 7:// cos 天翼云
|
||||
$domainName = 'https://' . $name . '.obs.' . $reagion . '.ctyun.cn';
|
||||
break;
|
||||
}
|
||||
return $domainName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取云存储配置
|
||||
* @param int $type
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function getConfig(int $type)
|
||||
{
|
||||
$res = ['name' => '', 'region' => '', 'domain' => '', 'cname' => ''];
|
||||
try {
|
||||
$config = $this->dao->get(['type' => $type, 'status' => 1, 'is_delete' => 0]);
|
||||
if ($config) {
|
||||
return ['name' => $config->name, 'region' => $config->region, 'domain' => $config->domain, 'cname' => $config->cname];
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
}
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取修改域名表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function getUpdateDomainForm(int $id)
|
||||
{
|
||||
$domain = $this->dao->value(['id' => $id], 'domain');
|
||||
$rule = [
|
||||
FormBuilder::input('domain', '空间域名', $domain),
|
||||
];
|
||||
return create_form('修改空间域名', $rule, '/setting/config/storage/domain/' . $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改域名并绑定
|
||||
* @param int $id
|
||||
* @param string $domain
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function updateDomain(int $id, string $domain, array $data = [])
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('没有查询到数据');
|
||||
}
|
||||
if ($info->domain != $domain) {
|
||||
if (4 === ((int)$info->type)) {
|
||||
$info->domain = $domain;
|
||||
return $info->save();
|
||||
}
|
||||
$info->domain = $domain;
|
||||
$upload = UploadService::init($info->type);
|
||||
//是否添加过域名不存在需要绑定域名
|
||||
$domainList = $upload->getDomian($info->name, $info->region);
|
||||
$domainParse = parse_url($domain);
|
||||
if (!in_array($domainParse['host'], $domainList)) {
|
||||
//绑定域名到云储存桶
|
||||
$res = $upload->bindDomian($info->name, $domain, $info->region);
|
||||
if (false === $res) {
|
||||
throw new ValidateException($upload->getError());
|
||||
}
|
||||
}
|
||||
//七牛云需要通过接口获取cname
|
||||
if (2 === ((int)$info->type)) {
|
||||
$resDomain = $upload->getDomianInfo($domain);
|
||||
$info->cname = $resDomain['cname'] ?? '';
|
||||
}
|
||||
return $info->save();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user