DecorateThemePageLogic.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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\adminapi\logic\theme;
  20. use app\common\{cache\HandleConcurrencyCache,
  21. enum\ShopPageEnum,
  22. enum\ThemePageEnum,
  23. service\ThemeService,
  24. service\WeChatService,
  25. model\DecorateThemePage};
  26. /**
  27. * 主题页面逻辑层
  28. * Class DecoratePageLogic
  29. * @package app\adminapi\logic\decorate
  30. */
  31. class DecorateThemePageLogic
  32. {
  33. /**
  34. * @notes 主题首页
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @author cjhao
  40. * @date 2021/8/13 18:29
  41. */
  42. public function index():array
  43. {
  44. $index = DecorateThemePage::where(['is_home'=>1])
  45. ->field('id,name,create_time,update_time')
  46. ->find()
  47. ->toArray();
  48. $h5Uri = request()->domain().'/mobile'.ShopPageEnum::HOME_PAGE['mobile'];
  49. $res = WeChatService::makeMpQrCode(['page' =>substr(ShopPageEnum::HOME_PAGE['mobile'],1)],'base64');
  50. $mpBase64 = '';
  51. if(true == $res){
  52. $mpBase64 = WeChatService::getReturnData();
  53. }
  54. return [
  55. 'home' => $index,
  56. 'mp' => [
  57. 'qr_code' => $mpBase64,
  58. ],
  59. 'oa' => [
  60. 'uri' => $h5Uri,
  61. // 'qr_code' => $oaBase64,
  62. ],
  63. ];
  64. }
  65. /**
  66. * @notes 主题页设置为主页
  67. * @param int $id
  68. * @return bool
  69. * @author cjhao
  70. * @date 2021/8/6 16:33
  71. */
  72. public function setHome(int $id): bool
  73. {
  74. DecorateThemePage::where(['is_home' => 1])->update(['is_home' => 0]);
  75. DecorateThemePage::where(['id' => $id])->update(['is_home' => 1]);
  76. return true;
  77. }
  78. /**
  79. * @notes 新增装修页面
  80. * @param array $params
  81. * @return bool
  82. * @author cjhao
  83. * @date 2021/8/5 10:58
  84. */
  85. public function add(array $params): int
  86. {
  87. $id = DecorateThemePage::order('id desc')->value('id');
  88. $decoratePage = new DecorateThemePage();
  89. $decoratePage->theme_id = 1;//todo 后面整合主题功能时需要修改
  90. $decoratePage->name = '默认页面'.$id+1;
  91. $decoratePage->type = $params['type'] ?? 1;
  92. $decoratePage->content = $params['content'] ?? [];
  93. $decoratePage->common = $params['common'] ?? [];
  94. $decoratePage->save();
  95. return $decoratePage->id;
  96. }
  97. /**
  98. * @notes 获取装修页面
  99. * @param int $id
  100. * @return array
  101. * @author cjhao
  102. * @date 2021/8/5 10:59
  103. */
  104. public function getPage(array $params)
  105. {
  106. //todo 传id获取某个页面;传type获取某个类型的页面
  107. if (isset($params['id'])) {
  108. $where = ['id' => $params['id']];
  109. } else {
  110. $where = ['type' => $params['type']];
  111. }
  112. $page = DecorateThemePage::where($where)
  113. ->field('id,name,type,is_home,content,common')
  114. ->find()->toArray();
  115. if(ThemePageEnum::TYPE_HOME === $page['type']){
  116. $config['source'] = 'admin';
  117. $page['content'] = ThemeService::getModuleData($page['content'],$config);
  118. }
  119. return $page;
  120. }
  121. /**
  122. * @notes 更新装修页面
  123. * @param array $params
  124. * @return bool
  125. * @author cjhao
  126. * @date 2021/8/5 11:14
  127. */
  128. public function edit(array $params): array
  129. {
  130. DecorateThemePage::update($params, [], ['name', 'content', 'common']);
  131. $isPreview = $params['is_preview'] ?? 0;
  132. $data = [];
  133. if($isPreview){
  134. //TODO 暂时拿当前域名
  135. switch ($params['type']){
  136. case ThemePageEnum::TYPE_HOME:
  137. if($params['is_home']){
  138. $url = request()->domain().'/mobile'.ShopPageEnum::HOME_PAGE['mobile'];
  139. }else{
  140. $url = request()->domain().'/mobile'.ShopPageEnum::MICRO_PAGE['mobile'].'?id='.$params['id'];
  141. }
  142. break;
  143. case ThemePageEnum::TYPE_GOODS_CATEGORY:
  144. $url = request()->domain().'/mobile'.ShopPageEnum::GOODS_CATEGORY_PAGE['mobile'];
  145. break;
  146. case ThemePageEnum::TYPE_MEMBER_CENTRE:
  147. $url = request()->domain().'/mobile'.ShopPageEnum::MEMBER_CENTRE_PAGE['mobile'];
  148. break;
  149. }
  150. $data['url'] = $url;
  151. }
  152. //删除缓存
  153. $HandleConcurrencyCache = new HandleConcurrencyCache();
  154. $HandleConcurrencyCache->deleteCache($HandleConcurrencyCache->getDecorateThemeHomeKey());
  155. return $data;
  156. }
  157. /**
  158. * @notes 删除主题页面
  159. * @param int $id
  160. * @return bool
  161. * @author cjhao
  162. * @date 2021/8/9 19:30
  163. */
  164. public function del(int $id): bool
  165. {
  166. DecorateThemePage::destroy($id);
  167. return true;
  168. }
  169. /**
  170. * @notes 获取商城页面
  171. * @return array
  172. * @author cjhao
  173. * @date 2021/8/12 16:27
  174. */
  175. public function getShopPage(string $type):array
  176. {
  177. $pageList = ShopPageEnum::SHOP_PAGE;
  178. $list = [];
  179. foreach ($pageList as $page){
  180. if($type === $page['type']){
  181. $list[] = $page;
  182. }
  183. }
  184. return $list;
  185. }
  186. }