BeanRepository.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Behavior;
  4. use App\Models\CommentRecord;
  5. use App\Models\GeneralRecord;
  6. use App\Models\Post;
  7. use App\Models\RegisteredRecord;
  8. use App\Models\ReleaseRecord;
  9. use Illuminate\Support\Carbon;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Log;
  12. use Tymon\JWTAuth\Facades\JWTAuth;
  13. use Illuminate\Support\Facades\Redis;
  14. class BeanRepository
  15. {
  16. public function beanDetail($request)
  17. {
  18. try {
  19. $sign = generateSign(['type' => $request['type']], config('customer.app_secret'));
  20. $url = config("customer.app_service_url") . '/user/v2/beanDetail';
  21. $array = [
  22. 'json' => ['sign' => $sign, 'type' => $request['type']], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
  23. ];
  24. return http($url, $array, 'get');
  25. } catch (\Exception $e) {
  26. Log::debug("beanDetail:".$e->getMessage());
  27. return [];
  28. }
  29. }
  30. //获取优秀居民信息
  31. function excellentResidents($request)
  32. {
  33. $get_excellent = Redis::get('yesterday_excellent_residents');
  34. $excellent_residents = json_decode($get_excellent,true);
  35. if ($excellent_residents){
  36. //获取评论内容
  37. $post_ids = array_column($excellent_residents,'related_content_id');
  38. $comment_content = Post::select('id', 'title', 'content')->whereIn('id', $post_ids)->get();
  39. foreach ($comment_content->toArray() as $value) {
  40. foreach ($excellent_residents as $k=>$v) {
  41. if (isset($v['related_content_id']) && $v['related_content_id'] == $value['id']) {
  42. if (!empty($value['title'])) {
  43. $excellent_residents[$k]['post_title'] = $value['title'];
  44. }
  45. if (empty($value['title']) && !empty($value['content'])){
  46. $content = strip_tags($value['content']);
  47. $excellent_residents[$k]['post_title'] = mb_substr($content, 0, 20);
  48. }
  49. }
  50. }
  51. }
  52. $content_author_id = array_column($excellent_residents,'content_author_id');
  53. $uids = implode(',', array_unique($content_author_id));
  54. $author_data = $this->getFollowMembersStatus($uids);
  55. if ($author_data){
  56. foreach ($excellent_residents as $k=>$v){
  57. if(!isset($author_data[$v['content_author_id']])) continue;
  58. $excellent_residents[$k]['follow_status'] = $author_data[$v['content_author_id']]['follow_status'];
  59. $excellent_residents[$k]['username'] = $author_data[$v['content_author_id']]['username'];
  60. $excellent_residents[$k]['avatar'] = $author_data[$v['content_author_id']]['avatar'];
  61. }
  62. }
  63. }
  64. return $excellent_residents;
  65. }
  66. public function rankingList($request)
  67. {
  68. if ($request['type'] == 0){//排行榜赚豆达人
  69. $yesterday = Carbon::yesterday()->toDateString();
  70. $all_beans = Redis::ZREVRANGEBYSCORE('user_rainbow_bean'.$yesterday, 100000000, 0, array('WITHSCORES'=>true,'limit' => array(0, 20)));
  71. $new_arr = [];
  72. if ($all_beans) {
  73. $i = 0;
  74. foreach ($all_beans as $key => $val) {
  75. $new_arr[$i]['uid'] = $key;
  76. $new_arr[$i]['count'] = $val;
  77. $i++;
  78. }
  79. $uids = implode(',', array_column($new_arr, 'uid'));
  80. $user_data = $this->getFollowMembersStatus($uids);
  81. if ($user_data) {
  82. foreach ($new_arr as $k => $v) {
  83. if (!isset($user_data[$v['uid']])) continue;
  84. $new_arr[$k]['follow_status'] = $user_data[$v['uid']]['follow_status'];
  85. $new_arr[$k]['username'] = $user_data[$v['uid']]['username'];
  86. $new_arr[$k]['avatar'] = $user_data[$v['uid']]['avatar'];
  87. }
  88. }
  89. }
  90. return $new_arr;
  91. }elseif ($request['type'] == 1){//排行榜人脉达人
  92. $registered_mosts = Redis::get('yesterday_registered_most');
  93. $registered_most = json_decode($registered_mosts,true);
  94. if ($registered_most){
  95. $superior_uid = array_column($registered_most,'superior_uid');
  96. $uids = implode(',', array_unique($superior_uid));
  97. $user_data = $this->getFollowMembersStatus($uids);
  98. if ($user_data){
  99. foreach ($registered_most as $k=>$v){
  100. if(!isset($user_data[$v['superior_uid']])) continue;
  101. $registered_most[$k]['follow_status'] = $user_data[$v['superior_uid']]['follow_status'];
  102. $registered_most[$k]['username'] = $user_data[$v['superior_uid']]['username'];
  103. $registered_most[$k]['avatar'] = $user_data[$v['superior_uid']]['avatar'];
  104. }
  105. }
  106. }
  107. return $registered_most;
  108. }else{//排行榜最佳作者
  109. $all_best_authors = Redis::get('yesterday_best_author');
  110. $all_best_author = json_decode($all_best_authors,true);
  111. if ($all_best_author){
  112. $content_author_id = array_column($all_best_author,'content_author_id');
  113. $uids = implode(',', array_unique($content_author_id));
  114. $user_data = $this->getFollowMembersStatus($uids);
  115. if ($user_data){
  116. foreach ($all_best_author as $k=>$v){
  117. if(!isset($user_data[$v['content_author_id']])) continue;
  118. $all_best_author[$k]['follow_status'] = $user_data[$v['content_author_id']]['follow_status'];
  119. $all_best_author[$k]['username'] = $user_data[$v['content_author_id']]['username'];
  120. $all_best_author[$k]['avatar'] = $user_data[$v['content_author_id']]['avatar'];
  121. }
  122. }
  123. }
  124. return $all_best_author;
  125. }
  126. }
  127. function getFollowMembersStatus($uids) {
  128. try {
  129. $url = config("customer.app_service_url").'/user/v2/member/getMemberIds';
  130. $array = [
  131. 'json' => ['uids' => $uids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  132. ];
  133. return http($url,$array,'get');
  134. } catch (\Exception $e) {
  135. Log::debug($e->getMessage());
  136. return [];
  137. }
  138. }
  139. //星球首页
  140. public function starHome($request)
  141. {
  142. $star_home = [];
  143. $user_bean = Redis::get('my_bean');
  144. $user_bean = json_decode($user_bean,true);
  145. $yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
  146. $star_home['mybean']['user_all_bean'] = $user_bean['user_all_bean'] ?? 0;//用户总彩虹豆
  147. $star_home['mybean']['yesterday_add_bean'] = $user_bean['yesterday_add_bean'] ?? 0;//昨日发放彩虹豆
  148. $star_home['mybean']['user_count'] = $user_bean['user_count'] ?? 0;//已入驻居民
  149. $star_home['mybean']['yesterday_add_user'] = $user_bean['yesterday_add_user'] ?? 0;//昨日新增居民
  150. $star_home['mybean']['yesterday_quantity_issued'] = $yesterday_quantity_issued ?? 0;//昨日发放总彩虹豆
  151. $star_home['excellent_residents'] = $this->excellentResidents($request);
  152. $star_home['daily_news'] = $this->getNews($request);
  153. $star_home['tips'] = $this->getPlatformContent($id = 1);
  154. return $star_home;
  155. }
  156. //获取每日新闻
  157. function getNews($request) {
  158. try {
  159. $url = config("customer.app_service_url").'/config/v2/starNews/lists';
  160. $array = [
  161. 'json' => [], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  162. ];
  163. return http($url,$array,'get');
  164. } catch (\Exception $e) {
  165. Log::debug($e->getMessage());
  166. return [];
  167. }
  168. }
  169. //获取平台内容
  170. function getPlatformContent($id) {
  171. try {
  172. $url = config("customer.app_service_url").'/config/v2/platformContent/lists';
  173. $array = [
  174. 'json' => ['id'=>$id], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  175. ];
  176. return http($url,$array,'get');
  177. } catch (\Exception $e) {
  178. Log::debug($e->getMessage());
  179. return [];
  180. }
  181. }
  182. }