This commit is contained in:
2023-03-08 09:16:04 +08:00
commit e78454540f
1318 changed files with 210569 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Modules\User\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Jason\Api\Api;
use Modules\Mall\Models\Order;
use Modules\Mall\Models\Refund as RefundModel;
use Modules\User\Http\Resources\Account\UserAccountResource;
use Modules\User\Models\Identity;
use Vinkla\Hashids\Facades\Hashids;
class UserInfoResource extends JsonResource
{
public function toArray($request): array
{
$identity = $this->identityFirst();
if ($identity->id > 2) {
$order = true;
} else {
$order = false;
}
return [
'user_id' => $this->id,
'username' => $this->username,
'nickname' => $this->info->nickname ?? '',
'avatar' => $this->info->avatar ?? '',
'account' => new UserAccountResource($this->account),
'identity' => new UserIdentityBaseResource($identity),
'service' => new UserServiceResource($identity->identities()->first()),
'water_mobile' => app('Conf_mall')['water_mobile'] ?? '',
'invite' => Hashids::connection('code')->encode($this->id),
'case' => $this->getStockData(),
'user_wechat' => new UserWechatResource($this->wechat),
'created_at' => (string) $this->created_at,
'sign' => $this->getSignData(),
'status' => $this->getStateData(),
'nowStatus' => $this->getNowStatus(),
'canPick' => $this->canPick(),
'count' => [
'coupon' => $this->couponGrants()->count(),//<2F>Ż<EFBFBD>ȯ<EFBFBD><C8AF><EFBFBD><EFBFBD>
'relation' => $this->getRelationCount(),//<2F>¼<EFBFBD>
'invites' => $this->invites()->count(),//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
'notifications' => $this->unreadNotifications()->count(),//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
'orders' => Order::byUser(Api::user())->common()->count(),//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
'refunds' => RefundModel::byUser(Api::user())->count(),//<2F>˿<CBBF><EEB5A5><EFBFBD><EFBFBD>
],
'identityShow' => $this->when(true, function () use ($identity) {
return [
'right' => new UserIdentityRightsResource($identity),
'times' => new IdentityMiddleResource($this->identityMiddle()->first()),
'is_top' => $identity->id == 4,
];
}),
];
}
}