uid = $uid; } else { $user = app()->make('user'); $this->uid = $user->id; } } public function __get($property_name) { if (isset($this->$property_name)) { return $this->$property_name; } else { if ($property_name == "is_annually") { $this->setAnnuallyUser(); return $this->is_annually; } else if ($property_name == "is_monthly") { $this->setMonthlyUser(); return $this->is_monthly; } } } /** * 设置用户包年属性 */ private function setAnnuallyUser() { $year_order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('order_type', 'YEAR')->orderBy('id', 'desc')->first(); if ($year_order && strtotime($year_order->created_at) > (time() - SysConsts::ONE_YEAR_DAYS * SysConsts::ONE_DAY_SECONDS)) { $this->is_annually = true; } else { $this->is_annually = false; } } /** * 设置用户包月属性 */ private function setMonthlyUser() { $month_order = UserMonthOrder::where('uid', $this->uid)->where('type', 'MONTH')->orderBy('id', 'desc')->first(); if ($month_order && strtotime($month_order->created_at) > (time() - SysConsts::ONE_YEAR_DAYS * SysConsts::ONE_DAY_SECONDS)) { $this->is_monthly = true; } else { $this->is_monthly = false; } } }