diff --git a/app/admin/controller/merchant/system/Cache.php b/app/admin/controller/merchant/system/Cache.php new file mode 100644 index 0000000..f737077 --- /dev/null +++ b/app/admin/controller/merchant/system/Cache.php @@ -0,0 +1,77 @@ +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,'清除缓存成功'); + } +} \ No newline at end of file diff --git a/app/admin/route/system.php b/app/admin/route/system.php index 3c58937..297e051 100644 --- a/app/admin/route/system.php +++ b/app/admin/route/system.php @@ -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, ]); \ No newline at end of file diff --git a/app/admin/view/merchant/system/merchant/descr/index.html b/app/admin/view/merchant/system/merchant/descr/index.html index 7e86548..0058526 100644 --- a/app/admin/view/merchant/system/merchant/descr/index.html +++ b/app/admin/view/merchant/system/merchant/descr/index.html @@ -8,19 +8,21 @@ {block name="body"}
- - +
店铺说明 +

店铺说明

+
- +
-
+
@@ -35,99 +37,47 @@ 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 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 }); - //上传缩略图 - var upload_thumb = layui.upload.render({ - elem: '#upload_btn_thumb', - url: '/admin/api/upload', - done: function (res) { - //如果上传失败 - if (res.code == 1) { - return layer.msg('上传失败'); + + $.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) } - //上传成功 - $('#upload_box_thumb input').attr('value', res.data.filepath); - $('#upload_box_thumb img').attr('src', res.data.filepath); + }, + fail:(e)=>{ + console.log(e) } - }); + }) - 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 editor = layui.tinymce; - var edit = editor.render({ - selector: "#container_content", - height: 500 - }); - //监听提交 - form.on('submit(webform)', function (data) { - data.field.content = tinyMCE.editors['container_content'].getContent(); - if (data.field.content == '') { - layer.msg('请先完善文章内容'); - return false; - } - let callback = function (e) { - layer.msg(e.msg); - if (e.code == 0) { - tool.tabRefresh(71); - tool.sideClose(1000); - } - } - tool.post('', data.field, callback); + //监听提交 + form.on('submit(webform)', function (data) { + data.field.agree = tinyMCE.editors['container_content'].getContent(); + if (data.field.content == '') { + layer.msg('请先完善文章内容'); return false; - }); + } + let callback = function (e) { + layer.msg(e.msg); + if (e.code == 0) { + tool.tabRefresh(71); + tool.sideClose(1000); + } + } + tool.post('/admin/agreement/sys_merchant_type', data.field, callback); + return false; + }); } diff --git a/app/common/model/merchant/system/Cache.php b/app/common/model/merchant/system/Cache.php new file mode 100644 index 0000000..570a050 --- /dev/null +++ b/app/common/model/merchant/system/Cache.php @@ -0,0 +1,309 @@ + '用户协议', '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 = << + + + + 隐私协议 + + + + + + + $content + + +HTML; + file_put_contents(public_path() . 'protocol.html', $html); + } + + public function setUserRegister($content) + { + $html = << + + + + 用户协议 + + + + + + + $content + + +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; + } +}