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; } }