DecorateThemeLogic.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\logic;
  20. use app\common\{cache\HandleConcurrencyCache,
  21. enum\ThemePageEnum,
  22. enum\YesNoEnum,
  23. model\Distribution,
  24. model\SelffetchVerifier,
  25. service\ThemeService,
  26. enum\ThemeConfigEnum,
  27. model\DecorateThemePage,
  28. model\DistributionConfig,
  29. model\DecorateThemeConfig};
  30. /**
  31. * 装修主题逻辑层
  32. * Class DecorateThemeLogic
  33. * @package app\shopapi\logic
  34. */
  35. class DecorateThemeLogic
  36. {
  37. /**
  38. * @notes 主题首页
  39. * @return array
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @author cjhao
  44. * @date 2021/8/12 18:35
  45. */
  46. public function index(int $userId)
  47. {
  48. //读取缓存
  49. $HandleConcurrencyCache = new HandleConcurrencyCache();
  50. $homePage = $HandleConcurrencyCache->getCache($HandleConcurrencyCache->getDecorateThemeHomeKey());
  51. if (!$homePage) {
  52. $homePage = DecorateThemePage::where(['is_home' => 1])
  53. ->field('id,content,common')
  54. ->find()->toArray();
  55. //设置缓存
  56. $HandleConcurrencyCache->setCache($HandleConcurrencyCache->getDecorateThemeHomeKey(),$homePage);
  57. }
  58. //替换组件内容
  59. $config = $this->getMenuConfig($userId);
  60. $config['user_id'] = $userId;
  61. $homePage['content'] = ThemeService::getModuleData($homePage['content'],$config);
  62. return $homePage;
  63. }
  64. /**
  65. * @notes 获取主题配置
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. * @author cjhao
  71. * @date 2021/8/13 16:00
  72. */
  73. public function getConfig()
  74. {
  75. //读取缓存
  76. $HandleConcurrencyCache = new HandleConcurrencyCache();
  77. $configList = $HandleConcurrencyCache->getCache($HandleConcurrencyCache->getDecorateThemeConfigKey());
  78. if ($configList !== false) {
  79. return $configList;
  80. }
  81. $themeConfig = DecorateThemeConfig::where(['type'=>[ThemeConfigEnum::TYPE_THEME_COLOR,ThemeConfigEnum::TYPE_BOTTOM_NA,ThemeConfigEnum::TYPE_OPEN_AD]])
  82. ->field('content')->select()->toArray();
  83. //转换数据结构,方便前端渲染
  84. $configList = [];
  85. foreach ($themeConfig as $configVal){
  86. $configKey = array_Keys($configVal['content']);
  87. $configList[$configKey[0]] = array_values($configVal['content'])[0];
  88. }
  89. //设置缓存
  90. $HandleConcurrencyCache->setCache($HandleConcurrencyCache->getDecorateThemeConfigKey(),$configList);
  91. return $configList;
  92. }
  93. /**
  94. * @notes 主题页面
  95. * @param array $params
  96. * @return array
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\DbException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. * @author cjhao
  101. * @date 2021/8/12 15:02
  102. */
  103. public function getPage(int $type,$userId,$goodsId)
  104. {
  105. //读取缓存
  106. // $HandleConcurrencyCache = new HandleConcurrencyCache();
  107. // $page = $HandleConcurrencyCache->getCache($HandleConcurrencyCache->getDecorateThemePageKey($type,$userId,$goodsId));
  108. // if ($page !== false) {
  109. // return $page;
  110. // }
  111. $page = DecorateThemePage::where(['type' => $type])
  112. ->field('id,content,common')
  113. ->findOrEmpty()->toArray();
  114. //用户中心,判断是否需要屏蔽分销中心入口
  115. if(ThemePageEnum::TYPE_MEMBER_CENTRE == $type || ThemePageEnum::TYPE_HOME == $type){
  116. $config = $this->getMenuConfig($userId);
  117. }
  118. $config['page_type'] = $type;
  119. $config['user_id'] = $userId;
  120. $config['goods_id'] = $goodsId;
  121. $page['content'] = ThemeService::getModuleData($page['content'],$config);
  122. //设置缓存
  123. // $HandleConcurrencyCache->setCache($HandleConcurrencyCache->getDecorateThemePageKey($type,$userId,$goodsId),$page,600);
  124. return $page;
  125. }
  126. /**
  127. * @notes 获取首页微页面
  128. * @param int $id
  129. * @return array
  130. * @author cjhao
  131. * @date 2021/9/1 14:53
  132. */
  133. public function getIndexPage(int $id):array
  134. {
  135. $page = DecorateThemePage::where(['id' => $id,'type'=>ThemePageEnum::TYPE_HOME])
  136. ->field('id,content,common')
  137. ->findOrEmpty()->toArray();
  138. //替换组件内容
  139. $page['content'] = ThemeService::getModuleData($page['content']);
  140. return $page;
  141. }
  142. /**
  143. * @notes 获取菜单配置 (是否屏蔽核销员、是否屏蔽核销菜单)
  144. * @param int $userId
  145. * @return array
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\DbException
  148. * @throws \think\db\exception\ModelNotFoundException
  149. * @author cjhao
  150. * @date 2021/9/27 18:09
  151. */
  152. public function getMenuConfig(int $userId):array
  153. {
  154. $config['is_verifier'] = false;
  155. $config['is_distribution'] = false;
  156. $distributionConfig = DistributionConfig::column('value','key');
  157. $switch = $distributionConfig['switch'] ?? 0;//是否开启分销功能
  158. $open = $distributionConfig['open'] ?? 1; //
  159. //分销开启,但是指定用户分销,且当前用户不是分销用户
  160. if(1 == $switch){
  161. if(3 == $open){
  162. $userDistribution = Distribution::where(['user_id'=>$userId,'is_distribution'=>1])->find();
  163. $userDistribution && $config['is_distribution'] = true;
  164. }else{
  165. $config['is_distribution'] = true;
  166. }
  167. }
  168. $userVerifier = SelffetchVerifier::where(['user_id'=>$userId,'status'=>YesNoEnum::YES])
  169. ->find();
  170. //用户为核销员
  171. if($userVerifier){
  172. $config['is_verifier'] = true;
  173. }
  174. return $config;
  175. }
  176. }