CacheConstants.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2018/12/10
  6. * Time: 上午11:53
  7. */
  8. namespace app\main\constants;
  9. use app\main\service\ToutiaoNotifyService;
  10. use think\Config;
  11. /**
  12. * 缓存常量配置信息
  13. * Class CacheConstants
  14. * @package app\main\constants
  15. */
  16. class CacheConstants
  17. {
  18. //推广链接缓存前缀
  19. const REFERRAL_PREFIX = 'REFE:';
  20. //用户缓存前缀
  21. const USER_PREFIX = 'UN:';
  22. //今日关注
  23. const SUBSCRIBE_OF_REFERRAL_ID_TODAY = 'RCT:';
  24. //今日阅读
  25. const READ_OF_REFERRAL_ID_TODAY = 'RUV_T:';
  26. //今日净关注
  27. const SUBSCRIBE_OF_PURE_REFERRAL_ID_TODAY = 'PCT:';
  28. //今日模糊关注
  29. const SUBSCRIBE_OF_DIM_REFERRAL_ID_TODAY = 'DCT:';
  30. //今日取关人数
  31. const UNSUBSCRIBE_OF_REFERRAL_ID_TODAY = 'UCT:';
  32. //书籍章节列表新的缓存key
  33. const BOOK_CHAPTER_LIST_CACHE_CHANGED = 'A04';
  34. //书籍章节列表老的缓存key
  35. const BOOK_CHAPTER_LIST_CACHE = 'basedata_chapter_owchcp_';
  36. //单章节缓存
  37. const BOOK_CHAPTER_SINGLE = 'BCCT:';
  38. //是否更新了书籍的redis缓存
  39. const BOOK_CHAPTER_CACHE_CHANGED_YES = true;
  40. const BOOK_CHAPTER_CACHE_CHANGED_NO = false;
  41. //用户代理商ID缓存key
  42. const USER_AGENT_ID_PREFIX = 'UA:';
  43. //用户IP缓存key
  44. const USER_IP_PREFIX = 'UIP:';
  45. //检测用户今天有没有在这本书扣过费的缓存key
  46. const BOOK_USER_IS_CONSUME_BOOK_BY_DAY = 'HC:';
  47. const BOOK_EDITED_CHAPTER = 'edited_chapter:';
  48. //Book 阅读数 UV过滤
  49. const BOOK_USER_READ_COUNT = 'BURC:';
  50. //头条关注窗口时间
  51. const TOUTIAO_SUB_WINDOW = 3600;
  52. const GDT_CLICLK_CACHE_EXPIRE_TIME = 86400;
  53. //清水规则缓存
  54. const LIGHT_RULE = 'LR';
  55. /**
  56. * 用户代理商缓存key
  57. * @param $user_id
  58. * @return string
  59. */
  60. public static function getAgentCacheKey($user_id)
  61. {
  62. return self::USER_AGENT_ID_PREFIX . $user_id;
  63. }
  64. //检测用户今天有没有在这本书扣过费
  65. public static function getUserIsConsumeBookByDayKey($book_id, $user_id)
  66. {
  67. return self::BOOK_USER_IS_CONSUME_BOOK_BY_DAY . $user_id . ':' . $book_id . ':' . date("d");
  68. }
  69. /**
  70. * 单章节缓存
  71. * @param $chapter_id
  72. * @return string
  73. */
  74. public static function getBookSingleChapterCacheKey($chapter_id)
  75. {
  76. return self::BOOK_CHAPTER_SINGLE . $chapter_id;
  77. }
  78. /**
  79. * 书籍章节列表新的缓存key
  80. * @param $book_id
  81. * @return string
  82. */
  83. public static function getBookChapterCacheKeyNew($book_id)
  84. {
  85. return self::BOOK_CHAPTER_LIST_CACHE_CHANGED . $book_id;
  86. }
  87. /**
  88. * 书籍章节列表老的缓存key
  89. * @param $book_id
  90. * @return string
  91. */
  92. public static function getBookChapterCacheKey($book_id)
  93. {
  94. return self::BOOK_CHAPTER_LIST_CACHE . $book_id;
  95. }
  96. /**
  97. * 推广链接缓存key
  98. * @param $user_id
  99. * @return string
  100. */
  101. public static function getReferralCacheKey($user_id)
  102. {
  103. return self::REFERRAL_PREFIX . $user_id;
  104. }
  105. /**
  106. * 获取用户缓存key
  107. * @param $user_id
  108. * @return string
  109. */
  110. public static function getUserCacheKey($user_id)
  111. {
  112. return self::USER_PREFIX . $user_id;
  113. }
  114. /**
  115. * 今日关注人数
  116. * @param $referral_id
  117. * @return string
  118. */
  119. public static function getSubscribeOfReferralIdKey($referral_id)
  120. {
  121. return self::SUBSCRIBE_OF_REFERRAL_ID_TODAY . date('Ymd') . ':' . $referral_id;
  122. }
  123. /**
  124. * 今日净关注人数
  125. * @param $referral_id
  126. * @return string
  127. */
  128. public static function getSubscribeOfPureReferralIdKey($referral_id)
  129. {
  130. return self::SUBSCRIBE_OF_PURE_REFERRAL_ID_TODAY . date('Ymd') . ':' . $referral_id;
  131. }
  132. /**
  133. * 今日模糊关注人数
  134. * @param $referral_id
  135. * @return string
  136. */
  137. public static function getSubscribeOfDimReferralIdKey($referral_id)
  138. {
  139. return self::SUBSCRIBE_OF_DIM_REFERRAL_ID_TODAY . date('Ymd') . ':' . $referral_id;
  140. }
  141. /**
  142. * 今日取消关注人数
  143. * @param $referral_id
  144. * @return string
  145. */
  146. public static function getUnsubscribeOfReferralIdKey($referral_id)
  147. {
  148. return self::UNSUBSCRIBE_OF_REFERRAL_ID_TODAY . date('Ymd') . ':' . $referral_id;
  149. }
  150. /**
  151. * 今日阅读人数
  152. * @param $referral_id
  153. * @return string
  154. */
  155. public static function getReadOfReferralIdKey($referral_id)
  156. {
  157. return self::READ_OF_REFERRAL_ID_TODAY . date('Ymd') . ':' . $referral_id;
  158. }
  159. /**
  160. * 获取单个商品信息
  161. * @param $goods_id
  162. * @return string
  163. */
  164. public static function getGoodsInfoKey($goods_id){
  165. return "GOODS_ID:{$goods_id}";
  166. }
  167. public static function getGoodsAllKey(){
  168. return 'GOODS_ALL';
  169. }
  170. /**
  171. * 商品列表
  172. * @param null $business
  173. * @param null $category
  174. * @param null $goods_type
  175. * @param null $is_test
  176. * @return string
  177. */
  178. public static function getGoodsListKey($business = null,$category = null,$goods_type = null,$is_test = null){
  179. $goods_list_key = 'GOODS_LS';
  180. if($business !== null){
  181. $goods_list_key .= ":{$business}";
  182. }
  183. if($category !== null){
  184. $goods_list_key .= ":{$category}";
  185. }
  186. if($goods_type !== null){
  187. $goods_list_key .= ":{$goods_type}";
  188. }
  189. if($is_test !== null){
  190. $goods_list_key .= ":{$is_test}";
  191. }
  192. return $goods_list_key;
  193. }
  194. /**
  195. * 商品列表
  196. * @param null $business
  197. * @return string
  198. */
  199. public static function getGoodsListAppKey($business = null){
  200. $goods_list_key = 'GOODS_LS_APP';
  201. if($business !== null){
  202. $goods_list_key .= ":{$business}";
  203. }
  204. return $goods_list_key;
  205. }
  206. /**
  207. * 渠道维度,配号代理商计算到渠道上边,新用户人数
  208. * @param $channel_id
  209. * @return string
  210. */
  211. public static function getNewUserCacheKey($channel_id)
  212. {
  213. return 'KL_C_USER_NEW:' . date('d') .':'. $channel_id;
  214. }
  215. /**
  216. * 起充人数
  217. * @param $channel_id
  218. * @return string
  219. */
  220. public static function getPayUserLimitCacheKey($channel_id)
  221. {
  222. return 'KL_C_USER_LIMIT:' . date('d') .':'. $channel_id;
  223. }
  224. /**
  225. * 老用户活跃人数
  226. * @param $channel_id
  227. * @return string
  228. */
  229. public static function getOldUserActiveCacheKey($channel_id)
  230. {
  231. return 'KL_C_USER_OLD_A:' . date('d') . ':' . $channel_id;
  232. }
  233. /**
  234. * 用户充值完成时间
  235. * @param $user_id
  236. * @return string
  237. */
  238. public static function getUserPayTimeCacheKey($user_id)
  239. {
  240. return 'KL_U_ORDER_T:' . $user_id;
  241. }
  242. /**
  243. * 用户订单完成数
  244. * @param $user_id
  245. * @return string
  246. */
  247. public static function getUserOrderCompletedCountCacheKey($user_id)
  248. {
  249. return 'KL_U_ORDER_C:' . $user_id;
  250. }
  251. /**
  252. * 渠道城市白名单
  253. * @param $channel_id
  254. * @return string
  255. */
  256. public static function getChannelWhiteCityCacheKey($channel_id)
  257. {
  258. return 'KL_C_CITY:' . $channel_id;
  259. }
  260. /**
  261. * 用户阅读章节
  262. * @param $user_id
  263. * @return string
  264. */
  265. public static function getUserChapterCacheKey($user_id)
  266. {
  267. return 'KL_U_CHAPTER:' . $user_id;
  268. }
  269. /**
  270. * 免费看点充值索引
  271. * @param $user_id
  272. * @return string
  273. */
  274. public static function getFreeKandianUserRechargeListCacheKey($user_id)
  275. {
  276. return 'ZR:'.$user_id;
  277. }
  278. /**
  279. * 免费看点充值信息
  280. * @param $user_id
  281. * @return string
  282. */
  283. public static function getFreeKandianUserRechargeCacheKey($user_id, $recharge_id)
  284. {
  285. return 'UR:' . $user_id . ':' . $recharge_id;
  286. }
  287. /**
  288. * 永久看点充值索引
  289. * @param $user_id
  290. * @return string
  291. */
  292. public static function getKandianUserRechargeListCacheKey($user_id)
  293. {
  294. return 'ZRP:'.$user_id;
  295. }
  296. /**
  297. * 永久看点充值信息
  298. * @param $user_id
  299. * @param $recharge_id
  300. * @return string
  301. */
  302. public static function getKandianUserRechargeCacheKey($user_id, $recharge_id)
  303. {
  304. return 'URP:' . $user_id . ':' . $recharge_id;
  305. }
  306. /**
  307. * 增购缓存限免书籍
  308. * @param $user_id
  309. * @return string
  310. */
  311. public static function getBuyMoreFreeLimitBookCache($user_id)
  312. {
  313. return 'BUYMFL:' . $user_id;
  314. }
  315. /**
  316. * 增购全本免费书籍
  317. * @param $user_id
  318. * @param $index
  319. * @return string
  320. */
  321. public static function getBuyMoreFreeBookCache($user_id, $index)
  322. {
  323. return 'BUYMF:' . $user_id . ':' . $index;
  324. }
  325. /**
  326. * 增购缓存限免书籍
  327. * @param $user_id
  328. * @return string
  329. */
  330. public static function getBuyMoreDiscountCache($user_id)
  331. {
  332. return 'BUYMD:' . $user_id;
  333. }
  334. /**
  335. * 增购缓存订单
  336. * @param $out_trade_no
  337. * @return string
  338. */
  339. public static function getBuyMoreOrderCache($out_trade_no)
  340. {
  341. return 'BUYMO:' . $out_trade_no;
  342. }
  343. /**
  344. * 内推单页缓存订单
  345. * @param $out_trade_no
  346. * @return string
  347. */
  348. public static function getSinglePushOrderCache($out_trade_no)
  349. {
  350. return 'SINGPO:' . $out_trade_no;
  351. }
  352. /**
  353. * 内推单页资源缓存
  354. * @param $out_trade_no
  355. * @return string
  356. */
  357. public static function getSinglePushResourceCache($id)
  358. {
  359. return 'SGRS:' . $id;
  360. }
  361. /**
  362. * 用户已购买的书籍缓存
  363. * @param $out_trade_no
  364. * @return string
  365. */
  366. public static function getSinglePushBuyBookCache($userId)
  367. {
  368. return 'SINGPB:' . $userId;
  369. }
  370. /**
  371. * 书籍入口追踪
  372. * @param $user_id
  373. * @param $book_id
  374. * @return string
  375. */
  376. public static function getTrackCacheKey($user_id, $book_id)
  377. {
  378. return 'UTK:' . $user_id . ':' . $book_id;
  379. }
  380. /**
  381. * 书籍入口追踪的过期时间,默认为3天
  382. * @return int
  383. */
  384. public static function getTrackCacheTime()
  385. {
  386. $time = (int)Config::get('book_click_expire');
  387. return $time ? $time : 259200;
  388. }
  389. public static function getKlRuleModifyInfo($ruleId)
  390. {
  391. return 'KL_C_ADMIN:' . $ruleId;
  392. }
  393. /**
  394. * 章节阅读消费缓存
  395. * @param $user_id
  396. * @param $chapter_id
  397. * @return string
  398. */
  399. public static function getConsumeCacheChapter($user_id, $chapter_id)
  400. {
  401. return 'CHCACHE:' . $user_id . ':' . $chapter_id;
  402. }
  403. /**
  404. * 头条引导微信关注
  405. * @param $ip
  406. * @param $ua
  407. * @return string
  408. */
  409. public static function getGuideWxSubscribe($ip, $ua)
  410. {
  411. $ua = ToutiaoNotifyService::instance()->getUaInfo($ua)->data;
  412. return 'GWS:' . $ip . ':' . $ua;
  413. }
  414. /**
  415. * gdt click_id缓存key
  416. * @param $ip
  417. * @param $ua
  418. * @return string
  419. */
  420. public static function gdtClickKey($ip, $ua)
  421. {
  422. $ua = ToutiaoNotifyService::instance()->getUaInfo($ua)->data;
  423. return 'GDTCLC:' . $ip . ':' . $ua;
  424. }
  425. /**
  426. * 用户的gdt click_id
  427. * @param $user_id
  428. * @return string
  429. */
  430. public static function gdtUserClickKey($user_id)
  431. {
  432. return 'UCCID:' . $user_id;
  433. }
  434. /**
  435. * 支付缓存
  436. * @param $user_id
  437. * @return string
  438. */
  439. public static function getGuideWxPay($user_id)
  440. {
  441. return 'GWSPAY:' . $user_id;
  442. }
  443. /**
  444. * 新增获客
  445. * @param $id
  446. * @return string
  447. */
  448. public static function getGuideWxNewCount($id)
  449. {
  450. return 'GWSNC:' . $id;
  451. }
  452. /**
  453. * 新增当日获客
  454. * @param $id
  455. * @return string
  456. */
  457. public static function getGuideWxDayNewCount($id)
  458. {
  459. return 'GWSNC:' .date('d'). $id;
  460. }
  461. /**
  462. * 支付次数累计
  463. * @param $id
  464. * @return string
  465. */
  466. public static function getGuideWxPayCount($id)
  467. {
  468. return 'GWSPC:' . $id;
  469. }
  470. /**
  471. * 支付次数累计
  472. * @param $id
  473. * @return string
  474. */
  475. public static function getGuideWxDayPayCount($id)
  476. {
  477. return 'GWSPC:' .date('d'). $id;
  478. }
  479. /**
  480. * 支付次数累计
  481. * @param $id
  482. * @return string
  483. */
  484. public static function getGuideWxPayMoney($id)
  485. {
  486. return 'GWSPM:' . $id;
  487. }
  488. /**
  489. * 支付次数累计
  490. * @param $id
  491. * @return string
  492. */
  493. public static function getGuideWxDayPayMoney($id)
  494. {
  495. return 'GWSPM:' .date('d'). $id;
  496. }
  497. /**
  498. * 头条落地页渠道配置信息
  499. * @param $channel_id
  500. * @return string
  501. */
  502. public static function getGuideWxSetting($channel_id)
  503. {
  504. return 'GWSS:' . $channel_id;
  505. }
  506. /**
  507. * 小额支付缓存添加
  508. * @param $userId
  509. * @return string
  510. */
  511. public static function getSmallPayCache($userId)
  512. {
  513. return 'SMALLP:'.$userId;
  514. }
  515. /**
  516. * 复粉使用
  517. * @param $user_id
  518. * @return string
  519. */
  520. public static function getWxpayFunfen($user_id)
  521. {
  522. return 'FuFen:' . $user_id;
  523. }
  524. /**
  525. * 复粉使用
  526. * @param $channel_id
  527. * @return string
  528. */
  529. public static function getChannelWxpayIds($channel_id)
  530. {
  531. return 'FuFenChWxId:' . $channel_id;
  532. }
  533. /**
  534. * 浮动条
  535. * @param $user_id
  536. * @return string
  537. */
  538. public static function getFloatTipsIdsByUserIds($user_id)
  539. {
  540. return 'FloatTipIdsUs:' . $user_id;
  541. }
  542. /**
  543. * 浮动条
  544. * @param $id
  545. * @return string
  546. */
  547. public static function getFloatTipsInfo($id)
  548. {
  549. return 'FloatTipsInfo:' . $id;
  550. }
  551. /**
  552. * 浮动条
  553. * @param $order_id
  554. * @return string
  555. */
  556. public static function getFloatTipsOrderId($order_id)
  557. {
  558. return 'FloatTipsOr:' . $order_id;
  559. }
  560. /**
  561. * 浮动条,下单人数
  562. * @param $float_id
  563. * @return string
  564. */
  565. public static function getFloatTipsOrderUser($float_id)
  566. {
  567. return 'FloatTipsOrUser:' . $float_id;
  568. }
  569. /**
  570. * 浮动条,下单人数,当日
  571. * @param $float_id
  572. * @return string
  573. */
  574. public static function getFloatTipsOrderUserDay($float_id)
  575. {
  576. return 'FloatTipsOrUser:' . date('d') . ':' . $float_id;
  577. }
  578. /**
  579. * 浮动条,充值金额
  580. * @param $float_id
  581. * @return string
  582. */
  583. public static function getFloatTipsOrderMoney($float_id)
  584. {
  585. return 'FloatTipsOrMo:' . $float_id;
  586. }
  587. /**
  588. * 浮动条,充值金额,当日
  589. * @param $float_id
  590. * @return string
  591. */
  592. public static function getFloatTipsOrderMoneyDay($float_id)
  593. {
  594. return 'FloatTipsOrMo:' . date('d') . ':' . $float_id;
  595. }
  596. /**
  597. * 章末推荐
  598. * @param $book_id
  599. * @return string
  600. */
  601. public static function getChapterEndRecommendIds($book_id)
  602. {
  603. return 'ChEndBookIds:' . $book_id;
  604. }
  605. public static function getCallbackLimitTout($user_id)
  606. {
  607. return 'CALLLIMIT:tout:'.$user_id;
  608. }
  609. public static function getCallbackLimitUc($user_id)
  610. {
  611. return 'CALLLIMIT:uc:'.$user_id;
  612. }
  613. public static function getCallbackLimitGdt($user_id)
  614. {
  615. return 'CALLLIMIT:gdt:'.$user_id;
  616. }
  617. public static function getCallbackLimitMp($user_id)
  618. {
  619. return 'CALLLIMIT:mp:'.$user_id;
  620. }
  621. public static function getCallbackLimitToutOnce($user_id)
  622. {
  623. return 'CALLLIMIT:tout:once:'.$user_id;
  624. }
  625. public static function getCallbackLimitUcOnce($user_id)
  626. {
  627. return 'CALLLIMIT:uc:once:'.$user_id;
  628. }
  629. public static function getCallbackLimitGdtOnce($user_id)
  630. {
  631. return 'CALLLIMIT:gdt:once:'.$user_id;
  632. }
  633. public static function getCallbackLimitMpOnce($user_id)
  634. {
  635. return 'CALLLIMIT:mp:once:'.$user_id;
  636. }
  637. public static function getSignReplyCache($channel_id)
  638. {
  639. return 'SIGN:'.$channel_id;
  640. }
  641. public static function getBookSubCache($user_id)
  642. {
  643. return 'UBC:' . $user_id;
  644. }
  645. /**
  646. * 获取高级群发消息当天UV
  647. * @param $send_channel_message_id
  648. * @param $time
  649. * @return string
  650. */
  651. public static function getHighMessageUvToDayKey($send_channel_message_id, $time = null)
  652. {
  653. $date_time = $time ? date('Ymd', $time) : date('Ymd');
  654. return "HM_UV_T:{$date_time}:{$send_channel_message_id}";
  655. }
  656. /**
  657. * 获取高级群发消息当天累计充值金额
  658. * @param $send_channel_message_id
  659. * @param null $time
  660. * @return string
  661. */
  662. public static function getHighMsgAmountToDayKey($send_channel_message_id)
  663. {
  664. $date_time = date('Ymd');
  665. return "HM_AMOUNT_D:{$date_time}:{$send_channel_message_id}";
  666. }
  667. public static function getExportFansUserCache($user_id)
  668. {
  669. return 'EFU:'.$user_id;
  670. }
  671. public static function getExportFansRow($id)
  672. {
  673. return 'EFR:'.$id;
  674. }
  675. public static function getChannelKlRuleManageCacheList(){
  676. return 'CKRML';
  677. }
  678. /**
  679. * 二期导量用户缓存
  680. * @param $user_id
  681. * @return string
  682. */
  683. public static function getLeadUser($user_id)
  684. {
  685. return 'EFC:SC:'.$user_id;
  686. }
  687. /**
  688. * 未充值的缓存
  689. * @param $user_id
  690. * @return string
  691. */
  692. public static function getFansUnrecharge($user_id)
  693. {
  694. return 'EFC:UR:'.$user_id;
  695. }
  696. /**
  697. * 获取用户的客服端缓存
  698. * @param $user_id
  699. * @return string
  700. */
  701. public static function getUserClientCache($user_id)
  702. {
  703. return 'UCC:'.$user_id;
  704. }
  705. public static function getChapterFeeCache($channel_id, $book_id)
  706. {
  707. return 'CFC:' . $channel_id . ':' . $book_id;
  708. }
  709. /**
  710. * 导量书币赠送次数缓存
  711. * @param $user_id
  712. * @return string
  713. */
  714. public static function getExportFansGiveKandianCount($user_id)
  715. {
  716. return 'EFC:GKC:' . date('d') . ':' . $user_id;
  717. }
  718. public static function getQrcodeVisitCache($fromUserName)
  719. {
  720. return 'QR_VISIT:'.$fromUserName;
  721. }
  722. }