CacheRepository.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\repositories\system;
  12. use app\common\dao\system\CacheDao;
  13. use app\common\repositories\BaseRepository;
  14. use think\db\exception\DbException;
  15. use think\exception\ValidateException;
  16. use think\facade\Cache;
  17. /**
  18. * Class CacheRepository
  19. * @package app\common\repositories\system
  20. * @author xaboy
  21. * @day 2020-04-24
  22. * @mixin CacheDao
  23. */
  24. class CacheRepository extends BaseRepository
  25. {
  26. //积分说明
  27. const INTEGRAL_RULE = 'sys_integral_rule';
  28. //商户入驻申请协议
  29. const INTEGRAL_AGREE = 'sys_intention_agree';
  30. //预售协议
  31. const PRESELL_AGREE = 'sys_product_presell_agree';
  32. //微信菜单
  33. const WECHAT_MENUS = 'wechat_menus';
  34. //发票说明
  35. const RECEIPT_AGREE = 'sys_receipt_agree';
  36. //佣金说明
  37. const EXTENSION_AGREE = 'sys_extension_agree';
  38. //商户类型说明
  39. const MERCHANT_TYPE = 'sys_merchant_type';
  40. //分销等级规则
  41. const SYS_BROKERAGE = 'sys_brokerage';
  42. //用户协议
  43. const USER_AGREE = 'sys_user_agree';
  44. //用户隐私协议
  45. const USER_PRIVACY = 'sys_userr_privacy';
  46. //免费会员
  47. const SYS_MEMBER = 'sys_member';
  48. //关于我们
  49. const ABOUT_US = 'sys_about_us';
  50. //资质证照
  51. const SYS_CERTIFICATE = 'sys_certificate';
  52. //注销声明
  53. const CANCELLATION_MSG = 'the_cancellation_msg';
  54. //注销重要提示
  55. const CANCELLATION_PROMPT = 'the_cancellation_prompt';
  56. //平台规则
  57. const PLATFORM_RULE = 'platform_rule';
  58. //优惠券说明
  59. const COUPON_AGREE = 'sys_coupon_agree';
  60. //付费会员协议
  61. const SYS_SVIP = 'sys_svip';
  62. public function getAgreeList($type)
  63. {
  64. $data = [
  65. ['label' => '用户协议', 'key' => self::USER_AGREE],
  66. ['label' => '隐私政策', 'key' => self::USER_PRIVACY],
  67. ['label' => '平台规则', 'key' => self::PLATFORM_RULE],
  68. ['label' => '注销重要提示', 'key' => self::CANCELLATION_PROMPT],
  69. ['label' => '商户入驻申请协议', 'key' => self::INTEGRAL_AGREE],
  70. ];
  71. if (!$type) {
  72. $data[] = ['label' => '注销声明', 'key' => self::CANCELLATION_MSG];
  73. $data[] = ['label' => '关于我们', 'key' => self::ABOUT_US];
  74. $data[] = ['label' => '资质证照', 'key' => self::SYS_CERTIFICATE];
  75. }
  76. return $data;
  77. }
  78. public function getAgreeKey(){
  79. return [
  80. self::INTEGRAL_RULE,
  81. self::INTEGRAL_AGREE,
  82. self::PRESELL_AGREE,
  83. self::WECHAT_MENUS,
  84. self::RECEIPT_AGREE,
  85. self::EXTENSION_AGREE,
  86. self::MERCHANT_TYPE,
  87. self::SYS_BROKERAGE,
  88. self::USER_AGREE,
  89. self::USER_PRIVACY,
  90. self::SYS_MEMBER,
  91. self::ABOUT_US,
  92. self::SYS_CERTIFICATE,
  93. self::CANCELLATION_MSG,
  94. self::CANCELLATION_PROMPT,
  95. self::PLATFORM_RULE,
  96. self::COUPON_AGREE,
  97. self::SYS_SVIP,
  98. ];
  99. }
  100. /**
  101. * CacheRepository constructor.
  102. * @param CacheDao $dao
  103. */
  104. public function __construct(CacheDao $dao)
  105. {
  106. $this->dao = $dao;
  107. }
  108. /**
  109. * @param string $key
  110. * @param $result
  111. * @param int $expire_time
  112. * @throws DbException
  113. * @author xaboy
  114. * @day 2020-04-24
  115. */
  116. public function save(string $key, $result, int $expire_time = 0)
  117. {
  118. if (!$this->dao->fieldExists('key', $key)) {
  119. $this->dao->create(compact('key', 'result', 'expire_time'));
  120. } else {
  121. $this->dao->keyUpdate($key, compact('result', 'expire_time'));
  122. }
  123. }
  124. public function getResult($key)
  125. {
  126. $data['title'] = '';
  127. foreach ($this->getAgreeList(1) as $item) {
  128. if ($item['key'] == $key) {
  129. $data['title'] = $item['label'];
  130. }
  131. }
  132. $data[$key] = $this->dao->getResult($key) ?? '';
  133. return $data;
  134. }
  135. public function getResultByKey($key)
  136. {
  137. return $this->dao->getResult($key);
  138. }
  139. public function saveAll(array $data)
  140. {
  141. foreach ($data as $k => $v) {
  142. $this->save($k, $v);
  143. }
  144. }
  145. /**
  146. * 设置用户协议内容
  147. * @return mixed
  148. */
  149. public function setUserAgreement($content)
  150. {
  151. $html = <<<HTML
  152. <!doctype html>
  153. <html class="x-admin-sm">
  154. <head>
  155. <meta charset="UTF-8">
  156. <title>隐私协议</title>
  157. <meta name="renderer" content="webkit|ie-comp|ie-stand">
  158. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  159. <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  160. <meta http-equiv="Cache-Control" content="no-siteapp" />
  161. </head>
  162. <body class="index">
  163. $content
  164. </body>
  165. </html>
  166. HTML;
  167. file_put_contents(public_path() . 'protocol.html', $html);
  168. }
  169. public function setUserRegister($content)
  170. {
  171. $html = <<<HTML
  172. <!doctype html>
  173. <html class="x-admin-sm">
  174. <head>
  175. <meta charset="UTF-8">
  176. <title>用户协议</title>
  177. <meta name="renderer" content="webkit|ie-comp|ie-stand">
  178. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  179. <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  180. <meta http-equiv="Cache-Control" content="no-siteapp" />
  181. </head>
  182. <body class="index">
  183. $content
  184. </body>
  185. </html>
  186. HTML;
  187. file_put_contents(public_path() . 'register.html', $html);
  188. }
  189. /*
  190. * 整理城市数据用的方法
  191. */
  192. public function addres()
  193. {
  194. return [];
  195. $re = (Cache::get('AAAAAA'));
  196. //halt($re);
  197. unset($re['省市编码']);
  198. if (!$re) throw new ValidateException('无数据');
  199. $shen = [];
  200. $shi = [];
  201. $qu = [];
  202. foreach ($re as $key => $value) {
  203. $item = explode(',', $value);
  204. $cout = count($item);
  205. //省
  206. if ($cout == 2) {
  207. $shen[$item[1]] = [
  208. 'value' => $key,
  209. 'label' => $item[1],
  210. ];
  211. }
  212. //市
  213. if ($cout == 3) {
  214. if ($item[1] == '') {
  215. $shen[$item[2]] = [
  216. 'value' => $key,
  217. 'label' => $item[2],
  218. ];
  219. $item[1] = $item[2];
  220. }
  221. $_v = [
  222. 'value' => $key,
  223. 'label' => $item[2]
  224. ];
  225. $shi[$item[1]][] = $_v;
  226. }
  227. //区
  228. if ($cout == 4) {
  229. $_v = [
  230. 'value' => $key,
  231. 'label' => $item[3]
  232. ];
  233. $qu[$item[2]][] = $_v;
  234. }
  235. }
  236. $data = [];
  237. foreach ($shen as $s => $c) {
  238. foreach ($shi as $i => $c_) {
  239. if ($c['label'] == $i) {
  240. if ($c['label'] == $i) {
  241. $san = [];
  242. foreach ($c_ as $key => $value) {
  243. if (isset($qu[$value['label']])) {
  244. $value['children'] = $qu[$value['label']];
  245. }
  246. $san[] = $value;
  247. }
  248. }
  249. $c['children'] = $san;
  250. }
  251. }
  252. $zls[$s] = $c;
  253. }
  254. $data = array_values($zls);
  255. file_put_contents('address.js', json_encode($data, JSON_UNESCAPED_UNICODE));
  256. //$this->save('applyments_addres',$data);
  257. }
  258. }