123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- <?php
- namespace App\Repositories;
- use App\Models\Post;
- use App\Repositories\Circle\CircleRepository;
- use App\Traits\PostTrait;
- use App\Traits\UserTrait;
- use Illuminate\Support\Carbon;
- 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 __construct(CircleRepository $circleRepository)
- {
- $this->circleRepository = $circleRepository;
- }
- public function beanDetail($request)
- {
- try {
- $token = JWTAuth::decode(JWTAuth::getToken());
- $uid = $token['user']->uid;
- $sign = generateSign(['type' => $request['type'], 'uid' => $uid], config('customer.app_secret'));
- $url = config("customer.app_service_url") . '/user/v2/beanDetail';
- $array = [
- 'json' => ['sign' => $sign, 'type' => $request['type'], 'uid' => $uid], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- Log::debug("beanDetail:" . $e->getMessage());
- return [];
- }
- }
- //获取优秀居民信息
- function excellentResidents($request)
- {
- $get_excellent = Redis::get('yesterday_excellent_residents');
- $excellent_residents = json_decode($get_excellent, true);
- if ($excellent_residents) {
- //获取评论内容
- $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) {
- 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'])) {
- $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');
- $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;
- $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'];
- }
- }
- }
- return $excellent_residents;
- }
- public function rankingList($request)
- {
- 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 = [];
- if ($all_beans) {
- $i = 0;
- foreach ($all_beans as $key => $val) {
- $new_arr[$i]['uid'] = $key;
- $new_arr[$i]['count'] = intval($val);
- $i++;
- }
- $uids = implode(',', array_column($new_arr, 'uid'));
- $user_data = $this->getFollowMembersStatus($uids);
- if ($user_data) {
- foreach ($new_arr as $k => $v) {
- if (!isset($user_data[$v['uid']])) continue;
- // $new_arr[$k]['follow_status'] = $user_data[$v['uid']]['follow_status'];
- $new_arr[$k]['username'] = $user_data[$v['uid']]['username'];
- $new_arr[$k]['avatar'] = $user_data[$v['uid']]['avatar'];
- }
- }
- }
- return $new_arr;
- } elseif ($request['type'] == 1) {//排行榜人脉达人
- $registered_mosts = Redis::get('yesterday_registered_most');
- 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');
- $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;
- $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'];
- $registered_most[$k]['avatar'] = $user_data[$v['superior_uid']]['avatar'];
- }
- }
- }
- return $registered_most;
- } else {//排行榜最佳作者
- $all_best_authors = Redis::get('yesterday_best_author');
- 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');
- $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;
- $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'];
- $all_best_author[$k]['avatar'] = $user_data[$v['content_author_id']]['avatar'];
- }
- }
- }
- return $all_best_author;
- }
- }
- function getFollowMembersStatus($uids)
- {
- try {
- $sign = generateSign(['uids' => $uids], config('customer.app_secret'));
- $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()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- Log::debug($e->getMessage());
- return [];
- }
- }
- //后院首页
- public function starHome($request)
- {
- $today = Carbon::now()->toDateString();
- $token = JWTAuth::decode(JWTAuth::getToken());
- $uid = $token['user']->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);
- $yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
- Log::debug($user_bean);
- $my_bean = $this->get_user_bean($uid);
- $star_home['mybean']['user_all_bean'] = intval($my_bean['user_all_bean']) ?? 0;//用户累计总U米
- $star_home['mybean']['user_surplus_bean'] = intval($my_bean['user_surplus_bean']) ?? 0;//用户剩余U米
- $star_home['mybean']['today_add_bean'] = intval($bean) ?? 0;//今日发放U米
- $star_home['mybean']['user_count'] = intval($user_bean['user_count']) ?? 0;//已入驻老板
- $star_home['mybean']['yesterday_add_user'] = intval($user_bean['yesterday_add_user']) ?? 0;//昨日新增老板
- $star_home['mybean']['yesterday_quantity_issued'] = intval($yesterday_quantity_issued) ?? 0;//昨日发放总U米
- //$star_home['excellent_residents'] = $this->excellentResidents($request) ?? [];
- $star_home['daily_news'] = $this->getNews($request);
- $star_home['tips'] = $this->getPlatformContent($id = 1);
- $backyard = $this->backyard($uid);
- $star_home['backyard']['backyard_imgs'] = [
- "http://oss.uptoyo.com/h5/planet/cover_01.png",
- "http://oss.uptoyo.com/h5/planet/cover_02.png",
- "http://oss.uptoyo.com/h5/planet/cover_03.png",
- "http://oss.uptoyo.com/h5/planet/cover_04.png",
- "http://oss.uptoyo.com/h5/planet/cover_05.png",
- "http://oss.uptoyo.com/h5/planet/cover_06.png",
- "http://oss.uptoyo.com/h5/planet/cover_07.png",
- "http://oss.uptoyo.com/h5/planet/cover_08.png",
- "http://oss.uptoyo.com/h5/planet/cover_09.png",
- "http://oss.uptoyo.com/h5/planet/cover_10.png"
- ];
- if ($backyard) {
- $star_home['backyard']['backyard_open'] = $backyard['backyard_open'];
- $star_home['backyard']['backyard_img'] = $backyard['backyard_img'];
- } 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'])??'战场四平八稳,劳驾老板亲自去战场督战';
- $circleList = $this->circleRepository->circleLists(['is_recommend' => 1]);
- $circles = [];
- foreach ($circleList as $circle) {
- $temp = [];
- $temp['circle_id'] = $circle['id'];
- $temp['image'] = $circle['image'];
- $temp['join_limit'] = $circle['join_limit'];
- $temp['circle_name'] = mb_substr($circle['name'], 0, 6);
- $circles[] = $temp;
- }
- $star_home['circles'] = $circles;
- //聊天室
- $tmpChatroom = Redis::get('user_service_chatroom');
- $chatrooms = $tmpChatroom ? json_decode($tmpChatroom, true) : [];
- $current = Carbon::now()->format('H:i:s');
- $chatRoomsData1 = [];
- $chatRoomsData0 = [];
- foreach ($chatrooms as &$chatroom) {
- if ($chatroom['start'] < $chatroom['end']) {
- if ($current < $chatroom['start'] || $current > $chatroom['end']) {
- $chatroom['is_open'] = 0;
- $chatRoomsData0[] = $chatroom;
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- } elseif ($chatroom['start'] > $chatroom['end']) {
- if ($current > $chatroom['end'] && $current < $chatroom['start']) {
- $chatroom['is_open'] = 0;
- $chatRoomsData0[] = $chatroom;
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- }
- $star_home['chatroom'] = array_merge($chatRoomsData1, $chatRoomsData0);
- $star_home['is_show'] = intval(config('customer.exchange_shop_is_show'));
- return $star_home;
- }
- 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());
- return $activityInfo;
- }
- }
- return $activityInfo;
- }
- //获取某用户豆数
- function get_user_bean($uid)
- {
- try {
- $url = config("customer.app_service_url") . '/user/v2/user_bean';
- $array = [
- 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- return [];
- }
- }
- //获取用户后院权限等信息
- function backyard($uid)
- {
- try {
- $url = config("customer.app_service_url") . '/user/v2/backyard';
- $array = [
- 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- return [];
- }
- }
- //获取每日新闻
- function getNews($request)
- {
- try {
- $url = config("customer.app_service_url") . '/config/v2/starNews/lists';
- $array = [
- 'json' => [], 'query' => [], 'http_errors' => false
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- Log::debug($e->getMessage());
- return [];
- }
- }
- //获取平台内容
- function getPlatformContent($id)
- {
- try {
- $url = config("customer.app_service_url") . '/config/v2/platformContent/lists';
- $array = [
- 'json' => ['id' => $id], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- Log::debug($e->getMessage());
- return [];
- }
- }
- public function starDetail($request)
- {
- $star_detail = [];
- $user_bean = Redis::get('my_bean');
- $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);
- }
- Log::debug($user_bean);
- Log::debug($yesterday_quantity_issued);
- Log::debug($exchange);
- if (isset($request['post_id']) && $request['post_id']) {
- $post = $this->getPostInfo($request['post_id'], 1);
- if ($post) {
- $user = $this->userInfo($post['uid']);
- $topic = $this->getTopic($post['topic_ids']);
- $post['created_time'] = Carbon::parse($post['created_at'])->diffForHumans();
- $post['topic'] = array_column($topic, 'name');
- $post['username'] = $user['username'];
- $post['avatar'] = $user['avatar'];
- $star_detail['post'] = $post;
- } else {
- Log::debug($request['post_id']);
- return jsonError('该帖子已被删除');
- }
- }
- $user_info = $this->getUserInfo($invite_code = $request['invite_code']);
- Log::debug($request['invite_code']);
- Log::debug($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 {
- Log::debug($request['invite_code']);
- //return jsonError('邀请码有误');
- }
- $star_detail['mybean']['user_count'] = intval($user_bean['user_count']) ?? 0;//已入驻老板
- $star_detail['mybean']['yesterday_add_user'] = intval($user_bean['yesterday_add_user']) ?? 0;//昨日新增老板
- $star_detail['mybean']['yesterday_quantity_issued'] = intval($yesterday_quantity_issued) ?? 0;//昨日发放总U米
- $star_detail['daily_news'] = $this->getNews($request);
- $star_detail['exchange'] = $exchange;
- $circleList = $this->circleRepository->circleLists(['is_recommend' => 1]);
- $circles = [];
- foreach ($circleList as $circle) {
- $temp = [];
- $temp['circle_id'] = $circle['id'];
- $temp['image'] = $circle['image'];
- $temp['join_limit'] = $circle['join_limit'];
- $temp['circle_name'] = mb_substr($circle['name'], 0, 6);
- $circles[] = $temp;
- }
- $star_detail['circles'] = $circles;
- return $star_detail;
- }
- //根据邀请码获取用户信息
- 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';
- $array = [
- 'json' => ['sign' => $sign, 'invite_code' => $invite_code], 'query' => [], 'http_errors' => false, 'headers' => ['Authorization' => "Bearer " . JWTAuth::getToken()]
- ];
- return http($url, $array, 'get');
- } catch (\Exception $e) {
- Log::debug($e->getMessage());
- return [];
- }
- }
- //不登录单独返回每日新闻、小贴士
- public function lists($request)
- {
- $star_lists = [];
- $user_bean = Redis::get('my_bean');
- $user_bean = json_decode($user_bean, true);
- $yesterday_quantity_issued = Redis::get('yesterday_quantity_issued');
- Log::debug($user_bean);
- Log::debug($yesterday_quantity_issued);
- $star_lists['mybean']['user_count'] = intval($user_bean['user_count']) ?? 0;//已入驻老板
- $star_lists['mybean']['yesterday_add_user'] = intval($user_bean['yesterday_add_user']) ?? 0;//昨日新增老板
- $star_lists['mybean']['yesterday_quantity_issued'] = intval($yesterday_quantity_issued) ?? 0;//昨日发放总U米
- $star_lists['daily_news'] = $this->getNews($request);
- $star_lists['tips'] = $this->getPlatformContent($id = 1);
- //聊天室
- $tmpChatroom = Redis::get('user_service_chatroom');
- $chatrooms = $tmpChatroom ? json_decode($tmpChatroom, true) : [];
- $current = Carbon::now()->format('H:i:s');
- $chatRoomsData1 = [];
- $chatRoomsData0 = [];
- foreach ($chatrooms as &$chatroom) {
- if ($chatroom['start'] < $chatroom['end']) {
- if ($current < $chatroom['start'] || $current > $chatroom['end']) {
- $chatroom['is_open'] = 0;
- $chatRoomsData0[] = $chatroom;
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- } elseif ($chatroom['start'] > $chatroom['end']) {
- if ($current > $chatroom['end'] && $current < $chatroom['start']) {
- $chatroom['is_open'] = 0;
- $chatRoomsData0[] = $chatroom;
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- } else {
- $chatroom['is_open'] = 1;
- $chatRoomsData1[] = $chatroom;
- }
- }
- $star_lists['chatroom'] = array_merge($chatRoomsData1, $chatRoomsData0);
- return $star_lists;
- }
- }
|