new files

This commit is contained in:
panchengyong
2026-03-07 22:29:07 +08:00
parent cd7e80b502
commit 7acbf45ff7
12516 changed files with 1808447 additions and 194 deletions

View File

@@ -0,0 +1,496 @@
<?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\controller\admin\v1\system\config;
use app\controller\admin\AuthController;
use app\Request;
use app\services\product\product\StoreProductServices;
use app\services\store\SystemStoreServices;
use app\services\system\config\SystemConfigServices;
use app\services\system\config\SystemConfigTabServices;
use crmeb\services\CacheService;
use think\annotation\Inject;
use think\facade\Cache;
/**
* 系统配置
* Class SystemConfig
* @package app\controller\admin\v1\setting
*/
class SystemConfig extends AuthController
{
/**
* @var SystemConfigServices
*/
#[Inject]
protected SystemConfigServices $services;
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$where = $this->request->getMore([
['tab_id', 0],
['status', -1]
]);
if (!$where['tab_id']) {
return $this->fail('参数错误');
}
if ($where['status'] == -1) {
unset($where['status']);
}
$where['is_store'] = 0;
return $this->success($this->services->getConfigList($where));
}
/**
* 显示创建资源表单页.
* @param $type
* @return \think\Response
*/
public function create()
{
[$type, $tabId] = $this->request->getMore([
[['type', 'd'], ''],
[['tab_id', 'd'], 1]
], true);
return $this->success($this->services->createFormRule($type, $tabId));
}
/**
* 保存新建的资源
*
* @return \think\Response
*/
public function save()
{
$data = $this->request->postMore([
['menu_name', ''],
['type', ''],
['input_type', ''],
['config_tab_id', []],
['parameter', ''],
['upload_type', 1],
['required', ''],
['width', 0],
['high', 0],
['value', ''],
['info', ''],
['desc', ''],
['sort', 0],
['status', 0],
['is_store', 0],
]);
if ($data['config_tab_id']) $data['config_tab_id'] = end($data['config_tab_id']);
if (!$data['info']) return $this->fail('请输入配置名称');
if (!$data['menu_name']) return $this->fail('请输入字段名称');
if (!$data['desc']) return $this->fail('请输入配置简介');
if ($data['sort'] < 0) {
$data['sort'] = 0;
}
if ($data['type'] == 'text') {
if (!$data['width']) return $this->fail('请输入文本框的宽度');
if ($data['width'] <= 0) return $this->fail('请输入正确的文本框的宽度');
}
if ($data['type'] == 'textarea') {
if (!$data['width']) return $this->fail('请输入多行文本框的宽度');
if (!$data['high']) return $this->fail('请输入多行文本框的高度');
if ($data['width'] < 0) return $this->fail('请输入正确的多行文本框的宽度');
if ($data['high'] < 0) return $this->fail('请输入正确的多行文本框的宽度');
}
if ($data['type'] == 'radio' || $data['type'] == 'checkbox') {
if (!$data['parameter']) return $this->fail('请输入配置参数');
$this->services->valiDateRadioAndCheckbox($data);
}
$data['value'] = json_encode($data['value']);
$config = $this->services->getOne(['menu_name' => $data['menu_name']]);
if ($config) {
$this->services->update($config['id'], $data, 'id');
} else {
$this->services->save($data);
}
event('config.create', [$data]);
return $this->success('添加配置成功!');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
if (!$id) {
return $this->fail('参数错误,请重新打开');
}
$info = $this->services->getReadList((int)$id);
return $this->success(compact('info'));
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
return $this->success($this->services->editConfigForm((int)$id));
}
/**
* 保存更新的资源
*
* @param int $id
* @return \think\Response
*/
public function update($id)
{
$type = request()->post('type');
if ($type == 'text' || $type == 'textarea' || $type == 'radio' || ($type == 'upload' && (request()->post('upload_type') == 1 || request()->post('upload_type') == 3))) {
$value = request()->post('value');
} else {
$value = request()->post('value/a');
}
if (!$value) $value = request()->post(request()->post('menu_name'));
$data = $this->request->postMore([
['type', ''],
['input_type', ''],
['config_tab_id', []],
['parameter', ''],
['upload_type', 1],
['required', ''],
['width', 0],
['high', 0],
['value', ''],
['info', ''],
['desc', ''],
['sort', 0],
['status', 0],
['is_store', 0],
]);
$data['config_tab_id'] = end($data['config_tab_id']);
if (!$this->services->get($id)) {
return $this->fail('编辑的记录不存在!');
}
$data['value'] = json_encode($data['value']);
$this->services->update($id, $data);
\crmeb\services\SystemConfigService::clear();
return $this->success('修改成功!');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
else {
event('config.delete', [$id]);
return $this->success('删除成功!');
}
}
/**
* 修改状态
* @param $id
* @param $status
* @return mixed
*/
public function set_status($id, $status)
{
if ($status == '' || $id == 0) {
return $this->fail('参数错误');
}
$this->services->update($id, ['status' => $status]);
event('config.status', [$id, $status]);
return $this->success($status == 0 ? '隐藏成功' : '显示成功');
}
/**
* 基础配置
* */
public function edit_basics(Request $request)
{
$tabId = $this->request->param('tab_id', 1);
if (!$tabId) {
return $this->fail('参数错误');
}
$url = $request->baseUrl();
return $this->success($this->services->getConfigForm($url, $tabId));
}
/**
* @param string $type
* @return mixed
*/
public function getNewFormBuild(string $type)
{
return $this->success($this->services->getNewFormBuildRule($type));
}
/**
* 获取用户配置
* @return mixed
*/
public function getUserConfig($type)
{
return $this->success($this->services->getUserConfig($type));
}
/**
* 保存用户配置
* @param $type
* @return mixed
*/
public function saveUserConfig($type)
{
$post = $this->request->post();
$this->validate($post, \app\validate\admin\setting\SystemConfigValidate::class);
$this->services->saveUserConfig($type, $post);
return $this->success('保存成功');
}
/**
* 获取缩略图配置
* @return mixed
*/
public function getImageConfig()
{
return $this->success($this->services->getImageConfig());
}
/**
* 保存数据 true
* */
public function save_basics(Request $request)
{
$isStore = $this->request->get('is_store', false);
$post = $this->request->post();
if ($isStore && isset($post['store_self_mention'])) {//门店配置
$baseData = [
'name' => '',
'phone' => '',
'address' => '',
'detailed_address' => '',
'day_time' => '',
'latlng' => '',
];
foreach ($baseData as $key => $value) {
unset($post[$key]);
}
}
foreach ($post as $k => $v) {
if (is_array($v)) {
$res = $this->services->getUploadTypeList($k);
foreach ($res as $kk => $vv) {
if ($kk == 'upload') {
if ($vv == 1 || $vv == 3) {
$post[$k] = $v[0];
}
}
}
}
}
if (!empty($post['links_list'])) {
foreach ($post['links_list'] as $item) {
foreach ($item as $v => $k) {
if ('' === $item[$v]) {
return $this->fail('友情链接内容不能为空');
}
}
}
}
// if (!empty($post['filing_list'])) {
// foreach ($post['filing_list'] as $item) {
// foreach ($item as $v => $k) {
// if ('' === $item[$v]) {
// return $this->fail('PC底部自定义展示内容不能为空');
// }
// }
// }
// }
$this->validate($post, \app\validate\admin\setting\SystemConfigValidate::class);
if (isset($post['upload_type'])) {
$this->services->checkThumbParam($post);
}
if (isset($post['store_brokerage_binding_status'])) {
$this->services->checkBrokerageBinding($post);
}
if (isset($post['store_brokerage_ratio']) && isset($post['store_brokerage_two'])) {
$num = $post['store_brokerage_ratio'] + $post['store_brokerage_two'];
if ($num > 100) {
return $this->fail('一二级返佣比例不能大于100%');
}
}
if (isset($post['spread_banner'])) {
$num = count($post['spread_banner']);
if ($num > 5) {
return $this->fail('分销海报不能多于5张');
}
}
if (isset($post['user_extract_min_price'])) {
if (!preg_match('/[0-9]$/', $post['user_extract_min_price'])) {
return $this->fail('提现最低金额只能为数字!');
}
}
if (isset($post['user_extract_max_price'])) {
if (!preg_match('/[0-9]$/', $post['user_extract_max_price'])) {
return $this->fail('提现最高金额只能为数字!');
}
}
if (isset($post['store_extract_max_price']) && isset($post['store_extract_min_price'])) {
if ($post['store_extract_max_price'] < $post['store_extract_min_price']) {
return $this->fail('门店提现最低金额不能大于最高金额');
}
}
//小程序支付
if (isset($post['pay_routine_open']) && $post['pay_routine_open']) {
if (empty($post['pay_routine_mchid'])) {
return $this->fail('小程序商户号不能为空');
}
}
if (isset($post['routine_auth_type'])) {
if (empty($post['routine_auth_type']) || count($post['routine_auth_type']) == 0) {
return app('json')->fail('手机号获取方式至少选择一个');
}
}
//全场包邮开关
// if (isset($post['whole_free_shipping'])) {
// $wholeFreeShipping = (int)$post['whole_free_shipping'];
// if (!$wholeFreeShipping) {
// $post['store_free_postage'] = 0;
// }
// unset($post['whole_free_shipping']);
// }
if (isset($post['ico_path'])) {
$from = public_path() . $post['ico_path'];
$toHome = public_path('home') . 'favicon.ico';
$toAdmin = public_path('admin') . 'favicon.ico';
$toSupplier = public_path('supplier') . 'favicon.ico';
$toPublic = public_path() . 'favicon.ico';
@copy($from, $toHome);
@copy($from, $toAdmin);
@copy($from, $toSupplier);
@copy($from, $toPublic);
}
//分销提现
if (isset($post['user_extract_alipay_status'])) {
if (!$post['user_extract_bank_status'] && !$post['user_extract_alipay_status'] && !$post['user_extract_wechat_status'] && !$post['user_extract_balance_status']) {
return app('json')->fail('分销提现方式至少请开启一个');
}
}
//社区设置
if (isset($post['community_exp']) && $post['community_exp'] == 1 && $post['community_exp_restrict'] && $post['community_exp_num'] > $post['community_exp_restrict']) {
return app('json')->fail('社区单次经验值不能大于每天经验值上限');
}
if (isset($post['community_integral']) && $post['community_integral'] == 1 && $post['community_integral_restrict'] && $post['community_integral_num'] > $post['community_integral_restrict']) {
return app('json')->fail('社区单次积分值不能大于每天积分值上限');
}
//系统参数过滤
if (isset($post['param_filter_data'])) {
$post['param_filter_data'] = base64_encode($post['param_filter_data']);
}
// 余额功能启用状态跟随余额支付开关
if (isset($post['yue_pay_status'])) {
$post['balance_func_status'] = $post['yue_pay_status'];
}
$is_store_stock = isset($post['store_stock']) && $post['store_stock'] != sys_config('store_stock');
foreach ($post as $k => $v) {
$config_one = $this->services->getOne(['menu_name' => $k]);
if ($config_one) {
$config_one['value'] = $v;
$this->services->valiDateValue($config_one);
$this->services->update($k, ['value' => json_encode($v)], 'menu_name');
}
}
//记录缓存时间
if (!empty($post['cache_config'])) {
Cache::store('redis')->set(CacheService::CACHE_EXPIRE_NAME, $post['cache_config']);
}
//修改警戒库存
if ($is_store_stock) {
/** @var StoreProductServices $storeProductServices */
$storeProductServices = app()->make(StoreProductServices::class);
$storeProductServices->productStockTips();
}
\crmeb\services\SystemConfigService::clear();
return $this->success('修改成功');
}
/**
* 获取系统设置头部分类
* @param SystemConfigTabServices $services
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function header_basics(SystemConfigTabServices $services)
{
[$type, $pid] = $this->request->getMore([
[['type', 'd'], 0],
[['pid', 'd'], 0]
], true);
if ($type == 3) {//其它分类
$config_tab = [];
} else {
$config_tab = $services->getConfigTab($pid);
}
return $this->success(compact('config_tab'));
}
/**
* 获取单个配置的值
* @param $name
* @return mixed
*/
public function get_system($name)
{
$value = sys_config($name);
return $this->success(compact('value'));
}
/**
* @return mixed
*/
public function getVersion()
{
$version = get_crmeb_version();
return $this->success([
'version' => $version,
'label' => strripos($version, 'min') === false ? 3 : 2
]);
}
}

View File

@@ -0,0 +1,161 @@
<?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\controller\admin\v1\system\config;
use app\controller\admin\AuthController;
use app\services\system\config\SystemConfigServices;
use app\services\system\config\SystemConfigTabServices;
use think\annotation\Inject;
/**
* 配置分类
* Class SystemConfigTab
* @package app\controller\admin\v1\setting
*/
class SystemConfigTab extends AuthController
{
/**
* @var SystemConfigTabServices
*/
#[Inject]
protected SystemConfigTabServices $services;
/**
* 显示资源列表
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
$where = $this->request->getMore([
['status', ''],
['title', ''],
['is_store', '']
]);
return $this->success($this->services->getConfgTabList($where));
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
return $this->success($this->services->createForm());
}
/**
* 保存新建的资源
*
* @return \think\Response
*/
public function save()
{
$data = $this->request->postMore([
'eng_title',
'status',
'title',
'icon',
['type', 0],
['sort', 0],
['pid', []],
['is_store', 0],
]);
$data['pid'] = end($data['pid']);
if (!$data['title']) return $this->fail('请输入按钮名称');
$this->services->save($data);
return $this->success('添加配置分类成功!');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
return $this->success($this->services->updateForm((int)$id));
}
/**
* 保存更新的资源
*
* @param int $id
* @return \think\Response
*/
public function update($id)
{
$data = $this->request->postMore([
'title',
'status',
'eng_title',
'icon',
['type', 0],
['sort', 0],
['pid', []],
['is_store', 0],
]);
$data['pid'] = end($data['pid']);
if (!$data['title']) return $this->fail('请输入分类昵称');
if (!$data['eng_title']) return $this->fail('请输入分类字段');
$this->services->update($id, $data);
return $this->success('修改成功!');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete(SystemConfigServices $services, $id)
{
if ($services->count(['tab_id' => $id])) {
return $this->fail('存在下级配置,无法删除!');
}
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
else
return $this->success('删除成功!');
}
/**
* 修改状态
* @param $id
* @param $status
* @return mixed
*/
public function set_status($id, $status)
{
if ($status == '' || $id == 0) {
return $this->fail('参数错误');
}
$this->services->update($id, ['status' => $status]);
return $this->success($status == 0 ? '隐藏成功' : '显示成功');
}
}

View File

@@ -0,0 +1,210 @@
<?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\controller\admin\v1\system\config;
use app\services\system\config\SystemGroupDataServices;
use think\annotation\Inject;
use app\controller\admin\AuthController;
use app\services\system\config\SystemGroupServices;
/**
* 组合数据
* Class SystemGroup
* @package app\controller\admin\v1\setting
*/
class SystemGroup extends AuthController
{
/**
* @var SystemGroupServices
*/
#[Inject]
protected SystemGroupServices $services;
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$where = $this->request->getMore([
['title', '']
]);
return $this->success($this->services->getGroupList($where));
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @return \think\Response
*/
public function save()
{
$params = $this->request->postMore([
['name', ''],
['config_name', ''],
[['cate_id', 'd'], 0],
['info', ''],
['typelist', []],
]);
//数据组名称判断
if (!$params['name']) {
return $this->fail('请输入数据组名称!');
}
if (!$params['config_name']) {
return $this->fail('请输入配置名称!');
}
$data["name"] = $params['name'];
$data["config_name"] = $params['config_name'];
$data["info"] = $params['info'];
$data["cate_id"] = $params['cate_id'];
//字段信息判断
if (!count($params['typelist']))
return $this->fail('字段至少存在一个!');
else {
$validate = ["name", "type", "title", "description"];
foreach ($params["typelist"] as $key => $value) {
foreach ($value as $name => $field) {
if (empty($field["value"]) && in_array($name, $validate))
return $this->fail("字段" . ($key + 1) . "" . $field["placeholder"] . "不能为空!");
else
$data["fields"][$key][$name] = $field["value"];
}
}
}
$data["fields"] = json_encode($data["fields"]);
$this->services->save($data);
\crmeb\services\GroupDataService::clear();
return $this->success('添加数据组成功!');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
$info = $this->services->get($id);
$fields = json_decode($info['fields'], true);
$type_list = [];
foreach ($fields as $key => $v) {
$type_list[$key]['name']['value'] = $v['name'];
$type_list[$key]['title']['value'] = $v['title'];
$type_list[$key]['type']['value'] = $v['type'];
$type_list[$key]['param']['value'] = $v['param'];
}
$info['typelist'] = $type_list;
unset($info['fields']);
return $this->success(compact('info'));
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param int $id
* @return \think\Response
*/
public function update($id)
{
$params = $this->request->postMore([
['name', ''],
['config_name', ''],
[['cate_id', 'd'], 0],
['info', ''],
['typelist', []],
]);
//数据组名称判断
if (!$params['name']) return $this->fail('请输入数据组名称!');
if (!$params['config_name']) return $this->fail('请输入配置名称!');
//判断ID是否存在存在就是编辑不存在就是添加
if (!$id) {
if ($this->services->count(['config_name' => $params['config_name']])) {
return $this->fail('数据关键字已存在!');
}
}
$data["name"] = $params['name'];
$data["config_name"] = $params['config_name'];
$data["info"] = $params['info'];
$data["cate_id"] = $params['cate_id'];
//字段信息判断
if (!count($params['typelist']))
return $this->fail('字段至少存在一个!');
else {
$validate = ["name", "type", "title", "description"];
foreach ($params["typelist"] as $key => $value) {
foreach ($value as $name => $field) {
if (empty($field["value"]) && in_array($name, $validate))
return $this->fail("字段" . ($key + 1) . "" . $field["placeholder"] . "不能为空!");
else
$data["fields"][$key][$name] = $field["value"];
}
}
}
$data["fields"] = json_encode($data["fields"]);
$this->services->update($id, $data);
\crmeb\services\GroupDataService::clear();
return $this->success('编辑数据组成功!');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id, SystemGroupDataServices $services)
{
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
else {
$services->delete($id, 'gid');
return $this->success('删除成功!');
}
}
/**
* 获取组合数据
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroup()
{
return $this->success($this->services->getGroupList(['cate_id' => 1], ['id', 'name', 'config_name'])['list']);
}
}

View File

@@ -0,0 +1,436 @@
<?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\controller\admin\v1\system\config;
use app\services\activity\seckill\StoreSeckillServices;
use crmeb\exceptions\AdminException;
use app\services\other\CacheServices;
use think\annotation\Inject;
use think\exception\ValidateException;
use app\controller\admin\AuthController;
use app\services\system\config\SystemGroupDataServices;
use app\services\system\config\SystemGroupServices;
/**
* 数据管理
* Class SystemGroupData
* @package app\controller\admin\v1\setting
*/
class SystemGroupData extends AuthController
{
/**
* @var SystemGroupDataServices
*/
#[Inject]
protected SystemGroupDataServices $services;
/**
* 获取数据列表头
* @return mixed
*/
public function header(SystemGroupServices $services)
{
[$gid, $config_name] = $this->request->getMore([
['gid', 0],
['config_name', '']
], true);
if (!$gid && !$config_name) return $this->fail('参数错误');
if (!$gid) {
$gid = $services->value(['config_name' => $config_name], 'id');
}
return $this->success($services->getGroupDataTabHeader($gid));
}
/**
* 显示资源列表
*
* @param SystemGroupServices $group
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index(SystemGroupServices $group)
{
$where = $this->request->getMore([
['gid', 0],
['status', ''],
['config_name', '']
]);
if (!$where['gid'] && !$where['config_name']) return $this->fail('参数错误');
if (!$where['gid']) {
$where['gid'] = $group->value(['config_name' => $where['config_name']], 'id');
}
unset($where['config_name']);
return $this->success($this->services->getGroupDataList($where));
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function create()
{
$gid = $this->request->param('gid/d');
if ($this->services->isGroupGidSave($gid, 4, 'index_categy_images')) {
return $this->fail('不能大于四个!');
}
if ($this->services->isGroupGidSave($gid, 7, 'sign_day_num')) {
return $this->fail('签到天数配置不能大于7天');
}
return $this->success($this->services->createForm($gid));
}
/**
* 保存新建的资源
*
* @param SystemGroupServices $services
* @return \think\Response
*/
public function save(SystemGroupServices $services)
{
$params = request()->post();
$gid = (int)$params['gid'];
$group = $services->getOne(['id' => $gid], 'id,config_name,fields');
if ($group && $group['config_name'] == 'order_details_images') {
$groupDatas = $this->services->getColumn(['gid' => $gid], 'value', 'id');
foreach ($groupDatas as $groupData) {
$groupData = json_decode($groupData, true);
if (isset($groupData['order_status']['value']) && $groupData['order_status']['value'] == $params['order_status']) {
return $this->fail('已存在请不要重复添加');
}
}
}
$this->checkSeckillTime($services, $gid, $params);
$this->checkSign($services, $gid, $params);
$this->checkRecharge($services, $gid, $params);
$fields = json_decode($group['fields'], true) ?? [];
$value = [];
foreach ($params as $key => $param) {
foreach ($fields as $index => $field) {
if ($key == $field["title"]) {
if ($key != 'give_money' && $param == "")
return $this->fail($field["name"] . "不能为空!");
else {
$value[$key]["type"] = $field["type"];
$value[$key]["value"] = $key == 'give_money' && $param == "" ? 0 : $param;
}
}
}
}
$data = [
"gid" => $params['gid'],
"add_time" => time(),
"value" => json_encode($value),
"sort" => $params["sort"] ?: 0,
"status" => $params["status"]
];
$res = $this->services->save($data);
$data['id'] = $res->id;
$this->services->cacheUpdate($data);
\crmeb\services\GroupDataService::clear();
return $this->success('添加数据成功!');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
$gid = $this->request->param('gid/d');
if (!$gid) {
return $this->fail('缺少参数');
}
return $this->success($this->services->updateForm((int)$gid, (int)$id));
}
public function saveAll()
{
$params = request()->post();
if (!isset($params['config_name']) || !isset($params['data'])) {
return $this->fail('缺少参数');
}
$this->services->saveAllData($params['data'], $params['config_name']);
return $this->success('添加数据成功!');
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(SystemGroupServices $services, $id)
{
$groupData = $this->services->get($id);
$fields = $services->getValueFields((int)$groupData["gid"]);
$params = request()->post();
$this->checkSeckillTime($services, $groupData["gid"], $params, $id);
$this->checkSign($services, $groupData["gid"], $params);
$this->checkRecharge($services, $groupData["gid"], $params);
foreach ($params as $key => $param) {
foreach ($fields as $index => $field) {
if ($key == $field["title"]) {
if ($key != 'give_money' && $param == '')
return $this->fail($field["name"] . "不能为空!");
else {
$value[$key]["type"] = $field["type"];
$value[$key]["value"] = $key == 'give_money' && $param == "" ? 0 : $param;
}
}
}
}
$data = [
"value" => json_encode($value),
"sort" => $params["sort"],
"status" => $params["status"]
];
$this->services->update($id, $data);
$this->services->cacheSaveValue($id, $data);
\crmeb\services\GroupDataService::clear();
return $this->success('修改成功!');
}
/**
* 删除指定资源
* @param SystemGroupServices $services
* @param StoreSeckillServices $seckillServices
* @param $id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delete(SystemGroupServices $services, StoreSeckillServices $seckillServices, $id)
{
$groupData = $this->services->get((int)$id);
if ($groupData) {
$gid = $groupData['gid'];
$group = $services->getOne(['id' => $gid], 'id,config_name,fields');
if ($group['config_name'] == 'routine_seckill_time') {//验证时间段下是否有商品
if ($seckillServices->getTimeCount((int)$id)) {
return $this->fail('有正在进行秒杀商品不能删除!');
}
}
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
}
\crmeb\services\GroupDataService::clear();
$this->services->cacheDelById($id);
return $this->success('删除成功!');
}
/**
* 修改状态
* @param $id
* @param $status
* @return mixed
*/
public function set_status($id, $status)
{
if ($status == '' || $id == 0) return $this->fail('参数错误');
$this->services->update($id, ['status' => $status]);
if ($status) {
$this->services->cacheSaveValue($id, 'status', $status);
} else {
$this->services->cacheDelById($id);
}
\crmeb\services\GroupDataService::clear();
return $this->success($status == 0 ? '隐藏成功' : '显示成功');
}
/**
* 检查秒杀时间段
* @param SystemGroupServices $services
* @param $gid
* @param $params
* @param int $id
* @return mixed
*/
public function checkSeckillTime(SystemGroupServices $services, $gid, $params, $id = 0)
{
$name = $services->value(['id' => $gid], 'config_name');
if ($name == 'routine_seckill_time') {
if ($params['time'] == '') {
throw new AdminException('请输入开始时间');
}
if (!$params['continued']) {
throw new AdminException('请输入持续时间');
}
if (!preg_match('/^(\d|1\d|2[0-3])$/', $params['time'])) {
throw new AdminException('请输入0-23点之前的整点数');
}
if (!preg_match('/^([1-9]|1\d|2[0-4])$/', $params['continued'])) {
throw new AdminException('请输入1-24点之前的持续时间');
}
if (($params['time'] + $params['continued']) > 24) throw new AdminException('开始时间+持续时间不能大于24小时');
$list = $this->services->getColumn(['gid' => $gid], 'value', 'id');
if ($id) unset($list[$id]);
$times = $time = [];
foreach ($list as $item) {
$info = json_decode($item, true);
for ($i = 0; $i < $info['continued']['value']; $i++) {
$times[] = $info['time']['value'] + $i;
}
}
for ($i = 0; $i < $params['continued']; $i++) {
$time[] = $params['time'] + $i;
}
foreach ($time as $v) {
if (in_array($v, $times)) throw new AdminException('时段已占用');
}
}
}
/**
* 检查签到配置
* @param SystemGroupServices $services
* @param $gid
* @param $params
* @param int $id
* @return mixed
*/
public function checkSign(SystemGroupServices $services, $gid, $params, $id = 0)
{
$name = $services->value(['id' => $gid], 'config_name');
if ($name == 'sign_day_num') {
if (!$params['sign_num']) {
throw new AdminException('请输入签到赠送积分');
}
if (!preg_match('/^\+?[1-9]\d*$/', $params['sign_num'])) {
throw new AdminException('请输入大于等于0的整数');
}
}
}
/**
* 检查充值金额配置
* @param SystemGroupServices $services
* @param $gid
* @param $params
* @param int $id
* @return mixed
*/
public function checkRecharge(SystemGroupServices $services, $gid, $params, $id = 0)
{
$name = $services->value(['id' => $gid], 'config_name');
if ($name == 'user_recharge_quota') {
if (!$params['price']) {
throw new AdminException('请输入售价');
}
if (!preg_match('/^[0-9]{0,8}+(.[0-9]{1,2})?$/', $params['price'])) {
throw new AdminException('售价限制最大10位浮点型且最多两位小数');
}
if ($params['give_money'] && !preg_match('/^[0-9]{0,8}+(.[0-9]{1,2})?$/', $params['give_money'])) {
throw new AdminException('赠送金额限制最大10位浮点型且最多两位小数');
}
if ($this->services->count(['gid' => $gid]) >= 20) {
throw new AdminException('充值优惠条数最多添加20个');
}
}
}
/**
* 获取客服页面广告内容
* @return mixed
*/
public function getKfAdv()
{
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$content = $cache->getDbCache('kf_adv', '');
return $this->success(compact('content'));
}
/**
* 设置客服页面广告内容
* @return mixed
*/
public function setKfAdv()
{
$content = $this->request->post('content');
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$cache->setDbCache('kf_adv', $content);
return $this->success('设置成功');
}
/**
* 获取用户协议内容
* @return mixed
*/
public function getUserAgreement($type)
{
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$content = $cache->getDbCache($type, '');
return $this->success(compact('content'));
}
/**
* 设置用户协议内容
* @return mixed
*/
public function setUserAgreement($type)
{
$content = $this->request->post('content');
/** @var CacheServices $cache */
$cache = app()->make(CacheServices::class);
$cache->setDbCache($type, $content);
if ('privacy' === $type) {
$html = <<<HTML
<!doctype html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>隐私协议</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
</head>
<body class="index">
$content
</body>
</html>
HTML;
$file_path = public_path() . 'protocol.html';
if (!file_exists($file_path)) {
try {
touch(str_replace('\\', '/', $file_path));
} catch (\Throwable $e) {
throw new ValidateException('请手动在:'. public_path() . '创建空文件protocol.html注意检查文件权限');
}
}
file_put_contents(public_path() . 'protocol.html', $html);
}
return $this->success('设置成功');
}
}

View File

@@ -0,0 +1,255 @@
<?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\controller\admin\v1\system\config;
use app\controller\admin\AuthController;
use app\services\system\config\SystemConfigServices;
use app\services\system\config\SystemStorageServices;
use crmeb\services\UploadService;
use think\annotation\Inject;
/**
* Class SystemStorage
* @package app\adminapi\controller\v1\setting
*/
class SystemStorage extends AuthController
{
/**
* @var SystemStorageServices
*/
#[Inject]
protected SystemStorageServices $services;
/**
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index()
{
return app('json')->success($this->services->getList(['type' => $this->request->get('type')]));
}
/**
* 获取创建数据表单
* @param $type
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function create($type)
{
if (!$type) {
return app('json')->fail('缺少参数');
}
return app('json')->success($this->services->getFormStorage((int)$type));
}
/**
* 获取配置表单
* @param $type
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function getConfigForm($type)
{
return app('json')->success($this->services->getFormStorageConfig((int)$type));
}
/**
* 获取配置类型
* @return mixed
*/
public function getConfig()
{
return app('json')->success(['type' => (int)sys_config('upload_type', 1)]);
}
/**
* @param SystemConfigServices $services
* @return mixed
*/
public function saveConfig(SystemConfigServices $services)
{
$type = (int)$this->request->post('type', 0);
$services->update('upload_type', ['value' => json_encode($type)], 'menu_name');
if (1 === $type) {
$this->services->transaction(function () {
$this->services->update(['status' => 1, 'is_delete' => 0], ['status' => 0]);
});
}
$data = $this->request->postMore([
['accessKey', ''],
['secretKey', ''],
['appid', ''],
['storageRegion', '']
]);
$this->services->saveConfig((int)$type, $data);
return app('json')->success('保存成功');
}
/**
* @param $type
* @return mixed
*/
public function synch($type)
{
try {
$this->services->synchronization((int)$type);
return app('json')->success('同步成功');
} catch (\Throwable $e) {
return app('json')->fail('同步失败,失败原因:' . $e->getMessage());
}
}
/**
* 保存类型
* @param $type
* @return mixed
*/
public function save($type)
{
$data = $this->request->postMore([
['accessKey', ''],
['secretKey', ''],
['appid', ''],
['name', ''],
['region', ''],
['acl', ''],
]);
$type = (int)$type;
if ($type === 4) {
if (!$data['appid'] && !sys_config('tengxun_appid')) {
return app('json')->fail('缺少APPID');
}
}
if (!$data['accessKey']) {
unset($data['accessKey'], $data['secretKey'], $data['appid']);
}
$this->services->saveStorage((int)$type, $data);
return app('json')->success('添加成功');
}
/**
* 修改状态
* @param $id
* @return mixed
*/
public function status($id)
{
if (!$id) {
return app('json')->fail('缺少参数');
}
$info = $this->services->get($id);
$info->status = 1;
if (!$info->domain) {
return app('json')->fail('请先设置空间域名');
}
//设置跨域规则
try {
$upload = UploadService::init($info->type);
$upload->setBucketCors($info->name, $info->region);
} catch (\Throwable $e) {
}
//修改状态
$this->services->transaction(function () use ($id, $info) {
$this->services->update(['type' => $info->type, 'status' => 1, 'is_delete' => 0], ['status' => 0]);
$info->save();
});
return app('json')->success('修改成功');
}
/**
* @param $id
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function getUpdateDomainForm($id)
{
return app('json')->success($this->services->getUpdateDomainForm((int)$id));
}
/**
* @param $id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function updateDomain($id)
{
$domain = $this->request->post('domain', '');
$data = $this->request->postMore([
['pri', ''],
['ca', '']
]);
if (!$domain) {
return app('json')->fail('缺少参数');
}
if (strstr($domain, 'https://') === false && strstr($domain, 'http://') === false) {
return app('json')->fail('格式错误请输入格式为http://域名');
}
// if (strstr($domain, 'https://') !== false && !$data['pri']) {
// return app('json')->fail('域名为HTTPS访问时必须填写证书');
// }
$this->services->updateDomain($id, $domain);
return app('json')->success('修改成功');
}
/**
* 删除
* @param $id
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delete($id)
{
if (!$id) {
return app('json')->fail('缺少参数');
}
if ($this->services->deleteStorage($id)) {
return app('json')->success('删除成功');
} else {
return app('json')->fail('删除失败');
}
}
/**
* 切换存储类型
* @param SystemConfigServices $services
* @param $type
* @return mixed
*/
public function uploadType(SystemConfigServices $services, $type)
{
$status = $this->services->count(['type' => $type, 'status' => 1]);
if (!$status && $type != 1) {
return app('json')->fail('未有正在使用的存储空间');
}
$services->update('upload_type', ['value' => json_encode($type)], 'menu_name');
\crmeb\services\SystemConfigService::clear();
return app('json')->success('切换成功');
}
}