|
@@ -1,5 +1,7 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace App\Repositories;
|
|
|
+
|
|
|
use App\Models\Post;
|
|
|
use App\Traits\PostTrait;
|
|
|
use App\Traits\UserTrait;
|
|
@@ -8,10 +10,12 @@ use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
+
|
|
|
class BeanRepository
|
|
|
{
|
|
|
use PostTrait;
|
|
|
use UserTrait;
|
|
|
+
|
|
|
public function beanDetail($request)
|
|
|
{
|
|
|
try {
|
|
@@ -33,32 +37,32 @@ class BeanRepository
|
|
|
function excellentResidents($request)
|
|
|
{
|
|
|
$get_excellent = Redis::get('yesterday_excellent_residents');
|
|
|
- $excellent_residents = json_decode($get_excellent,true);
|
|
|
+ $excellent_residents = json_decode($get_excellent, true);
|
|
|
|
|
|
- if ($excellent_residents){
|
|
|
+ if ($excellent_residents) {
|
|
|
//获取评论内容
|
|
|
- $post_ids = array_column($excellent_residents,'related_content_id');
|
|
|
+ $post_ids = array_column($excellent_residents, 'related_content_id');
|
|
|
$comment_content = Post::select('id', 'title', 'content')->whereIn('id', $post_ids)->get();
|
|
|
|
|
|
foreach ($comment_content->toArray() as $value) {
|
|
|
- foreach ($excellent_residents as $k=>$v) {
|
|
|
+ foreach ($excellent_residents as $k => $v) {
|
|
|
if (isset($v['related_content_id']) && $v['related_content_id'] == $value['id']) {
|
|
|
if (!empty($value['title'])) {
|
|
|
$excellent_residents[$k]['post_title'] = $value['title'];
|
|
|
}
|
|
|
- if (empty($value['title']) && !empty($value['content'])){
|
|
|
+ if (empty($value['title']) && !empty($value['content'])) {
|
|
|
$content = strip_tags($value['content']);
|
|
|
$excellent_residents[$k]['post_title'] = mb_substr($content, 0, 20);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $content_author_id = array_column($excellent_residents,'content_author_id');
|
|
|
+ $content_author_id = array_column($excellent_residents, 'content_author_id');
|
|
|
$uids = implode(',', array_unique($content_author_id));
|
|
|
$author_data = $this->getFollowMembersStatus($uids);
|
|
|
- if ($author_data){
|
|
|
- foreach ($excellent_residents as $k=>$v){
|
|
|
- if(!isset($author_data[$v['content_author_id']])) continue;
|
|
|
+ if ($author_data) {
|
|
|
+ foreach ($excellent_residents as $k => $v) {
|
|
|
+ if (!isset($author_data[$v['content_author_id']])) continue;
|
|
|
$excellent_residents[$k]['follow_status'] = $author_data[$v['content_author_id']]['follow_status'];
|
|
|
$excellent_residents[$k]['username'] = $author_data[$v['content_author_id']]['username'];
|
|
|
$excellent_residents[$k]['avatar'] = $author_data[$v['content_author_id']]['avatar'];
|
|
@@ -71,10 +75,10 @@ class BeanRepository
|
|
|
|
|
|
public function rankingList($request)
|
|
|
{
|
|
|
- if ($request['type'] == 0){//排行榜U米达人
|
|
|
+ if ($request['type'] == 0) {//排行榜U米达人
|
|
|
$yesterday = Carbon::yesterday()->toDateString();
|
|
|
- $all_beans = Redis::ZREVRANGEBYSCORE('user_rainbow_bean'.$yesterday, 100000000, 0, array('WITHSCORES'=>true,'limit' => array(0, 10)));
|
|
|
- $new_arr = [];
|
|
|
+ $all_beans = Redis::ZREVRANGEBYSCORE('user_rainbow_bean' . $yesterday, 100000000, 0, array('WITHSCORES' => true, 'limit' => array(0, 10)));
|
|
|
+ $new_arr = [];
|
|
|
if ($all_beans) {
|
|
|
$i = 0;
|
|
|
foreach ($all_beans as $key => $val) {
|
|
@@ -95,20 +99,20 @@ class BeanRepository
|
|
|
}
|
|
|
return $new_arr;
|
|
|
|
|
|
- }elseif ($request['type'] == 1){//排行榜人脉达人
|
|
|
+ } elseif ($request['type'] == 1) {//排行榜人脉达人
|
|
|
$registered_mosts = Redis::get('yesterday_registered_most');
|
|
|
- if ($registered_mosts){
|
|
|
- $registered_most = json_decode($registered_mosts,true);
|
|
|
- }else{
|
|
|
+ if ($registered_mosts) {
|
|
|
+ $registered_most = json_decode($registered_mosts, true);
|
|
|
+ } else {
|
|
|
$registered_most = [];
|
|
|
}
|
|
|
if (count($registered_most) > 0) {
|
|
|
- $superior_uid = array_column($registered_most,'superior_uid');
|
|
|
+ $superior_uid = array_column($registered_most, 'superior_uid');
|
|
|
$uids = implode(',', array_unique($superior_uid));
|
|
|
$user_data = $this->getFollowMembersStatus($uids);
|
|
|
- if ($user_data){
|
|
|
- foreach ($registered_most as $k=>$v){
|
|
|
- if(!isset($user_data[$v['superior_uid']])) continue;
|
|
|
+ if ($user_data) {
|
|
|
+ foreach ($registered_most as $k => $v) {
|
|
|
+ if (!isset($user_data[$v['superior_uid']])) continue;
|
|
|
$registered_most[$k]['count'] = intval($v['count']);
|
|
|
// $registered_most[$k]['follow_status'] = $user_data[$v['superior_uid']]['follow_status'];
|
|
|
$registered_most[$k]['username'] = $user_data[$v['superior_uid']]['username'];
|
|
@@ -118,20 +122,20 @@ class BeanRepository
|
|
|
}
|
|
|
return $registered_most;
|
|
|
|
|
|
- }else{//排行榜最佳作者
|
|
|
+ } else {//排行榜最佳作者
|
|
|
$all_best_authors = Redis::get('yesterday_best_author');
|
|
|
- if ($all_best_authors){
|
|
|
- $all_best_author = json_decode($all_best_authors,true);
|
|
|
- }else{
|
|
|
+ if ($all_best_authors) {
|
|
|
+ $all_best_author = json_decode($all_best_authors, true);
|
|
|
+ } else {
|
|
|
$all_best_author = [];
|
|
|
}
|
|
|
if (count($all_best_author) > 0) {
|
|
|
- $content_author_id = array_column($all_best_author,'content_author_id');
|
|
|
+ $content_author_id = array_column($all_best_author, 'content_author_id');
|
|
|
$uids = implode(',', array_unique($content_author_id));
|
|
|
$user_data = $this->getFollowMembersStatus($uids);
|
|
|
- if ($user_data){
|
|
|
- foreach ($all_best_author as $k=>$v){
|
|
|
- if(!isset($user_data[$v['content_author_id']])) continue;
|
|
|
+ if ($user_data) {
|
|
|
+ foreach ($all_best_author as $k => $v) {
|
|
|
+ if (!isset($user_data[$v['content_author_id']])) continue;
|
|
|
$all_best_author[$k]['count'] = intval($v['count']);
|
|
|
// $all_best_author[$k]['follow_status'] = $user_data[$v['content_author_id']]['follow_status'];
|
|
|
$all_best_author[$k]['username'] = $user_data[$v['content_author_id']]['username'];
|
|
@@ -144,14 +148,15 @@ class BeanRepository
|
|
|
}
|
|
|
|
|
|
|
|
|
- function getFollowMembersStatus($uids) {
|
|
|
+ function getFollowMembersStatus($uids)
|
|
|
+ {
|
|
|
try {
|
|
|
$sign = generateSign(['uids' => $uids], config('customer.app_secret'));
|
|
|
- $url = config("customer.app_service_url").'/user/v2/member/getMemberIds';
|
|
|
+ $url = config("customer.app_service_url") . '/user/v2/member/getMemberIds';
|
|
|
$array = [
|
|
|
- 'json' => ['sign' => $sign,'uids' => $uids], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
+ 'json' => ['sign' => $sign, 'uids' => $uids], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
];
|
|
|
- return http($url,$array,'get');
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
Log::debug($e->getMessage());
|
|
|
return [];
|
|
@@ -163,16 +168,16 @@ class BeanRepository
|
|
|
public function starHome($request)
|
|
|
{
|
|
|
$today = Carbon::now()->toDateString();
|
|
|
- $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
$uid = $token['user']->uid;
|
|
|
- $bean = Redis::ZSCORE('user_rainbow_bean'.$today,$uid);
|
|
|
+ $bean = Redis::ZSCORE('user_rainbow_bean' . $today, $uid);
|
|
|
|
|
|
$userInfo = $this->userInfo($uid);
|
|
|
|
|
|
$star_home = [];
|
|
|
$user_bean = Redis::get('my_bean');
|
|
|
Log::debug($user_bean);
|
|
|
- $user_bean = json_decode($user_bean,true);
|
|
|
+ $user_bean = json_decode($user_bean, true);
|
|
|
$yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
|
|
|
Log::debug($user_bean);
|
|
|
|
|
@@ -200,31 +205,33 @@ class BeanRepository
|
|
|
"http://oss.caihongxingqiu.com/h5/planet/cover_07.png",
|
|
|
"http://oss.caihongxingqiu.com/h5/planet/cover_08.png"
|
|
|
];
|
|
|
- if($backyard){
|
|
|
+ if ($backyard) {
|
|
|
$star_home['backyard']['backyard_open'] = $backyard['backyard_open'];
|
|
|
$star_home['backyard']['backyard_img'] = $backyard['backyard_img'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$star_home['backyard']['backyard_open'] = 0;
|
|
|
$star_home['backyard']['backyard_img'] = '';
|
|
|
}
|
|
|
$star_home['user']['username'] = $userInfo['username'];
|
|
|
$star_home['user']['avatar'] = $userInfo['avatar'];
|
|
|
//battle信息
|
|
|
- $activityInfo = $this->getActivity();
|
|
|
- $star_home['battle']['start'] = $activityInfo['start'];
|
|
|
- $star_home['battle']['end'] = $activityInfo['end'];
|
|
|
- $star_home['battle']['news'] = Redis::get('battle_latest_info_'.$activityInfo['id'])??'战场四平八稳,劳驾老板亲自去战场督战';
|
|
|
+// $activityInfo = $this->getActivity();
|
|
|
+// $star_home['battle']['start'] = $activityInfo['start'];
|
|
|
+// $star_home['battle']['end'] = $activityInfo['end'];
|
|
|
+// $star_home['battle']['news'] = Redis::get('battle_latest_info_'.$activityInfo['id'])??'战场四平八稳,劳驾老板亲自去战场督战';
|
|
|
return $star_home;
|
|
|
|
|
|
}
|
|
|
- function getActivity(){
|
|
|
+
|
|
|
+ function getActivity()
|
|
|
+ {
|
|
|
$activity = config('customer.battle_activity_info');
|
|
|
- $activityInfo = ['id'=>1];
|
|
|
- if($activity){
|
|
|
- try{
|
|
|
- $activityInfo = \GuzzleHttp\json_decode($activity,true);
|
|
|
- }catch (\Exception $e){
|
|
|
- Log::debug('解析活动信息配置失败:'.$e->getMessage());
|
|
|
+ $activityInfo = ['id' => 1];
|
|
|
+ if ($activity) {
|
|
|
+ try {
|
|
|
+ $activityInfo = \GuzzleHttp\json_decode($activity, true);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::debug('解析活动信息配置失败:' . $e->getMessage());
|
|
|
return $activityInfo;
|
|
|
}
|
|
|
}
|
|
@@ -235,11 +242,11 @@ class BeanRepository
|
|
|
function get_user_bean($uid)
|
|
|
{
|
|
|
try {
|
|
|
- $url = config("customer.app_service_url").'/user/v2/user_bean';
|
|
|
+ $url = config("customer.app_service_url") . '/user/v2/user_bean';
|
|
|
$array = [
|
|
|
- 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
+ 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
];
|
|
|
- return http($url,$array,'get');
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
return [];
|
|
|
}
|
|
@@ -250,11 +257,11 @@ class BeanRepository
|
|
|
function backyard($uid)
|
|
|
{
|
|
|
try {
|
|
|
- $url = config("customer.app_service_url").'/user/v2/backyard';
|
|
|
+ $url = config("customer.app_service_url") . '/user/v2/backyard';
|
|
|
$array = [
|
|
|
- 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
+ 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
];
|
|
|
- return http($url,$array,'get');
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
return [];
|
|
|
}
|
|
@@ -262,21 +269,24 @@ class BeanRepository
|
|
|
}
|
|
|
|
|
|
//获取每日新闻
|
|
|
- function getNews($request) {
|
|
|
+ function getNews($request)
|
|
|
+ {
|
|
|
try {
|
|
|
- $url = config("customer.app_service_url").'/config/v2/starNews/lists';
|
|
|
+ $url = config("customer.app_service_url") . '/config/v2/starNews/lists';
|
|
|
$array = [
|
|
|
'json' => [], 'query' => [], 'http_errors' => false
|
|
|
];
|
|
|
- return http($url,$array,'get');
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
Log::debug($e->getMessage());
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
//获取平台内容
|
|
|
- function getPlatformContent($id) {
|
|
|
+ function getPlatformContent($id)
|
|
|
+ {
|
|
|
try {
|
|
|
$url = config("customer.app_service_url") . '/config/v2/platformContent/lists';
|
|
|
$array = [
|
|
@@ -294,19 +304,19 @@ class BeanRepository
|
|
|
{
|
|
|
$star_detail = [];
|
|
|
$user_bean = Redis::get('my_bean');
|
|
|
- $user_bean = json_decode($user_bean,true);
|
|
|
+ $user_bean = json_decode($user_bean, true);
|
|
|
$yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
|
|
|
- $exchange = Redis::ZREVRANGEBYSCORE('post_purchase_message','+inf','-inf');
|
|
|
- foreach ($exchange as $k=>$v){
|
|
|
- $exchange[$k] = json_decode($v,true);
|
|
|
+ $exchange = Redis::ZREVRANGEBYSCORE('post_purchase_message', '+inf', '-inf');
|
|
|
+ foreach ($exchange as $k => $v) {
|
|
|
+ $exchange[$k] = json_decode($v, true);
|
|
|
}
|
|
|
Log::debug($user_bean);
|
|
|
Log::debug($yesterday_quantity_issued);
|
|
|
Log::debug($exchange);
|
|
|
|
|
|
- if (isset($request['post_id']) && $request['post_id']){
|
|
|
+ if (isset($request['post_id']) && $request['post_id']) {
|
|
|
$post = $this->getPostInfo($request['post_id'], 1);
|
|
|
- if ($post){
|
|
|
+ if ($post) {
|
|
|
$user = $this->userInfo($post['uid']);
|
|
|
$topic = $this->getTopic($post['topic_ids']);
|
|
|
$post['created_time'] = Carbon::parse($post['created_at'])->diffForHumans();
|
|
@@ -314,7 +324,7 @@ class BeanRepository
|
|
|
$post['username'] = $user['username'];
|
|
|
$post['avatar'] = $user['avatar'];
|
|
|
$star_detail['post'] = $post;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Log::debug($request['post_id']);
|
|
|
return jsonError('该帖子已被删除');
|
|
|
}
|
|
@@ -322,11 +332,11 @@ class BeanRepository
|
|
|
$user_info = $this->getUserInfo($invite_code = $request['invite_code']);
|
|
|
Log::debug($request['invite_code']);
|
|
|
Log::debug($user_info);
|
|
|
- if ($user_info){
|
|
|
+ if ($user_info) {
|
|
|
$star_detail['invite']['username'] = $user_info['username'] ?? '';
|
|
|
$star_detail['invite']['avatar'] = $user_info['avatar'] ?? '';
|
|
|
$star_detail['invite']['bean'] = config("customer.share_post_bean") ?? 0;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Log::debug($request['invite_code']);
|
|
|
return jsonError('邀请码有误');
|
|
|
}
|
|
@@ -343,14 +353,15 @@ class BeanRepository
|
|
|
}
|
|
|
|
|
|
//根据邀请码获取用户信息
|
|
|
- function getUserInfo($invite_code) {
|
|
|
+ function getUserInfo($invite_code)
|
|
|
+ {
|
|
|
try {
|
|
|
$sign = generateSign(['invite_code' => $invite_code], config('customer.app_secret'));
|
|
|
- $url = config("customer.app_service_url").'/user/v2/member/getInviteCodeMember';
|
|
|
+ $url = config("customer.app_service_url") . '/user/v2/member/getInviteCodeMember';
|
|
|
$array = [
|
|
|
- 'json' => ['sign' => $sign,'invite_code' => $invite_code], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
|
|
|
+ 'json' => ['sign' => $sign, 'invite_code' => $invite_code], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
|
|
|
];
|
|
|
- return http($url,$array,'get');
|
|
|
+ return http($url, $array, 'get');
|
|
|
} catch (\Exception $e) {
|
|
|
Log::debug($e->getMessage());
|
|
|
return [];
|
|
@@ -363,7 +374,7 @@ class BeanRepository
|
|
|
{
|
|
|
$star_lists = [];
|
|
|
$user_bean = Redis::get('my_bean');
|
|
|
- $user_bean = json_decode($user_bean,true);
|
|
|
+ $user_bean = json_decode($user_bean, true);
|
|
|
$yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
|
|
|
Log::debug($user_bean);
|
|
|
Log::debug($yesterday_quantity_issued);
|