MemberCenterDataService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/1
  6. * Time: 下午4:37
  7. */
  8. namespace app\frontend\modules\member\services;
  9. use app\common\modules\shop\MemberCenterConfig;
  10. use app\common\services\member\MemberCenterService;
  11. use app\frontend\modules\member\models\MemberFavorite;
  12. use app\frontend\modules\member\models\MemberHistory;
  13. class MemberCenterDataService
  14. {
  15. public $apiData;
  16. public function __construct($apiData = null)
  17. {
  18. $this->apiData = $apiData;
  19. }
  20. public function getEnablePlugins()
  21. {
  22. $memberId = \YunShop::app()->getMemberId();
  23. $memberCenter = new MemberCenterService();
  24. $arr = $memberCenter->getMemberData($memberId);//获取会员中心页面各入口
  25. $arr['plugins'] = [];
  26. $plugin = $memberCenter->defaultPluginData($memberId);
  27. foreach ($arr as $key => $item) {
  28. if (!in_array($key,['is_open','hotel','plugins','ViewSet'])) {
  29. $plugin = array_merge($plugin,$item);
  30. unset($arr[$key]);
  31. }
  32. }
  33. $arr['plugin_head'] = $this->getPluginHead($memberId);
  34. if ($plugin) {
  35. $plugin = collect($plugin);
  36. foreach ($memberCenter->sortPluginData() as $item) {
  37. $data = $plugin->where('name',$item);
  38. //存在相同name的入口,改为循环
  39. if ($data->isNotEmpty()) {
  40. $data->each(function ($v) use (&$arr) {
  41. if (count($arr['plugins']) < 19) {
  42. $arr['plugins'][] = $v;
  43. }
  44. });
  45. }
  46. // if ($data) {
  47. // $arr['plugins'][] = $data;
  48. // }
  49. if (count($arr['plugins']) >= 19) {
  50. break;
  51. }
  52. }
  53. }
  54. return $arr;
  55. }
  56. public function getPluginHead($memberId)
  57. {
  58. $head = [
  59. [
  60. 'title' => '商品收藏',
  61. 'class' => 'icon-fontclass-shoucang',
  62. 'value' => MemberFavorite::getFavoriteCount($memberId)?:0,
  63. 'mini_url'=> "/packageD/member/collection/collection",
  64. 'url' => "collection"
  65. ],
  66. [
  67. 'title' => '浏览记录',
  68. 'class' => 'icon-fontclass-liulan',
  69. 'value' => MemberHistory::getMemberHistoryCount($memberId)?:0,
  70. 'mini_url'=> "/packageD/member/footprint/footprint",
  71. 'url' => "footprint"
  72. ],
  73. ];
  74. $set = \Setting::get('plugin.instation-message');
  75. if (app('plugins')->isEnabled('instation-message') && !empty($set['is_open'])) {
  76. $head[] = [
  77. 'title' => '消息',
  78. 'class' => 'icon-fontclass-xiaoxi',
  79. 'value' => \Yunshop\InstationMessage\models\InstationMessageDataModel::where('uniacid',intval(\YunShop::app()->uniacid))
  80. ->where('member_id',intval($memberId))
  81. ->where('is_read',intval(1))
  82. ->count()?:0,
  83. 'mini_url'=> '/packageE/stationNotice/stationNotice',
  84. 'url' => "stationNotice"
  85. ];
  86. }
  87. return $head;
  88. }
  89. /**
  90. * @param $code
  91. * @param bool $returnNav 导航
  92. * @return array
  93. */
  94. public function getPluginData($code,$returnNav = true)
  95. {
  96. $nav = [];
  97. $config = MemberCenterConfig::current()->getItem('plugin_data');
  98. $config = collect($config)->sortBy('sort')->all();
  99. if ($returnNav) {
  100. foreach ($config as $key => $item) {
  101. $class = new $item['class'];
  102. if (!($class instanceof MemberCenterPluginBaseService)) {
  103. continue;
  104. }
  105. if (!$class->getEnabled()) {
  106. continue;
  107. }
  108. $nav[] = [
  109. 'name' => $item['name'],
  110. 'code' => $item['code'],
  111. ];
  112. }
  113. }
  114. $data = [];
  115. if (!$code) {
  116. //默认寻找第一个可以显示的导航
  117. foreach ($config as $key => $item) {
  118. $class = new $item['class'];
  119. if (!($class instanceof MemberCenterPluginBaseService)) {
  120. continue;
  121. }
  122. if (!$class->getEnabled()) {
  123. continue;
  124. }
  125. $find = $item;
  126. break;
  127. }
  128. } else {
  129. $find = collect($config)->where('code',$code)->first();
  130. }
  131. if (isset($find)) {
  132. $class = new $find['class'];
  133. if ($class instanceof MemberCenterPluginBaseService && $class->getEnabled()) {
  134. $class->init(request());
  135. $data = $class->getData();
  136. }
  137. }
  138. return ['nav' => $nav,'data' => $data];
  139. }
  140. public function getService($integrated)
  141. {
  142. //1.商城客服设置
  143. $shopSet = \Setting::get('shop.shop');
  144. $shop_cservice= $shopSet['cservice']?:'';
  145. //2.客服插件设置
  146. if (app('plugins')->isEnabled('customer-service')) {
  147. $set = array_pluck(\Setting::getAllByGroup('customer-service')->toArray(), 'value', 'key');
  148. if ($set['is_open'] == 1) {
  149. if (request()->type == 2) {
  150. $arr = [
  151. 'cservice'=>$set['mini_link'],
  152. 'customer_open'=>$set['mini_open'],
  153. 'service_QRcode' => yz_tomedia($set['mini_QRcode']),
  154. 'service_mobile' => $set['mini_mobile']
  155. ];
  156. }else{
  157. $arr = [
  158. 'cservice'=>$set['link'],
  159. 'service_QRcode' => yz_tomedia($set['QRcode']),
  160. 'service_mobile' => $set['mobile']
  161. ];
  162. }
  163. $alonge_cservice = $arr;
  164. }
  165. }
  166. return !empty($alonge_cservice)?$alonge_cservice:$shop_cservice;
  167. }
  168. }