where('goods_id', $goods_id) ->first(); } public function goods(){ return $this->belongsTo(Goods::class); } public function check(){ if ($this->status) { $startTime = Carbon::createFromTimestamp($this->start_time); if (Carbon::now()->lessThan($startTime)) { throw new AppException('此商品将于' . $startTime->toDateTimeString() . '开启限时购买'); } $endTime = Carbon::createFromTimestamp($this->end_time); if (Carbon::now()->greaterThanOrEqualTo($endTime)) { throw new AppException('商品['.$this->goods->title.']已于' . $endTime->toDateTimeString() . '结束限时购买'); } } } }