DecorateThemePageLogic.php 6.1 KB

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