73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
use App\Models\{GoodsCart, Order};
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
use App\Models\Traits\SendMiniprogramMessageTrait;
|
|
use App\Models\Traits\SendQuanTicketTrait;
|
|
|
|
class User extends Authenticatable implements JWTSubject
|
|
{
|
|
use HasFactory, Notifiable, HasDateTimeFormatter, SendMiniprogramMessageTrait, SendQuanTicketTrait;
|
|
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'phone',
|
|
];
|
|
|
|
public function getUserCart(){
|
|
$list = GoodsCart::with('goods')->where([
|
|
'user_id'=>$this->id,
|
|
])->get();
|
|
return $list;
|
|
}
|
|
|
|
public function cleanUserCart(){
|
|
GoodsCart::where([
|
|
'user_id'=>$this->id,
|
|
])->delete();
|
|
}
|
|
|
|
public function activity(){
|
|
return $this->hasOne(ActivityUser::class, 'user_id');
|
|
}
|
|
|
|
public function rankLv(){
|
|
$user_rank = json_decode(admin_setting('user_rank'));
|
|
|
|
//计算用户累计消费金额
|
|
$total_price = Order::where(['user_id'=>$this->id, 'order_status'=>1, 'pay_status'=>1])->sum('pay_price');
|
|
$lv = $i = 0;
|
|
if(is_array($user_rank) && count($user_rank) >0){
|
|
foreach ($user_rank as $key => $rank) {
|
|
$i++;
|
|
if($total_price >= $rank->rank_limit){
|
|
$lv = $i;
|
|
}
|
|
}
|
|
}
|
|
return $lv;
|
|
}
|
|
}
|