DecorateThemeLogic.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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\{
  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. $homePage = DecorateThemePage::where(['is_home' => 1])
  49. ->field('id,content,common')
  50. ->find()->toArray();
  51. //替换组件内容
  52. $config = $this->getMenuConfig($userId);
  53. $config['user_id'] = $userId;
  54. $homePage['content'] = ThemeService::getModuleData($homePage['content'],$config);
  55. return $homePage;
  56. }
  57. /**
  58. * @notes 获取主题配置
  59. * @return array
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. * @author cjhao
  64. * @date 2021/8/13 16:00
  65. */
  66. public function getConfig()
  67. {
  68. $themeConfig = DecorateThemeConfig::where(['type'=>[ThemeConfigEnum::TYPE_THEME_COLOR,ThemeConfigEnum::TYPE_BOTTOM_NA,ThemeConfigEnum::TYPE_OPEN_AD]])
  69. ->field('content')->select()->toArray();
  70. //转换数据结构,方便前端渲染
  71. $configList = [];
  72. foreach ($themeConfig as $configVal){
  73. $configKey = array_Keys($configVal['content']);
  74. $configList[$configKey[0]] = array_values($configVal['content'])[0];
  75. }
  76. return $configList;
  77. }
  78. /**
  79. * @notes 主题页面
  80. * @param array $params
  81. * @return array
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @author cjhao
  86. * @date 2021/8/12 15:02
  87. */
  88. public function getPage(int $type,$userId,$goodsId)
  89. {
  90. $page = DecorateThemePage::where(['type' => $type])
  91. ->field('id,content,common')
  92. ->findOrEmpty()->toArray();
  93. //用户中心,判断是否需要屏蔽分销中心入口
  94. if(ThemePageEnum::TYPE_MEMBER_CENTRE == $type || ThemePageEnum::TYPE_HOME == $type){
  95. $config = $this->getMenuConfig($userId);
  96. }
  97. $config['page_type'] = $type;
  98. $config['user_id'] = $userId;
  99. $config['goods_id'] = $goodsId;
  100. $page['content'] = ThemeService::getModuleData($page['content'],$config);
  101. return $page;
  102. }
  103. /**
  104. * @notes 获取首页微页面
  105. * @param int $id
  106. * @return array
  107. * @author cjhao
  108. * @date 2021/9/1 14:53
  109. */
  110. public function getIndexPage(int $id):array
  111. {
  112. $page = DecorateThemePage::where(['id' => $id,'type'=>ThemePageEnum::TYPE_HOME])
  113. ->field('id,content,common')
  114. ->findOrEmpty()->toArray();
  115. //替换组件内容
  116. $page['content'] = ThemeService::getModuleData($page['content']);
  117. return $page;
  118. }
  119. /**
  120. * @notes 获取菜单配置 (是否屏蔽核销员、是否屏蔽核销菜单)
  121. * @param int $userId
  122. * @return array
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\DbException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. * @author cjhao
  127. * @date 2021/9/27 18:09
  128. */
  129. public function getMenuConfig(int $userId):array
  130. {
  131. $config['is_verifier'] = false;
  132. $config['is_distribution'] = false;
  133. $distributionConfig = DistributionConfig::column('value','key');
  134. $switch = $distributionConfig['switch'] ?? 0;//是否开启分销功能
  135. $open = $distributionConfig['open'] ?? 1; //
  136. //分销开启,但是指定用户分销,且当前用户不是分销用户
  137. if(1 == $switch){
  138. if(3 == $open){
  139. $userDistribution = Distribution::where(['user_id'=>$userId,'is_distribution'=>1])->find();
  140. $userDistribution && $config['is_distribution'] = true;
  141. }else{
  142. $config['is_distribution'] = true;
  143. }
  144. }
  145. $userVerifier = SelffetchVerifier::where(['user_id'=>$userId,'status'=>YesNoEnum::YES])
  146. ->find();
  147. //用户为核销员
  148. if($userVerifier){
  149. $config['is_verifier'] = true;
  150. }
  151. return $config;
  152. }
  153. }