Commit 7bc97129 by 杨树贤

丰富好友助力列表的返回信息

parent ed9df7eb
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Services\AssistService; use App\Services\AssistService;
use App\Services\UserExchangeService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
/** /**
...@@ -35,12 +36,25 @@ class AssistsController extends Controller ...@@ -35,12 +36,25 @@ class AssistsController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$userId = $request->user->user_id;
$exchangeId = $request->get('exchange_id');
$map = [ $map = [
'user_id' => $request->user->user_id, 'user_id' => $userId,
'is_api' => 1, 'is_api' => 1,
'exchange_id' => $request->get('exchange_id'), 'exchange_id' => $exchangeId,
];
$list = $this->service->getAssistList($map);
$result['data']['assist_list'] = $list;
$userExchangeService = new UserExchangeService();
$userExchange = array_get($userExchangeService->getUserExchange(['id' => $exchangeId]), 'data');
$result['data']['amount'] = array_get($userExchange, 'amount', '0');
$user = $this->service->getUserInfo($userId);
$result['data']['user_info'] = [
'avatar' => array_get($user, 'avatar'),
'company_name' => array_get($user, 'company_name', ''),
]; ];
$result = $this->service->getAssistList($map); $needAssistCount = 2;
$result['data']['need_assist_count'] = $needAssistCount - count($list);
return $this->Export(0, 'ok', $result); return $this->Export(0, 'ok', $result);
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
namespace App\Services; namespace App\Services;
use Common\Model\RedisModel;
class AssistService extends BaseService class AssistService extends BaseService
{ {
public function getAssistList($map = []) public function getAssistList($map = [])
...@@ -11,23 +13,25 @@ class AssistService extends BaseService ...@@ -11,23 +13,25 @@ class AssistService extends BaseService
$url = config('website.BaseUrl') . '/assists/list'; $url = config('website.BaseUrl') . '/assists/list';
$result = reportCurl($url, $map, true); $result = reportCurl($url, $map, true);
$result = json_decode($result, true); $result = json_decode($result, true);
$userNames = []; $userNames = $userAvatars = [];
if (isset($result['data']) && $result['data']) { if (isset($result['data']) && $result['data']) {
//获取到被邀请人的信息 //获取到被邀请人的信息
$ids = array_column($result['data'], 'assist_user_id'); $ids = array_column($result['data'], 'assist_user_id');
$users = $this->getUsersFromRedis($ids); $users = $this->getUsersFromRedis($ids);
foreach ($users as $user) { foreach ($users as $user) {
$userNames[$user['user_id']] = isset($user['company_name']) ?: $user['mobile']; $userNames[$user['user_id']] = isset($user['company_name']) ?: $user['mobile'];
$userAvatars[$user['user_id']] = $user['avatar'];
} }
$result['data'] = array_map(function ($value) use ($userNames) { $result['data'] = array_map(function ($value) use ($userNames,$userAvatars) {
$value['assist_user_name'] = $userNames[$value['assist_user_id']]; $value['assist_user_name'] = $userNames[$value['assist_user_id']];
$value['assist_user_avatar'] = $userAvatars[$value['assist_user_id']];
return $value; return $value;
}, $result['data']); }, $result['data']);
} }
return $result; return $result['data'];
} }
public function addAssist($map = []) public function addAssist($map = [])
...@@ -38,4 +42,13 @@ class AssistService extends BaseService ...@@ -38,4 +42,13 @@ class AssistService extends BaseService
return $result; return $result;
} }
//获取用户信息
public function getUserInfo($userId)
{
$redis = new RedisModel();
$user = json_decode($redis->hget('ic_user', $userId), true);
return $user;
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment