类型说明功能调整

This commit is contained in:
liuxiaoquan 2023-03-15 12:39:41 +08:00
parent 67d225cb9e
commit 1595573f52
4 changed files with 429 additions and 93 deletions

View File

@ -0,0 +1,77 @@
<?php
/**
* 商城 cache 管理
* 说明: 主要是一些说明、协议之类的文档管理
*
* @author刘孝全
* @emailq8197264@126.com
* @date 2023年03月3日
*/
namespace app\admin\controller\merchant\system;
use app\admin\BaseController;
use think\App;
use app\common\model\merchant\system\Cache as CacheModel;
class Cache extends BaseController
{
protected $cache;
public function __construct(App $app, CacheModel $cache)
{
parent::__construct($app);
$this->cache = $cache;
}
/**
*
*/
public function getKeyLst()
{
$type = $this->request->param('type',0);
$data = $this->cache->getAgreeList($type);
return to_assign(0,'',$data);
}
/**
* @return mixed
*/
public function getAgree($key)
{
$allow = $this->cache->getAgreeKey();
if (!in_array($key, $allow)) return app('json')->fail('数据不存在');
$data = $this->cache->getResult($key);
return to_assign(0,'success', $data);
}
/**
* @return mixed
*/
public function saveAgree($key)
{
$allow = $this->cache->getAgreeKey();
if (!in_array($key, $allow)) return app('json')->fail('KEY不存在');
$value = get_params('agree');
$this->cache->saveCache($key, $value);
if ($key == CacheModel::USER_PRIVACY)
$this->cache->setUserAgreement($value);
if ($key == CacheModel::USER_AGREE)
$this->cache->setUserRegister($value);
return to_assign(0, '保存成功');
}
/**
* TODO 清除缓存
* @return \think\response\Json
*/
public function clearCache()
{
return to_assign(0,'清除缓存成功');
}
}

View File

@ -20,7 +20,7 @@ Route::group('agreement', function () {
'_init' => [ \crmeb\services\UpdateAuthInit::class,'agreement'],
]);
})->prefix('admin.system.Cache')->option([
})->prefix('merchant.system.Cache')->option([
'_path' => '/setting/agreements',
'_auth' => true,
]);

View File

@ -8,19 +8,21 @@
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
<!-- <h3 class="pb-3">新建文章</h3> -->
<table class="layui-table layui-table-form">
<tr>
<td colspan="6" class="layui-td-gray" style="text-align:left">店铺说明</td>
<td colspan="6" class="layui-td-gray" style="text-align:center">
<h3>店铺说明</h3>
</td>
</tr>
<tr>
<td colspan="6">
<textarea class="layui-textarea" id="container_content"></textarea>
<textarea class="layui-textarea" id="container_content">
</textarea>
</td>
</tr>
</table>
<div class="pt-3">
<div class="pt-3" style="text-align: center;">
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
@ -35,85 +37,33 @@
var moduleInit = ['tool', 'tagpicker', 'tinymce'];
var group_access = "{:session('gougu_admin')['group_access']}"
function gouguInit() {
var form =layui.form, tool = layui.tool,tagspicker = layui.tagpicker,laydate=layui.laydate;
laydate.render({
elem: '#test1' //指定元素
});
//上传缩略图
var upload_thumb = layui.upload.render({
elem: '#upload_btn_thumb',
url: '/admin/api/upload',
done: function (res) {
//如果上传失败
if (res.code == 1) {
return layer.msg('上传失败');
}
//上传成功
$('#upload_box_thumb input').attr('value', res.data.filepath);
$('#upload_box_thumb img').attr('src', res.data.filepath);
}
});
street();
village();
form.on('select(area_id)', function (data) {
street(data.value)
});
function street (id) {
var demo1 = xmSelect.render({
name: 'township',
el: '#demo1',
initValue: [],
prop: {
name: 'name',
value: 'code',
},
data: [],
radio: true,
disabled: group_access == 2 ||group_access == 4? true : false,
on: function (data) {
var arr = data.arr;
if(arr.length > 0){
village(arr[0]['code']);
}else{
village();
}
},
})
$.get('/api/geo/street?pcode=' + id, function (result) {
demo1.update({
data: result.data
})
});
}
function village (id) {
var demo2 = xmSelect.render({
name: 'village',
el: '#demo2',
initValue: [],
prop: {
name: 'name',
value: 'id',
},
data: [],
radio: true,
disabled: group_access == 2 ? true : false,
})
$.get('/api/geo/village?pcode=' + id, function (result) {
demo2.update({
data: result.data
})
});
}
var form =layui.form, tool = layui.tool
// ,tagspicker = layui.tagpicker,laydate=layui.laydate;
var editor = layui.tinymce;
var edit = editor.render({
selector: "#container_content",
height: 500
});
$.ajax({
url:'/admin/agreement/sys_merchant_type',
method:'get',
success: (data)=>{
if (data.code==0){
tinyMCE.editors['container_content'].setContent(data.data.sys_merchant_type);
}else{
console.log(data)
}
},
fail:(e)=>{
console.log(e)
}
})
//监听提交
form.on('submit(webform)', function (data) {
data.field.content = tinyMCE.editors['container_content'].getContent();
data.field.agree = tinyMCE.editors['container_content'].getContent();
if (data.field.content == '') {
layer.msg('请先完善文章内容');
return false;
@ -125,7 +75,7 @@
tool.sideClose(1000);
}
}
tool.post('', data.field, callback);
tool.post('/admin/agreement/sys_merchant_type', data.field, callback);
return false;
});

View File

@ -0,0 +1,309 @@
<?php
/**
* 商城 cache 管理
* 说明: 主要是一些说明、协议之类的文档管理
*
* @author刘孝全
* @emailq8197264@126.com
* @date 2023年03月3日
*/
declare (strict_types = 1);
namespace app\common\model\merchant\system;
use think\Model;
use think\exception\ValidateException;
/**
* @mixin \think\Model
*/
class Cache extends Model
{
protected $connection = 'shop';
protected $table = 'eb_cache';
protected $pk = 'key';
//积分说明
const INTEGRAL_RULE = 'sys_integral_rule';
//商户入驻申请协议
const INTEGRAL_AGREE = 'sys_intention_agree';
//预售协议
const PRESELL_AGREE = 'sys_product_presell_agree';
//微信菜单
const WECHAT_MENUS = 'wechat_menus';
//发票说明
const RECEIPT_AGREE = 'sys_receipt_agree';
//佣金说明
const EXTENSION_AGREE = 'sys_extension_agree';
//商户类型说明
const MERCHANT_TYPE = 'sys_merchant_type';
//分销等级规则
const SYS_BROKERAGE = 'sys_brokerage';
//用户协议
const USER_AGREE = 'sys_user_agree';
//用户隐私协议
const USER_PRIVACY = 'sys_userr_privacy';
//免费会员
const SYS_MEMBER = 'sys_member';
//关于我们
const ABOUT_US = 'sys_about_us';
//资质证照
const SYS_CERTIFICATE = 'sys_certificate';
//注销声明
const CANCELLATION_MSG = 'the_cancellation_msg';
//注销重要提示
const CANCELLATION_PROMPT = 'the_cancellation_prompt';
//平台规则
const PLATFORM_RULE = 'platform_rule';
//优惠券说明
const COUPON_AGREE = 'sys_coupon_agree';
//付费会员协议
const SYS_SVIP = 'sys_svip';
public function getAgreeList($type)
{
$data = [
['label' => '用户协议', 'key' => self::USER_AGREE],
['label' => '隐私政策', 'key' => self::USER_PRIVACY],
['label' => '平台规则', 'key' => self::PLATFORM_RULE],
['label' => '注销重要提示', 'key' => self::CANCELLATION_PROMPT],
['label' => '商户入驻申请协议', 'key' => self::INTEGRAL_AGREE],
];
if (!$type) {
$data[] = ['label' => '注销声明', 'key' => self::CANCELLATION_MSG];
$data[] = ['label' => '关于我们', 'key' => self::ABOUT_US];
$data[] = ['label' => '资质证照', 'key' => self::SYS_CERTIFICATE];
}
return $data;
}
public function getAgreeKey(){
return [
self::INTEGRAL_RULE,
self::INTEGRAL_AGREE,
self::PRESELL_AGREE,
self::WECHAT_MENUS,
self::RECEIPT_AGREE,
self::EXTENSION_AGREE,
self::MERCHANT_TYPE,
self::SYS_BROKERAGE,
self::USER_AGREE,
self::USER_PRIVACY,
self::SYS_MEMBER,
self::ABOUT_US,
self::SYS_CERTIFICATE,
self::CANCELLATION_MSG,
self::CANCELLATION_PROMPT,
self::PLATFORM_RULE,
self::COUPON_AGREE,
self::SYS_SVIP,
];
}
/**
* @param string $key
* @param $result
* @param int $expire_time
* @throws DbException
*/
public function saveCache(string $key, $result, int $expire_time = 0)
{
if (!Cache::keyExist($key)) {
Cache::create(compact('key', 'result', 'expire_time'));
} else {
$this->keyUpdate($key, compact('result', 'expire_time'));
}
}
public function getResult($key)
{
$data['title'] = '';
foreach ($this->getAgreeList(1) as $item) {
if ($item['key'] == $key) {
$data['title'] = $item['label'];
}
}
$data[$key] = $this->getCache($key) ?? '';
return $data;
}
public function getResultByKey($key)
{
return $this->getCache($key);
}
public function batchSaveCache(array $data)
{
foreach ($data as $k => $v) {
$this->saveCache($k, $v);
}
}
/**
* 设置用户协议内容
* @return mixed
*/
public function setUserAgreement($content)
{
$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_put_contents(public_path() . 'protocol.html', $html);
}
public function setUserRegister($content)
{
$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_put_contents(public_path() . 'register.html', $html);
}
/*
* 整理城市数据用的方法
*/
public function addres()
{
return [];
$re = (Cache::get('AAAAAA'));
//halt($re);
unset($re['省市编码']);
if (!$re) throw new ValidateException('无数据');
$shen = [];
$shi = [];
$qu = [];
foreach ($re as $key => $value) {
$item = explode(',', $value);
$cout = count($item);
//省
if ($cout == 2) {
$shen[$item[1]] = [
'value' => $key,
'label' => $item[1],
];
}
//市
if ($cout == 3) {
if ($item[1] == '') {
$shen[$item[2]] = [
'value' => $key,
'label' => $item[2],
];
$item[1] = $item[2];
}
$_v = [
'value' => $key,
'label' => $item[2]
];
$shi[$item[1]][] = $_v;
}
//区
if ($cout == 4) {
$_v = [
'value' => $key,
'label' => $item[3]
];
$qu[$item[2]][] = $_v;
}
}
$data = [];
foreach ($shen as $s => $c) {
foreach ($shi as $i => $c_) {
if ($c['label'] == $i) {
if ($c['label'] == $i) {
$san = [];
foreach ($c_ as $key => $value) {
if (isset($qu[$value['label']])) {
$value['children'] = $qu[$value['label']];
}
$san[] = $value;
}
}
$c['children'] = $san;
}
}
$zls[$s] = $c;
}
$data = array_values($zls);
file_put_contents('address.js', json_encode($data, JSON_UNESCAPED_UNICODE));
//$this->save('applyments_addres',$data);
}
/** ----------- dao function ----------- */
/**
* @param $key
* @return mixed
* @author xaboy
* @day 2020-04-24
*/
protected function getCache($key)
{
$val = Cache::where('key', $key)->value('result');
return $val ? json_decode($val, true) : null;
}
/**
* 判断是key是否存在
*/
protected function keyExist($key)
{
return Cache::where('key', $key)->count();
}
/**
* @param string $key
* @param $data
* @throws DbException
* @author xaboy
* @day 2020-04-24
*/
protected function keyUpdate(string $key, $data)
{
if (isset($data['result']))
$data['result'] = json_encode($data['result'], JSON_UNESCAPED_UNICODE);
Cache::where('key', $key)->update($data);
}
protected function search(array $keys)
{
$cache = Cache::whereIn('key',$keys)->column('result','key');
$ret = [];
foreach ($cache as $k => $v) {
$ret[$k] = json_decode($v);
}
return $ret;
}
}