6
0
Fork 0

粉丝列表

release
李静 2021-12-30 15:16:20 +08:00
parent e35656f87d
commit 7108f71630
4 changed files with 71 additions and 3 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace App\Endpoint\Api\Http\Controllers\Merchant;
use App\Endpoint\Api\Http\Controllers\Controller;
use App\Endpoint\Api\Http\Resources\Merchant\FanResource;
use App\Helpers\Paginator as PaginatorHelper;
use Illuminate\Http\Request;
class FanController extends Controller
{
/**
* 粉丝列表
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50);
$fans = $request->user()
->fans()
->latest('id')
->simplePaginate($perPage);
$fans->load('userInfo');
return FanResource::collection($fans);
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace App\Endpoint\Api\Http\Resources\Merchant;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Str;
class FanResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'nickname' => (string) $this->userInfo->nickname,
'avatar' => (string) $this->userInfo->avatar,
'phone' => Str::mask($this->phone, '*', 3, 4),
'agent_level_name' => (string) $this->userInfo->agent_level_name,
'team_sales_value' => $this->userInfo?->team_sales_value,
];
}
}

View File

@ -182,6 +182,8 @@ Route::group([
],
], function () {
Route::get('account', [Merchant\UserController::class, 'account']);
// 粉丝列表
Route::get('fans', [Merchant\FanController::class, 'index']);
// 配额日志
Route::get('quota-logs', [Merchant\QuotaLogController::class, 'index']);
// 个人销售值日志

View File

@ -274,7 +274,7 @@ class UserInfo extends Model
}
// 如果成长值不足650时不能升级
if (bccomp($this->group_sales_value, '650') < 0) {
if (bccomp($this->growth_value, '650') < 0) {
return;
}
@ -283,8 +283,7 @@ class UserInfo extends Model
$lvl = static::AGENT_LEVEL_VIP;
}
// 总团队销售值 = 团队销售值 + 个人成长值
$salesValue = bcadd($this->group_sales_value, $this->growth_value, 2);
$salesValue = $this->team_sales_value;
if ($lvl === static::AGENT_LEVEL_VIP) {
$vipsCount = $this->getVipAgentsCount();
@ -410,4 +409,14 @@ class UserInfo extends Model
{
return Str::finish($this->path.$this->getKey(), '/');
}
/**
* 获团队销售值
*
* @return string
*/
public function getTeamSalesValueAttribute(): string
{
return bcadd($this->growth_value, $this->group_sales_value, 2);
}
}