ShopPublicDataService.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. namespace app\frontend\modules\home\services;
  3. use app\common\helpers\Cache;
  4. use app\common\services\popularize\PortType;
  5. use app\frontend\modules\member\services\MemberLevelAuth;
  6. use app\frontend\modules\shop\controllers\IndexController;
  7. Class ShopPublicDataService
  8. {
  9. public $is_decorate = 0;
  10. public $page_type;
  11. public $foot_cache = true;
  12. public $page_id;
  13. private static $instance;
  14. private function __construct()
  15. {
  16. $this->page_type = request()->type;
  17. $this->page_id = $page_id = (int) request()->page_id ?: 0;
  18. }
  19. public static function getInstance()
  20. {
  21. if (self::$instance instanceof self) {
  22. return self::$instance;
  23. }
  24. // 判断是使用新装修还是旧装修
  25. if (app('plugins')->isEnabled('decorate') && \Setting::get('plugin.decorate.is_open') == "1") {
  26. self::$instance = new \Yunshop\Decorate\services\ShopPublicDataService();
  27. } elseif (app('plugins')->isEnabled('designer')) {
  28. self::$instance = new \Yunshop\Designer\services\ShopPublicDataService();
  29. } else {
  30. self::$instance = new self();
  31. }
  32. return self::$instance;
  33. }
  34. public function getFootMenus()
  35. {
  36. $this->foot_cache = false;
  37. $i = request()->i;
  38. $mid = request()->mid;
  39. $type = request()->type;
  40. //默认菜单
  41. $Menu = Array(
  42. Array(
  43. "id" => 1,
  44. "title" => "首页",
  45. "icon" => "fa fa-home",
  46. "url" => "/addons/yun_shop/?#/home?i=" . $i . "&mid=" . $mid . "&type=" . $type,
  47. "name" => "home",
  48. "subMenus" => [],
  49. "textcolor" => "#70c10b",
  50. "bgcolor" => "#24d7e6",
  51. "bordercolor" => "#bfbfbf",
  52. "iconcolor" => "#666666"
  53. ),
  54. Array(
  55. "id" => "menu_1489731310493",
  56. "title" => "分类",
  57. "icon" => "fa fa-th-large",
  58. "url" => "/addons/yun_shop/?#/category?i=" . $i . "&mid=" . $mid . "&type=" . $type,
  59. "name" => "category",
  60. "subMenus" => [],
  61. "textcolor" => "#70c10b",
  62. "bgcolor" => "#24d7e6",
  63. "iconcolor" => "#666666",
  64. "bordercolor" => "#bfbfbf"
  65. ),
  66. Array(
  67. "id" => "menu_1489735163419",
  68. "title" => "购物车",
  69. "icon" => "fa fa-cart-plus",
  70. "url" => "/addons/yun_shop/?#/cart?i=" . $i . "&mid=" . $mid . "&type=" . $type,
  71. "name" => "cart",
  72. "subMenus" => [],
  73. "textcolor" => "#70c10b",
  74. "bgcolor" => "#24d7e6",
  75. "iconcolor" => "#666666",
  76. "bordercolor" => "#bfbfbf"
  77. ),
  78. Array(
  79. "id" => "menu_1491619644306",
  80. "title" => "会员中心",
  81. "icon" => "fa fa-user",
  82. "url" => "/addons/yun_shop/?#/member?i=" . $i . "&mid=" . $mid . "&type=" . $type,
  83. "name" => "member",
  84. "subMenus" => [],
  85. "textcolor" => "#70c10b",
  86. "bgcolor" => "#24d7e6",
  87. "iconcolor" => "#666666",
  88. "bordercolor" => "#bfbfbf"
  89. ),
  90. );
  91. $promoteMenu = Array(
  92. "id" => "menu_1489731319695",
  93. "classt" => "no",
  94. "title" => "推广",
  95. "icon" => "fa fa-send",
  96. "url" => "/addons/yun_shop/?#/member/extension?i=" . $i . "&mid=" . $mid . "&type=" . $type,
  97. "name" => "extension",
  98. "subMenus" => [],
  99. "textcolor" => "#666666",
  100. "bgcolor" => "#837aef",
  101. "iconcolor" => "#666666",
  102. "bordercolor" => "#bfbfbf"
  103. );
  104. $extension_status = \Setting::get('shop_app.pay.extension_status');
  105. if (isset($extension_status) && $extension_status == 0) {
  106. $extension_status = 0;
  107. } else {
  108. $extension_status = 1;
  109. }
  110. if ($type == 7 && $extension_status == 0) {
  111. unset($promoteMenu);
  112. } else {
  113. //是否显示推广按钮
  114. if (PortType::popularizeShow($type)) {
  115. $Menu[4] = $Menu[3]; //第 5 个按钮改成"会员中心"
  116. $Menu[3] = $Menu[2]; //第 4 个按钮改成"购物车"
  117. $Menu[2] = $promoteMenu; //在第 3 个按钮的位置加入"推广"
  118. }
  119. }
  120. return ['menus'=>$Menu,'menustyle'=>$this->getFootMenusStyle(),'footermenu'=>'','footertype'=>''];
  121. }
  122. public function getViewSet()
  123. {
  124. return [];
  125. }
  126. public function getFootMenusStyle()
  127. {
  128. return Array(
  129. "previewbg" => "#ef372e",
  130. "height" => "49px",
  131. "textcolor" => "#666666",
  132. "textcolorhigh" => "#ff4949",
  133. "iconcolor" => "#666666",
  134. "iconcolorhigh" => "#ff4949",
  135. "bgcolor" => "#FFF",
  136. "bgcolorhigh" => "#FFF",
  137. "bordercolor" => "#010101",
  138. "bordercolorhigh" => "#bfbfbf",
  139. "showtext" => 1,
  140. "showborder" => "0",
  141. "showicon" => 2,
  142. "textcolor2" => "#666666",
  143. "bgcolor2" => "#fafafa",
  144. "bordercolor2" => "#1856f8",
  145. "showborder2" => 1,
  146. "bgalpha" => ".5",
  147. );
  148. }
  149. public function getDefaultDesign()
  150. {
  151. if (!Cache::has('shop_category')) {
  152. $set = \Setting::get('shop.category');
  153. Cache::put('shop_category', $set, 4200);
  154. } else {
  155. $set = Cache::get('shop_category');
  156. }
  157. $set['cat_adv_img'] = replace_yunshop(yz_tomedia($set['cat_adv_img']));
  158. if (!Cache::has('shop_default_design')) {
  159. $result = Array(
  160. 'ads' => (new IndexController())->getAds(),
  161. 'advs' => (new IndexController())->getAdv(),
  162. 'brand' => (new IndexController())->getRecommentBrandList(),
  163. 'category' => (new IndexController())->getRecommentCategoryList(),
  164. 'time_goods' => (new IndexController())->getTimeLimitGoods(),
  165. 'set' => $set,
  166. 'goods' => (new IndexController())->getRecommentGoods(),
  167. );
  168. Cache::put('shop_default_design', $result, 1);
  169. } else {
  170. $result = Cache::get('shop_default_design');
  171. }
  172. return $result;
  173. }
  174. public function getIndexData()
  175. {
  176. $result['default'] = $this->getDefaultDesign();
  177. $result['item']['data'] = ''; //前端需要该字段
  178. $result['item']['topmenu'] = [
  179. 'menus' => [],
  180. 'params' => [],
  181. 'isshow' => false
  182. ];
  183. $result = $this->getLoginMemberLevel($result);
  184. return $result;
  185. }
  186. public function getLoginMemberLevel($result)
  187. {
  188. $member_id = \YunShop::app()->getMemberId();
  189. $allow_auth = $result['item']['pageinfo']['params']['checkitem'];//允许登录的用户等级
  190. $member_service = new MemberLevelAuth();
  191. $auth = $member_service->doAuth($member_id,$allow_auth);
  192. if (!$auth) {
  193. $result['item']['pageinfo']['params']['allowauth'] = 0;
  194. } else {
  195. $result['item']['pageinfo']['params']['allowauth'] = 1;
  196. }
  197. return $result;
  198. }
  199. }