更新代码
This commit is contained in:
91
app/Api/Resources/UserInfoResource.php
Normal file
91
app/Api/Resources/UserInfoResource.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sunny
|
||||
* Date: 2019/2/27
|
||||
* Time: 8:55 AM
|
||||
*/
|
||||
|
||||
namespace App\Api\Resources;
|
||||
|
||||
use App\Models\VipPament;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserRelation\Models\UserRelation;
|
||||
|
||||
class UserInfoResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* 小程序,用户信息返回的数据
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
|
||||
|
||||
public function toArray($request)
|
||||
{
|
||||
$vipPay = VipPament::where(['user_id' => $this->id, 'state' => 'SUCCESS'])->first();
|
||||
$isVipUser = $vipPay ? true : false;
|
||||
$vipOrder = Order::where(['user_id' => $this->id, 'item_type' => 'VIP_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();
|
||||
$canCreateVipOrder = !$vipOrder && $isVipUser ? true : false;
|
||||
|
||||
|
||||
$isfull = $this->account->act_a > 0 ? true : false;//是否满仓
|
||||
$fullOrder = Order::where(['user_id' => $this->id, 'item_type' => 'FULL_GIFT'])->whereRaw('substring(cast(status as char),1,1) = 1')->first();//满仓订单
|
||||
$canCreateFullOrder = !$fullOrder && $isfull ? true : false;//是否可以创建满仓订单
|
||||
|
||||
|
||||
$all = UserRelation::where('bloodline', 'like', "%," . $this->id . ",%")->where('layer', '<=', $this->relation->layer + 6)->count();
|
||||
$today = UserRelation::where('bloodline', 'like', "%," . $this->id . ",%")->where('layer', '<=', $this->relation->layer + 6)->whereBetween('created_at', [Carbon::today()->toDateTimeString(), Carbon::tomorrow()->toDateTimeString()])->count();
|
||||
$tomorrow = UserRelation::where('bloodline', 'like', "%," . $this->id . ",%")->where('layer', '<=', $this->relation->layer + 6)->whereBetween('created_at', [Carbon::yesterday()->toDateTimeString(), Carbon::today()->toDateTimeString()])->count();
|
||||
$task = $this->identity->logs()->where('channel', 'AdminUp')->first();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'mobile' => $this->mobile,
|
||||
'userInfo' => [
|
||||
'nickname' => $this->info->nickname,
|
||||
'wechatNo' => $this->info->wechat_no,
|
||||
'avatar' => $this->info->headimgurl,
|
||||
],
|
||||
'identity' => [
|
||||
'id' => $this->identity->identity_id,
|
||||
'text' => $this->identity_text,
|
||||
],
|
||||
'account' => [
|
||||
'cash' => $this->account->cash,
|
||||
'score' => $this->account->score,
|
||||
],
|
||||
'parent' => [
|
||||
'id' => $this->parent->id,
|
||||
'avatar' => $this->parent->info->headimgurl,
|
||||
'nickname' => $this->parent->info->nickname ?? '99联盟',
|
||||
'mobile' => $this->parent->mobile,
|
||||
'wechatNo' => $this->parent->info->wechat_no,
|
||||
],
|
||||
|
||||
'fansCount' => [
|
||||
'all' => $all,
|
||||
'today' => $today,
|
||||
'tomorrow' => $tomorrow,
|
||||
],
|
||||
|
||||
'leaderTask' => [
|
||||
'isLeader' => $task ? true : false,
|
||||
'taskedNum' => $task ? $task->other['full'] : 0,
|
||||
'unTaskedNum' => $task ? $task->other['full'] - $task->user->identity->activation_childs : 0,
|
||||
],
|
||||
|
||||
'handleOption' => [
|
||||
'canTakeVipGift' => $canCreateVipOrder,
|
||||
'canTakeFullGift' => $canCreateFullOrder,
|
||||
'canBindParent' => $this->identity->identity_id === 0 && $this->parent->id == 1 ? true : false,
|
||||
'canManageCdkeys' => $this->identity->identity_id > 0 ? true : false,
|
||||
'canShowDashboard' => in_array($this->id, [62, 75, 1757]) ? true : false,
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user