with(['User','Shop','HealthyOrderProduct']) ->when($keywords != '', function ($query) use ($keywords){ $query->where('order_sn', 'like', '%' . $keywords . '%'); }) ->orderBy('order_create_time','DESC') ->forPage($page, $limit) ->get(); $count = static::when($keywords != '', function ($query) use ($keywords){ $query->where('order_sn', 'like', '%' . $keywords . '%'); }) ->count(); return [$list, $count]; } //关联用户 public function User(){ return $this->belongsTo(User::class,'order_user_id','user_id'); } //关联店铺 public function Shop(){ return $this->belongsTo(MerchantShop::class,'order_shop_id','shop_id'); } //关联商品信息 public function HealthyOrderProduct(){ return $this->hasMany(HealthyOrderProduct::class,'order_product_order_id','order_id'); } //时间格式 public function getOrderCreateTimeAttribute($value) { return date('Y-m-d H:i:s', $value); } }